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.
48 static $_links = NULL;
51 * We use desc to remind us what that column is, name is used in the tpl
55 static $_columnHeaders;
58 * Properties of contact we're interested in displaying
62 static $_properties = array(
77 'activity_campaign_id',
78 'activity_engagement_level',
82 * Are we restricting ourselves to a single contact
86 protected $_single = FALSE;
89 * Are we restricting ourselves to a single contact
93 protected $_limit = NULL;
96 * What context are we being invoked from
100 protected $_context = NULL;
103 * What component context are we being invoked from
107 protected $_compContext = NULL;
110 * QueryParams is the array returned by exportValues called on
111 * the HTML_QuickForm_Controller for that page.
115 public $_queryParams;
118 * Represent the type of selector
125 * The additional clause that we restrict the search with
129 protected $_activityClause = NULL;
141 * @param array $queryParams
142 * Array of parameters for query.
143 * @param \const|int $action - action of search basic or advanced.
144 * @param string $activityClause
145 * If the caller wants to further restrict the search (used in activities).
146 * @param bool $single
147 * Are we dealing only with one contact?.
149 * How many activities do we want returned.
151 * @param string $context
152 * @param null $compContext
154 * @return \CRM_Activity_Selector_Search
156 public function __construct(
158 $action = CRM_Core_Action
::NONE
,
159 $activityClause = NULL,
165 // submitted form values
166 $this->_queryParams
= &$queryParams;
168 $this->_single
= $single;
169 $this->_limit
= $limit;
170 $this->_context
= $context;
171 $this->_compContext
= $compContext;
173 $this->_activityClause
= $activityClause;
176 $this->_action
= $action;
177 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
178 CRM_Activity_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_ACTIVITY
,
182 CRM_Contact_BAO_Query
::MODE_ACTIVITY
184 $this->_query
->_distinctComponentClause
= '( civicrm_activity.id )';
185 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_activity.id ";
189 * Getter for array of the parameters required for creating pager.
192 * @param array $params
194 public function getPagerParams($action, &$params) {
195 $params['status'] = ts('Activities %%StatusMessage%%');
196 $params['csvString'] = NULL;
197 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
198 $params['buttonTop'] = 'PagerTopButton';
199 $params['buttonBottom'] = 'PagerBottomButton';
203 * Returns total number of rows for the query.
208 * Total number of rows
210 public function getTotalCount($action) {
211 return $this->_query
->searchQuery(0, 0, NULL,
215 $this->_activityClause
220 * Returns all the rows in the given offset and rowCount
222 * @param string $action
223 * The action being performed.
225 * The row number to start from.
226 * @param int $rowCount
227 * The number of rows to return.
228 * @param string $sort
229 * The sql string that describes the sort order.
230 * @param string $output
231 * What should the result set include (web/email/csv).
234 * rows in the given offset and rowCount
236 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
237 $result = $this->_query
->searchQuery(
238 $offset, $rowCount, $sort,
242 $this->_activityClause
245 $mailingIDs = CRM_Mailing_BAO_Mailing
::mailingACLIDs();
246 $accessCiviMail = CRM_Core_Permission
::check('access CiviMail');
249 $allCampaigns = CRM_Campaign_BAO_Campaign
::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
251 $engagementLevels = CRM_Campaign_PseudoConstant
::engagementLevel();
252 $activityContacts = CRM_Core_OptionGroup
::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
253 $sourceID = CRM_Utils_Array
::key('Activity Source', $activityContacts);
254 $assigneeID = CRM_Utils_Array
::key('Activity Assignees', $activityContacts);
255 $targetID = CRM_Utils_Array
::key('Activity Targets', $activityContacts);
256 //get all activity types
257 $activityTypes = CRM_Core_PseudoConstant
::activityType(TRUE, TRUE, FALSE, 'name', TRUE);
259 while ($result->fetch()) {
262 // ignore rows where we dont have an activity id
263 if (empty($result->activity_id
)) {
267 // the columns we are interested in
268 foreach (self
::$_properties as $property) {
269 if (isset($result->$property)) {
270 $row[$property] = $result->$property;
274 $contactId = CRM_Utils_Array
::value('contact_id', $row);
276 $contactId = CRM_Utils_Array
::value('source_contact_id', $row);
279 $row['target_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $targetID);
280 $row['assignee_contact_name'] = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $assigneeID);
281 list($row['source_contact_name'], $row['source_contact_id']) = CRM_Activity_BAO_ActivityContact
::getNames($row['activity_id'], $sourceID, TRUE);
282 $row['source_contact_name'] = implode(',', array_values($row['source_contact_name']));
283 $row['source_contact_id'] = implode(',', $row['source_contact_id']);
285 if ($this->_context
== 'search') {
286 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->activity_id
;
288 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
290 $accessMailingReport = FALSE;
291 $activityTypeId = $row['activity_type_id'];
292 if ($row['activity_is_test']) {
293 $row['activity_type'] = $row['activity_type'] . " (test)";
295 $bulkActivityTypeID = CRM_Utils_Array
::key('Bulk Email', $activityTypes);
296 $row['mailingId'] = '';
299 ($mailingIDs === TRUE ||
in_array($result->source_record_id
, $mailingIDs)) &&
300 ($bulkActivityTypeID == $activityTypeId)
302 $row['mailingId'] = CRM_Utils_System
::url('civicrm/mailing/report',
303 "mid={$result->source_record_id}&reset=1&cid={$contactId}&context=activitySelector"
305 $row['recipients'] = ts('(recipients)');
306 $row['target_contact_name'] = '';
307 $row['assignee_contact_name'] = '';
308 $accessMailingReport = TRUE;
310 $activityActions = new CRM_Activity_Selector_Activity($result->contact_id
, NULL);
311 $actionLinks = $activityActions->actionLinks($activityTypeId,
312 CRM_Utils_Array
::value('source_record_id', $row),
313 $accessMailingReport,
314 CRM_Utils_Array
::value('activity_id', $row),
318 $row['action'] = CRM_Core_Action
::formLink($actionLinks, NULL,
320 'id' => $result->activity_id
,
322 'cxt' => $this->_context
,
326 'activity.selector.row',
331 //carry campaign to selector.
332 $row['campaign'] = CRM_Utils_Array
::value($result->activity_campaign_id
, $allCampaigns);
333 $row['campaign_id'] = $result->activity_campaign_id
;
335 if ($engagementLevel = CRM_Utils_Array
::value('activity_engagement_level', $row)) {
336 $row['activity_engagement_level'] = CRM_Utils_Array
::value($engagementLevel,
337 $engagementLevels, $engagementLevel
341 //Check if recurring activity
342 $isRecurringActivity = CRM_Core_BAO_RecurringEntity
::getParentFor($row['activity_id'], 'civicrm_activity');
344 if ($isRecurringActivity) {
345 if ($row['activity_id'] == $isRecurringActivity) {
346 $row['repeat'] = 'Recurring Activity - (Parent)';
349 $row['repeat'] = 'Recurring Activity - (Child)';
360 * which contains an array of strings
362 public function getQILL() {
363 return $this->_query
->qill();
367 * Returns the column headers as an array of tuples:
368 * (name, sortName (key to the sort array))
370 * @param string $action
371 * The action being performed.
372 * @param string $output
373 * What should the result set include (web/email/csv).
376 * the column headers that need to be displayed
378 public function &getColumnHeaders($action = NULL, $output = NULL) {
379 if (!isset(self
::$_columnHeaders)) {
380 self
::$_columnHeaders = array(
382 'name' => ts('Type'),
383 'sort' => 'activity_type_id',
384 'direction' => CRM_Utils_Sort
::DONTCARE
,
387 'name' => ts('Subject'),
388 'sort' => 'activity_subject',
389 'direction' => CRM_Utils_Sort
::DONTCARE
,
392 'name' => ts('Added By'),
393 'sort' => 'source_contact',
394 'direction' => CRM_Utils_Sort
::DONTCARE
,
396 array('name' => ts('With')),
397 array('name' => ts('Assigned')),
399 'name' => ts('Date'),
400 'sort' => 'activity_date_time',
401 'direction' => CRM_Utils_Sort
::DESCENDING
,
404 'name' => ts('Status'),
405 'sort' => 'activity_status',
406 'direction' => CRM_Utils_Sort
::DONTCARE
,
409 'desc' => ts('Actions'),
413 return self
::$_columnHeaders;
419 public function alphabetQuery() {
420 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
426 public function &getQuery() {
427 return $this->_query
;
431 * Name of export file.
433 * @param string $output
439 public function getExportFileName($output = 'csv') {
440 return ts('CiviCRM Activity Search');