3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id: Selector.php 11510 2007-09-18 09:21:34Z lobo $
37 * This class is used to retrieve and display a range of
38 * contacts that match the given criteria (specifically for
39 * results of advanced search options.
42 class CRM_Contact_Selector_Custom
extends CRM_Contact_Selector
{
45 * This defines two actions- View and Edit.
50 static $_links = NULL;
53 * we use desc to remind us what that column is, name is used in the tpl
58 static $_columnHeaders;
61 * Properties of contact we're interested in displaying
65 static $_properties = array('contact_id', 'contact_type', 'display_name');
68 * formValues is the array returned by exportValues called on
69 * the HTML_QuickForm_Controller for that page.
77 * params is the array in a value used by the search query creator
85 * represent the type of selector
95 * the public visible fields to be shown to the user
103 * The object that implements the search interface
107 protected $_customSearchClass;
112 * @param array $formValues array of form values imported
113 * @param array $params array of parameters for query
114 * @param int $action - action of search basic or advanced.
116 * @return CRM_Contact_Selector
119 function __construct(
123 $returnProperties = NULL,
124 $action = CRM_Core_Action
::NONE
,
125 $includeContactIds = FALSE,
126 $searchChildGroups = TRUE,
127 $searchContext = 'search',
130 $this->_customSearchClass
= $customSearchClass;
131 $this->_formValues
= $formValues;
132 $this->_includeContactIds
= $includeContactIds;
134 $ext = CRM_Extension_System
::singleton()->getMapper();
136 if (!$ext->isExtensionKey($customSearchClass)) {
137 if ($ext->isExtensionClass($customSearchClass)) {
138 $customSearchFile = $ext->classToPath($customSearchClass);
139 require_once ($customSearchFile);
142 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $customSearchClass) . '.php');
144 $this->_search
= new $customSearchClass( $formValues );
147 $customSearchFile = $ext->keyToPath($customSearchClass, 'search');
148 $this->_search
= new $ext->keyToClass($customSearchClass, 'search')( $formValues );
154 * This method returns the links that are given for each search row.
155 * currently the links added for each row are
164 static function &links() {
165 if (!(self
::$_links)) {
166 self
::$_links = array(
167 CRM_Core_Action
::VIEW
=> array(
168 'name' => ts('View'),
169 'url' => 'civicrm/contact/view',
170 'qs' => 'reset=1&cid=%%id%%',
171 'title' => ts('View Contact Details'),
173 CRM_Core_Action
::UPDATE
=> array(
174 'name' => ts('Edit'),
175 'url' => 'civicrm/contact/add',
176 'qs' => 'reset=1&action=update&cid=%%id%%',
177 'title' => ts('Edit Contact Details'),
181 $config = CRM_Core_Config
::singleton();
182 if ($config->mapAPIKey
&& $config->mapProvider
) {
183 self
::$_links[CRM_Core_Action
::MAP
] = array(
185 'url' => 'civicrm/contact/map',
186 'qs' => 'reset=1&cid=%%id%%&searchType=custom',
187 'title' => ts('Map Contact'),
191 return self
::$_links;
196 * getter for array of the parameters required for creating pager.
201 function getPagerParams($action, &$params) {
202 $params['status'] = ts('Contact %%StatusMessage%%');
203 $params['csvString'] = NULL;
204 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
206 $params['buttonTop'] = 'PagerTopButton';
207 $params['buttonBottom'] = 'PagerBottomButton';
212 * returns the column headers as an array of tuples:
213 * (name, sortName (key to the sort array))
215 * @param string $action the action being performed
216 * @param enum $output what should the result set include (web/email/csv)
218 * @return array the column headers that need to be displayed
221 function &getColumnHeaders($action = NULL, $output = NULL) {
222 $columns = $this->_search
->columns();
223 if ($output == CRM_Core_Selector_Controller
::EXPORT
) {
224 return array_keys($columns);
228 foreach ($columns as $name => $key) {
233 'direction' => CRM_Utils_Sort
::ASCENDING
,
237 $headers[] = array();
245 * Returns total number of rows for the query.
249 * @return int Total number of rows
252 function getTotalCount($action) {
253 return $this->_search
->count();
257 * returns all the rows in the given offset and rowCount
259 * @param enum $action the action being performed
260 * @param int $offset the row number to start from
261 * @param int $rowCount the number of rows to return
262 * @param string $sort the sql string that describes the sort order
263 * @param enum $output what should the result set include (web/email/csv)
265 * @return int the total number of rows for this action
267 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
269 $includeContactIDs = FALSE;
270 if (($output == CRM_Core_Selector_Controller
::EXPORT ||
271 $output == CRM_Core_Selector_Controller
::SCREEN
273 $this->_formValues
['radio_ts'] == 'ts_sel'
275 $includeContactIDs = TRUE;
278 $sql = $this->_search
->all($offset, $rowCount, $sort, $includeContactIDs);
280 $dao = CRM_Core_DAO
::executeQuery($sql, CRM_Core_DAO
::$_nullArray);
282 $columns = $this->_search
->columns();
283 $columnNames = array_values($columns);
284 $links = self
::links();
286 $permissions = array(CRM_Core_Permission
::getPermission());
287 if (CRM_Core_Permission
::check('delete contacts')) {
288 $permissions[] = CRM_Core_Permission
::DELETE
;
290 $mask = CRM_Core_Action
::mask($permissions);
293 if (method_exists($this->_customSearchClass
,
299 if (is_a($this->_search
, 'CRM_Contact_Form_Search_Custom_Basic')) {
302 // process the result of the query
304 while ($dao->fetch()) {
308 // the columns we are interested in
309 foreach ($columnNames as $property) {
310 $row[$property] = $dao->$property;
311 if (!empty($dao->$property)) {
316 $contactID = isset($dao->contact_id
) ?
$dao->contact_id
: NULL;
318 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $contactID;
319 $row['action'] = CRM_Core_Action
::formLink($links,
321 array('id' => $contactID)
323 $row['contact_id'] = $contactID;
326 $this->_search
->alterRow($row);
330 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($dao->contact_sub_type ?
331 $dao->contact_sub_type
: $dao->contact_type
, FALSE, $contactID
338 $this->buildPrevNextCache($sort);
344 * Given the current formValues, gets the query in local
348 reference) $formValues submitted formValues
350 * @return array $qill which contains an array of strings
353 public function getQILL() {
357 public function getSummary() {
358 return $this->_search
->summary();
362 * name of export file.
364 * @param string $output type of output
366 * @return string name of the file
368 function getExportFileName($output = 'csv') {
369 return ts('CiviCRM Custom Search');
372 function alphabetQuery() {
376 function &contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') {
378 $sql = $this->_search
->contactIDs($params);
380 return CRM_Core_DAO
::executeQuery($sql, $params);
383 function addActions(&$rows) {
384 $links = self
::links();
386 $permissions = array(CRM_Core_Permission
::getPermission());
387 if (CRM_Core_Permission
::check('delete contacts')) {
388 $permissions[] = CRM_Core_Permission
::DELETE
;
390 $mask = CRM_Core_Action
::mask($permissions);
392 foreach ($rows as $id => & $row) {
393 $row['action'] = CRM_Core_Action
::formLink($links,
395 array('id' => $row['contact_id'])
400 function removeActions(&$rows) {
401 foreach ($rows as $rid => & $rValue) {
402 unset($rValue['action']);