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 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-2014
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 \const|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 * @param string $context
146 * @return \CRM_Case_Selector_Search
149 function __construct(&$queryParams,
150 $action = CRM_Core_Action
::NONE
,
151 $additionalClause = NULL,
156 // submitted form values
157 $this->_queryParams
= &$queryParams;
159 $this->_single
= $single;
160 $this->_limit
= $limit;
161 $this->_context
= $context;
163 $this->_additionalClause
= $additionalClause;
166 $this->_action
= $action;
168 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
169 CRM_Case_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_CASE
,
173 CRM_Contact_BAO_Query
::MODE_CASE
176 $this->_query
->_distinctComponentClause
= " civicrm_case.id ";
177 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_case.id ";
181 * This method returns the links that are given for each search row.
182 * currently the links added for each row are
187 * @param bool $isDeleted
194 function &links($isDeleted = FALSE, $key = NULL) {
195 $extraParams = ($key) ?
"&key={$key}" : NULL;
198 self
::$_links = array(
199 CRM_Core_Action
::RENEW
=> array(
200 'name' => ts('Restore'),
201 'url' => 'civicrm/contact/view/case',
202 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
203 'ref' => 'restore-case',
204 'title' => ts('Restore Case'),
209 self
::$_links = array(
210 CRM_Core_Action
::VIEW
=> array(
211 'name' => ts('Manage'),
212 'url' => 'civicrm/contact/view/case',
213 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
214 'ref' => 'manage-case',
215 'class' => 'no-popup',
216 'title' => ts('Manage Case'),
218 CRM_Core_Action
::DELETE
=> array(
219 'name' => ts('Delete'),
220 'url' => 'civicrm/contact/view/case',
221 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
222 'ref' => 'delete-case',
223 'title' => ts('Delete Case'),
225 CRM_Core_Action
::UPDATE
=> array(
226 'name' => ts('Assign to Another Client'),
227 'url' => 'civicrm/contact/view/case/editClient',
228 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
230 'class' => 'medium-popup',
231 'title' => ts('Assign to Another Client'),
236 $actionLinks = array();
237 foreach (self
::$_links as $key => $value) {
238 if ($value['ref'] == 'reassign') {
239 $actionLinks['moreActions'][$key] = $value;
242 $actionLinks['primaryActions'][$key] = $value;
250 * getter for array of the parameters required for creating pager.
253 * @param array $params
257 function getPagerParams($action, &$params) {
258 $params['status'] = ts('Case') . ' %%StatusMessage%%';
259 $params['csvString'] = NULL;
261 $params['rowCount'] = $this->_limit
;
264 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
267 $params['buttonTop'] = 'PagerTopButton';
268 $params['buttonBottom'] = 'PagerBottomButton';
272 * Returns total number of rows for the query.
276 * @return int Total number of rows
279 function getTotalCount($action) {
280 return $this->_query
->searchQuery(0, 0, NULL,
284 $this->_additionalClause
289 * returns all the rows in the given offset and rowCount
291 * @param enum $action the action being performed
292 * @param int $offset the row number to start from
293 * @param int $rowCount the number of rows to return
294 * @param string $sort the sql string that describes the sort order
295 * @param enum $output what should the result set include (web/email/csv)
297 * @return int the total number of rows for this action
299 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
300 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
304 $this->_additionalClause
306 // process the result of the query
309 //CRM-4418 check for view, edit, delete
310 $permissions = array(CRM_Core_Permission
::VIEW
);
311 if (CRM_Core_Permission
::check('access all cases and activities')
312 || CRM_Core_Permission
::check('access my cases and activities')
314 $permissions[] = CRM_Core_Permission
::EDIT
;
316 if (CRM_Core_Permission
::check('delete in CiviCase')) {
317 $permissions[] = CRM_Core_Permission
::DELETE
;
319 $mask = CRM_Core_Action
::mask($permissions);
321 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
323 $scheduledInfo = array();
325 while ($result->fetch()) {
327 // the columns we are interested in
328 foreach (self
::$_properties as $property) {
329 if (isset($result->$property)) {
330 $row[$property] = $result->$property;
335 if ($result->case_deleted
) {
337 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />(deleted)';
340 $scheduledInfo['case_id'][] = $result->case_id
;
341 $scheduledInfo['contact_id'][] = $result->contact_id
;
342 $scheduledInfo['case_deleted'] = $result->case_deleted
;
343 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
345 $links = self
::links($isDeleted, $this->_key
);
346 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
348 'id' => $result->case_id
,
349 'cid' => $result->contact_id
,
350 'cxt' => $this->_context
,
354 'case.selector.actions',
358 $row['moreActions'] = CRM_Core_Action
::formLink(CRM_Utils_Array
::value('moreActions', $links),
360 'id' => $result->case_id
,
361 'cid' => $result->contact_id
,
362 'cxt' => $this->_context
,
366 'case.selector.moreActions',
371 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
372 $result->contact_sub_type
: $result->contact_type
375 //adding case manager to case selector.CRM-4510.
376 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
377 $caseManagerContact = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
379 if (!empty($caseManagerContact)) {
380 $row['casemanager_id'] = CRM_Utils_Array
::value('casemanager_id', $caseManagerContact);
381 $row['casemanager'] = CRM_Utils_Array
::value('casemanager', $caseManagerContact);
384 if (isset($result->case_status_id
) &&
385 array_key_exists($result->case_status_id
, $caseStatus)
387 $row['class'] = "status-urgent";
390 $row['class'] = "status-normal";
393 $rows[$result->case_id
] = $row;
396 //retrive the scheduled & recent Activity type and date for selector
397 if (!empty($scheduledInfo)) {
398 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
399 foreach ($schdeduledActivity as $key => $value) {
400 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
401 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
403 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
404 foreach ($recentActivity as $key => $value) {
405 $rows[$key]['case_recent_activity_date'] = $value['date'];
406 $rows[$key]['case_recent_activity_type'] = $value['type'];
413 * @return array $qill which contains an array of strings
417 // the current internationalisation is bad, but should more or less work
418 // for most of "European" languages
419 public function getQILL() {
420 return $this->_query
->qill();
424 * returns the column headers as an array of tuples:
425 * (name, sortName (key to the sort array))
427 * @param string $action the action being performed
428 * @param enum $output what should the result set include (web/email/csv)
430 * @return array the column headers that need to be displayed
433 public function &getColumnHeaders($action = NULL, $output = NULL) {
434 if (!isset(self
::$_columnHeaders)) {
435 self
::$_columnHeaders = array(
437 'name' => ts('Subject'),
438 'direction' => CRM_Utils_Sort
::DONTCARE
,
441 'name' => ts('Status'),
442 'sort' => 'case_status',
443 'direction' => CRM_Utils_Sort
::DONTCARE
,
446 'name' => ts('Case Type'),
447 'sort' => 'case_type',
448 'direction' => CRM_Utils_Sort
::DONTCARE
,
451 'name' => ts('My Role'),
452 'sort' => 'case_role',
453 'direction' => CRM_Utils_Sort
::DONTCARE
,
456 'name' => ts('Case Manager'),
457 'direction' => CRM_Utils_Sort
::DONTCARE
,
460 'name' => ts('Most Recent'),
461 'sort' => 'case_recent_activity_date',
462 'direction' => CRM_Utils_Sort
::DONTCARE
,
465 'name' => ts('Next Sched.'),
466 'sort' => 'case_scheduled_activity_date',
467 'direction' => CRM_Utils_Sort
::DONTCARE
,
469 array('name' => ts('Actions')),
472 if (!$this->_single
) {
475 'name' => ts('Client'),
476 'sort' => 'sort_name',
477 'direction' => CRM_Utils_Sort
::ASCENDING
,
481 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
484 return self
::$_columnHeaders;
490 function alphabetQuery() {
491 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
497 function &getQuery() {
498 return $this->_query
;
502 * name of export file.
504 * @param string $output type of output
506 * @return string name of the file
508 function getExportFileName($output = 'csv') {
509 return ts('Case Search');