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.
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 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
189 public function &links($isDeleted = FALSE, $key = NULL) {
190 $extraParams = ($key) ?
"&key={$key}" : NULL;
193 self
::$_links = array(
194 CRM_Core_Action
::RENEW
=> array(
195 'name' => ts('Restore'),
196 'url' => 'civicrm/contact/view/case',
197 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
198 'ref' => 'restore-case',
199 'title' => ts('Restore Case'),
204 self
::$_links = array(
205 CRM_Core_Action
::VIEW
=> array(
206 'name' => ts('Manage'),
207 'url' => 'civicrm/contact/view/case',
208 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
209 'ref' => 'manage-case',
210 'class' => 'no-popup',
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 'class' => 'medium-popup',
226 'title' => ts('Assign to Another Client'),
231 $actionLinks = array();
232 foreach (self
::$_links as $key => $value) {
233 if ($value['ref'] == 'reassign') {
234 $actionLinks['moreActions'][$key] = $value;
237 $actionLinks['primaryActions'][$key] = $value;
245 * Getter for array of the parameters required for creating pager.
248 * @param array $params
250 public 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';
265 * Returns total number of rows for the query.
270 * Total number of rows
272 public function getTotalCount($action) {
273 return $this->_query
->searchQuery(0, 0, NULL,
277 $this->_additionalClause
282 * Returns all the rows in the given offset and rowCount
284 * @param string $action
285 * The action being performed.
287 * The row number to start from.
288 * @param int $rowCount
289 * The number of rows to return.
290 * @param string $sort
291 * The sql string that describes the sort order.
292 * @param string $output
293 * What should the result set include (web/email/csv).
296 * the total number of rows for this action
298 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
299 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
303 $this->_additionalClause
305 // process the result of the query
308 //CRM-4418 check for view, edit, delete
309 $permissions = array(CRM_Core_Permission
::VIEW
);
310 if (CRM_Core_Permission
::check('access all cases and activities')
311 || CRM_Core_Permission
::check('access my cases and activities')
313 $permissions[] = CRM_Core_Permission
::EDIT
;
315 if (CRM_Core_Permission
::check('delete in CiviCase')) {
316 $permissions[] = CRM_Core_Permission
::DELETE
;
318 $mask = CRM_Core_Action
::mask($permissions);
320 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
322 $scheduledInfo = array();
324 while ($result->fetch()) {
326 // the columns we are interested in
327 foreach (self
::$_properties as $property) {
328 if (isset($result->$property)) {
329 $row[$property] = $result->$property;
334 if ($result->case_deleted
) {
336 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />(deleted)';
339 $scheduledInfo['case_id'][] = $result->case_id
;
340 $scheduledInfo['contact_id'][] = $result->contact_id
;
341 $scheduledInfo['case_deleted'] = $result->case_deleted
;
342 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
344 $links = self
::links($isDeleted, $this->_key
);
345 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
347 'id' => $result->case_id
,
348 'cid' => $result->contact_id
,
349 'cxt' => $this->_context
,
353 'case.selector.actions',
357 $row['moreActions'] = CRM_Core_Action
::formLink(CRM_Utils_Array
::value('moreActions', $links),
359 'id' => $result->case_id
,
360 'cid' => $result->contact_id
,
361 'cxt' => $this->_context
,
365 'case.selector.moreActions',
370 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
373 //adding case manager to case selector.CRM-4510.
374 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
375 $caseManagerContact = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
377 if (!empty($caseManagerContact)) {
378 $row['casemanager_id'] = CRM_Utils_Array
::value('casemanager_id', $caseManagerContact);
379 $row['casemanager'] = CRM_Utils_Array
::value('casemanager', $caseManagerContact);
382 if (isset($result->case_status_id
) &&
383 array_key_exists($result->case_status_id
, $caseStatus)
385 $row['class'] = "status-urgent";
388 $row['class'] = "status-normal";
391 $rows[$result->case_id
] = $row;
394 //retrive the scheduled & recent Activity type and date for selector
395 if (!empty($scheduledInfo)) {
396 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
397 foreach ($schdeduledActivity as $key => $value) {
398 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
399 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
401 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
402 foreach ($recentActivity as $key => $value) {
403 $rows[$key]['case_recent_activity_date'] = $value['date'];
404 $rows[$key]['case_recent_activity_type'] = $value['type'];
413 public function getQILL() {
414 return $this->_query
->qill();
418 * Returns the column headers as an array of tuples:
419 * (name, sortName (key to the sort array))
421 * @param string $action
422 * The action being performed.
423 * @param string $output
424 * What should the result set include (web/email/csv).
427 * the column headers that need to be displayed
429 public function &getColumnHeaders($action = NULL, $output = NULL) {
430 if (!isset(self
::$_columnHeaders)) {
431 self
::$_columnHeaders = array(
433 'name' => ts('Subject'),
434 'direction' => CRM_Utils_Sort
::DONTCARE
,
437 'name' => ts('Status'),
438 'sort' => 'case_status',
439 'direction' => CRM_Utils_Sort
::DONTCARE
,
442 'name' => ts('Case Type'),
443 'sort' => 'case_type',
444 'direction' => CRM_Utils_Sort
::DONTCARE
,
447 'name' => ts('My Role'),
448 'sort' => 'case_role',
449 'direction' => CRM_Utils_Sort
::DONTCARE
,
452 'name' => ts('Case Manager'),
453 'direction' => CRM_Utils_Sort
::DONTCARE
,
456 'name' => ts('Most Recent'),
457 'sort' => 'case_recent_activity_date',
458 'direction' => CRM_Utils_Sort
::DONTCARE
,
461 'name' => ts('Next Sched.'),
462 'sort' => 'case_scheduled_activity_date',
463 'direction' => CRM_Utils_Sort
::DONTCARE
,
465 array('name' => ts('Actions')),
468 if (!$this->_single
) {
471 'name' => ts('Client'),
472 'sort' => 'sort_name',
473 'direction' => CRM_Utils_Sort
::ASCENDING
,
477 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
480 return self
::$_columnHeaders;
486 public function alphabetQuery() {
487 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
493 public function &getQuery() {
494 return $this->_query
;
498 * Name of export file.
500 * @param string $output
506 public function getExportFileName($output = 'csv') {
507 return ts('Case Search');