3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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_Activity_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
45 * This defines two actions- View and Edit.
49 static $_links = NULL;
52 * We use desc to remind us what that column is, name is used in the tpl
56 static $_columnHeaders;
59 * Properties of contact we're interested in displaying
63 static $_properties = array(
78 'activity_campaign_id',
79 'activity_engagement_level',
83 * Are we restricting ourselves to a single contact.
87 protected $_single = FALSE;
90 * Are we restricting ourselves to a single contact.
94 protected $_limit = NULL;
97 * What context are we being invoked from.
101 protected $_context = NULL;
104 * What component context are we being invoked from.
108 protected $_compContext = NULL;
111 * QueryParams is the array returned by exportValues called on.
112 * the HTML_QuickForm_Controller for that page.
116 public $_queryParams;
119 * Represent the type of selector.
126 * The additional clause that we restrict the search with.
130 protected $_activityClause = NULL;
142 * @param array $queryParams
143 * Array of parameters for query.
144 * @param \const|int $action - action of search basic or advanced.
145 * @param string $activityClause
146 * If the caller wants to further restrict the search (used in activities).
147 * @param bool $single
148 * Are we dealing only with one contact?.
150 * How many activities do we want returned.
152 * @param string $context
153 * @param null $compContext
155 * @return \CRM_Activity_Selector_Search
157 public function __construct(
159 $action = CRM_Core_Action
::NONE
,
160 $activityClause = NULL,
166 // submitted form values
167 $this->_queryParams
= &$queryParams;
169 $this->_single
= $single;
170 $this->_limit
= $limit;
171 $this->_context
= $context;
172 $this->_compContext
= $compContext;
174 $this->_activityClause
= $activityClause;
177 if (! CRM_Core_Permission
::check('access CiviContribute')) {
178 $componentRestriction = ' (activity_type.component_id IS NULL OR activity_type.component_id <> 2) ';
179 if (empty($this->_activityClause
)) {
180 $this->_activityClause
= $componentRestriction;
183 $this->_activityClause
.= ' AND ' . $componentRestriction;
188 $this->_action
= $action;
189 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
190 CRM_Activity_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_ACTIVITY
,
194 CRM_Contact_BAO_Query
::MODE_ACTIVITY
196 $this->_query
->_distinctComponentClause
= '( civicrm_activity.id )';
197 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
201 * Getter for array of the parameters required for creating pager.
204 * @param array $params
206 public function getPagerParams($action, &$params) {
207 $params['status'] = ts('Activities %%StatusMessage%%');
208 $params['csvString'] = NULL;
209 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
210 $params['buttonTop'] = 'PagerTopButton';
211 $params['buttonBottom'] = 'PagerBottomButton';
215 * Returns total number of rows for the query.
217 * @param string $action
220 * Total number of rows
222 public function getTotalCount($action) {
223 return $this->_query
->searchQuery(0, 0, NULL,
227 $this->_activityClause
232 * Returns all the rows in the given offset and rowCount.
234 * @param string $action
235 * The action being performed.
237 * The row number to start from.
238 * @param int $rowCount
239 * The number of rows to return.
240 * @param string $sort
241 * The sql string that describes the sort order.
242 * @param string $output
243 * What should the result set include (web/email/csv).
246 * rows in the given offset and rowCount
248 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
249 $result = $this->_query
->searchQuery(
250 $offset, $rowCount, $sort,
254 $this->_activityClause
257 $mailingIDs = CRM_Mailing_BAO_Mailing
::mailingACLIDs();
258 $accessCiviMail = CRM_Core_Permission
::check('access CiviMail');
261 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
263 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
264 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
265 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
266 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
267 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
268 //get all activity types
269 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
271 while ($result->fetch()) {
274 // ignore rows where we dont have an activity id
275 if (empty($result->activity_id
)) {
279 // the columns we are interested in
280 foreach (self
::$_properties as $property) {
281 if (isset($result->$property)) {
282 $row[$property] = $result->$property;
286 $contactId = CRM_Utils_Array
::value('contact_id', $row);
288 $contactId = CRM_Utils_Array
::value('source_contact_id', $row);
291 $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $targetID);
292 $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $assigneeID);
293 list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $sourceID, TRUE);
294 $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
295 $row['source_contact_id'] = implode(',', $row['source_contact_id']);
297 if ($this->_context
== 'search') {
298 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->activity_id
;
300 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
302 $accessMailingReport = FALSE;
303 $activityTypeId = $row['activity_type_id'];
304 if ($row['activity_is_test']) {
305 $row['activity_type'] = $row['activity_type'] . " (test)";
307 $bulkActivityTypeID = CRM_Utils_Array
::key('Bulk Email', $activityTypes);
308 $row['mailingId'] = '';
311 ($mailingIDs === TRUE ||
in_array($result->source_record_id
, $mailingIDs)) &&
312 ($bulkActivityTypeID == $activityTypeId)
314 $row['mailingId'] = CRM_Utils_System
::url('civicrm/mailing/report',
315 "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector"
317 $row['recipients'] = ts('(recipients)');
318 $row['target_contact_name'] = '';
319 $row['assignee_contact_name'] = '';
320 $accessMailingReport = TRUE;
322 $activityActions = new CRM_Activity_Selector_Activity($result->contact_id
, NULL);
323 $actionLinks = $activityActions->actionLinks($activityTypeId,
324 CRM_Utils_Array
::value('source_record_id', $row),
325 $accessMailingReport,
326 CRM_Utils_Array
::value('activity_id', $row),
330 $row['action'] = CRM_Core_Action
::formLink($actionLinks, NULL,
332 'id' => $result->activity_id
,
334 'cxt' => $this->_context
,
338 'activity.selector.row',
343 //carry campaign to selector.
344 $row['campaign'] = CRM_Utils_Array
::value($result->activity_campaign_id
, $allCampaigns);
345 $row['campaign_id'] = $result->activity_campaign_id
;
347 if ($engagementLevel = CRM_Utils_Array
::value('activity_engagement_level', $row)) {
348 $row['activity_engagement_level'] = CRM_Utils_Array
::value($engagementLevel,
349 $engagementLevels, $engagementLevel
353 //Check if recurring activity
354 $repeat = CRM_Core_BAO_RecurringEntity
::getPositionAndCount($row['activity_id'], 'civicrm_activity');
357 $row['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1]));
367 * which contains an array of strings
369 public function getQILL() {
370 return $this->_query
->qill();
374 * Returns the column headers as an array of tuples:
375 * (name, sortName (key to the sort array))
377 * @param string $action
378 * The action being performed.
379 * @param string $output
380 * What should the result set include (web/email/csv).
383 * the column headers that need to be displayed
385 public function &getColumnHeaders($action = NULL, $output = NULL) {
386 if (!isset(self
::$_columnHeaders)) {
387 self
::$_columnHeaders = array(
389 'name' => ts('Type'),
390 'sort' => 'activity_type_id',
391 'direction' => CRM_Utils_Sort
::DONTCARE
,
394 'name' => ts('Subject'),
395 'sort' => 'activity_subject',
396 'direction' => CRM_Utils_Sort
::DONTCARE
,
399 'name' => ts('Added By'),
400 'sort' => 'source_contact',
401 'direction' => CRM_Utils_Sort
::DONTCARE
,
403 array('name' => ts('With')),
404 array('name' => ts('Assigned')),
406 'name' => ts('Date'),
407 'sort' => 'activity_date_time',
408 'direction' => CRM_Utils_Sort
::DESCENDING
,
411 'name' => ts('Status'),
412 'sort' => 'activity_status',
413 'direction' => CRM_Utils_Sort
::DONTCARE
,
416 'desc' => ts('Actions'),
420 return self
::$_columnHeaders;
426 public function alphabetQuery() {
427 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
433 public function &getQuery() {
434 return $this->_query
;
438 * Name of export file.
440 * @param string $output
446 public function getExportFileName($output = 'csv') {
447 return ts('CiviCRM Activity Search');