3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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.
49 static $_links = NULL;
52 * We use desc to remind us what that column is, name is used in the tpl
56 static $_columnHeaders;
59 * Properties of contact we're interested in displaying
62 static $_properties = array(
78 * Are we restricting ourselves to a single contact
82 protected $_single = FALSE;
85 * Are we restricting ourselves to a single contact
89 protected $_limit = NULL;
92 * What context are we being invoked from
96 protected $_context = NULL;
99 * QueryParams is the array returned by exportValues called on
100 * the HTML_QuickForm_Controller for that page.
104 public $_queryParams;
107 * Represent the type of selector
114 * The additional clause that we restrict the search with
118 protected $_additionalClause = NULL;
130 * @param array $queryParams
131 * Array of parameters for query.
132 * @param \const|int $action - action of search basic or advanced.
133 * @param string $additionalClause
134 * If the caller wants to further restrict the search (used in participations).
135 * @param bool $single
136 * Are we dealing only with one contact?.
138 * How many signers do we want returned.
140 * @param string $context
142 * @return \CRM_Case_Selector_Search
144 public function __construct(
146 $action = CRM_Core_Action
::NONE
,
147 $additionalClause = NULL,
152 // submitted form values
153 $this->_queryParams
= &$queryParams;
155 $this->_single
= $single;
156 $this->_limit
= $limit;
157 $this->_context
= $context;
159 $this->_additionalClause
= $additionalClause;
162 $this->_action
= $action;
164 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
165 CRM_Case_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_CASE
,
169 CRM_Contact_BAO_Query
::MODE_CASE
172 $this->_query
->_distinctComponentClause
= " civicrm_case.id ";
173 $this->_query
->_groupByComponentClause
= " GROUP BY civicrm_case.id ";
177 * This method returns the links that are given for each search row.
178 * currently the links added for each row are
183 * @param bool $isDeleted
188 static public function &links($isDeleted = FALSE, $key = NULL) {
189 $extraParams = ($key) ?
"&key={$key}" : NULL;
192 self
::$_links = array(
193 CRM_Core_Action
::RENEW
=> array(
194 'name' => ts('Restore'),
195 'url' => 'civicrm/contact/view/case',
196 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
197 'ref' => 'restore-case',
198 'title' => ts('Restore Case'),
203 self
::$_links = array(
204 CRM_Core_Action
::VIEW
=> array(
205 'name' => ts('Manage'),
206 'url' => 'civicrm/contact/view/case',
207 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
208 'ref' => 'manage-case',
209 'class' => 'no-popup',
210 'title' => ts('Manage Case'),
212 CRM_Core_Action
::DELETE
=> array(
213 'name' => ts('Delete'),
214 'url' => 'civicrm/contact/view/case',
215 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
216 'ref' => 'delete-case',
217 'title' => ts('Delete Case'),
219 CRM_Core_Action
::UPDATE
=> array(
220 'name' => ts('Assign to Another Client'),
221 'url' => 'civicrm/contact/view/case/editClient',
222 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
224 'class' => 'medium-popup',
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;
244 * Getter for array of the parameters required for creating pager.
247 * @param array $params
249 public function getPagerParams($action, &$params) {
250 $params['status'] = ts('Case') . ' %%StatusMessage%%';
251 $params['csvString'] = NULL;
253 $params['rowCount'] = $this->_limit
;
256 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
259 $params['buttonTop'] = 'PagerTopButton';
260 $params['buttonBottom'] = 'PagerBottomButton';
264 * Returns total number of rows for the query.
269 * Total number of rows
271 public function getTotalCount($action) {
272 return $this->_query
->searchQuery(0, 0, NULL,
276 $this->_additionalClause
281 * Returns all the rows in the given offset and rowCount.
283 * @param string $action
284 * The action being performed.
286 * The row number to start from.
287 * @param int $rowCount
288 * The number of rows to return.
289 * @param string $sort
290 * The sql string that describes the sort order.
291 * @param string $output
292 * What should the result set include (web/email/csv).
295 * the total number of rows for this action
297 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
298 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
302 $this->_additionalClause
304 // process the result of the query
307 //CRM-4418 check for view, edit, delete
308 $permissions = array(CRM_Core_Permission
::VIEW
);
309 if (CRM_Core_Permission
::check('access all cases and activities')
310 || CRM_Core_Permission
::check('access my cases and activities')
312 $permissions[] = CRM_Core_Permission
::EDIT
;
314 if (CRM_Core_Permission
::check('delete in CiviCase')) {
315 $permissions[] = CRM_Core_Permission
::DELETE
;
317 $mask = CRM_Core_Action
::mask($permissions);
319 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
321 $scheduledInfo = array();
323 while ($result->fetch()) {
325 // the columns we are interested in
326 foreach (self
::$_properties as $property) {
327 if (isset($result->$property)) {
328 $row[$property] = $result->$property;
333 if ($result->case_deleted
) {
335 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />(deleted)';
338 $scheduledInfo['case_id'][] = $result->case_id
;
339 $scheduledInfo['contact_id'][] = $result->contact_id
;
340 $scheduledInfo['case_deleted'] = $result->case_deleted
;
341 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
343 $links = self
::links($isDeleted, $this->_key
);
344 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
346 'id' => $result->case_id
,
347 'cid' => $result->contact_id
,
348 'cxt' => $this->_context
,
352 'case.selector.actions',
356 $row['moreActions'] = CRM_Core_Action
::formLink(CRM_Utils_Array
::value('moreActions', $links),
358 'id' => $result->case_id
,
359 'cid' => $result->contact_id
,
360 'cxt' => $this->_context
,
364 'case.selector.moreActions',
369 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
372 //adding case manager to case selector.CRM-4510.
373 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
374 $caseManagerContact = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
376 if (!empty($caseManagerContact)) {
377 $row['casemanager_id'] = CRM_Utils_Array
::value('casemanager_id', $caseManagerContact);
378 $row['casemanager'] = CRM_Utils_Array
::value('casemanager', $caseManagerContact);
381 if (isset($result->case_status_id
) &&
382 array_key_exists($result->case_status_id
, $caseStatus)
384 $row['class'] = "status-urgent";
387 $row['class'] = "status-normal";
390 $rows[$result->case_id
] = $row;
393 //retrive the scheduled & recent Activity type and date for selector
394 if (!empty($scheduledInfo)) {
395 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
396 foreach ($schdeduledActivity as $key => $value) {
397 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
398 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
400 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
401 foreach ($recentActivity as $key => $value) {
402 $rows[$key]['case_recent_activity_date'] = $value['date'];
403 $rows[$key]['case_recent_activity_type'] = $value['type'];
412 public function getQILL() {
413 return $this->_query
->qill();
417 * Returns the column headers as an array of tuples:
418 * (name, sortName (key to the sort array))
420 * @param string $action
421 * The action being performed.
422 * @param string $output
423 * What should the result set include (web/email/csv).
426 * the column headers that need to be displayed
428 public function &getColumnHeaders($action = NULL, $output = NULL) {
429 if (!isset(self
::$_columnHeaders)) {
430 self
::$_columnHeaders = array(
432 'name' => ts('Subject'),
433 'direction' => CRM_Utils_Sort
::DONTCARE
,
436 'name' => ts('Status'),
437 'sort' => 'case_status',
438 'direction' => CRM_Utils_Sort
::DONTCARE
,
441 'name' => ts('Case Type'),
442 'sort' => 'case_type',
443 'direction' => CRM_Utils_Sort
::DONTCARE
,
446 'name' => ts('My Role'),
447 'sort' => 'case_role',
448 'direction' => CRM_Utils_Sort
::DONTCARE
,
451 'name' => ts('Case Manager'),
452 'direction' => CRM_Utils_Sort
::DONTCARE
,
455 'name' => ts('Most Recent'),
456 'sort' => 'case_recent_activity_date',
457 'direction' => CRM_Utils_Sort
::DONTCARE
,
460 'name' => ts('Next Sched.'),
461 'sort' => 'case_scheduled_activity_date',
462 'direction' => CRM_Utils_Sort
::DONTCARE
,
464 array('name' => ts('Actions')),
467 if (!$this->_single
) {
470 'name' => ts('Client'),
471 'sort' => 'sort_name',
472 'direction' => CRM_Utils_Sort
::ASCENDING
,
476 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
479 return self
::$_columnHeaders;
485 public function alphabetQuery() {
486 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
492 public function &getQuery() {
493 return $this->_query
;
497 * Name of export file.
499 * @param string $output
505 public function getExportFileName($output = 'csv') {
506 return ts('Case Search');