3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
35 * This class is used to retrieve and display a range of contacts that match the given criteria.
37 class CRM_Case_Selector_Search
extends CRM_Core_Selector_Base
{
40 * This defines two actions- View and Edit.
44 public static $_links = NULL;
47 * We use desc to remind us what that column is, name is used in the tpl
51 public static $_columnHeaders;
54 * Properties of contact we're interested in displaying
57 public static $_properties = [
73 * Are we restricting ourselves to a single contact
77 protected $_single = FALSE;
80 * Are we restricting ourselves to a single contact
84 protected $_limit = NULL;
87 * What context are we being invoked from
91 protected $_context = NULL;
94 * QueryParams is the array returned by exportValues called on
95 * the HTML_QuickForm_Controller for that page.
102 * Represent the type of selector
109 * The additional clause that we restrict the search with
113 protected $_additionalClause = NULL;
125 * @param array $queryParams
126 * Array of parameters for query.
127 * @param \const|int $action - action of search basic or advanced.
128 * @param string $additionalClause
129 * If the caller wants to further restrict the search (used in participations).
130 * @param bool $single
131 * Are we dealing only with one contact?.
133 * How many signers do we want returned.
135 * @param string $context
137 * @return \CRM_Case_Selector_Search
139 public function __construct(
141 $action = CRM_Core_Action
::NONE
,
142 $additionalClause = NULL,
147 // submitted form values
148 $this->_queryParams
= &$queryParams;
150 $this->_single
= $single;
151 $this->_limit
= $limit;
152 $this->_context
= $context;
154 $this->_additionalClause
= $additionalClause;
157 $this->_action
= $action;
159 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
160 CRM_Case_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_CASE
,
164 CRM_Contact_BAO_Query
::MODE_CASE
167 $this->_query
->_distinctComponentClause
= " civicrm_case.id ";
168 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_case.id ";
172 * This method returns the links that are given for each search row.
173 * currently the links added for each row are
178 * @param bool $isDeleted
183 public static function &links($isDeleted = FALSE, $key = NULL) {
184 $extraParams = ($key) ?
"&key={$key}" : NULL;
188 CRM_Core_Action
::RENEW
=> [
189 'name' => ts('Restore'),
190 'url' => 'civicrm/contact/view/case',
191 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
192 'ref' => 'restore-case',
193 'title' => ts('Restore Case'),
199 CRM_Core_Action
::VIEW
=> [
200 'name' => ts('Manage'),
201 'url' => 'civicrm/contact/view/case',
202 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
203 'ref' => 'manage-case',
204 'class' => 'no-popup',
205 'title' => ts('Manage Case'),
207 CRM_Core_Action
::DELETE
=> [
208 'name' => ts('Delete'),
209 'url' => 'civicrm/contact/view/case',
210 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
211 'ref' => 'delete-case',
212 'title' => ts('Delete Case'),
214 CRM_Core_Action
::UPDATE
=> [
215 'name' => ts('Assign to Another Client'),
216 'url' => 'civicrm/contact/view/case/editClient',
217 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
219 'class' => 'medium-popup',
220 'title' => ts('Assign to Another Client'),
226 foreach (self
::$_links as $key => $value) {
227 $actionLinks['primaryActions'][$key] = $value;
234 * Getter for array of the parameters required for creating pager.
237 * @param array $params
239 public function getPagerParams($action, &$params) {
240 $params['status'] = ts('Case') . ' %%StatusMessage%%';
241 $params['csvString'] = NULL;
243 $params['rowCount'] = $this->_limit
;
246 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
249 $params['buttonTop'] = 'PagerTopButton';
250 $params['buttonBottom'] = 'PagerBottomButton';
254 * Returns total number of rows for the query.
259 * Total number of rows
261 public function getTotalCount($action) {
262 return $this->_query
->searchQuery(0, 0, NULL,
266 $this->_additionalClause
271 * Returns all the rows in the given offset and rowCount.
273 * @param string $action
274 * The action being performed.
276 * The row number to start from.
277 * @param int $rowCount
278 * The number of rows to return.
279 * @param string $sort
280 * The sql string that describes the sort order.
281 * @param string $output
282 * What should the result set include (web/email/csv).
285 * the total number of rows for this action
287 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
288 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
292 $this->_additionalClause
294 // process the result of the query
297 //CRM-4418 check for view, edit, delete
298 $permissions = [CRM_Core_Permission
::VIEW
];
299 if (CRM_Core_Permission
::check('access all cases and activities')
300 || CRM_Core_Permission
::check('access my cases and activities')
302 $permissions[] = CRM_Core_Permission
::EDIT
;
304 if (CRM_Core_Permission
::check('delete in CiviCase')) {
305 $permissions[] = CRM_Core_Permission
::DELETE
;
307 $mask = CRM_Core_Action
::mask($permissions);
309 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
313 while ($result->fetch()) {
315 // the columns we are interested in
316 foreach (self
::$_properties as $property) {
317 if (isset($result->$property)) {
318 $row[$property] = $result->$property;
323 if ($result->case_deleted
) {
325 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />' . ts('(deleted)');
328 $scheduledInfo['case_id'][] = $result->case_id
;
329 $scheduledInfo['contact_id'][] = $result->contact_id
;
330 $scheduledInfo['case_deleted'] = $result->case_deleted
;
331 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
333 $links = self
::links($isDeleted, $this->_key
);
334 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
336 'id' => $result->case_id
,
337 'cid' => $result->contact_id
,
338 'cxt' => $this->_context
,
342 'case.selector.actions',
347 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
350 //adding case manager to case selector.CRM-4510.
351 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
352 $row['casemanager'] = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
354 if (isset($result->case_status_id
) &&
355 array_key_exists($result->case_status_id
, $caseStatus)
357 $row['class'] = "status-urgent";
360 $row['class'] = "status-normal";
363 $rows[$result->case_id
] = $row;
366 //retrive the scheduled & recent Activity type and date for selector
367 if (!empty($scheduledInfo)) {
368 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
369 foreach ($schdeduledActivity as $key => $value) {
370 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
371 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
373 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
374 foreach ($recentActivity as $key => $value) {
375 $rows[$key]['case_recent_activity_date'] = $value['date'];
376 $rows[$key]['case_recent_activity_type'] = $value['type'];
385 public function getQILL() {
386 return $this->_query
->qill();
390 * Returns the column headers as an array of tuples:
391 * (name, sortName (key to the sort array))
393 * @param string $action
394 * The action being performed.
395 * @param string $output
396 * What should the result set include (web/email/csv).
399 * the column headers that need to be displayed
401 public function &getColumnHeaders($action = NULL, $output = NULL) {
402 if (!isset(self
::$_columnHeaders)) {
403 self
::$_columnHeaders = [
405 'name' => ts('Subject'),
406 'direction' => CRM_Utils_Sort
::DONTCARE
,
409 'name' => ts('Status'),
410 'sort' => 'case_status',
411 'direction' => CRM_Utils_Sort
::DONTCARE
,
414 'name' => ts('Case Type'),
415 'sort' => 'case_type',
416 'direction' => CRM_Utils_Sort
::DONTCARE
,
419 'name' => ts('My Role'),
420 'sort' => 'case_role',
421 'direction' => CRM_Utils_Sort
::DONTCARE
,
424 'name' => ts('Case Manager'),
425 'direction' => CRM_Utils_Sort
::DONTCARE
,
428 'name' => ts('Most Recent'),
429 'sort' => 'case_recent_activity_date',
430 'direction' => CRM_Utils_Sort
::DONTCARE
,
433 'name' => ts('Next Sched.'),
434 'sort' => 'case_scheduled_activity_date',
435 'direction' => CRM_Utils_Sort
::DONTCARE
,
437 ['name' => ts('Actions')],
440 if (!$this->_single
) {
443 'name' => ts('Client'),
444 'sort' => 'sort_name',
445 'direction' => CRM_Utils_Sort
::ASCENDING
,
449 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
452 return self
::$_columnHeaders;
458 public function alphabetQuery() {
459 return $this->_query
->alphabetQuery();
465 public function &getQuery() {
466 return $this->_query
;
470 * Name of export file.
472 * @param string $output
478 public function getExportFileName($output = 'csv') {
479 return ts('Case Search');