3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 $customSearchClass
113 * @param array $formValues array of form values imported
114 * @param array $params array of parameters for query
115 * @param null $returnProperties
116 * @param \const|int $action - action of search basic or advanced.
118 * @param bool $includeContactIds
119 * @param bool $searchChildGroups
120 * @param string $searchContext
121 * @param null $contextMenu
123 * @return \CRM_Contact_Selector_Custom
126 function __construct(
130 $returnProperties = NULL,
131 $action = CRM_Core_Action
::NONE
,
132 $includeContactIds = FALSE,
133 $searchChildGroups = TRUE,
134 $searchContext = 'search',
137 $this->_customSearchClass
= $customSearchClass;
138 $this->_formValues
= $formValues;
139 $this->_includeContactIds
= $includeContactIds;
141 $ext = CRM_Extension_System
::singleton()->getMapper();
143 if (!$ext->isExtensionKey($customSearchClass)) {
144 if ($ext->isExtensionClass($customSearchClass)) {
145 $customSearchFile = $ext->classToPath($customSearchClass);
146 require_once ($customSearchFile);
149 require_once (str_replace('_', DIRECTORY_SEPARATOR
, $customSearchClass) . '.php');
151 $this->_search
= new $customSearchClass( $formValues );
154 $fnName = $ext->keyToPath
;
155 $customSearchFile = $fnName($customSearchClass, 'search');
156 $className = $ext->keyToClass($customSearchClass, 'search');
157 $this->_search
= new $className($formValues);
163 * This method returns the links that are given for each search row.
164 * currently the links added for each row are
173 static function &links() {
174 list($key) = func_get_args();
175 $searchContext = "&context=custom";
176 $extraParams = ($key) ?
"&key={$key}" : NULL;
178 if (!(self
::$_links)) {
179 self
::$_links = array(
180 CRM_Core_Action
::VIEW
=> array(
181 'name' => ts('View'),
182 'url' => 'civicrm/contact/view',
183 'qs' => "reset=1&cid=%%id%%{$extraParams}{$searchContext}",
184 'class' => 'no-popup',
185 'title' => ts('View Contact Details'),
187 CRM_Core_Action
::UPDATE
=> array(
188 'name' => ts('Edit'),
189 'url' => 'civicrm/contact/add',
190 'qs' => 'reset=1&action=update&cid=%%id%%',
191 'class' => 'no-popup',
192 'title' => ts('Edit Contact Details'),
196 $config = CRM_Core_Config
::singleton();
197 if ($config->mapAPIKey
&& $config->mapProvider
) {
198 self
::$_links[CRM_Core_Action
::MAP
] = array(
200 'url' => 'civicrm/contact/map',
201 'qs' => 'reset=1&cid=%%id%%&searchType=custom',
202 'class' => 'no-popup',
203 'title' => ts('Map Contact'),
207 return self
::$_links;
212 * getter for array of the parameters required for creating pager.
220 function getPagerParams($action, &$params) {
221 $params['status'] = ts('Contact %%StatusMessage%%');
222 $params['csvString'] = NULL;
223 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
225 $params['buttonTop'] = 'PagerTopButton';
226 $params['buttonBottom'] = 'PagerBottomButton';
231 * returns the column headers as an array of tuples:
232 * (name, sortName (key to the sort array))
234 * @param string $action the action being performed
235 * @param enum $output what should the result set include (web/email/csv)
237 * @return array the column headers that need to be displayed
240 function &getColumnHeaders($action = NULL, $output = NULL) {
241 $columns = $this->_search
->columns();
242 if ($output == CRM_Core_Selector_Controller
::EXPORT
) {
243 return array_keys($columns);
247 foreach ($columns as $name => $key) {
252 'direction' => CRM_Utils_Sort
::ASCENDING
,
256 $headers[] = array();
264 * Returns total number of rows for the query.
268 * @return int Total number of rows
271 function getTotalCount($action) {
272 return $this->_search
->count();
276 * returns all the rows in the given offset and rowCount
278 * @param enum $action the action being performed
279 * @param int $offset the row number to start from
280 * @param int $rowCount the number of rows to return
281 * @param string $sort the sql string that describes the sort order
282 * @param enum $output what should the result set include (web/email/csv)
284 * @return int the total number of rows for this action
286 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
288 $includeContactIDs = FALSE;
289 if (($output == CRM_Core_Selector_Controller
::EXPORT ||
290 $output == CRM_Core_Selector_Controller
::SCREEN
292 $this->_formValues
['radio_ts'] == 'ts_sel'
294 $includeContactIDs = TRUE;
297 $sql = $this->_search
->all($offset, $rowCount, $sort, $includeContactIDs);
298 // contact query object used for creating $sql
299 $contactQueryObj = NULL;
300 if (method_exists($this->_search
, 'getQueryObj') &&
301 is_a($this->_search
->getQueryObj(), 'CRM_Contact_BAO_Query')) {
302 $contactQueryObj = $this->_search
->getQueryObj();
305 $dao = CRM_Core_DAO
::executeQuery($sql, CRM_Core_DAO
::$_nullArray);
307 $columns = $this->_search
->columns();
308 $columnNames = array_values($columns);
309 $links = self
::links($this->_key
);
311 $permissions = array(CRM_Core_Permission
::getPermission());
312 if (CRM_Core_Permission
::check('delete contacts')) {
313 $permissions[] = CRM_Core_Permission
::DELETE
;
315 $mask = CRM_Core_Action
::mask($permissions);
318 if (method_exists($this->_customSearchClass
,
324 if (is_a($this->_search
, 'CRM_Contact_Form_Search_Custom_Basic')) {
327 // process the result of the query
329 while ($dao->fetch()) {
333 // if contact query object present
334 // process pseudo constants
335 if ($contactQueryObj) {
336 $contactQueryObj->convertToPseudoNames($dao);
339 // the columns we are interested in
340 foreach ($columnNames as $property) {
341 $row[$property] = $dao->$property;
342 if (!empty($dao->$property)) {
347 $contactID = isset($dao->contact_id
) ?
$dao->contact_id
: NULL;
349 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $contactID;
350 $row['action'] = CRM_Core_Action
::formLink($links,
352 array('id' => $contactID),
355 'contact.custom.actions',
359 $row['contact_id'] = $contactID;
362 $this->_search
->alterRow($row);
366 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($dao->contact_sub_type ?
367 $dao->contact_sub_type
: $dao->contact_type
, FALSE, $contactID
374 $this->buildPrevNextCache($sort);
380 * Given the current formValues, gets the query in local
384 reference) $formValues submitted formValues
386 * @return array $qill which contains an array of strings
389 public function getQILL() {
396 public function getSummary() {
397 return $this->_search
->summary();
401 * name of export file.
403 * @param string $output type of output
405 * @return string name of the file
407 function getExportFileName($output = 'csv') {
408 return ts('CiviCRM Custom Search');
414 function alphabetQuery() {
422 * @param null $displayRelationshipType
423 * @param string $queryOperator
427 function &contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') {
429 $sql = $this->_search
->contactIDs($params);
431 return CRM_Core_DAO
::executeQuery($sql, $params);
437 function addActions(&$rows) {
438 $links = self
::links($this->_key
);
440 $permissions = array(CRM_Core_Permission
::getPermission());
441 if (CRM_Core_Permission
::check('delete contacts')) {
442 $permissions[] = CRM_Core_Permission
::DELETE
;
444 $mask = CRM_Core_Action
::mask($permissions);
446 foreach ($rows as $id => & $row) {
447 $row['action'] = CRM_Core_Action
::formLink($links,
449 array('id' => $row['contact_id']),
452 'contact.custom.actions',
462 function removeActions(&$rows) {
463 foreach ($rows as $rid => & $rValue) {
464 unset($rValue['action']);