3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
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 * what component context are we being invoked from
114 protected $_compContext = NULL;
117 * queryParams is the array returned by exportValues called on
118 * the HTML_QuickForm_Controller for that page.
123 public $_queryParams;
126 * represent the type of selector
134 * The additional clause that we restrict the search with
138 protected $_activityClause = NULL;
150 * @param array $queryParams array of parameters for query
151 * @param \const|int $action - action of search basic or advanced.
152 * @param string $activityClause if the caller wants to further restrict the search (used in activities)
153 * @param boolean $single are we dealing only with one contact?
154 * @param int $limit how many activities do we want returned
156 * @param string $context
157 * @param null $compContext
159 * @return \CRM_Activity_Selector_Search
162 function __construct(&$queryParams,
163 $action = CRM_Core_Action
::NONE
,
164 $activityClause = NULL,
170 // submitted form values
171 $this->_queryParams
= &$queryParams;
173 $this->_single
= $single;
174 $this->_limit
= $limit;
175 $this->_context
= $context;
176 $this->_compContext
= $compContext;
178 $this->_activityClause
= $activityClause;
181 $this->_action
= $action;
182 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
183 CRM_Activity_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_ACTIVITY
,
187 CRM_Contact_BAO_Query
::MODE_ACTIVITY
189 $this->_query
->_distinctComponentClause
= '( civicrm_activity.id )';
190 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
191 //CRM_Core_Error::debug( $this->_query ); exit();
196 * getter for array of the parameters required for creating pager.
204 function getPagerParams($action, &$params) {
205 $params['status'] = ts('Activities %%StatusMessage%%');
206 $params['csvString'] = NULL;
207 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
208 $params['buttonTop'] = 'PagerTopButton';
209 $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,
226 $this->_activityClause
231 * returns all the rows in the given offset and rowCount
233 * @param enum $action the action being performed
234 * @param int $offset the row number to start from
235 * @param int $rowCount the number of rows to return
236 * @param string $sort the sql string that describes the sort order
237 * @param enum $output what should the result set include (web/email/csv)
239 * @return array rows in the given offset and rowCount
241 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
242 $result = $this->_query
->searchQuery(
243 $offset, $rowCount, $sort,
247 $this->_activityClause
250 $mailingIDs = CRM_Mailing_BAO_Mailing
::mailingACLIDs();
251 $accessCiviMail = CRM_Core_Permission
::check('access CiviMail');
254 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
256 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
257 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
258 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
259 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
260 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
261 //get all activity types
262 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
264 while ($result->fetch()) {
267 // ignore rows where we dont have an activity id
268 if (empty($result->activity_id
)) {
272 // the columns we are interested in
273 foreach (self
::$_properties as $property) {
274 if (isset($result->$property)) {
275 $row[$property] = $result->$property;
279 $contactId = CRM_Utils_Array
::value('contact_id', $row);
281 $contactId = CRM_Utils_Array
::value('source_contact_id', $row);
284 $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $targetID);
285 $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $assigneeID);
286 list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $sourceID, TRUE);
287 $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
288 $row['source_contact_id'] = implode(',', $row['source_contact_id']);
290 if ($this->_context
== 'search') {
291 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->activity_id
;
293 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
294 $result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
296 $accessMailingReport = FALSE;
297 $activityTypeId = $row['activity_type_id'];
298 if ($row['activity_is_test']) {
299 $row['activity_type'] = $row['activity_type'] . " (test)";
301 $bulkActivityTypeID = CRM_Utils_Array
::key('Bulk Email', $activityTypes);
302 $row['mailingId'] = '';
305 ($mailingIDs === TRUE ||
in_array($result->source_record_id
, $mailingIDs)) &&
306 ($bulkActivityTypeID == $activityTypeId)
308 $row['mailingId'] = CRM_Utils_System
::url('civicrm/mailing/report',
309 "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector"
311 $row['recipients'] = ts('(recipients)');
312 $row['target_contact_name'] = '';
313 $row['assignee_contact_name'] = '';
314 $accessMailingReport = TRUE;
316 $activityActions = new CRM_Activity_Selector_Activity($result->contact_id
, NULL);
317 $actionLinks = $activityActions->actionLinks($activityTypeId,
318 CRM_Utils_Array
::value('source_record_id', $row),
319 $accessMailingReport,
320 CRM_Utils_Array
::value('activity_id', $row),
324 $row['action'] = CRM_Core_Action
::formLink($actionLinks, NULL,
326 'id' => $result->activity_id
,
328 'cxt' => $this->_context
,
332 'activity.selector.row',
337 //carry campaign to selector.
338 $row['campaign'] = CRM_Utils_Array
::value($result->activity_campaign_id
, $allCampaigns);
339 $row['campaign_id'] = $result->activity_campaign_id
;
341 if ($engagementLevel = CRM_Utils_Array
::value('activity_engagement_level', $row)) {
342 $row['activity_engagement_level'] = CRM_Utils_Array
::value($engagementLevel,
343 $engagementLevels, $engagementLevel
355 * @return array $qill which contains an array of strings
358 public function getQILL() {
359 return $this->_query
->qill();
363 * returns the column headers as an array of tuples:
364 * (name, sortName (key to the sort array))
366 * @param string $action the action being performed
367 * @param enum $output what should the result set include (web/email/csv)
369 * @return array the column headers that need to be displayed
372 public function &getColumnHeaders($action = NULL, $output = NULL) {
373 if (!isset(self
::$_columnHeaders)) {
374 self
::$_columnHeaders = array(
376 'name' => ts('Type'),
377 'sort' => 'activity_type_id',
378 'direction' => CRM_Utils_Sort
::DONTCARE
,
381 'name' => ts('Subject'),
382 'sort' => 'activity_subject',
383 'direction' => CRM_Utils_Sort
::DONTCARE
,
386 'name' => ts('Added By'),
387 'sort' => 'source_contact',
388 'direction' => CRM_Utils_Sort
::DONTCARE
,
390 array('name' => ts('With')),
391 array('name' => ts('Assigned')),
393 'name' => ts('Date'),
394 'sort' => 'activity_date_time',
395 'direction' => CRM_Utils_Sort
::DESCENDING
,
398 'name' => ts('Status'),
399 'sort' => 'status_id',
400 'direction' => CRM_Utils_Sort
::DONTCARE
,
403 'desc' => ts('Actions'),
407 return self
::$_columnHeaders;
413 function alphabetQuery() {
414 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
420 function &getQuery() {
421 return $this->_query
;
425 * name of export file.
427 * @param string $output type of output
429 * @return string name of the file
431 function getExportFileName($output = 'csv') {
432 return ts('CiviCRM Activity Search');