3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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.
76 * Params is the array in a value used by the search query creator
83 * Represent the type of selector
92 * The public visible fields to be shown to the user
99 * The object that implements the search interface
103 protected $_customSearchClass;
108 * @param $customSearchClass
109 * @param array $formValues
110 * Array of form values imported.
111 * @param array $params
112 * Array of parameters for query.
113 * @param null $returnProperties
114 * @param \const|int $action - action of search basic or advanced.
116 * @param bool $includeContactIds
117 * @param bool $searchChildGroups
118 * @param string $searchContext
119 * @param null $contextMenu
121 * @return \CRM_Contact_Selector_Custom
124 function __construct(
128 $returnProperties = NULL,
129 $action = CRM_Core_Action
::NONE
,
130 $includeContactIds = FALSE,
131 $searchChildGroups = TRUE,
132 $searchContext = 'search',
135 $this->_customSearchClass
= $customSearchClass;
136 $this->_formValues
= $formValues;
137 $this->_includeContactIds
= $includeContactIds;
139 $ext = CRM_Extension_System
::singleton()->getMapper();
141 if (!$ext->isExtensionKey($customSearchClass)) {
142 if ($ext->isExtensionClass($customSearchClass)) {
143 $customSearchFile = $ext->classToPath($customSearchClass);
144 require_once $customSearchFile;
147 require_once str_replace('_', DIRECTORY_SEPARATOR
, $customSearchClass) . '.php';
149 $this->_search
= new $customSearchClass( $formValues );
152 $fnName = $ext->keyToPath
;
153 $customSearchFile = $fnName($customSearchClass, 'search');
154 $className = $ext->keyToClass($customSearchClass, 'search');
155 $this->_search
= new $className($formValues);
160 * This method returns the links that are given for each search row.
161 * currently the links added for each row are
169 public static function &links() {
170 list($key) = func_get_args();
171 $searchContext = "&context=custom";
172 $extraParams = ($key) ?
"&key={$key}" : NULL;
174 if (!(self
::$_links)) {
175 self
::$_links = array(
176 CRM_Core_Action
::VIEW
=> array(
177 'name' => ts('View'),
178 'url' => 'civicrm/contact/view',
179 'qs' => "reset=1&cid=%%id%%{$extraParams}{$searchContext}",
180 'class' => 'no-popup',
181 'title' => ts('View Contact Details'),
183 CRM_Core_Action
::UPDATE
=> array(
184 'name' => ts('Edit'),
185 'url' => 'civicrm/contact/add',
186 'qs' => 'reset=1&action=update&cid=%%id%%',
187 'class' => 'no-popup',
188 'title' => ts('Edit Contact Details'),
192 $config = CRM_Core_Config
::singleton();
193 if ($config->mapAPIKey
&& $config->mapProvider
) {
194 self
::$_links[CRM_Core_Action
::MAP
] = array(
196 'url' => 'civicrm/contact/map',
197 'qs' => 'reset=1&cid=%%id%%&searchType=custom',
198 'class' => 'no-popup',
199 'title' => ts('Map Contact'),
203 return self
::$_links;
207 * Getter for array of the parameters required for creating pager.
210 * @param array $params
213 public function getPagerParams($action, &$params) {
214 $params['status'] = ts('Contact %%StatusMessage%%');
215 $params['csvString'] = NULL;
216 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
218 $params['buttonTop'] = 'PagerTopButton';
219 $params['buttonBottom'] = 'PagerBottomButton';
223 * Returns the column headers as an array of tuples:
224 * (name, sortName (key to the sort array))
226 * @param string $action
227 * The action being performed.
228 * @param enum $output
229 * What should the result set include (web/email/csv).
231 * @return array the column headers that need to be displayed
233 public function &getColumnHeaders($action = NULL, $output = NULL) {
234 $columns = $this->_search
->columns();
235 if ($output == CRM_Core_Selector_Controller
::EXPORT
) {
236 return array_keys($columns);
240 foreach ($columns as $name => $key) {
245 'direction' => CRM_Utils_Sort
::ASCENDING
,
249 $headers[] = array();
257 * Returns total number of rows for the query.
261 * @return int Total number of rows
263 public function getTotalCount($action) {
264 return $this->_search
->count();
268 * Returns all the rows in the given offset and rowCount
270 * @param enum $action
271 * The action being performed.
273 * The row number to start from.
274 * @param int $rowCount
275 * The number of rows to return.
276 * @param string $sort
277 * The sql string that describes the sort order.
278 * @param enum $output
279 * What should the result set include (web/email/csv).
281 * @return int the total number of rows for this action
283 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
285 $includeContactIDs = FALSE;
286 if (($output == CRM_Core_Selector_Controller
::EXPORT ||
287 $output == CRM_Core_Selector_Controller
::SCREEN
289 $this->_formValues
['radio_ts'] == 'ts_sel'
291 $includeContactIDs = TRUE;
294 $sql = $this->_search
->all($offset, $rowCount, $sort, $includeContactIDs);
295 // contact query object used for creating $sql
296 $contactQueryObj = NULL;
297 if (method_exists($this->_search
, 'getQueryObj') &&
298 is_a($this->_search
->getQueryObj(), 'CRM_Contact_BAO_Query')) {
299 $contactQueryObj = $this->_search
->getQueryObj();
302 $dao = CRM_Core_DAO
::executeQuery($sql, CRM_Core_DAO
::$_nullArray);
304 $columns = $this->_search
->columns();
305 $columnNames = array_values($columns);
306 $links = self
::links($this->_key
);
308 $permissions = array(CRM_Core_Permission
::getPermission());
309 if (CRM_Core_Permission
::check('delete contacts')) {
310 $permissions[] = CRM_Core_Permission
::DELETE
;
312 $mask = CRM_Core_Action
::mask($permissions);
315 if (method_exists($this->_customSearchClass
,
321 if (is_a($this->_search
, 'CRM_Contact_Form_Search_Custom_Basic')) {
324 // process the result of the query
326 while ($dao->fetch()) {
330 // if contact query object present
331 // process pseudo constants
332 if ($contactQueryObj) {
333 $contactQueryObj->convertToPseudoNames($dao);
336 // the columns we are interested in
337 foreach ($columnNames as $property) {
338 $row[$property] = $dao->$property;
339 if (!empty($dao->$property)) {
344 $contactID = isset($dao->contact_id
) ?
$dao->contact_id
: NULL;
346 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $contactID;
347 $row['action'] = CRM_Core_Action
::formLink($links,
349 array('id' => $contactID),
352 'contact.custom.actions',
356 $row['contact_id'] = $contactID;
359 $this->_search
->alterRow($row);
363 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($dao->contact_sub_type ?
$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
384 public function getQILL() {
391 public function getSummary() {
392 return $this->_search
->summary();
396 * Name of export file.
398 * @param string $output
401 * @return string name of the file
403 public function getExportFileName($output = 'csv') {
404 return ts('CiviCRM Custom Search');
410 public function alphabetQuery() {
415 * @param array $params
418 * @param null $displayRelationshipType
419 * @param string $queryOperator
423 public function &contactIDQuery($params, $action, $sortID, $displayRelationshipType = NULL, $queryOperator = 'AND') {
425 $sql = $this->_search
->contactIDs($params);
427 return CRM_Core_DAO
::executeQuery($sql, $params);
433 public 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 public function removeActions(&$rows) {
459 foreach ($rows as $rid => & $rValue) {
460 unset($rValue['action']);