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);
162 * This method returns the links that are given for each search row.
163 * currently the links added for each row are
172 static function &links() {
173 list($key) = func_get_args();
174 $searchContext = "&context=custom";
175 $extraParams = ($key) ?
"&key={$key}" : NULL;
177 if (!(self
::$_links)) {
178 self
::$_links = array(
179 CRM_Core_Action
::VIEW
=> array(
180 'name' => ts('View'),
181 'url' => 'civicrm/contact/view',
182 'qs' => "reset=1&cid=%%id%%{$extraParams}{$searchContext}",
183 'class' => 'no-popup',
184 'title' => ts('View Contact Details'),
186 CRM_Core_Action
::UPDATE
=> array(
187 'name' => ts('Edit'),
188 'url' => 'civicrm/contact/add',
189 'qs' => 'reset=1&action=update&cid=%%id%%',
190 'class' => 'no-popup',
191 'title' => ts('Edit Contact Details'),
195 $config = CRM_Core_Config
::singleton();
196 if ($config->mapAPIKey
&& $config->mapProvider
) {
197 self
::$_links[CRM_Core_Action
::MAP
] = array(
199 'url' => 'civicrm/contact/map',
200 'qs' => 'reset=1&cid=%%id%%&searchType=custom',
201 'class' => 'no-popup',
202 'title' => ts('Map Contact'),
206 return self
::$_links;
210 * Getter for array of the parameters required for creating pager.
213 * @param array $params
217 function getPagerParams($action, &$params) {
218 $params['status'] = ts('Contact %%StatusMessage%%');
219 $params['csvString'] = NULL;
220 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
222 $params['buttonTop'] = 'PagerTopButton';
223 $params['buttonBottom'] = 'PagerBottomButton';
227 * Returns the column headers as an array of tuples:
228 * (name, sortName (key to the sort array))
230 * @param string $action the action being performed
231 * @param enum $output what should the result set include (web/email/csv)
233 * @return array the column headers that need to be displayed
236 function &getColumnHeaders($action = NULL, $output = NULL) {
237 $columns = $this->_search
->columns();
238 if ($output == CRM_Core_Selector_Controller
::EXPORT
) {
239 return array_keys($columns);
243 foreach ($columns as $name => $key) {
248 'direction' => CRM_Utils_Sort
::ASCENDING
,
252 $headers[] = array();
260 * Returns total number of rows for the query.
264 * @return int Total number of rows
267 function getTotalCount($action) {
268 return $this->_search
->count();
272 * Returns all the rows in the given offset and rowCount
274 * @param enum $action the action being performed
275 * @param int $offset the row number to start from
276 * @param int $rowCount the number of rows to return
277 * @param string $sort the sql string that describes the sort order
278 * @param enum $output what should the result set include (web/email/csv)
280 * @return int the total number of rows for this action
282 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
284 $includeContactIDs = FALSE;
285 if (($output == CRM_Core_Selector_Controller
::EXPORT ||
286 $output == CRM_Core_Selector_Controller
::SCREEN
288 $this->_formValues
['radio_ts'] == 'ts_sel'
290 $includeContactIDs = TRUE;
293 $sql = $this->_search
->all($offset, $rowCount, $sort, $includeContactIDs);
294 // contact query object used for creating $sql
295 $contactQueryObj = NULL;
296 if (method_exists($this->_search
, 'getQueryObj') &&
297 is_a($this->_search
->getQueryObj(), 'CRM_Contact_BAO_Query')) {
298 $contactQueryObj = $this->_search
->getQueryObj();
301 $dao = CRM_Core_DAO
::executeQuery($sql, CRM_Core_DAO
::$_nullArray);
303 $columns = $this->_search
->columns();
304 $columnNames = array_values($columns);
305 $links = self
::links($this->_key
);
307 $permissions = array(CRM_Core_Permission
::getPermission());
308 if (CRM_Core_Permission
::check('delete contacts')) {
309 $permissions[] = CRM_Core_Permission
::DELETE
;
311 $mask = CRM_Core_Action
::mask($permissions);
314 if (method_exists($this->_customSearchClass
,
320 if (is_a($this->_search
, 'CRM_Contact_Form_Search_Custom_Basic')) {
323 // process the result of the query
325 while ($dao->fetch()) {
329 // if contact query object present
330 // process pseudo constants
331 if ($contactQueryObj) {
332 $contactQueryObj->convertToPseudoNames($dao);
335 // the columns we are interested in
336 foreach ($columnNames as $property) {
337 $row[$property] = $dao->$property;
338 if (!empty($dao->$property)) {
343 $contactID = isset($dao->contact_id
) ?
$dao->contact_id
: NULL;
345 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $contactID;
346 $row['action'] = CRM_Core_Action
::formLink($links,
348 array('id' => $contactID),
351 'contact.custom.actions',
355 $row['contact_id'] = $contactID;
358 $this->_search
->alterRow($row);
362 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($dao->contact_sub_type ?
363 $dao->contact_sub_type
: $dao->contact_type
, FALSE, $contactID
370 $this->buildPrevNextCache($sort);
376 * Given the current formValues, gets the query in local
380 reference) $formValues submitted formValues
382 * @return array $qill which contains an array of strings
385 public function getQILL() {
392 public function getSummary() {
393 return $this->_search
->summary();
397 * Name of export file.
399 * @param string $output type of output
401 * @return string name of the file
403 function getExportFileName($output = 'csv') {
404 return ts('CiviCRM Custom Search');
410 function alphabetQuery() {
415 * @param array $params
418 * @param null $displayRelationshipType
419 * @param string $queryOperator
423 function &contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') {
425 $sql = $this->_search
->contactIDs($params);
427 return CRM_Core_DAO
::executeQuery($sql, $params);
433 function addActions(&$rows) {
434 $links = self
::links($this->_key
);
436 $permissions = array(CRM_Core_Permission
::getPermission());
437 if (CRM_Core_Permission
::check('delete contacts')) {
438 $permissions[] = CRM_Core_Permission
::DELETE
;
440 $mask = CRM_Core_Action
::mask($permissions);
442 foreach ($rows as $id => & $row) {
443 $row['action'] = CRM_Core_Action
::formLink($links,
445 array('id' => $row['contact_id']),
448 'contact.custom.actions',
458 function removeActions(&$rows) {
459 foreach ($rows as $rid => & $rValue) {
460 unset($rValue['action']);