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 ";
182 * This method returns the links that are given for each search row.
183 * currently the links added for each row are
188 * @param bool $isDeleted
195 function &links($isDeleted = FALSE, $key = NULL) {
196 $extraParams = ($key) ?
"&key={$key}" : NULL;
199 self
::$_links = array(
200 CRM_Core_Action
::RENEW
=> array(
201 'name' => ts('Restore'),
202 'url' => 'civicrm/contact/view/case',
203 'qs' => 'reset=1&action=renew&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
204 'ref' => 'restore-case',
205 'title' => ts('Restore Case'),
210 self
::$_links = array(
211 CRM_Core_Action
::VIEW
=> array(
212 'name' => ts('Manage'),
213 'url' => 'civicrm/contact/view/case',
214 'qs' => 'reset=1&id=%%id%%&cid=%%cid%%&action=view&context=%%cxt%%&selectedChild=case' . $extraParams,
215 'ref' => 'manage-case',
216 'class' => 'no-popup',
217 'title' => ts('Manage Case'),
219 CRM_Core_Action
::DELETE
=> array(
220 'name' => ts('Delete'),
221 'url' => 'civicrm/contact/view/case',
222 'qs' => 'reset=1&action=delete&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
223 'ref' => 'delete-case',
224 'title' => ts('Delete Case'),
226 CRM_Core_Action
::UPDATE
=> array(
227 'name' => ts('Assign to Another Client'),
228 'url' => 'civicrm/contact/view/case/editClient',
229 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%' . $extraParams,
231 'class' => 'medium-popup',
232 'title' => ts('Assign to Another Client'),
237 $actionLinks = array();
238 foreach (self
::$_links as $key => $value) {
239 if ($value['ref'] == 'reassign') {
240 $actionLinks['moreActions'][$key] = $value;
243 $actionLinks['primaryActions'][$key] = $value;
252 * getter for array of the parameters required for creating pager.
260 function getPagerParams($action, &$params) {
261 $params['status'] = ts('Case') . ' %%StatusMessage%%';
262 $params['csvString'] = NULL;
264 $params['rowCount'] = $this->_limit
;
267 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
270 $params['buttonTop'] = 'PagerTopButton';
271 $params['buttonBottom'] = 'PagerBottomButton';
276 * Returns total number of rows for the query.
280 * @return int Total number of rows
283 function getTotalCount($action) {
284 return $this->_query
->searchQuery(0, 0, NULL,
288 $this->_additionalClause
293 * returns all the rows in the given offset and rowCount
295 * @param enum $action the action being performed
296 * @param int $offset the row number to start from
297 * @param int $rowCount the number of rows to return
298 * @param string $sort the sql string that describes the sort order
299 * @param enum $output what should the result set include (web/email/csv)
301 * @return int the total number of rows for this action
303 function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
304 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
308 $this->_additionalClause
310 // process the result of the query
313 //CRM-4418 check for view, edit, delete
314 $permissions = array(CRM_Core_Permission
::VIEW
);
315 if (CRM_Core_Permission
::check('access all cases and activities')
316 || CRM_Core_Permission
::check('access my cases and activities')
318 $permissions[] = CRM_Core_Permission
::EDIT
;
320 if (CRM_Core_Permission
::check('delete in CiviCase')) {
321 $permissions[] = CRM_Core_Permission
::DELETE
;
323 $mask = CRM_Core_Action
::mask($permissions);
325 $caseStatus = CRM_Core_OptionGroup
::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' ");
327 $scheduledInfo = array();
329 while ($result->fetch()) {
331 // the columns we are interested in
332 foreach (self
::$_properties as $property) {
333 if (isset($result->$property)) {
334 $row[$property] = $result->$property;
339 if ($result->case_deleted
) {
341 $row['case_status_id'] = empty($row['case_status_id']) ?
"" : $row['case_status_id'] . '<br />(deleted)';
344 $scheduledInfo['case_id'][] = $result->case_id
;
345 $scheduledInfo['contact_id'][] = $result->contact_id
;
346 $scheduledInfo['case_deleted'] = $result->case_deleted
;
347 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->case_id
;
349 $links = self
::links($isDeleted, $this->_key
);
350 $row['action'] = CRM_Core_Action
::formLink($links['primaryActions'],
352 'id' => $result->case_id
,
353 'cid' => $result->contact_id
,
354 'cxt' => $this->_context
,
358 'case.selector.actions',
362 $row['moreActions'] = CRM_Core_Action
::formLink(CRM_Utils_Array
::value('moreActions', $links),
364 'id' => $result->case_id
,
365 'cid' => $result->contact_id
,
366 'cxt' => $this->_context
,
370 'case.selector.moreActions',
375 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
376 $result->contact_sub_type
: $result->contact_type
379 //adding case manager to case selector.CRM-4510.
380 $caseType = CRM_Case_BAO_Case
::getCaseType($result->case_id
, 'name');
381 $caseManagerContact = CRM_Case_BAO_Case
::getCaseManagerContact($caseType, $result->case_id
);
383 if (!empty($caseManagerContact)) {
384 $row['casemanager_id'] = CRM_Utils_Array
::value('casemanager_id', $caseManagerContact);
385 $row['casemanager'] = CRM_Utils_Array
::value('casemanager', $caseManagerContact);
388 if (isset($result->case_status_id
) &&
389 array_key_exists($result->case_status_id
, $caseStatus)
391 $row['class'] = "status-urgent";
394 $row['class'] = "status-normal";
397 $rows[$result->case_id
] = $row;
400 //retrive the scheduled & recent Activity type and date for selector
401 if (!empty($scheduledInfo)) {
402 $schdeduledActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'upcoming');
403 foreach ($schdeduledActivity as $key => $value) {
404 $rows[$key]['case_scheduled_activity_date'] = $value['date'];
405 $rows[$key]['case_scheduled_activity_type'] = $value['type'];
407 $recentActivity = CRM_Case_BAO_Case
::getNextScheduledActivity($scheduledInfo, 'recent');
408 foreach ($recentActivity as $key => $value) {
409 $rows[$key]['case_recent_activity_date'] = $value['date'];
410 $rows[$key]['case_recent_activity_type'] = $value['type'];
418 * @return array $qill which contains an array of strings
422 // the current internationalisation is bad, but should more or less work
423 // for most of "European" languages
424 public function getQILL() {
425 return $this->_query
->qill();
429 * returns the column headers as an array of tuples:
430 * (name, sortName (key to the sort array))
432 * @param string $action the action being performed
433 * @param enum $output what should the result set include (web/email/csv)
435 * @return array the column headers that need to be displayed
438 public function &getColumnHeaders($action = NULL, $output = NULL) {
439 if (!isset(self
::$_columnHeaders)) {
440 self
::$_columnHeaders = array(
442 'name' => ts('Subject'),
443 'direction' => CRM_Utils_Sort
::DONTCARE
,
446 'name' => ts('Status'),
447 'sort' => 'case_status',
448 'direction' => CRM_Utils_Sort
::DONTCARE
,
451 'name' => ts('Case Type'),
452 'sort' => 'case_type_id',
453 'direction' => CRM_Utils_Sort
::DONTCARE
,
456 'name' => ts('My Role'),
457 'sort' => 'case_role',
458 'direction' => CRM_Utils_Sort
::DONTCARE
,
461 'name' => ts('Case Manager'),
462 'direction' => CRM_Utils_Sort
::DONTCARE
,
465 'name' => ts('Most Recent'),
466 'sort' => 'case_recent_activity_date',
467 'direction' => CRM_Utils_Sort
::DONTCARE
,
470 'name' => ts('Next Sched.'),
471 'sort' => 'case_scheduled_activity_date',
472 'direction' => CRM_Utils_Sort
::DONTCARE
,
474 array('name' => ts('Actions')),
477 if (!$this->_single
) {
480 'name' => ts('Client'),
481 'sort' => 'sort_name',
482 'direction' => CRM_Utils_Sort
::ASCENDING
,
486 self
::$_columnHeaders = array_merge($pre, self
::$_columnHeaders);
489 return self
::$_columnHeaders;
495 function alphabetQuery() {
496 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
502 function &getQuery() {
503 return $this->_query
;
507 * name of export file.
509 * @param string $output type of output
511 * @return string name of the file
513 function getExportFileName($output = 'csv') {
514 return ts('Case Search');