3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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-2013
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_Case_Selector_Search
extends CRM_Core_Selector_Base
{
45 * This defines two actions- View and Edit.
50 static $_links = NULL;
53 * we use desc to remind us what that column is, name is used in the tpl
58 static $_columnHeaders;
61 * Properties of contact we're interested in displaying
65 static $_properties = array(
81 * are we restricting ourselves to a single contact
86 protected $_single = FALSE;
89 * are we restricting ourselves to a single contact
94 protected $_limit = NULL;
97 * what context are we being invoked from
102 protected $_context = NULL;
105 * queryParams is the array returned by exportValues called on
106 * the HTML_QuickForm_Controller for that page.
111 public $_queryParams;
114 * represent the type of selector
122 * The additional clause that we restrict the search with
126 protected $_additionalClause = NULL;
138 * @param array $queryParams array of parameters for query
139 * @param int $action - action of search basic or advanced.
140 * @param string $additionalClause if the caller wants to further restrict the search (used in participations)
141 * @param boolean $single are we dealing only with one contact?
142 * @param int $limit how many signers do we want returned
144 * @return CRM_Contact_Selector
146 */ function __construct(&$queryParams,
147 $action = CRM_Core_Action
::NONE
,
148 $additionalClause = NULL,
153 // submitted form values
154 $this->_queryParams
= &$queryParams;
156 $this->_single
= $single;
157 $this->_limit
= $limit;
158 $this->_context
= $context;
160 $this->_additionalClause
= $additionalClause;
163 $this->_action
= $action;
165 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
166 CRM_Case_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_CASE
,
170 CRM_Contact_BAO_Query
::MODE_CASE
173 $this->_query
->_distinctComponentClause
= " civicrm_case.id ";
174 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_case.id ";
179 * This method returns the links that are given for each search row.
180 * currently the links added for each row are
190 function &links($isDeleted = FALSE, $key = NULL) {
191 $extraParams = ($key) ?
"&key={$key}" : NULL;
194 self
::$_links = array(
195 CRM_Core_Action
::RENEW
=> array(
196 'name' => ts('Restore'),
197 'url' => 'civicrm/contact/view/case',
198 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
199 'ref' => 'restore-case',
200 'title' => ts('Restore Case'),
205 self
::$_links = array(
206 CRM_Core_Action
::VIEW
=> array(
207 'name' => ts('Manage'),
208 'url' => 'civicrm/contact/view/case',
209 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
210 'ref' => 'manage-case',
211 'title' => ts('Manage Case'),
213 CRM_Core_Action
::DELETE
=> array(
214 'name' => ts('Delete'),
215 'url' => 'civicrm/contact/view/case',
216 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
217 'ref' => 'delete-case',
218 'title' => ts('Delete Case'),
220 CRM_Core_Action
::UPDATE
=> array(
221 'name' => ts('Assign to Another Client'),
222 'url' => 'civicrm/contact/view/case/editClient',
223 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
225 'title' => ts('Assign to Another Client'),
230 $actionLinks = array();
231 foreach (self
::$_links as $key => $value) {
232 if ($value['ref'] == 'reassign') {
233 $actionLinks['moreActions'][$key] = $value;
236 $actionLinks['primaryActions'][$key] = $value;
245 * getter for array of the parameters required for creating pager.
250 function getPagerParams($action, &$params) {
251 $params['status'] = ts('Case') . ' %%StatusMessage%%';
252 $params['csvString'] = NULL;
254 $params['rowCount'] = $this->_limit
;
257 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
260 $params['buttonTop'] = 'PagerTopButton';
261 $params['buttonBottom'] = 'PagerBottomButton';
266 * Returns total number of rows for the query.
270 * @return int Total number of rows
273 function getTotalCount($action) {
274 return $this->_query
->searchQuery(0, 0, NULL,
278 $this->_additionalClause
283 * returns all the rows in the given offset and rowCount
285 * @param enum $action the action being performed
286 * @param int $offset the row number to start from
287 * @param int $rowCount the number of rows to return
288 * @param string $sort the sql string that describes the sort order
289 * @param enum $output what should the result set include (web/email/csv)
291 * @return int the total number of rows for this action
293 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
294 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
298 $this->_additionalClause
300 // process the result of the query
303 //CRM-4418 check for view, edit, delete
304 $permissions = array(CRM_Core_Permission
::VIEW
);
305 if (CRM_Core_Permission
::check('access all cases and activities')
306 || CRM_Core_Permission
::check('access my cases and activities')
308 $permissions[] = CRM_Core_Permission
::EDIT
;
310 if (CRM_Core_Permission
::check('delete in CiviCase')) {
311 $permissions[] = CRM_Core_Permission
::DELETE
;
313 $mask = CRM_Core_Action
::mask($permissions);
315 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
317 $scheduledInfo = array();
319 while ($result->fetch()) {
321 // the columns we are interested in
322 foreach (self
::$_properties as $property) {
323 if (isset($result->$property)) {
324 $row[$property] = $result->$property;
329 if ($result->case_deleted
) {
331 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />(deleted)';
334 $scheduledInfo['case_id'][] = $result->case_id
;
335 $scheduledInfo['contact_id'][] = $result->contact_id
;
336 $scheduledInfo['case_deleted'] = $result->case_deleted
;
337 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
339 $links = self
::links($isDeleted, $this->_key
);
340 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
342 'id' => $result->case_id
,
343 'cid' => $result->contact_id
,
344 'cxt' => $this->_context
,
347 $row['moreActions'] = CRM_Core_Action
::formLink(CRM_Utils_Array
::value('moreActions', $links),
349 'id' => $result->case_id
,
350 'cid' => $result->contact_id
,
351 'cxt' => $this->_context
,
357 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
358 $result->contact_sub_type
: $result->contact_type
361 //adding case manager to case selector.CRM-4510.
362 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
363 $caseManagerContact = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
365 if (!empty($caseManagerContact)) {
366 $row['casemanager_id'] = CRM_Utils_Array
::value('casemanager_id', $caseManagerContact);
367 $row['casemanager'] = CRM_Utils_Array
::value('casemanager', $caseManagerContact);
370 if (isset($result->case_status_id
) &&
371 array_key_exists($result->case_status_id
, $caseStatus)
373 $row['class'] = "status-urgent";
376 $row['class'] = "status-normal";
379 $rows[$result->case_id
] = $row;
382 //retrive the scheduled & recent Activity type and date for selector
383 if (!empty($scheduledInfo)) {
384 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
385 foreach ($schdeduledActivity as $key => $value) {
386 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
387 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
389 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
390 foreach ($recentActivity as $key => $value) {
391 $rows[$key]['case_recent_activity_date'] = $value['date'];
392 $rows[$key]['case_recent_activity_type'] = $value['type'];
400 * @return array $qill which contains an array of strings
404 // the current internationalisation is bad, but should more or less work
405 // for most of "European" languages
406 public function getQILL() {
407 return $this->_query
->qill();
411 * returns the column headers as an array of tuples:
412 * (name, sortName (key to the sort array))
414 * @param string $action the action being performed
415 * @param enum $output what should the result set include (web/email/csv)
417 * @return array the column headers that need to be displayed
420 public function &getColumnHeaders($action = NULL, $output = NULL) {
421 if (!isset(self
::$_columnHeaders)) {
422 self
::$_columnHeaders = array(
424 'name' => ts('Subject'),
425 'direction' => CRM_Utils_Sort
::DONTCARE
,
428 'name' => ts('Status'),
429 'sort' => 'case_status',
430 'direction' => CRM_Utils_Sort
::DONTCARE
,
433 'name' => ts('Case Type'),
434 'sort' => 'case_type_id',
435 'direction' => CRM_Utils_Sort
::DONTCARE
,
438 'name' => ts('My Role'),
439 'sort' => 'case_role',
440 'direction' => CRM_Utils_Sort
::DONTCARE
,
443 'name' => ts('Case Manager'),
444 'direction' => CRM_Utils_Sort
::DONTCARE
,
447 'name' => ts('Most Recent'),
448 'sort' => 'case_recent_activity_date',
449 'direction' => CRM_Utils_Sort
::DONTCARE
,
452 'name' => ts('Next Sched.'),
453 'sort' => 'case_scheduled_activity_date',
454 'direction' => CRM_Utils_Sort
::DONTCARE
,
456 array('name' => ts('Actions')),
459 if (!$this->_single
) {
462 'name' => ts('Client'),
463 'sort' => 'sort_name',
464 'direction' => CRM_Utils_Sort
::ASCENDING
,
468 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
471 return self
::$_columnHeaders;
474 function alphabetQuery() {
475 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
478 function &getQuery() {
479 return $this->_query
;
483 * name of export file.
485 * @param string $output type of output
487 * @return string name of the file
489 function getExportFileName($output = 'csv') {
490 return ts('Case Search');