From 5f1c8c57201c5ac91878aa9a7f722dfd28b6aede Mon Sep 17 00:00:00 2001 From: "deb.monish" Date: Tue, 21 Nov 2017 18:56:55 +0530 Subject: [PATCH] CRM-21461: Case Dashlet enhancement --- CRM/Case/BAO/Case.php | 343 ++++++++++-------- CRM/Case/BAO/Query.php | 8 +- CRM/Case/Form/Activity.php | 4 +- CRM/Case/Page/AJAX.php | 26 ++ CRM/Case/Page/DashBoard.php | 30 +- CRM/Case/Page/Tab.php | 3 +- CRM/Case/xml/Menu/Case.xml | 4 + CRM/Dashlet/Page/AllCases.php | 15 +- CRM/Dashlet/Page/CaseDashboard.php | 5 +- CRM/Dashlet/Page/MyCases.php | 15 +- css/civicrm.css | 5 - templates/CRM/Case/Form/CaseFilter.tpl | 51 +++ templates/CRM/Case/Page/DashBoard.tpl | 22 +- templates/CRM/Case/Page/DashboardSelector.tpl | 105 ++---- templates/CRM/Dashlet/Page/AllCases.tpl | 9 +- templates/CRM/Dashlet/Page/MyCases.tpl | 9 +- 16 files changed, 385 insertions(+), 269 deletions(-) create mode 100644 templates/CRM/Case/Form/CaseFilter.tpl diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 4a9aa6e03b..45d0dcabf1 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -407,51 +407,64 @@ WHERE cc.contact_id = %1 AND civicrm_case_type.name = '{$caseType}'"; * * @return string */ - public static function getCaseActivityQuery($type = 'upcoming', $userID = NULL, $condition = NULL) { - if (!$userID) { - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); - } + public static function getCaseActivityCountQuery($type = 'upcoming', $userID, $condition = NULL) { + return sprintf(" SELECT COUNT(*) FROM (%s) temp ", self::getCaseActivityQuery($type, $userID, $condition)); + } - $query = "SELECT -civicrm_case.id as case_id, -civicrm_case.subject as case_subject, -civicrm_contact.id as contact_id, -civicrm_contact.sort_name as sort_name, -civicrm_phone.phone as phone, -civicrm_contact.contact_type as contact_type, -civicrm_contact.contact_sub_type as contact_sub_type, -t_act.activity_type_id, -c_type.title as case_type, -civicrm_case.case_type_id as case_type_id, -cov_status.label as case_status, -cov_status.label as case_status_name, -t_act.status_id, -civicrm_case.start_date as case_start_date, -case_relation_type.label_b_a as case_role, "; + /** + * @param string $type + * @param int $userID + * @param string $condition + * @param string $limit + * + * @return string + */ + public static function getCaseActivityQuery($type = 'upcoming', $userID, $condition = NULL, $limit = NULL, $order = NULL) { + $selectClauses = array( + 'civicrm_case.id as case_id', + 'civicrm_case.subject as case_subject', + 'civicrm_contact.id as contact_id', + 'civicrm_contact.sort_name as sort_name', + 'civicrm_phone.phone as phone', + 'civicrm_contact.contact_type as contact_type', + 'civicrm_contact.contact_sub_type as contact_sub_type', + 't_act.activity_type_id', + 'c_type.title as case_type', + 'civicrm_case.case_type_id as case_type_id', + 'cov_status.label as case_status', + 'cov_status.label as case_status_name', + 't_act.status_id', + 'civicrm_case.start_date as case_start_date', + 'case_relation_type.label_b_a as case_role', + ); if ($type == 'upcoming') { - $query .= " -t_act.desired_date as case_scheduled_activity_date, -t_act.id as case_scheduled_activity_id, -t_act.act_type_name as case_scheduled_activity_type_name, -t_act.act_type AS case_scheduled_activity_type "; + $selectClauses = array_merge($selectClauses, array( + 't_act.desired_date as case_scheduled_activity_date', + 't_act.id as case_scheduled_activity_id', + 't_act.act_type_name as case_scheduled_activity_type_name', + 't_act.act_type AS case_scheduled_activity_type', + )); } elseif ($type == 'recent') { - $query .= " -t_act.desired_date as case_recent_activity_date, -t_act.id as case_recent_activity_id, -t_act.act_type_name as case_recent_activity_type_name, -t_act.act_type AS case_recent_activity_type "; + $selectClauses = array_merge($selectClauses, array( + 't_act.desired_date as case_recent_activity_date', + 't_act.id as case_recent_activity_id', + 't_act.act_type_name as case_recent_activity_type_name', + 't_act.act_type AS case_recent_activity_type', + )); } elseif ($type == 'any') { - $query .= " -t_act.desired_date as case_activity_date, -t_act.id as case_activity_id, -t_act.act_type_name as case_activity_type_name, -t_act.act_type AS case_activity_type "; + $selectClauses = array_merge($selectClauses, array( + 't_act.desired_date as case_activity_date', + 't_act.id as case_activity_id', + 't_act.act_type_name as case_activity_type_name', + 't_act.act_type AS case_activity_type', + )); } + $query = CRM_Contact_BAO_Query::appendAnyValueToSelect($selectClauses, 'case_id'); + $query .= " FROM civicrm_case INNER JOIN civicrm_case_contact ON civicrm_case.id = civicrm_case_contact.case_id INNER JOIN civicrm_contact ON civicrm_case_contact.contact_id = civicrm_contact.id "; @@ -535,17 +548,27 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type' if ($condition) { // CRM-8749 backwards compatibility - callers of this function expect to start $condition with "AND" - $query .= " WHERE (1) $condition "; + $query .= " WHERE (1) AND $condition "; } + $query .= " GROUP BY case_id "; - if ($type == 'upcoming') { - $query .= " ORDER BY case_scheduled_activity_date ASC "; + if ($order) { + $query .= $order; } - elseif ($type == 'recent') { - $query .= " ORDER BY case_recent_activity_date ASC "; + else { + if ($type == 'upcoming') { + $query .= " ORDER BY case_scheduled_activity_date ASC "; + } + elseif ($type == 'recent') { + $query .= " ORDER BY case_recent_activity_date ASC "; + } + elseif ($type == 'any') { + $query .= " ORDER BY case_activity_date ASC "; + } } - elseif ($type == 'any') { - $query .= " ORDER BY case_activity_date ASC "; + + if ($limit) { + $query .= $limit; } return $query; @@ -555,29 +578,37 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type' * Retrieve cases related to particular contact or whole contact used in Dashboard and Tab. * * @param bool $allCases - * - * @param int $userID - * - * @param string $type - * /upcoming,recent,all/. - * + * @param array $params * @param string $context + * @param bool $getCount * * @return array * Array of Cases */ - public static function getCases($allCases = TRUE, $userID = NULL, $type = 'upcoming', $context = 'dashboard') { + public static function getCases($allCases = TRUE, $params = array(), $context = 'dashboard', $getCount = FALSE) { $condition = NULL; $casesList = array(); //validate access for own cases. if (!self::accessCiviCase()) { - return $casesList; + return $getCount ? 0 : $casesList; } - if (!$userID) { - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); + $type = CRM_Utils_Array::value('type', $params, 'upcoming'); + $userID = CRM_Core_Session::singleton()->get('userID'); + + $caseActivityTypeColumn = 'case_activity_type_name'; + $caseActivityDateColumn = 'case_activity_date'; + $caseActivityIDColumn = 'case_activity_id'; + if ($type == 'upcoming') { + $caseActivityDateColumn = 'case_scheduled_activity_date'; + $caseActivityTypeColumn = 'case_scheduled_activity_type'; + $caseActivityIDColumn = 'case_scheduled_activity_id'; + } + elseif ($type == 'recent') { + $caseActivityDateColumn = 'case_recent_activity_date'; + $caseActivityTypeColumn = 'case_recent_activity_type'; + $caseActivityIDColumn = 'case_recent_activity_id'; } //validate access for all cases. @@ -585,62 +616,50 @@ LEFT JOIN civicrm_option_group aog ON aog.name='activity_type' $allCases = FALSE; } - $condition = " AND civicrm_case.is_deleted = 0 AND civicrm_contact.is_deleted <> 1"; + $whereClauses = array('civicrm_case.is_deleted = 0 AND civicrm_contact.is_deleted <> 1'); if (!$allCases) { - $condition .= " AND case_relationship.contact_id_b = {$userID} "; + $whereClauses[] .= " case_relationship.contact_id_b = {$userID} "; } - if ($type == 'upcoming' || $type == 'any') { - $closedId = CRM_Core_PseudoConstant::getKey('CRM_Case_BAO_Case', 'case_status_id', 'Closed'); - $condition .= " -AND civicrm_case.status_id != $closedId"; + if (empty($params['status_id']) && ($type == 'upcoming' || $type == 'any')) { + $whereClauses[] = " civicrm_case.status_id != " . CRM_Core_PseudoConstant::getKey('CRM_Case_BAO_Case', 'case_status_id', 'Closed'); } - $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', - ); + foreach (array('case_type_id', 'status_id') as $column) { + if (!empty($params[$column])) { + $whereClauses[] = sprintf("civicrm_case.%s IN (%s)", $column, $params[$column]); + } + } + $condition = implode(' AND ', $whereClauses); - if ($type == 'upcoming') { - $resultFields[] = 'case_scheduled_activity_date'; - $resultFields[] = 'case_scheduled_activity_type_name'; - $resultFields[] = 'case_scheduled_activity_type'; - $resultFields[] = 'case_scheduled_activity_id'; + $totalCount = CRM_Core_DAO::singleValueQuery(self::getCaseActivityCountQuery($type, $userID, $condition)); + if ($getCount) { + return $totalCount; } - elseif ($type == 'recent') { - $resultFields[] = 'case_recent_activity_date'; - $resultFields[] = 'case_recent_activity_type_name'; - $resultFields[] = 'case_recent_activity_type'; - $resultFields[] = 'case_recent_activity_id'; + $casesList['total'] = $totalCount; + + $limit = ''; + if (!empty($params['rp'])) { + $params['offset'] = ($params['page'] - 1) * $params['rp']; + $params['rowCount'] = $params['rp']; + if (!empty($params['rowCount']) && $params['rowCount'] > 0) { + $limit = " LIMIT {$params['offset']}, {$params['rowCount']} "; + } } - elseif ($type == 'any') { - $resultFields[] = 'case_activity_date'; - $resultFields[] = 'case_activity_type_name'; - $resultFields[] = 'case_activity_type'; - $resultFields[] = 'case_activity_id'; + + $order = NULL; + if (!empty($params['sortBy'])) { + if (strstr($params['sortBy'], 'date ')) { + $params['sortBy'] = str_replace('date', $caseActivityDateColumn, $params['sortBy']); + } + $order = "ORDER BY " . $params['sortBy']; } + $query = self::getCaseActivityQuery($type, $userID, $condition, $limit, $order); + $result = CRM_Core_DAO::executeQuery($query); + + $caseStatus = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND v.name = 'Urgent' "); + // we're going to use the usual actions, so doesn't make sense to duplicate definitions $actions = CRM_Case_Selector_Search::links(); @@ -656,55 +675,80 @@ AND civicrm_case.status_id != $closedId"; } $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 - ); - } - elseif ($field == 'case_status') { - if (in_array($result->$field, $caseStatus)) { - $casesList[$result->case_id]['class'] = "status-urgent"; + $caseTypes = CRM_Case_PseudoConstant::caseType('name'); + foreach ($result->fetchAll() as $key => $case) { + $casesList[$key] = array(); + $casesList[$key]['DT_RowId'] = $case['case_id']; + $casesList[$key]['DT_RowAttr'] = array('data-entity' => 'case', 'data-id' => $case['case_id']); + $casesList[$key]['DT_RowClass'] = "crm-entity"; + + $casesList[$key]['activity_list'] = sprintf('', + ts('Activities'), + CRM_Utils_System::url('civicrm/case/details', array('caseid' => $case['case_id'], 'cid' => $case['contact_id'], 'type' => $type)) + ); + + $phone = empty($case['phone']) ? '' : '
' . $case['phone'] . ''; + $casesList[$key]['contact_id'] = sprintf('%s%s
%s: %d', + CRM_Utils_System::url('civicrm/contact/view', array('cid' => $case['contact_id'])), + $case['sort_name'], + $phone, + ts('Case ID'), + $case['case_id'] + ); + $casesList[$key]['subject'] = $case['case_subject']; + $casesList[$key]['case_status'] = in_array($case['case_status'], $caseStatus) ? sprintf('%s', strtoupper($case['case_status'])) : $case['case_status']; + $casesList[$key]['case_type'] = $case['case_type']; + $casesList[$key]['case_role'] = CRM_Utils_Array::value('case_role', $case, '---'); + + $caseManagerContact = self::getCaseManagerContact($caseTypes[$case['case_type_id']], $case['case_id']); + if (!empty($caseManagerContact)) { + $casesList[$key]['manager'] = sprintf('%s', + CRM_Utils_System::url('civicrm/contact/view', array('cid' => CRM_Utils_Array::value('casemanager_id', $caseManagerContact))), + CRM_Utils_Array::value('casemanager', $caseManagerContact) + ); + } + $casesList[$key]['date'] = $case[$caseActivityTypeColumn]; + if (($actId = CRM_Utils_Array::value('case_scheduled_activity_id', $case)) || + ($actId = CRM_Utils_Array::value('case_recent_activity_id', $case)) + ) { + if (self::checkPermission($actId, 'view', $case['activity_type_id'], $userID)) { + if ($type == 'recent') { + $casesList[$key]['date'] = sprintf('%s', + CRM_Utils_System::url('civicrm/case/activity/view', array('reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case[$caseActivityIDColumn])), + ts('View activity'), + $case[$caseActivityTypeColumn] + ); } else { - $casesList[$result->case_id]['class'] = "status-normal"; + $status = CRM_Utils_Date::overdue($case[$caseActivityDateColumn]) ? 'status-overdue' : 'status-scheduled'; + $casesList[$key]['date'] = sprintf('%s   ', + $status, + CRM_Utils_System::url('civicrm/case/activity/view', array('reset' => 1, 'cid' => $case['contact_id'], 'aid' => $case[$caseActivityIDColumn])), + ts('View activity'), + $case[$caseActivityTypeColumn] + ); } } + if (self::checkPermission($actId, 'edit', $case['activity_type_id'], $userID)) { + $casesList[$key]['date'] .= sprintf('', + CRM_Utils_System::url('civicrm/case/activity', array('reset' => 1, 'cid' => $case['contact_id'], 'caseid' => $case['case_id'], 'action' => 'update')), + ts('Edit activity') + ); + } } - //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 - ); - } + $casesList[$key]['date'] .= "
" . CRM_Utils_Date::customFormat($case[$caseActivityDateColumn]); + $casesList[$key]['links'] = CRM_Core_Action::formLink($actions['primaryActions'], $mask, + array( + 'id' => $case['case_id'], + 'cid' => $case['contact_id'], + 'cxt' => $context, + ), + ts('more'), + FALSE, + 'case.actions.primary', + 'Case', + $case['case_id'] + ); } return $casesList; @@ -714,10 +758,9 @@ AND civicrm_case.status_id != $closedId"; * Get the summary of cases counts by type and status. * * @param bool $allCases - * @param int $userID * @return array */ - public static function getCasesSummary($allCases = TRUE, $userID) { + public static function getCasesSummary($allCases = TRUE) { $caseSummary = array(); //validate access for civicase. @@ -725,6 +768,8 @@ AND civicrm_case.status_id != $closedId"; return $caseSummary; } + $userID = CRM_Core_Session::singleton()->get('userID'); + //validate access for all cases. if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) { $allCases = FALSE; @@ -1545,8 +1590,7 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c $caseID = implode(',', $cases['case_id']); $contactID = implode(',', $cases['contact_id']); - $condition = " - AND civicrm_case_contact.contact_id IN( {$contactID} ) + $condition = " civicrm_case_contact.contact_id IN( {$contactID} ) AND civicrm_case.id IN( {$caseID}) AND civicrm_case.is_deleted = {$cases['case_deleted']}"; @@ -1980,8 +2024,7 @@ SELECT civicrm_contact.id as casemanager_id, $doFilterCases = FALSE; if (!CRM_Core_Permission::check('access all cases and activities')) { $doFilterCases = TRUE; - $session = CRM_Core_Session::singleton(); - $filterCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID')); + $filterCases = CRM_Case_BAO_Case::getCases(FALSE); } //2. fetch the details of related cases. diff --git a/CRM/Case/BAO/Query.php b/CRM/Case/BAO/Query.php index 59a4f4efb7..5c9dd702b2 100644 --- a/CRM/Case/BAO/Query.php +++ b/CRM/Case/BAO/Query.php @@ -698,6 +698,9 @@ case_relation_type.id = case_relationship.relationship_type_id )"; $accessAllCases = TRUE; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); + if ($form->get('context') != 'dashboard') { + $form->add('checkbox', 'upcoming', ts('Search Cases with Upcoming Activities')); + } } $form->assign('accessAllCases', $accessAllCases); @@ -726,7 +729,10 @@ case_relation_type.id = case_relationship.relationship_type_id )"; self::addCustomFormFields($form, array('Case')); - $form->setDefaults(array('case_owner' => 1)); + $form->setDefaults(array( + 'case_owner' => 1, + 'upcoming' => 1, + )); } /** diff --git a/CRM/Case/Form/Activity.php b/CRM/Case/Form/Activity.php index 7a0809cc8c..9bebe8b97e 100644 --- a/CRM/Case/Form/Activity.php +++ b/CRM/Case/Form/Activity.php @@ -100,8 +100,8 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity { if ($this->_caseId && !CRM_Core_Permission::check('access all cases and activities') ) { - $session = CRM_Core_Session::singleton(); - $allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any'); + $params = array('type' => 'any'); + $allCases = CRM_Case_BAO_Case::getCases(TRUE, $params); if (count(array_intersect($this->_caseId, array_keys($allCases))) == 0) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } diff --git a/CRM/Case/Page/AJAX.php b/CRM/Case/Page/AJAX.php index cd30c11488..2d643559fd 100644 --- a/CRM/Case/Page/AJAX.php +++ b/CRM/Case/Page/AJAX.php @@ -186,4 +186,30 @@ class CRM_Case_Page_AJAX { CRM_Utils_System::civiExit(); } + public static function getCases() { + $requiredParameters = array( + 'type' => 'String', + ); + $optionalParameters = array( + 'case_type_id' => 'String', + 'status_id' => 'String', + 'all' => 'Positive', + ); + $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(); + $params += CRM_Core_Page_AJAX::validateParams($requiredParameters, $optionalParameters); + + $allCases = (bool) $params['all']; + + $cases = CRM_Case_BAO_Case::getCases($allCases, $params); + + $casesDT = array( + 'recordsFiltered' => $cases['total'], + 'recordsTotal' => $cases['total'], + ); + unset($cases['total']); + $casesDT['data'] = $cases; + + CRM_Utils_JSON::output($casesDT); + } + } diff --git a/CRM/Case/Page/DashBoard.php b/CRM/Case/Page/DashBoard.php index da548c7711..9ce8d4bd09 100644 --- a/CRM/Case/Page/DashBoard.php +++ b/CRM/Case/Page/DashBoard.php @@ -58,7 +58,7 @@ class CRM_Case_Page_DashBoard extends CRM_Core_Page { } $session = CRM_Core_Session::singleton(); - $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $session); + $allCases = CRM_Utils_Request::retrieve('all', 'Positive', $this); CRM_Utils_System::setTitle(ts('CiviCase Dashboard')); @@ -66,9 +66,10 @@ class CRM_Case_Page_DashBoard extends CRM_Core_Page { //validate access for all cases. if ($allCases && !CRM_Core_Permission::check('access all cases and activities')) { - $allCases = FALSE; + $allCases = 0; CRM_Core_Session::setStatus(ts('You are not authorized to access all cases and activities.'), ts('Sorry'), 'error'); } + $this->assign('all', $allCases); if (!$allCases) { $this->assign('myCases', TRUE); } @@ -82,22 +83,27 @@ class CRM_Case_Page_DashBoard extends CRM_Core_Page { ) { $this->assign('newClient', TRUE); } - $summary = CRM_Case_BAO_Case::getCasesSummary($allCases, $userID); - $upcoming = CRM_Case_BAO_Case::getCases($allCases, $userID, 'upcoming'); - $recent = CRM_Case_BAO_Case::getCases($allCases, $userID, 'recent'); + $summary = CRM_Case_BAO_Case::getCasesSummary($allCases); + $upcoming = CRM_Case_BAO_Case::getCases($allCases, array(), 'dashboard', TRUE); + $recent = CRM_Case_BAO_Case::getCases($allCases, array('type' => 'recent'), 'dashboard', TRUE); - foreach ($upcoming as $key => $value) { - if (strtotime($value['case_scheduled_activity_date']) < time()) { - $upcoming[$key]['activity_status'] = 'status-overdue'; - } - } $this->assign('casesSummary', $summary); if (!empty($upcoming)) { - $this->assign('upcomingCases', $upcoming); + $this->assign('upcomingCases', TRUE); } if (!empty($recent)) { - $this->assign('recentCases', $recent); + $this->assign('recentCases', TRUE); } + + $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', + ts('Case'), CRM_Core_Action::BROWSE, + NULL, + FALSE, FALSE, TRUE + ); + $controller->set('context', 'dashboard'); + $controller->setEmbedded(TRUE); + $controller->process(); + $controller->run(); } /** diff --git a/CRM/Case/Page/Tab.php b/CRM/Case/Page/Tab.php index 64599e6a7c..8be97d37d8 100644 --- a/CRM/Case/Page/Tab.php +++ b/CRM/Case/Page/Tab.php @@ -67,8 +67,7 @@ class CRM_Case_Page_Tab extends CRM_Core_Page { if ($this->_id && ($this->_action & CRM_Core_Action::VIEW)) { //user might have special permissions to view this case, CRM-5666 if (!CRM_Core_Permission::check('access all cases and activities')) { - $session = CRM_Core_Session::singleton(); - $userCases = CRM_Case_BAO_Case::getCases(FALSE, $session->get('userID'), 'any'); + $userCases = CRM_Case_BAO_Case::getCases(FALSE, array('type' => 'any')); if (!array_key_exists($this->_id, $userCases)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } diff --git a/CRM/Case/xml/Menu/Case.xml b/CRM/Case/xml/Menu/Case.xml index 386cdc131d..91d5ceb984 100644 --- a/CRM/Case/xml/Menu/Case.xml +++ b/CRM/Case/xml/Menu/Case.xml @@ -136,4 +136,8 @@ civicrm/ajax/delcaserole CRM_Case_Page_AJAX::deleteCaseRoles + + civicrm/ajax/get-cases + CRM_Case_Page_AJAX::getCases + diff --git a/CRM/Dashlet/Page/AllCases.php b/CRM/Dashlet/Page/AllCases.php index a6f6078a11..733cfcf6fc 100644 --- a/CRM/Dashlet/Page/AllCases.php +++ b/CRM/Dashlet/Page/AllCases.php @@ -53,12 +53,17 @@ class CRM_Dashlet_Page_AllCases extends CRM_Core_Page { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); - $upcoming = CRM_Case_BAO_Case::getCases(TRUE, $userID, 'upcoming', $context); + $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', + ts('Case'), CRM_Core_Action::BROWSE, + NULL, + FALSE, FALSE, TRUE + ); + $controller->setEmbedded(TRUE); + $controller->process(); + $controller->run(); - if (!empty($upcoming)) { - $this->assign('AllCases', $upcoming); + if (CRM_Case_BAO_Case::getCases(TRUE, array('type' => 'any'), 'dashboard', TRUE)) { + $this->assign('casePresent', TRUE); } return parent::run(); } diff --git a/CRM/Dashlet/Page/CaseDashboard.php b/CRM/Dashlet/Page/CaseDashboard.php index 0765646103..79627fd5f5 100644 --- a/CRM/Dashlet/Page/CaseDashboard.php +++ b/CRM/Dashlet/Page/CaseDashboard.php @@ -45,15 +45,12 @@ class CRM_Dashlet_Page_CaseDashboard extends CRM_Core_Page { * @return void */ public function run() { - //check for civicase access. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } - $session = &CRM_Core_Session::singleton(); - $userID = $session->get('userID'); - $summary = CRM_Case_BAO_Case::getCasesSummary(TRUE, $userID); + $summary = CRM_Case_BAO_Case::getCasesSummary(TRUE); if (!empty($summary)) { $this->assign('casesSummary', $summary); diff --git a/CRM/Dashlet/Page/MyCases.php b/CRM/Dashlet/Page/MyCases.php index 51d9b06385..234e4c6d56 100644 --- a/CRM/Dashlet/Page/MyCases.php +++ b/CRM/Dashlet/Page/MyCases.php @@ -53,12 +53,17 @@ class CRM_Dashlet_Page_MyCases extends CRM_Core_Page { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } - $session = CRM_Core_Session::singleton(); - $userID = $session->get('userID'); - $upcoming = CRM_Case_BAO_Case::getCases(FALSE, $userID, 'upcoming', $context); + $controller = new CRM_Core_Controller_Simple('CRM_Case_Form_Search', + ts('Case'), CRM_Core_Action::BROWSE, + NULL, + FALSE, FALSE, TRUE + ); + $controller->setEmbedded(TRUE); + $controller->process(); + $controller->run(); - if (!empty($upcoming)) { - $this->assign('upcomingCases', $upcoming); + if (CRM_Case_BAO_Case::getCases(FALSE, array('type' => 'any'), $context, TRUE)) { + $this->assign('casePresent', TRUE); } return parent::run(); } diff --git a/css/civicrm.css b/css/civicrm.css index a30c25c3c3..c459281324 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -1634,11 +1634,6 @@ input.crm-form-entityref { clear: both; } -#crm-container table.caseSelector td.status-urgent { - font-weight: bold; - text-transform: uppercase; -} - .crm-container .crm-clearfix:after { clear: both; content: "."; diff --git a/templates/CRM/Case/Form/CaseFilter.tpl b/templates/CRM/Case/Form/CaseFilter.tpl new file mode 100644 index 0000000000..fdf156d91c --- /dev/null +++ b/templates/CRM/Case/Form/CaseFilter.tpl @@ -0,0 +1,51 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.7 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2017 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +
+
+
+ {ts}Filter by Case{/ts} +
+
+ + + + + {if $accessAllCases && $form.upcoming} + + {/if} + +
+ {$form.case_type_id.label}
{$form.case_type_id.html} +
+ {$form.case_status_id.label}
{$form.case_status_id.html} +
+
+ {$form.upcoming.html} {$form.upcoming.label} +
+
+
+
+
diff --git a/templates/CRM/Case/Page/DashBoard.tpl b/templates/CRM/Case/Page/DashBoard.tpl index 8ea796483c..082b0323b5 100644 --- a/templates/CRM/Case/Page/DashBoard.tpl +++ b/templates/CRM/Case/Page/DashBoard.tpl @@ -40,19 +40,18 @@
{if $myCases} - {* check for access all cases and activities *} - {if call_user_func(array('CRM_Core_Permission','check'), 'access all cases and activities')} -
{ts}All Cases with Upcoming Activities{/ts}
-
{ts}My Cases with Upcoming Activities{/ts}
- {/if} + {* check for access all cases and activities *} + {if call_user_func(array('CRM_Core_Permission','check'), 'access all cases and activities')} +
{ts}All Cases with Upcoming Activities{/ts}
+
{ts}My Cases with Upcoming Activities{/ts}
+ {/if} {else} -
{ts}All Cases with Upcoming Activities{/ts}
-
{ts}My Cases with Upcoming Activities{/ts}
+
{ts}All Cases with Upcoming Activities{/ts}
+
{ts}My Cases with Upcoming Activities{/ts}
{/if}
-

{if $myCases} {ts}Summary of Involvement{/ts} @@ -88,8 +87,9 @@

{if $myCases}{ts}My Cases With Upcoming Activities{/ts}{else}{ts}All Cases With Upcoming Activities{/ts}{/if}

{if $upcomingCases} + {include file="CRM/Case/Form/CaseFilter.tpl" context="$context" list="upcoming"}
- {include file="CRM/Case/Page/DashboardSelector.tpl" context="dashboard" list="upcoming" rows=$upcomingCases} + {include file="CRM/Case/Page/DashboardSelector.tpl" context="dashboard" list="upcoming" all="$all"}
{else}
@@ -100,13 +100,15 @@

{if $myCases}{ts}My Cases With Recently Performed Activities{/ts}{else}{ts}All Cases With Recently Performed Activities{/ts}{/if}

{if $recentCases} + {include file="CRM/Case/Form/CaseFilter.tpl" context="$context" list="recent"}
- {include file="CRM/Case/Page/DashboardSelector.tpl" context="dashboard" list="recent" rows=$recentCases} + {include file="CRM/Case/Page/DashboardSelector.tpl" context="dashboard" list="recent" all="$all"}
{else}
{ts 1=$findCasesURL}There are no cases with activities scheduled in the past two weeks. Use %1 to expand your search.{/ts}
{/if} +
{/if} diff --git a/templates/CRM/Case/Page/DashboardSelector.tpl b/templates/CRM/Case/Page/DashboardSelector.tpl index 808f8ccac0..70349625ff 100644 --- a/templates/CRM/Case/Page/DashboardSelector.tpl +++ b/templates/CRM/Case/Page/DashboardSelector.tpl @@ -25,74 +25,49 @@ *} {capture assign=expandIconURL}{ts}open section{/ts}{/capture} {strip} - - - - - - - - - - - +
{ts}Contact{/ts}{ts}Subject{/ts}{ts}Status{/ts}{ts}Type{/ts}{ts}My Role{/ts}{ts}Manager{/ts}{if $list EQ 'upcoming'}{ts}Next Sched.{/ts}{elseif $list EQ 'recent'}{ts}Most Recent{/ts}{/if}
+ + + + + + + + + + + + +
{ts}Contact{/ts}{ts}Subject{/ts}{ts}Status{/ts}{ts}Type{/ts}{ts}My Role{/ts}{ts}Manager{/ts}{if $list EQ 'upcoming'}{ts}Next Sched.{/ts}{elseif $list EQ 'recent'}{ts}Most Recent{/ts}{/if} 
- {counter start=0 skip=1 print=false} - {foreach from=$rows item=row} - - - - - - - {$row.sort_name}{if $row.phone}
{$row.phone}{/if}
{ts}Case ID{/ts}: {$row.case_id} - {$row.case_subject} - {$row.case_status} - {$row.case_type} - {if $row.case_role}{$row.case_role}{else}---{/if} - {if $row.casemanager_id}{$row.casemanager}{else}---{/if} - {if $list eq 'upcoming'} - - {if $row.case_upcoming_activity_viewable} - {$row.case_scheduled_activity_type} - {else} - {$row.case_scheduled_activity_type} - {/if} -    - {if $row.case_upcoming_activity_editable} - - {/if} -
- {$row.case_scheduled_activity_date|crmDate} - - - {elseif $list eq 'recent'} - - {if $row.case_recent_activity_viewable} - {$row.case_recent_activity_type} - {else} - {$row.case_recent_activity_type} - {/if} - {if $row.case_recent_activity_editable and $row.case_recent_activity_type_name != 'Inbound Email' && $row.case_recent_activity_type_name != 'Email'}   - {/if}
- {$row.case_recent_activity_date|crmDate} - - {/if} - - {$row.action}{$row.moreActions} - - {/foreach} - - {* Dashboard only lists 10 most recent casess. *} - {if $context EQ 'dashboard' and $limit and $pager->_totalItems GT $limit } - - » {ts}Find more cases{/ts}... - - {/if} +{literal} + +{/literal} {/strip} - {crmScript file='js/crm.expandRow.js'} diff --git a/templates/CRM/Dashlet/Page/AllCases.tpl b/templates/CRM/Dashlet/Page/AllCases.tpl index fe1e781881..0431db42fa 100644 --- a/templates/CRM/Dashlet/Page/AllCases.tpl +++ b/templates/CRM/Dashlet/Page/AllCases.tpl @@ -23,10 +23,11 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if $AllCases} -
- {include file="CRM/Case/Page/DashboardSelector.tpl" context="$context" list="allcases" rows=$AllCases} -
+{if $casePresent} + {include file="CRM/Case/Form/CaseFilter.tpl" context="$context" list="all-cases" all="1"} +
+ {include file="CRM/Case/Page/DashboardSelector.tpl" context="$context" list="all-cases" all="1"} +
{else}
{capture assign="findCasesURL"}{crmURL p='civicrm/case/search' q='reset=1'}{/capture} diff --git a/templates/CRM/Dashlet/Page/MyCases.tpl b/templates/CRM/Dashlet/Page/MyCases.tpl index b51f312677..8380910399 100644 --- a/templates/CRM/Dashlet/Page/MyCases.tpl +++ b/templates/CRM/Dashlet/Page/MyCases.tpl @@ -23,10 +23,11 @@ | see the CiviCRM license FAQ at http://civicrm.org/licensing | +--------------------------------------------------------------------+ *} -{if $upcomingCases} -
- {include file="CRM/Case/Page/DashboardSelector.tpl" context="$context" list="upcoming" rows=$upcomingCases} -
+{if $casePresent} + {include file="CRM/Case/Form/CaseFilter.tpl" context="$context" list="my-cases" all="0"} +
+ {include file="CRM/Case/Page/DashboardSelector.tpl" context="$context" list="my-cases" all="0"} +
{else}
{capture assign="findCasesURL"}{crmURL p='civicrm/case/search' q='reset=1'}{/capture} -- 2.25.1