3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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
35 * This class is used to retrieve and display a range of contacts that match the given criteria.
37 * Specifically for results of advanced search options.
39 class CRM_Activity_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
42 * This defines two actions- View and Edit.
46 static $_links = NULL;
49 * We use desc to remind us what that column is, name is used in the tpl
53 static $_columnHeaders;
56 * Properties of contact we're interested in displaying
60 static $_properties = array(
75 'activity_campaign_id',
76 'activity_engagement_level',
80 * Are we restricting ourselves to a single contact.
84 protected $_single = FALSE;
87 * Are we restricting ourselves to a single contact.
91 protected $_limit = NULL;
94 * What context are we being invoked from.
98 protected $_context = NULL;
101 * What component context are we being invoked from.
105 protected $_compContext = NULL;
108 * QueryParams is the array returned by exportValues called on.
109 * the HTML_QuickForm_Controller for that page.
113 public $_queryParams;
116 * Represent the type of selector.
123 * The additional clause that we restrict the search with.
127 protected $_activityClause = NULL;
139 * @param array $queryParams
140 * Array of parameters for query.
141 * @param \const|int $action - action of search basic or advanced.
142 * @param string $activityClause
143 * If the caller wants to further restrict the search (used in activities).
144 * @param bool $single
145 * Are we dealing only with one contact?.
147 * How many activities do we want returned.
149 * @param string $context
150 * @param null $compContext
152 * @return \CRM_Activity_Selector_Search
154 public function __construct(
156 $action = CRM_Core_Action
::NONE
,
157 $activityClause = NULL,
163 // submitted form values
164 $this->_queryParams
= &$queryParams;
166 $this->_single
= $single;
167 $this->_limit
= $limit;
168 $this->_context
= $context;
169 $this->_compContext
= $compContext;
171 $this->_activityClause
= $activityClause;
174 $components = CRM_Core_Component
::getNames();
175 $componentClause = array();
176 foreach ($components as $componentID => $componentName) {
177 if (!CRM_Core_Permission
::check("access $componentName")) {
178 $componentClause[] = " (activity_type.component_id IS NULL OR activity_type.component_id <> {$componentID}) ";
182 if (!empty($componentClause)) {
183 $componentRestriction = implode(' AND ', $componentClause);
184 if (empty($this->_activityClause
)) {
185 $this->_activityClause
= $componentRestriction;
188 $this->_activityClause
.= ' AND ' . $componentRestriction;
193 $this->_action
= $action;
194 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
195 CRM_Activity_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_ACTIVITY
,
199 CRM_Contact_BAO_Query
::MODE_ACTIVITY
201 $this->_query
->_distinctComponentClause
= '( civicrm_activity.id )';
202 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
206 * Getter for array of the parameters required for creating pager.
209 * @param array $params
211 public function getPagerParams($action, &$params) {
212 $params['status'] = ts('Activities %%StatusMessage%%');
213 $params['csvString'] = NULL;
214 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
215 $params['buttonTop'] = 'PagerTopButton';
216 $params['buttonBottom'] = 'PagerBottomButton';
220 * Returns total number of rows for the query.
222 * @param string $action
225 * Total number of rows
227 public function getTotalCount($action) {
228 return $this->_query
->searchQuery(0, 0, NULL,
232 $this->_activityClause
237 * Returns all the rows in the given offset and rowCount.
239 * @param string $action
240 * The action being performed.
242 * The row number to start from.
243 * @param int $rowCount
244 * The number of rows to return.
245 * @param string $sort
246 * The sql string that describes the sort order.
247 * @param string $output
248 * What should the result set include (web/email/csv).
251 * rows in the given offset and rowCount
253 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
254 $result = $this->_query
->searchQuery(
255 $offset, $rowCount, $sort,
259 $this->_activityClause
262 $mailingIDs = CRM_Mailing_BAO_Mailing
::mailingACLIDs();
263 $accessCiviMail = CRM_Core_Permission
::check('access CiviMail');
266 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
268 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
269 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
270 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
271 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
272 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
273 //get all activity types
274 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
276 while ($result->fetch()) {
279 // ignore rows where we dont have an activity id
280 if (empty($result->activity_id
)) {
284 // the columns we are interested in
285 foreach (self
::$_properties as $property) {
286 if (isset($result->$property)) {
287 $row[$property] = $result->$property;
291 $contactId = CRM_Utils_Array
::value('contact_id', $row);
293 $contactId = CRM_Utils_Array
::value('source_contact_id', $row);
296 $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $targetID);
297 $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $assigneeID);
298 list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $sourceID, TRUE);
299 $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
300 $row['source_contact_id'] = implode(',', $row['source_contact_id']);
302 if ($this->_context
== 'search') {
303 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->activity_id
;
305 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
307 $accessMailingReport = FALSE;
308 $activityTypeId = $row['activity_type_id'];
309 if ($row['activity_is_test']) {
310 $row['activity_type'] = $row['activity_type'] . " (test)";
312 $bulkActivityTypeID = CRM_Utils_Array
::key('Bulk Email', $activityTypes);
313 $row['mailingId'] = '';
316 ($mailingIDs === TRUE ||
in_array($result->source_record_id
, $mailingIDs)) &&
317 ($bulkActivityTypeID == $activityTypeId)
319 $row['mailingId'] = CRM_Utils_System
::url('civicrm/mailing/report',
320 "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector"
322 $row['recipients'] = ts('(recipients)');
323 $row['target_contact_name'] = '';
324 $row['assignee_contact_name'] = '';
325 $accessMailingReport = TRUE;
327 $activityActions = new CRM_Activity_Selector_Activity($result->contact_id
, NULL);
328 $actionLinks = $activityActions->actionLinks($activityTypeId,
329 CRM_Utils_Array
::value('source_record_id', $row),
330 $accessMailingReport,
331 CRM_Utils_Array
::value('activity_id', $row),
335 $row['action'] = CRM_Core_Action
::formLink($actionLinks, NULL,
337 'id' => $result->activity_id
,
339 'cxt' => $this->_context
,
343 'activity.selector.row',
348 //carry campaign to selector.
349 $row['campaign'] = CRM_Utils_Array
::value($result->activity_campaign_id
, $allCampaigns);
350 $row['campaign_id'] = $result->activity_campaign_id
;
352 if ($engagementLevel = CRM_Utils_Array
::value('activity_engagement_level', $row)) {
353 $row['activity_engagement_level'] = CRM_Utils_Array
::value($engagementLevel,
354 $engagementLevels, $engagementLevel
358 //Check if recurring activity
359 $repeat = CRM_Core_BAO_RecurringEntity
::getPositionAndCount($row['activity_id'], 'civicrm_activity');
362 $row['repeat'] = ts('Repeating (%1 of %2)', array(1 => $repeat[0], 2 => $repeat[1]));
372 * which contains an array of strings
374 public function getQILL() {
375 return $this->_query
->qill();
379 * Returns the column headers as an array of tuples:
380 * (name, sortName (key to the sort array))
382 * @param string $action
383 * The action being performed.
384 * @param string $output
385 * What should the result set include (web/email/csv).
388 * the column headers that need to be displayed
390 public function &getColumnHeaders($action = NULL, $output = NULL) {
391 if (!isset(self
::$_columnHeaders)) {
392 self
::$_columnHeaders = array(
394 'name' => ts('Type'),
395 'sort' => 'activity_type_id',
396 'direction' => CRM_Utils_Sort
::DONTCARE
,
399 'name' => ts('Subject'),
400 'sort' => 'activity_subject',
401 'direction' => CRM_Utils_Sort
::DONTCARE
,
404 'name' => ts('Added By'),
405 'sort' => 'source_contact',
406 'direction' => CRM_Utils_Sort
::DONTCARE
,
408 array('name' => ts('With')),
409 array('name' => ts('Assigned')),
411 'name' => ts('Date'),
412 'sort' => 'activity_date_time',
413 'direction' => CRM_Utils_Sort
::DESCENDING
,
416 'name' => ts('Status'),
417 'sort' => 'activity_status',
418 'direction' => CRM_Utils_Sort
::DONTCARE
,
421 'desc' => ts('Actions'),
425 return self
::$_columnHeaders;
431 public function alphabetQuery() {
432 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
438 public function &getQuery() {
439 return $this->_query
;
443 * Name of export file.
445 * @param string $output
451 public function getExportFileName($output = 'csv') {
452 return ts('CiviCRM Activity Search');