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 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
85 protected $_single = FALSE;
88 * Are we restricting ourselves to a single contact
92 protected $_limit = NULL;
95 * What context are we being invoked from
99 protected $_context = NULL;
102 * QueryParams is the array returned by exportValues called on
103 * the HTML_QuickForm_Controller for that page.
107 public $_queryParams;
110 * Represent the type of selector
117 * The additional clause that we restrict the search with
121 protected $_additionalClause = NULL;
133 * @param array $queryParams
134 * Array of parameters for query.
135 * @param \const|int $action - action of search basic or advanced.
136 * @param string $additionalClause
137 * If the caller wants to further restrict the search (used in participations).
138 * @param bool $single
139 * Are we dealing only with one contact?.
141 * How many signers do we want returned.
143 * @param string $context
145 * @return \CRM_Case_Selector_Search
148 function __construct(
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
193 public function &links($isDeleted = FALSE, $key = NULL) {
194 $extraParams = ($key) ?
"&key={$key}" : NULL;
197 self
::$_links = array(
198 CRM_Core_Action
::RENEW
=> array(
199 'name' => ts('Restore'),
200 'url' => 'civicrm/contact/view/case',
201 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
202 'ref' => 'restore-case',
203 'title' => ts('Restore Case'),
208 self
::$_links = array(
209 CRM_Core_Action
::VIEW
=> array(
210 'name' => ts('Manage'),
211 'url' => 'civicrm/contact/view/case',
212 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
213 'ref' => 'manage-case',
214 'class' => 'no-popup',
215 'title' => ts('Manage Case'),
217 CRM_Core_Action
::DELETE
=> array(
218 'name' => ts('Delete'),
219 'url' => 'civicrm/contact/view/case',
220 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
221 'ref' => 'delete-case',
222 'title' => ts('Delete Case'),
224 CRM_Core_Action
::UPDATE
=> array(
225 'name' => ts('Assign to Another Client'),
226 'url' => 'civicrm/contact/view/case/editClient',
227 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
229 'class' => 'medium-popup',
230 'title' => ts('Assign to Another Client'),
235 $actionLinks = array();
236 foreach (self
::$_links as $key => $value) {
237 if ($value['ref'] == 'reassign') {
238 $actionLinks['moreActions'][$key] = $value;
241 $actionLinks['primaryActions'][$key] = $value;
249 * Getter for array of the parameters required for creating pager.
252 * @param array $params
254 public function getPagerParams($action, &$params) {
255 $params['status'] = ts('Case') . ' %%StatusMessage%%';
256 $params['csvString'] = NULL;
258 $params['rowCount'] = $this->_limit
;
261 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
264 $params['buttonTop'] = 'PagerTopButton';
265 $params['buttonBottom'] = 'PagerBottomButton';
269 * Returns total number of rows for the query.
274 * Total number of rows
276 public function getTotalCount($action) {
277 return $this->_query
->searchQuery(0, 0, NULL,
281 $this->_additionalClause
286 * Returns all the rows in the given offset and rowCount
288 * @param string $action
289 * The action being performed.
291 * The row number to start from.
292 * @param int $rowCount
293 * The number of rows to return.
294 * @param string $sort
295 * The sql string that describes the sort order.
296 * @param string $output
297 * What should the result set include (web/email/csv).
300 * the total number of rows for this action
302 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
303 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
307 $this->_additionalClause
309 // process the result of the query
312 //CRM-4418 check for view, edit, delete
313 $permissions = array(CRM_Core_Permission
::VIEW
);
314 if (CRM_Core_Permission
::check('access all cases and activities')
315 || CRM_Core_Permission
::check('access my cases and activities')
317 $permissions[] = CRM_Core_Permission
::EDIT
;
319 if (CRM_Core_Permission
::check('delete in CiviCase')) {
320 $permissions[] = CRM_Core_Permission
::DELETE
;
322 $mask = CRM_Core_Action
::mask($permissions);
324 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
326 $scheduledInfo = array();
328 while ($result->fetch()) {
330 // the columns we are interested in
331 foreach (self
::$_properties as $property) {
332 if (isset($result->$property)) {
333 $row[$property] = $result->$property;
338 if ($result->case_deleted
) {
340 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />(deleted)';
343 $scheduledInfo['case_id'][] = $result->case_id
;
344 $scheduledInfo['contact_id'][] = $result->contact_id
;
345 $scheduledInfo['case_deleted'] = $result->case_deleted
;
346 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
348 $links = self
::links($isDeleted, $this->_key
);
349 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
351 'id' => $result->case_id
,
352 'cid' => $result->contact_id
,
353 'cxt' => $this->_context
,
357 'case.selector.actions',
361 $row['moreActions'] = CRM_Core_Action
::formLink(CRM_Utils_Array
::value('moreActions', $links),
363 'id' => $result->case_id
,
364 'cid' => $result->contact_id
,
365 'cxt' => $this->_context
,
369 'case.selector.moreActions',
374 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
377 //adding case manager to case selector.CRM-4510.
378 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
379 $caseManagerContact = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
381 if (!empty($caseManagerContact)) {
382 $row['casemanager_id'] = CRM_Utils_Array
::value('casemanager_id', $caseManagerContact);
383 $row['casemanager'] = CRM_Utils_Array
::value('casemanager', $caseManagerContact);
386 if (isset($result->case_status_id
) &&
387 array_key_exists($result->case_status_id
, $caseStatus)
389 $row['class'] = "status-urgent";
392 $row['class'] = "status-normal";
395 $rows[$result->case_id
] = $row;
398 //retrive the scheduled & recent Activity type and date for selector
399 if (!empty($scheduledInfo)) {
400 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
401 foreach ($schdeduledActivity as $key => $value) {
402 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
403 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
405 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
406 foreach ($recentActivity as $key => $value) {
407 $rows[$key]['case_recent_activity_date'] = $value['date'];
408 $rows[$key]['case_recent_activity_type'] = $value['type'];
417 public function getQILL() {
418 return $this->_query
->qill();
422 * Returns the column headers as an array of tuples:
423 * (name, sortName (key to the sort array))
425 * @param string $action
426 * The action being performed.
427 * @param string $output
428 * What should the result set include (web/email/csv).
431 * 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 public function alphabetQuery() {
491 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
497 public function &getQuery() {
498 return $this->_query
;
502 * Name of export file.
504 * @param string $output
510 public function getExportFileName($output = 'csv') {
511 return ts('Case Search');