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
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_Campaign_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
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(
80 'survey_activity_target_id',
81 'survey_activity_target_contact_id',
85 * Are we restricting ourselves to a single contact
90 protected $_single = FALSE;
93 * Are we restricting ourselves to a single contact
98 protected $_limit = NULL;
101 * What context are we being invoked from
106 protected $_context = NULL;
109 * QueryParams is the array returned by exportValues called on
110 * the HTML_QuickForm_Controller for that page.
115 public $_queryParams;
118 * Represent the type of selector
126 * The additional clause that we restrict the search with
130 protected $_surveyClause = NULL;
142 * @param array $queryParams array of parameters for query
143 * @param \const|int $action - action of search basic or advanced.
144 * @param string $surveyClause if the caller wants to further restrict the search.
145 * @param boolean $single are we dealing only with one contact?
146 * @param int $limit how many voters do we want returned
148 * @param string $context
150 * @return \CRM_Campaign_Selector_Search
153 function __construct(&$queryParams,
154 $action = CRM_Core_Action
::NONE
,
155 $surveyClause = NULL,
160 // submitted form values
161 $this->_queryParams
= &$queryParams;
163 $this->_single
= $single;
164 $this->_limit
= $limit;
165 $this->_context
= $context;
167 $this->_campaignClause
= $surveyClause;
168 $this->_campaignFromClause
= CRM_Utils_Array
::value('fromClause', $surveyClause);
169 $this->_campaignWhereClause
= CRM_Utils_Array
::value('whereClause', $surveyClause);
172 $this->_action
= $action;
174 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
175 NULL, NULL, FALSE, FALSE,
176 CRM_Contact_BAO_Query
::MODE_CAMPAIGN
,
182 * This method returns the links that are given for each search row.
183 * currently the links added for each row are
194 return self
::$_links = array();
198 * Getter for array of the parameters required for creating pager.
201 * @param array $params
205 function getPagerParams($action, &$params) {
206 $params['csvString'] = NULL;
207 $params['status'] = ts('Respondents') . ' %%StatusMessage%%';
208 $params['rowCount'] = ($this->_limit
) ?
$this->_limit
: CRM_Utils_Pager
::ROWCOUNT
;
209 $params['buttonTop'] = 'PagerTopButton';
210 $params['buttonBottom'] = 'PagerBottomButton';
214 * Returns total number of rows for the query.
218 * @return int Total number of rows
221 function getTotalCount($action) {
222 return $this->_query
->searchQuery(0, 0, NULL,
225 $this->_campaignWhereClause
,
227 $this->_campaignFromClause
232 * Returns all the rows in the given offset and rowCount
234 * @param enum $action the action being performed
235 * @param int $offset the row number to start from
236 * @param int $rowCount the number of rows to return
237 * @param string $sort the sql string that describes the sort order
238 * @param enum $output what should the result set include (web/email/csv)
240 * @return int the total number of rows for this action
242 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
243 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
246 FALSE, $this->_campaignWhereClause
,
248 $this->_campaignFromClause
252 // process the result of the query
255 While ($result->fetch()) {
256 $this->_query
->convertToPseudoNames($result);
258 // the columns we are interested in
259 foreach (self
::$_properties as $property) {
260 if (property_exists($result, $property)) {
261 $row[$property] = $result->$property;
264 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->contact_id
;
265 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_type
, FALSE, $result->contact_id
);
269 $this->buildPrevNextCache($sort);
277 function buildPrevNextCache($sort) {
278 //for prev/next pagination
279 $crmPID = CRM_Utils_Request
::retrieve('crmPID', 'Integer', CRM_Core_DAO
::$_nullObject);
282 $cacheKey = "civicrm search {$this->_key}";
283 CRM_Core_BAO_PrevNextCache
::deleteItem(NULL, $cacheKey, 'civicrm_contact');
285 $sql = $this->_query
->searchQuery(0, 0, $sort,
288 TRUE, $this->_campaignWhereClause
,
290 $this->_campaignFromClause
292 list($select, $from) = explode(' FROM ', $sql);
294 INSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )
295 SELECT 'civicrm_contact', contact_a.id, contact_a.id, '$cacheKey', contact_a.display_name
298 $errorScope = CRM_Core_TemporaryErrorScope
::ignoreException();
299 $result = CRM_Core_DAO
::executeQuery($insertSQL);
302 if (is_a($result, 'DB_Error')) {
305 // also record an entry in the cache key table, so we can delete it periodically
306 CRM_Core_BAO_Cache
::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
311 * @return array $qill which contains an array of strings
314 public function getQILL() {
315 return $this->_query
->qill();
319 * Returns the column headers as an array of tuples:
320 * (name, sortName (key to the sort array))
322 * @param string $action the action being performed
323 * @param enum $output what should the result set include (web/email/csv)
325 * @return array the column headers that need to be displayed
328 public function &getColumnHeaders($action = NULL, $output = NULL) {
329 self
::$_columnHeaders = array();
331 if (!$this->_single
) {
332 $contactDetails = array(
333 array('name' => ts('Contact Name'),
334 'sort' => 'sort_name',
335 'direction' => CRM_Utils_Sort
::ASCENDING
,
337 array('name' => ts('Street Number'),
338 'sort' => 'street_number',
340 array('name' => ts('Street Name'),
341 'sort' => 'street_name',
343 array('name' => ts('Street Address')),
344 array('name' => ts('City'),
347 array('name' => ts('Postal Code'),
348 'sort' => 'postal_code',
350 array('name' => ts('State'),
351 'sort' => 'state_province_name',
353 array('name' => ts('Country')),
354 array('name' => ts('Email')),
355 array('name' => ts('Phone')),
357 self
::$_columnHeaders = array_merge($contactDetails, self
::$_columnHeaders);
360 return self
::$_columnHeaders;
366 function &getQuery() {
367 return $this->_query
;
371 * Name of export file.
373 * @param string $output type of output
375 * @return string name of the file
377 function getExportFileName($output = 'csv') {
378 return ts('CiviCRM Respondent Search');