3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * This class is used to retrieve and display a range of contacts that match the given criteria.
37 class CRM_Campaign_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
40 * This defines two actions- View and Edit.
44 public static $_links = NULL;
47 * We use desc to remind us what that column is, name is used in the tpl
51 public static $_columnHeaders;
54 * Properties of contact we're interested in displaying
57 public static $_properties = [
72 'survey_activity_target_id',
73 'survey_activity_target_contact_id',
77 * Are we restricting ourselves to a single contact
81 protected $_single = FALSE;
84 * Are we restricting ourselves to a single contact
88 protected $_limit = NULL;
91 * What context are we being invoked from
95 protected $_context = NULL;
98 * QueryParams is the array returned by exportValues called on
99 * the HTML_QuickForm_Controller for that page.
103 public $_queryParams;
106 * Represent the type of selector.
113 * The additional clause that we restrict the search with.
117 protected $_surveyClause = NULL;
129 * @param array $queryParams
130 * Array of parameters for query.
131 * @param \const|int $action - action of search basic or advanced.
132 * @param string $surveyClause
133 * If the caller wants to further restrict the search.
134 * @param bool $single
135 * Are we dealing only with one contact?.
137 * How many voters do we want returned.
139 * @param string $context
141 * @return \CRM_Campaign_Selector_Search
143 public function __construct(
145 $action = CRM_Core_Action
::NONE
,
146 $surveyClause = NULL,
151 // submitted form values
152 $this->_queryParams
= &$queryParams;
154 $this->_single
= $single;
155 $this->_limit
= $limit;
156 $this->_context
= $context;
158 $this->_campaignClause
= $surveyClause;
159 $this->_campaignFromClause
= CRM_Utils_Array
::value('fromClause', $surveyClause);
160 $this->_campaignWhereClause
= CRM_Utils_Array
::value('whereClause', $surveyClause);
163 $this->_action
= $action;
165 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
166 NULL, NULL, FALSE, FALSE,
167 CRM_Contact_BAO_Query
::MODE_CAMPAIGN
,
173 * This method returns the links that are given for each search row.
174 * currently the links added for each row are
181 public static function &links() {
182 return self
::$_links = [];
186 * Getter for array of the parameters required for creating pager.
189 * @param array $params
191 public function getPagerParams($action, &$params) {
192 $params['csvString'] = NULL;
193 $params['status'] = ts('Respondents') . ' %%StatusMessage%%';
194 $params['rowCount'] = ($this->_limit
) ?
$this->_limit
: CRM_Utils_Pager
::ROWCOUNT
;
195 $params['buttonTop'] = 'PagerTopButton';
196 $params['buttonBottom'] = 'PagerBottomButton';
200 * Returns total number of rows for the query.
202 * @param string $action
205 * Total number of rows
207 public function getTotalCount($action) {
208 return $this->_query
->searchQuery(0, 0, NULL,
211 $this->_campaignWhereClause
,
213 $this->_campaignFromClause
218 * Returns all the rows in the given offset and rowCount.
220 * @param string $action
221 * The action being performed.
223 * The row number to start from.
224 * @param int $rowCount
225 * The number of rows to return.
226 * @param string $sort
227 * The sql string that describes the sort order.
228 * @param string $output
229 * What should the result set include (web/email/csv).
232 * the total number of rows for this action
234 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
235 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
238 FALSE, $this->_campaignWhereClause
,
240 $this->_campaignFromClause
243 // process the result of the query
246 while ($result->fetch()) {
247 $this->_query
->convertToPseudoNames($result);
249 // the columns we are interested in
250 foreach (self
::$_properties as $property) {
251 if (property_exists($result, $property)) {
252 $row[$property] = $result->$property;
255 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->contact_id
;
256 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_type
, FALSE, $result->contact_id
);
260 $this->buildPrevNextCache($sort);
268 public function buildPrevNextCache($sort) {
269 //for prev/next pagination
270 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer');
273 $cacheKey = "civicrm search {$this->_key}";
274 Civi
::service('prevnext')->deleteItem(NULL, $cacheKey, 'civicrm_contact');
276 $sql = $this->_query
->getSearchSQLParts(0, 0, $sort,
279 $this->_campaignWhereClause
,
281 $this->_campaignFromClause
285 SELECT %1, contact_a.id, contact_a.display_name
290 Civi
::service('prevnext')->fillWithSql($cacheKey, $selectSQL, [1 => [$cacheKey, 'String']]);
292 catch (CRM_Core_Exception
$e) {
293 // Heavy handed, no? Seems like this merits an explanation.
297 if (Civi
::service('prevnext') instanceof CRM_Core_PrevNextCache_Sql
) {
298 // SQL-backed prevnext cache uses an extra record for pruning the cache.
299 Civi
::cache('prevNextCache')->set($cacheKey, $cacheKey);
306 * which contains an array of strings
308 public function getQILL() {
309 return $this->_query
->qill();
313 * Returns the column headers as an array of tuples:
314 * (name, sortName (key to the sort array))
316 * @param string $action
317 * The action being performed.
318 * @param string $output
319 * What should the result set include (web/email/csv).
322 * the column headers that need to be displayed
324 public function &getColumnHeaders($action = NULL, $output = NULL) {
325 self
::$_columnHeaders = [];
327 if (!$this->_single
) {
330 'name' => ts('Contact Name'),
331 'sort' => 'sort_name',
332 'direction' => CRM_Utils_Sort
::ASCENDING
,
335 'name' => ts('Street Number'),
336 'sort' => 'street_number',
339 'name' => ts('Street Name'),
340 'sort' => 'street_name',
342 ['name' => ts('Street Address')],
344 'name' => ts('City'),
348 'name' => ts('Postal Code'),
349 'sort' => 'postal_code',
352 'name' => ts('State'),
353 'sort' => 'state_province_name',
355 ['name' => ts('Country')],
356 ['name' => ts('Email')],
357 ['name' => ts('Phone')],
359 self
::$_columnHeaders = array_merge($contactDetails, self
::$_columnHeaders);
362 return self
::$_columnHeaders;
368 public function &getQuery() {
369 return $this->_query
;
373 * Name of export file.
375 * @param string $output
381 public function getExportFileName($output = 'csv') {
382 return ts('CiviCRM Respondent Search');