/** * Retrieve cases related to particular contact or whole contact * used in Dashboad and Tab * * @param boolean $allCases * * @param int $userID * * @param String $type /upcoming,recent,all/ * * @param string $context * * @return array Array of Cases * * @access public */ static function getCases($allCases = TRUE, $userID = NULL, $type = 'upcoming', $context = 'dashboard') { $condition = NULL; $casesList = array(); //validate access for own cases. if (!self::accessCiviCase()) { return $casesList; } if (!$userID) { $session = CRM_Core_Session::singleton(); $userID = $session->get('userID'); } //validate access for all cases. if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) { $allCases = FALSE; } $condition = " AND civicrm_case.is_deleted = 0 "; if (!$allCases) { $condition .= " AND case_relationship.contact_id_b = {$userID} "; } if ($type == 'upcoming' || $type == 'any') { $closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name'); $condition .= "\nAND civicrm_case.status_id != {$closedId}"; } $query = self::getCaseActivityQuery($type, $userID, $condition); $queryParams = array(); $result = CRM_Core_DAO::executeQuery($query, $queryParams); $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' "); $resultFields = array('contact_id', 'contact_type', 'sort_name', 'phone', 'case_id', 'case_subject', 'case_type', 'case_type_id', 'status_id', 'case_status', 'case_status_name', 'activity_type_id', 'case_start_date', 'case_role'); if ($type == 'upcoming') { $resultFields[] = 'case_scheduled_activity_date'; $resultFields[] = 'case_scheduled_activity_type_name'; $resultFields[] = 'case_scheduled_activity_type'; $resultFields[] = 'case_scheduled_activity_id'; } elseif ($type == 'recent') { $resultFields[] = 'case_recent_activity_date'; $resultFields[] = 'case_recent_activity_type_name'; $resultFields[] = 'case_recent_activity_type'; $resultFields[] = 'case_recent_activity_id'; } elseif ($type == 'any') { $resultFields[] = 'case_activity_date'; $resultFields[] = 'case_activity_type_name'; $resultFields[] = 'case_activity_type'; $resultFields[] = 'case_activity_id'; } // we're going to use the usual actions, so doesn't make sense to duplicate definitions $actions = CRM_Case_Selector_Search::links(); // check is the user has view/edit signer permission $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('access all cases and activities') || !$allCases && CRM_Core_Permission::check('access my cases and activities')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviCase')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); while ($result->fetch()) { foreach ($resultFields as $donCare => $field) { $casesList[$result->case_id][$field] = $result->{$field}; if ($field == 'contact_type') { $casesList[$result->case_id]['contact_type_icon'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type); $casesList[$result->case_id]['action'] = CRM_Core_Action::formLink($actions['primaryActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $context), ts('more'), FALSE, 'case.actions.primary', 'Case', $result->case_id); $casesList[$result->case_id]['moreActions'] = CRM_Core_Action::formLink($actions['moreActions'], $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => $context), ts('more'), TRUE, 'case.actions.more', 'Case', $result->case_id); } elseif ($field == 'case_status') { if (in_array($result->{$field}, $caseStatus)) { $casesList[$result->case_id]['class'] = "status-urgent"; } else { $casesList[$result->case_id]['class'] = "status-normal"; } } } //CRM-4510. $caseTypes = CRM_Case_PseudoConstant::caseType('name'); $caseManagerContact = self::getCaseManagerContact($caseTypes[$result->case_type_id], $result->case_id); if (!empty($caseManagerContact)) { $casesList[$result->case_id]['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact); $casesList[$result->case_id]['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact); } //do check user permissions for edit/view activity. if (($actId = CRM_Utils_Array::value('case_scheduled_activity_id', $casesList[$result->case_id])) || ($actId = CRM_Utils_Array::value('case_recent_activity_id', $casesList[$result->case_id]))) { $casesList[$result->case_id]["case_{$type}_activity_editable"] = self::checkPermission($actId, 'edit', $casesList[$result->case_id]['activity_type_id'], $userID); $casesList[$result->case_id]["case_{$type}_activity_viewable"] = self::checkPermission($actId, 'view', $casesList[$result->case_id]['activity_type_id'], $userID); } } return $casesList; }
/** * Returns the column headers as an array of tuples: * (name, sortName (key to the sort array)) * * @param string $action * The action being performed. * @param string $output * What should the result set include (web/email/csv). * * @return array * the column headers that need to be displayed */ public function &getColumnHeaders($action = NULL, $output = NULL) { if (!isset(self::$_columnHeaders)) { self::$_columnHeaders = array(array('name' => ts('Subject'), 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Status'), 'sort' => 'case_status', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Case Type'), 'sort' => 'case_type', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('My Role'), 'sort' => 'case_role', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Case Manager'), 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Most Recent'), 'sort' => 'case_recent_activity_date', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Next Sched.'), 'sort' => 'case_scheduled_activity_date', 'direction' => CRM_Utils_Sort::DONTCARE), array('name' => ts('Actions'))); if (!$this->_single) { $pre = array(array('name' => ts('Client'), 'sort' => 'sort_name', 'direction' => CRM_Utils_Sort::ASCENDING)); self::$_columnHeaders = array_merge($pre, self::$_columnHeaders); } } return self::$_columnHeaders; }
/** * The post processing of the form gets done here. * * Key things done during post processing are * - check for reset or next request. if present, skip post procesing. * - now check if user requested running a saved search, if so, then * the form values associated with the saved search are used for searching. * - if user has done a submit with new values the regular post submissing is * done. * The processing consists of using a Selector / Controller framework for getting the * search results. */ public function postProcess() { if ($this->_done) { return; } $this->_done = TRUE; $this->_formValues = $this->controller->exportValues($this->_name); $this->fixFormValues(); if (isset($this->_ssID) && empty($_POST)) { // if we are editing / running a saved search and the form has not been posted $this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID); } //search for civicase if (!$this->_force) { if (array_key_exists('case_owner', $this->_formValues) && !$this->_formValues['case_owner']) { $this->_formValues['case_owner'] = 0; } } if (empty($this->_formValues['case_deleted'])) { $this->_formValues['case_deleted'] = 0; } CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues); $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $this->set('formValues', $this->_formValues); $this->set('queryParams', $this->_queryParams); $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->_actionButtonName) { // check actionName and if next, then do not repeat a search, since we are going to the next page // hack, make sure we reset the task values $stateMachine = $this->controller->getStateMachine(); $formName = $stateMachine->getTaskFormName(); $this->controller->resetPage($formName); return; } $sortID = NULL; if ($this->get(CRM_Utils_Sort::SORT_ID)) { $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID), $this->get(CRM_Utils_Sort::SORT_DIRECTION)); } $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues); $selector = new CRM_Case_Selector_Search($this->_queryParams, $this->_action, NULL, $this->_single, $this->_limit, $this->_context); $selector->setKey($this->controller->_key); $prefix = NULL; if ($this->_context == 'user') { $prefix = $this->_prefix; } $this->assign("{$prefix}limit", $this->_limit); $this->assign("{$prefix}single", $this->_single); $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $sortID, CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::SESSION, $prefix); $controller->setEmbedded(TRUE); $query =& $selector->getQuery(); if ($this->_context == 'user') { $query->setSkipPermission(TRUE); } $controller->run(); }
/** * Retrieve cases related to particular contact or whole contact * used in Dashboad and Tab * * @param boolean $allCases * * @param int $userID * * @param String $type /upcoming,recent,all/ * * @return array Array of Cases * * @access public * */ function getCases($allCases = true, $userID = null, $type = 'upcoming') { $condition = null; if (!$allCases) { $condition = " AND case_relationship.contact_id_b = {$userID}"; } $condition .= " \nAND civicrm_activity.is_deleted = 0\nAND civicrm_case.is_deleted = 0"; if ($type == 'upcoming') { $closedId = CRM_Core_OptionGroup::getValue('case_status', 'Closed', 'name'); $condition .= "\nAND civicrm_case.status_id != {$closedId}"; } $query = self::getCaseActivityQuery($type, $userID, $condition); $queryParams = array(); $result = CRM_Core_DAO::executeQuery($query, $queryParams); require_once 'CRM/Core/OptionGroup.php'; $caseStatus = CRM_Core_OptionGroup::values('case_status', false, false, false, " AND v.name = 'Urgent' "); $resultFields = array('contact_id', 'contact_type', 'sort_name', 'phone', 'case_id', 'case_type', 'case_type_name', 'status_id', 'case_status', 'case_status_name', 'activity_type_id', 'case_role'); if ($type == 'upcoming') { $resultFields[] = 'case_scheduled_activity_date'; $resultFields[] = 'case_scheduled_activity_type_name'; $resultFields[] = 'case_scheduled_activity_type'; $resultFields[] = 'case_scheduled_activity_id'; } else { if ($type == 'recent') { $resultFields[] = 'case_recent_activity_date'; $resultFields[] = 'case_recent_activity_type_name'; $resultFields[] = 'case_recent_activity_type'; $resultFields[] = 'case_recent_activity_id'; } } // we're going to use the usual actions, so doesn't make sense to duplicate definitions require_once 'CRM/Case/Selector/Search.php'; $actions = CRM_Case_Selector_Search::links(); require_once "CRM/Contact/BAO/Contact/Utils.php"; $casesList = array(); // check is the user has view/edit signer permission $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit cases')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviCase')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); while ($result->fetch()) { foreach ($resultFields as $donCare => $field) { $casesList[$result->case_id][$field] = $result->{$field}; if ($field == 'contact_type') { $casesList[$result->case_id]['contact_type_icon'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type); $casesList[$result->case_id]['action'] = CRM_Core_Action::formLink($actions, $mask, array('id' => $result->case_id, 'cid' => $result->contact_id, 'cxt' => 'dashboard')); } elseif ($field == 'case_status') { if (in_array($result->{$field}, $caseStatus)) { $casesList[$result->case_id]['class'] = "status-urgent"; } else { $casesList[$result->case_id]['class'] = "status-normal"; } } } //CRM-4510. $caseManagerContact = self::getCaseManagerContact($result->case_type_name, $result->case_id); if (!empty($caseManagerContact)) { $casesList[$result->case_id]['casemanager_id'] = CRM_Utils_Array::value('casemanager_id', $caseManagerContact); $casesList[$result->case_id]['casemanager'] = CRM_Utils_Array::value('casemanager', $caseManagerContact); } } return $casesList; }