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. |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2014
36 * This class is used to retrieve and display a range of
37 * contacts that match the given criteria (specifically for
38 * results of advanced search options.
41 class CRM_Activity_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
44 * 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
57 static $_columnHeaders;
60 * Properties of contact we're interested in displaying
65 static $_properties = array(
80 'activity_campaign_id',
81 'activity_engagement_level',
85 * Are we restricting ourselves to a single contact
89 protected $_single = FALSE;
92 * Are we restricting ourselves to a single contact
96 protected $_limit = NULL;
99 * What context are we being invoked from
103 protected $_context = NULL;
106 * What component context are we being invoked from
110 protected $_compContext = NULL;
113 * QueryParams is the array returned by exportValues called on
114 * the HTML_QuickForm_Controller for that page.
118 public $_queryParams;
121 * Represent the type of selector
128 * The additional clause that we restrict the search with
132 protected $_activityClause = NULL;
144 * @param array $queryParams
145 * Array of parameters for query.
146 * @param \const|int $action - action of search basic or advanced.
147 * @param string $activityClause
148 * If the caller wants to further restrict the search (used in activities).
149 * @param bool $single
150 * Are we dealing only with one contact?.
152 * How many activities do we want returned.
154 * @param string $context
155 * @param null $compContext
157 * @return \CRM_Activity_Selector_Search
160 function __construct(
162 $action = CRM_Core_Action
::NONE
,
163 $activityClause = NULL,
169 // submitted form values
170 $this->_queryParams
= &$queryParams;
172 $this->_single
= $single;
173 $this->_limit
= $limit;
174 $this->_context
= $context;
175 $this->_compContext
= $compContext;
177 $this->_activityClause
= $activityClause;
180 $this->_action
= $action;
181 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
182 CRM_Activity_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_ACTIVITY
,
186 CRM_Contact_BAO_Query
::MODE_ACTIVITY
188 $this->_query
->_distinctComponentClause
= '( civicrm_activity.id )';
189 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
193 * Getter for array of the parameters required for creating pager.
196 * @param array $params
198 public function getPagerParams($action, &$params) {
199 $params['status'] = ts('Activities %%StatusMessage%%');
200 $params['csvString'] = NULL;
201 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
202 $params['buttonTop'] = 'PagerTopButton';
203 $params['buttonBottom'] = 'PagerBottomButton';
207 * Returns total number of rows for the query.
212 * Total number of rows
214 public function getTotalCount($action) {
215 return $this->_query
->searchQuery(0, 0, NULL,
219 $this->_activityClause
224 * Returns all the rows in the given offset and rowCount
226 * @param string $action
227 * The action being performed.
229 * The row number to start from.
230 * @param int $rowCount
231 * The number of rows to return.
232 * @param string $sort
233 * The sql string that describes the sort order.
234 * @param string $output
235 * What should the result set include (web/email/csv).
238 * rows in the given offset and rowCount
240 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
241 $result = $this->_query
->searchQuery(
242 $offset, $rowCount, $sort,
246 $this->_activityClause
249 $mailingIDs = CRM_Mailing_BAO_Mailing
::mailingACLIDs();
250 $accessCiviMail = CRM_Core_Permission
::check('access CiviMail');
253 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
255 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
256 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
257 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
258 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
259 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
260 //get all activity types
261 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
263 while ($result->fetch()) {
266 // ignore rows where we dont have an activity id
267 if (empty($result->activity_id
)) {
271 // the columns we are interested in
272 foreach (self
::$_properties as $property) {
273 if (isset($result->$property)) {
274 $row[$property] = $result->$property;
278 $contactId = CRM_Utils_Array
::value('contact_id', $row);
280 $contactId = CRM_Utils_Array
::value('source_contact_id', $row);
283 $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $targetID);
284 $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $assigneeID);
285 list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $sourceID, TRUE);
286 $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
287 $row['source_contact_id'] = implode(',', $row['source_contact_id']);
289 if ($this->_context
== 'search') {
290 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->activity_id
;
292 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
294 $accessMailingReport = FALSE;
295 $activityTypeId = $row['activity_type_id'];
296 if ($row['activity_is_test']) {
297 $row['activity_type'] = $row['activity_type'] . " (test)";
299 $bulkActivityTypeID = CRM_Utils_Array
::key('Bulk Email', $activityTypes);
300 $row['mailingId'] = '';
303 ($mailingIDs === TRUE ||
in_array($result->source_record_id
, $mailingIDs)) &&
304 ($bulkActivityTypeID == $activityTypeId)
306 $row['mailingId'] = CRM_Utils_System
::url('civicrm/mailing/report',
307 "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector"
309 $row['recipients'] = ts('(recipients)');
310 $row['target_contact_name'] = '';
311 $row['assignee_contact_name'] = '';
312 $accessMailingReport = TRUE;
314 $activityActions = new CRM_Activity_Selector_Activity($result->contact_id
, NULL);
315 $actionLinks = $activityActions->actionLinks($activityTypeId,
316 CRM_Utils_Array
::value('source_record_id', $row),
317 $accessMailingReport,
318 CRM_Utils_Array
::value('activity_id', $row),
322 $row['action'] = CRM_Core_Action
::formLink($actionLinks, NULL,
324 'id' => $result->activity_id
,
326 'cxt' => $this->_context
,
330 'activity.selector.row',
335 //carry campaign to selector.
336 $row['campaign'] = CRM_Utils_Array
::value($result->activity_campaign_id
, $allCampaigns);
337 $row['campaign_id'] = $result->activity_campaign_id
;
339 if ($engagementLevel = CRM_Utils_Array
::value('activity_engagement_level', $row)) {
340 $row['activity_engagement_level'] = CRM_Utils_Array
::value($engagementLevel,
341 $engagementLevels, $engagementLevel
345 //Check if recurring activity
346 $isRecurringActivity = CRM_Core_BAO_RecurringEntity
::getParentFor($row['activity_id'], 'civicrm_activity');
348 if ($isRecurringActivity) {
349 if ($row['activity_id'] == $isRecurringActivity) {
350 $row['repeat'] = 'Recurring Activity - (Parent)';
353 $row['repeat'] = 'Recurring Activity - (Child)';
364 * which contains an array of strings
366 public function getQILL() {
367 return $this->_query
->qill();
371 * Returns the column headers as an array of tuples:
372 * (name, sortName (key to the sort array))
374 * @param string $action
375 * The action being performed.
376 * @param string $output
377 * What should the result set include (web/email/csv).
380 * the column headers that need to be displayed
382 public function &getColumnHeaders($action = NULL, $output = NULL) {
383 if (!isset(self
::$_columnHeaders)) {
384 self
::$_columnHeaders = array(
386 'name' => ts('Type'),
387 'sort' => 'activity_type_id',
388 'direction' => CRM_Utils_Sort
::DONTCARE
,
391 'name' => ts('Subject'),
392 'sort' => 'activity_subject',
393 'direction' => CRM_Utils_Sort
::DONTCARE
,
396 'name' => ts('Added By'),
397 'sort' => 'source_contact',
398 'direction' => CRM_Utils_Sort
::DONTCARE
,
400 array('name' => ts('With')),
401 array('name' => ts('Assigned')),
403 'name' => ts('Date'),
404 'sort' => 'activity_date_time',
405 'direction' => CRM_Utils_Sort
::DESCENDING
,
408 'name' => ts('Status'),
409 'sort' => 'activity_status',
410 'direction' => CRM_Utils_Sort
::DONTCARE
,
413 'desc' => ts('Actions'),
417 return self
::$_columnHeaders;
423 public function alphabetQuery() {
424 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
430 public function &getQuery() {
431 return $this->_query
;
435 * Name of export file.
437 * @param string $output
443 public function getExportFileName($output = 'csv') {
444 return ts('CiviCRM Activity Search');