From ad280fb669e26f136bb9f56b29556ad70a78d3a6 Mon Sep 17 00:00:00 2001 From: Joseph Lacey Date: Wed, 29 Apr 2015 20:39:19 -0600 Subject: [PATCH] CRM-16353 - Case DataTables refactoring ---------------------------------------- * CRM-16353: Upgrade datatables integration to use v2 api https://issues.civicrm.org/jira/browse/CRM-16353 --- CRM/Activity/BAO/Activity.php | 4 + CRM/Activity/Page/AJAX.php | 197 ++++----- CRM/Case/BAO/Case.php | 338 ++++++++------- templates/CRM/Case/Form/ActivityTab.tpl | 161 ++----- templates/CRM/Case/Form/CaseView.js | 6 +- templates/CRM/Case/Form/CaseView.tpl | 550 +++++++++--------------- 6 files changed, 513 insertions(+), 743 deletions(-) diff --git a/CRM/Activity/BAO/Activity.php b/CRM/Activity/BAO/Activity.php index 41be25ada3..a6cb989faa 100644 --- a/CRM/Activity/BAO/Activity.php +++ b/CRM/Activity/BAO/Activity.php @@ -2514,6 +2514,8 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n $activity['activity_type'] = $values['activity_type']; $activity['subject'] = $values['subject']; + + $activity['source_contact_name'] = ''; if ($params['contact_id'] == $values['source_contact_id']) { $activity['source_contact_name'] = $values['source_contact_name']; } @@ -2525,6 +2527,7 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n $activity['source_contact_name'] = 'n/a'; } + $activity['target_contact_name'] = ''; if (isset($values['mailingId']) && !empty($values['mailingId'])) { $activity['target_contact'] = CRM_Utils_System::href($values['recipients'], 'civicrm/mailing/report/event', @@ -2548,6 +2551,7 @@ INNER JOIN civicrm_option_group grp ON ( grp.id = val.option_group_id AND grp.n $activity['target_contact_name'] = 'n/a'; } + $activity['assignee_contact_name'] = ''; if (empty($values['assignee_contact_name'])) { $activity['assignee_contact_name'] = 'n/a'; } diff --git a/CRM/Activity/Page/AJAX.php b/CRM/Activity/Page/AJAX.php index 9f6c7ee94f..5e69a054cd 100644 --- a/CRM/Activity/Page/AJAX.php +++ b/CRM/Activity/Page/AJAX.php @@ -42,25 +42,19 @@ class CRM_Activity_Page_AJAX { $userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer'); $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String'); - $sortMapper = array( - 0 => 'display_date', - 1 => 'ca.subject', - 2 => 'ca.activity_type_id', - 3 => 'acc.sort_name', - 4 => 'cc.sort_name', - 5 => 'ca.status_id', - ); + $sortMapper = array(); + foreach ($_GET['columns'] as $key => $value) { + $sortMapper[$key] = $value['data']; + }; - $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); - $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; - $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; - $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; - $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; + $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; + $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; - $params = $_POST; + $params = $_GET; if ($sort && $sortOrder) { - $params['sortname'] = $sort; - $params['sortorder'] = $sortOrder; + $params['sortBy'] = $sort . ' ' . $sortOrder; } $params['page'] = ($offset / $rowCount) + 1; $params['rp'] = $rowCount; @@ -68,37 +62,22 @@ class CRM_Activity_Page_AJAX { // get the activities related to given case $activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID); - $iFilteredTotal = $iTotal = $params['total']; - $selectorElements = array( - 'display_date', - 'subject', - 'type', - 'with_contacts', - 'reporter', - 'status', - 'links', - 'class', - ); - - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encodeDataTableSelector($activities, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - CRM_Utils_System::civiExit(); + CRM_Utils_JSON::output($activities); } public static function getCaseGlobalRelationships() { - $sortMapper = array( - 0 => 'sort_name', - 1 => 'phone', - 2 => 'email', - ); + $sortMapper = array(); + foreach ($_GET['columns'] as $key => $value) { + $sortMapper[$key] = $value['data']; + }; - $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); - $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; - $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; - $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL; - $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; + $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; + $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; + + $params = $_GET; - $params = $_POST; //CRM-14466 initialize variable to avoid php notice $sortSQL = ""; if ($sort && $sortOrder) { @@ -113,35 +92,42 @@ class CRM_Activity_Page_AJAX { // limit the rows $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $sortSQL, $showLinks = TRUE, FALSE, $offset, $rowCount); - $iFilteredTotal = $iTotal = $relGlobalTotalCount; - $selectorElements = array('sort_name', 'phone', 'email'); + $relationships = array(); + // after sort we can update username fields to be a url + foreach ($relGlobal as $key => $value) { + $relationship = array(); + $relationship['sort_name'] = $value['sort_name']; + $relationship['phone'] = $value['phone']; + $relationship['email'] = $value['email']; + + array_push($relationships, $relationship); + } - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encodeDataTableSelector($relGlobal, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - CRM_Utils_System::civiExit(); + $params['total'] = count($relationships); + + $globalRelationshipsDT = array(); + $globalRelationshipsDT['data'] = $relationships; + $globalRelationshipsDT['recordsTotal'] = $params['total']; + $globalRelationshipsDT['recordsFiltered'] = $params['total']; + + CRM_Utils_JSON::output($globalRelationshipsDT); } public static function getCaseClientRelationships() { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); - $sortMapper = array( - 0 => 'relation', - 1 => 'name', - 2 => 'phone', - 3 => 'email', - ); + $sortMapper = array(); + foreach ($_GET['columns'] as $key => $value) { + $sortMapper[$key] = $value['data']; + }; - $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); - $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; - $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; - $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; - $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; + $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; + $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; - $params = $_POST; - if ($sort && $sortOrder) { - $sortSQL = $sort . ' ' . $sortOrder; - } + $params = $_GET; // Retrieve ALL client relationships $relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID, @@ -167,22 +153,27 @@ class CRM_Activity_Page_AJAX { $sort_type = "SORT_" . strtoupper($sortOrder); array_multisort($sortArray, constant($sort_type), $clientRelationships); - //limit the rows - $allClientRelationships = $clientRelationships; - $clientRelationships = array_slice($allClientRelationships, $offset, $rowCount, TRUE); - + $relationships = array(); // after sort we can update username fields to be a url foreach ($clientRelationships as $key => $value) { - $clientRelationships[$key]['name'] = '' . $clientRelationships[$key]['name'] . ''; + $relationship['phone'] = $value['phone']; + $relationship['email'] = $value['email']; + + array_push($relationships, $relationship); } - $iFilteredTotal = $iTotal = $params['total'] = count($allClientRelationships); - $selectorElements = array('relation', 'name', 'phone', 'email'); + $params['total'] = count($relationships); - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encodeDataTableSelector($clientRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - CRM_Utils_System::civiExit(); + $clientRelationshipsDT = array(); + $clientRelationshipsDT['data'] = $relationships; + $clientRelationshipsDT['recordsTotal'] = $params['total']; + $clientRelationshipsDT['recordsFiltered'] = $params['total']; + + CRM_Utils_JSON::output($clientRelationshipsDT); } @@ -190,24 +181,17 @@ class CRM_Activity_Page_AJAX { $caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer'); $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); - $sortMapper = array( - 0 => 'relation', - 1 => 'name', - 2 => 'phone', - 3 => 'email', - 4 => 'actions', - ); + $sortMapper = array(); + foreach ($_GET['columns'] as $key => $value) { + $sortMapper[$key] = $value['data']; + }; - $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); - $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; - $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; - $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : 'relation'; - $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc'; + $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0; + $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25; + $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL; + $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc'; - $params = $_POST; - if ($sort && $sortOrder) { - $sortSQL = $sort . ' ' . $sortOrder; - } + $params = $_GET; $caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID); $caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name'); @@ -221,6 +205,8 @@ class CRM_Activity_Page_AJAX { $caseRoles[$managerRoleId] = $caseRoles[$managerRoleId] . '
' . '(' . ts('Case Manager') . ')'; } + $relationships = array(); + foreach ($caseRelationships as $key => $value) { //calculate roles that don't have relationships if (!empty($caseRoles[$value['relation_type']])) { @@ -266,18 +252,13 @@ class CRM_Activity_Page_AJAX { foreach ($caseRelationships as $key => $row) { $sortArray[$key] = $row[$sort]; } - $sort_type = "SORT_" . strtoupper($sortOrder); array_multisort($sortArray, constant($sort_type), $caseRelationships); - //limit rows display - $allCaseRelationships = $caseRelationships; - $caseRelationships = array_slice($allCaseRelationships, $offset, $rowCount, TRUE); + $relationships = array(); // set user name, email and edit columns links - // idx will count number of current row / needed by edit links - $idx = 1; - foreach ($caseRelationships as &$row) { + foreach ($caseRelationships as $key => &$row) { // Get rid of the "
(Case Manager)" from label list($typeLabel) = explode('<', $row['relation']); // view user links @@ -296,8 +277,7 @@ class CRM_Activity_Page_AJAX { $contactType = $contactType == 'Contact' ? '' : $contactType; switch ($row['source']) { case 'caseRel': - $row['actions'] - = '' . + $row['actions'] = '' . '' . '' . '' . @@ -306,21 +286,28 @@ class CRM_Activity_Page_AJAX { break; case 'caseRoles': - $row['actions'] - = '' . + $row['actions'] = '' . '' . ''; break; } } - $idx++; + unset($row['cid']); + unset($row['relation_type']); + unset($row['rel_id']); + unset($row['client_id']); + unset($row['source']); + array_push($relationships, $row); } - $iFilteredTotal = $iTotal = $params['total'] = count($allCaseRelationships); - $selectorElements = array('relation', 'name', 'phone', 'email', 'actions'); + $params['total'] = count($relationships); + + $caseRelationshipsDT = array(); + $caseRelationshipsDT['data'] = $relationships; + $caseRelationshipsDT['recordsTotal'] = $params['total']; + $caseRelationshipsDT['recordsFiltered'] = $params['total']; + + CRM_Utils_JSON::output($caseRelationshipsDT); - header('Content-Type: application/json'); - echo CRM_Utils_JSON::encodeDataTableSelector($caseRelationships, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); - CRM_Utils_System::civiExit(); } public static function convertToCaseActivity() { diff --git a/CRM/Case/BAO/Case.php b/CRM/Case/BAO/Case.php index 3b53743b30..05030a9860 100644 --- a/CRM/Case/BAO/Case.php +++ b/CRM/Case/BAO/Case.php @@ -1043,132 +1043,142 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c // CRM-5081 - formatting the dates to omit seconds. // Note the 00 in the date format string is needed otherwise later on it thinks scheduled ones are overdue. - $select = "SELECT count(ca.id) as ismultiple, ca.id as id, - ca.activity_type_id as type, - ca.activity_type_id as activity_type_id, - cc.sort_name as reporter, - cc.id as reporter_id, - acc.sort_name AS assignee, - acc.id AS assignee_id, - DATE_FORMAT(IF(ca.activity_date_time < NOW() AND ca.status_id=ov.value, - ca.activity_date_time, - DATE_ADD(NOW(), INTERVAL 1 YEAR) - ), '%Y%m%d%H%i00') as overdue_date, - DATE_FORMAT(ca.activity_date_time, '%Y%m%d%H%i00') as display_date, - ca.status_id as status, - ca.subject as subject, - ca.is_deleted as deleted, - ca.priority_id as priority, - ca.weight as weight, - GROUP_CONCAT(ef.file_id) as attachment_ids "; + $select = " + SELECT COUNT(ca.id) AS ismultiple, + ca.id AS id, + ca.activity_type_id AS type, + ca.activity_type_id AS activity_type_id, + tcc.sort_name AS target_contact_name, + tcc.id AS target_contact_id, + scc.sort_name AS source_contact_name, + scc.id AS source_contact_id, + acc.sort_name AS assignee_contact_name, + acc.id AS assignee_contact_id, + DATE_FORMAT( + IF(ca.activity_date_time < NOW() AND ca.status_id=ov.value, + ca.activity_date_time, + DATE_ADD(NOW(), INTERVAL 1 YEAR) + ), '%Y%m%d%H%i00') AS overdue_date, + DATE_FORMAT(ca.activity_date_time, '%Y%m%d%H%i00') AS display_date, + ca.status_id AS status, + ca.subject AS subject, + ca.is_deleted AS deleted, + ca.priority_id AS priority, + ca.weight AS weight, + GROUP_CONCAT(ef.file_id) AS attachment_ids "; $from = " - FROM civicrm_case_activity cca - INNER JOIN civicrm_activity ca ON ca.id = cca.activity_id - INNER JOIN civicrm_activity_contact cac ON cac.activity_id = ca.id AND cac.record_type_id = {$sourceID} - INNER JOIN civicrm_contact cc ON cc.id = cac.contact_id - INNER JOIN civicrm_option_group cog ON cog.name = 'activity_type' - INNER JOIN civicrm_option_value cov ON cov.option_group_id = cog.id - AND cov.value = ca.activity_type_id AND cov.is_active = 1 - LEFT JOIN civicrm_entity_file ef on ef.entity_table = 'civicrm_activity' AND ef.entity_id = ca.id - LEFT OUTER JOIN civicrm_option_group og ON og.name = 'activity_status' - LEFT OUTER JOIN civicrm_option_value ov ON ov.option_group_id=og.id AND ov.name = 'Scheduled' - LEFT JOIN civicrm_activity_contact caa - ON caa.activity_id = ca.id AND caa.record_type_id = {$assigneeID} - LEFT JOIN civicrm_contact acc ON acc.id = caa.contact_id "; - - $where = 'WHERE cca.case_id= %1 - AND ca.is_current_revision = 1'; - - if (!empty($params['reporter_id'])) { - $where .= " AND cac.contact_id = " . CRM_Utils_Type::escape($params['reporter_id'], 'Integer'); + FROM civicrm_case_activity cca + INNER JOIN civicrm_activity ca + ON ca.id = cca.activity_id + INNER JOIN civicrm_activity_contact cas + ON cas.activity_id = ca.id + AND cas.record_type_id = {$sourceID} + INNER JOIN civicrm_contact scc + ON scc.id = cas.contact_id + LEFT JOIN civicrm_activity_contact caa + ON caa.activity_id = ca.id + AND caa.record_type_id = {$assigneeID} + LEFT JOIN civicrm_contact acc + ON acc.id = caa.contact_id + LEFT JOIN civicrm_activity_contact cat + ON cat.activity_id = ca.id + AND cat.record_type_id = {$targetID} + LEFT JOIN civicrm_contact tcc + ON tcc.id = cat.contact_id + INNER JOIN civicrm_option_group cog + ON cog.name = 'activity_type' + INNER JOIN civicrm_option_value cov + ON cov.option_group_id = cog.id + AND cov.value = ca.activity_type_id + AND cov.is_active = 1 + LEFT JOIN civicrm_entity_file ef + ON ef.entity_table = 'civicrm_activity' + AND ef.entity_id = ca.id + LEFT OUTER JOIN civicrm_option_group og + ON og.name = 'activity_status' + LEFT OUTER JOIN civicrm_option_value ov + ON ov.option_group_id=og.id + AND ov.name = 'Scheduled'"; + + $where = ' + WHERE cca.case_id= %1 + AND ca.is_current_revision = 1'; + + if (!empty($params['source_contact_id'])) { + $where .= " + AND cas.contact_id = " . CRM_Utils_Type::escape($params['source_contact_id'], 'Integer'); } if (!empty($params['status_id'])) { - $where .= " AND ca.status_id = " . CRM_Utils_Type::escape($params['status_id'], 'Integer'); + $where .= " + AND ca.status_id = " . CRM_Utils_Type::escape($params['status_id'], 'Integer'); } if (!empty($params['activity_deleted'])) { - $where .= " AND ca.is_deleted = 1"; + $where .= " + AND ca.is_deleted = 1"; } else { - $where .= " AND ca.is_deleted = 0"; + $where .= " + AND ca.is_deleted = 0"; } if (!empty($params['activity_type_id'])) { - $where .= " AND ca.activity_type_id = " . CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'); + $where .= " + AND ca.activity_type_id = " . CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'); } if (!empty($params['activity_date_low'])) { $fromActivityDate = CRM_Utils_Type::escape(CRM_Utils_Date::processDate($params['activity_date_low']), 'Date'); } + if (!empty($fromActivityDate)) { + $where .= " + AND ca.activity_date_time >= '{$fromActivityDate}'"; + } + if (!empty($params['activity_date_high'])) { $toActivityDate = CRM_Utils_Type::escape(CRM_Utils_Date::processDate($params['activity_date_high']), 'Date'); $toActivityDate = $toActivityDate ? $toActivityDate + 235959 : NULL; } - - if (!empty($fromActivityDate)) { - $where .= " AND ca.activity_date_time >= '{$fromActivityDate}'"; - } - if (!empty($toActivityDate)) { - $where .= " AND ca.activity_date_time <= '{$toActivityDate}'"; - } - - // hack to handle to allow initial sorting to be done by query - if (CRM_Utils_Array::value('sortname', $params) == 'undefined') { - $params['sortname'] = NULL; - } - - if (CRM_Utils_Array::value('sortorder', $params) == 'undefined') { - $params['sortorder'] = NULL; + $where .= " + AND ca.activity_date_time <= '{$toActivityDate}'"; } - $sortname = CRM_Utils_Array::value('sortname', $params); - $sortorder = CRM_Utils_Array::value('sortorder', $params); - - $groupBy = " GROUP BY ca.id "; + $groupBy = " + GROUP BY ca.id "; - if (!$sortname AND !$sortorder) { + $sortBy = CRM_Utils_Array::value('sortBy', $params); + if (!$sortBy) { // CRM-5081 - added id to act like creation date - $orderBy = " ORDER BY overdue_date ASC, display_date DESC, weight DESC"; + $orderBy = " + ORDER BY overdue_date ASC, display_date DESC, weight DESC"; } else { - $sort = "{$sortname} {$sortorder}"; - $sort = CRM_Utils_Type::escape($sort, 'String'); - $orderBy = " ORDER BY $sort "; - if ($sortname != 'display_date') { - $orderBy .= ', display_date DESC'; - } + $sortBy = CRM_Utils_Type::escape($sortBy, 'String'); + $orderBy = " ORDER BY $sortBy "; } - $page = CRM_Utils_Array::value('page', $params); - $rp = CRM_Utils_Array::value('rp', $params); - if (!$page) { $page = 1; } if (!$rp) { $rp = 10; } - $start = (($page - 1) * $rp); - $query = $select . $from . $where . $groupBy . $orderBy; + $limit = " LIMIT $start, $rp"; + $query = $select . $from . $where . $groupBy . $orderBy . $limit; $params = array(1 => array($caseID, 'Integer')); - $dao = CRM_Core_DAO::executeQuery($query, $params); - $params['total'] = $dao->N; - //FIXME: need to optimize/cache these queries - $limit = " LIMIT $start, $rp"; - $query .= $limit; - - //EXIT; $dao = CRM_Core_DAO::executeQuery($query, $params); + $page = CRM_Utils_Array::value('page', $params); + $rp = CRM_Utils_Array::value('rp', $params); + $activityTypes = CRM_Case_PseudoConstant::caseActivityType(FALSE, TRUE); - $activityStatus = CRM_Core_PseudoConstant::activityStatus(); - $activityPriority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id'); + $activityStatuses = CRM_Core_PseudoConstant::activityStatus(); $url = CRM_Utils_System::url("civicrm/case/activity", "reset=1&cid={$contactID}&caseid={$caseID}", FALSE, NULL, FALSE @@ -1214,9 +1224,8 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c foreach ($compStatusNames as $name) { $compStatusValues[] = CRM_Core_OptionGroup::getValue('activity_status', $name, 'name'); } - $contactViewUrl = CRM_Utils_System::url("civicrm/contact/view", - "reset=1&cid=", FALSE, NULL, FALSE - ); + + $contactViewUrl = CRM_Utils_System::url("civicrm/contact/view", "reset=1&cid=", FALSE, NULL, FALSE); $hasViewContact = CRM_Core_Permission::giveMeAllACLs(); $clientIds = self::retrieveContactIdsByCaseId($caseID); @@ -1225,11 +1234,15 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c $userID = $session->get('userID'); } + $caseActivities = array(); + while ($dao->fetch()) { + $caseActivity = array(); + $caseActivityId = $dao->id; - $allowView = self::checkPermission($dao->id, 'view', $dao->activity_type_id, $userID); - $allowEdit = self::checkPermission($dao->id, 'edit', $dao->activity_type_id, $userID); - $allowDelete = self::checkPermission($dao->id, 'delete', $dao->activity_type_id, $userID); + $allowView = self::checkPermission($caseActivityId, 'view', $dao->activity_type_id, $userID); + $allowEdit = self::checkPermission($caseActivityId, 'edit', $dao->activity_type_id, $userID); + $allowDelete = self::checkPermission($caseActivityId, 'delete', $dao->activity_type_id, $userID); //do not have sufficient permission //to access given case activity record. @@ -1237,56 +1250,82 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c continue; } - $values[$dao->id]['id'] = $dao->id; - $values[$dao->id]['type'] = $activityTypes[$dao->type]['label']; + //Add classes to the row, via DataTables syntax + $caseActivity['DT_RowClass'] = "crm-entity"; - $reporterName = $dao->reporter; - if ($hasViewContact) { - $reporterName = '' . $dao->reporter . ''; - } - $values[$dao->id]['reporter'] = $reporterName; - $targetNames = CRM_Activity_BAO_ActivityContact::getNames($dao->id, $targetID); - $targetContactUrls = $withContacts = array(); - foreach ($targetNames as $targetId => $targetName) { - if (!in_array($targetId, $clientIds)) { - $withContacts[$targetId] = $targetName; + if (CRM_Utils_Array::crmInArray($dao->status, $compStatusValues)) { + $caseActivity['DT_RowClass'] .= " status-completed"; + } + else { + if (CRM_Utils_Date::overdue($dao->display_date)) { + $caseActivity['DT_RowClass'] .= " status-overdue"; + } + else { + $caseActivity['DT_RowClass'] .= " status-scheduled"; } } - foreach ($withContacts as $cid => $name) { - if ($hasViewContact) { - $name = '' . $name . ''; + + if (!empty($dao->priority)) { + if ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Urgent', 'name')) { + $caseActivity['DT_RowClass'] .= " priority-urgent "; + } + elseif ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Low', 'name')) { + $caseActivity['DT_RowClass'] .= " priority-low "; } - $targetContactUrls[] = $name; } - $values[$dao->id]['with_contacts'] = implode('; ', $targetContactUrls); - $values[$dao->id]['display_date'] = CRM_Utils_Date::customFormat($dao->display_date); - $values[$dao->id]['status'] = $activityStatus[$dao->status]; + //Add data to the row for inline editing, via DataTable syntax + $caseActivity['DT_RowData'] = array(); + $caseActivity['DT_RowData']['entity'] = 'activity'; + $caseActivity['DT_RowData']['id'] = $caseActivityId; - //check for view activity. - $subject = (empty($dao->subject)) ? '(' . ts('no subject') . ')' : $dao->subject; - if ($allowView) { - $url = CRM_Utils_System::url('civicrm/case/activity/view', array('cid' => $contactID, 'aid' => $dao->id)); - $subject = '' . $subject . ''; - } - $values[$dao->id]['subject'] = $subject; + //Activity Date and Time + $caseActivity['activity_date_time'] = CRM_Utils_Date::customFormat($dao->display_date); - // add activity assignee to activity selector. CRM-4485. - if (isset($dao->assignee)) { - if ($dao->ismultiple == 1) { - if ($dao->reporter_id != $dao->assignee_id) { - $values[$dao->id]['reporter'] .= ($hasViewContact) ? ' / ' . "$dao->assignee" : ' / ' . $dao->assignee; - } - $values[$dao->id]['assignee'] = $dao->assignee; + //Activity Subject + $caseActivity['subject'] = $dao->subject; + + //Activity Type + $caseActivity['type'] = $activityTypes[$dao->type]['label']; + + //Activity Target (With) + $targetContact = ''; + if (isset($dao->target_contact_id)) { + $targetContact = $dao->target_contact_name; + if ($hasViewContact) { + $targetContact = '' . $dao->target_contact_name . ''; } - else { - $values[$dao->id]['reporter'] .= ' / ' . ts('(multiple)'); + } + $caseActivity['target_contact_name'] = $targetContact; + + //Activity Source Contact (Reporter) + $sourceContact = $dao->source_contact_name; + if ($hasViewContact) { + $sourceContact = '' . $dao->source_contact_name . ''; + } + $caseActivity['source_contact_name'] = $sourceContact; + + //Activity Assignee. CRM-4485. + $assigneeContact = ''; + if (isset($dao->assignee_contact_id)) { + $assigneeContact = $dao->assignee_contact_name; + if ($hasViewContact) { + $assigneeContact = '' . $dao->assignee_contact_name . ''; } } + $caseActivity['assignee_contact_name'] = $assigneeContact; + + //Activity Status + $caseActivity['status_id'] = $activityStatuses[$dao->status]; + // FIXME: Why are we not using CRM_Core_Action for these links? This is too much manual work and likely to get out-of-sync with core markup. $url = ""; $css = 'class="action-item crm-hover-button"'; - $additionalUrl = "&id={$dao->id}"; + if ($allowView) { + $url = CRM_Utils_System::url('civicrm/case/activity/view', array('cid' => $contactID, 'aid' => $caseActivityId)); + //$subject = '' . $subject . ''; + } + $additionalUrl = "&id={$caseActivityId}"; if (!$dao->deleted) { //hide edit link of activity type email.CRM-4530. if (!in_array($dao->type, $emailActivityTypeIDs)) { @@ -1301,25 +1340,25 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c } elseif (!$caseDeleted) { $url = ' ' . ts('Restore') . ''; - $values[$dao->id]['status'] = $values[$dao->id]['status'] . '
(deleted)'; + $caseActivity['status_id'] = $caseActivity['status_id'] . '
(deleted)'; } //check for operations. - if (self::checkPermission($dao->id, 'Move To Case', $dao->activity_type_id)) { - $url .= ' ' . ts('Move To Case') . ' '; + if (self::checkPermission($caseActivityId, 'Move To Case', $dao->activity_type_id)) { + $url .= ' ' . ts('Move To Case') . ' '; } - if (self::checkPermission($dao->id, 'Copy To Case', $dao->activity_type_id)) { - $url .= ' ' . ts('Copy To Case') . ' '; + if (self::checkPermission($caseActivityId, 'Copy To Case', $dao->activity_type_id)) { + $url .= ' ' . ts('Copy To Case') . ' '; } // if there are file attachments we will return how many and, if only one, add a link to it if (!empty($dao->attachment_ids)) { $attachmentIDs = explode(',', $dao->attachment_ids); - $values[$dao->id]['no_attachments'] = count($attachmentIDs); - if ($values[$dao->id]['no_attachments'] == 1) { + $caseActivity['no_attachments'] = count($attachmentIDs); + if ($caseActivity['no_attachments'] == 1) { // if there is only one it's easy to do a link - otherwise just flag it $attachmentViewUrl = CRM_Utils_System::url( "civicrm/file", - "reset=1&eid=" . $dao->id . "&id=" . $dao->attachment_ids, + "reset=1&eid=" . $caseActivityId . "&id=" . $dao->attachment_ids, FALSE, NULL, FALSE @@ -1328,37 +1367,18 @@ SELECT case_status.label AS case_status, status_id, civicrm_case_type.title AS c } } - $values[$dao->id]['links'] = $url; - $values[$dao->id]['class'] = ""; + $caseActivity['links'] = $url; - if (!empty($dao->priority)) { - if ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Urgent', 'name')) { - $values[$dao->id]['class'] = $values[$dao->id]['class'] . "priority-urgent "; - } - elseif ($dao->priority == CRM_Core_OptionGroup::getValue('priority', 'Low', 'name')) { - $values[$dao->id]['class'] = $values[$dao->id]['class'] . "priority-low "; - } - } - - if (CRM_Utils_Array::crmInArray($dao->status, $compStatusValues)) { - $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-completed"; - } - else { - if (CRM_Utils_Date::overdue($dao->display_date)) { - $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-overdue"; - } - else { - $values[$dao->id]['class'] = $values[$dao->id]['class'] . " status-scheduled"; - } - } - - if ($allowEdit) { - $values[$dao->id]['status'] = '
' . $values[$dao->id]['status'] . '
'; - } + array_push($caseActivities, $caseActivity); } $dao->free(); - return $values; + $caseActivitiesDT = array(); + $caseActivitiesDT['data'] = $caseActivities; + $caseActivitiesDT['recordsTotal'] = $params['total']; + $caseActivitiesDT['recordsFiltered'] = $params['total']; + + return $caseActivitiesDT; } /** diff --git a/templates/CRM/Case/Form/ActivityTab.tpl b/templates/CRM/Case/Form/ActivityTab.tpl index 1166416029..d7a0da2a36 100644 --- a/templates/CRM/Case/Form/ActivityTab.tpl +++ b/templates/CRM/Case/Form/ActivityTab.tpl @@ -24,6 +24,7 @@ +--------------------------------------------------------------------+ *} {*this template is used for activity accordion*} +{assign var=caseid value=$caseID}
{ts}Activities{/ts} @@ -42,24 +43,17 @@
{$form.status_id.html} - - {assign var=caseid value=$caseID} - - - - - - {assign var=activitylow value=activity_date_low_$caseID} + {assign var=activitylow value=activity_date_low_$caseID} {$form.$activitylow.label}
- {include file="CRM/common/jcalendar.tpl" elementName=$activitylow} + {include file="CRM/common/jcalendar.tpl" elementName=$activitylow} - {assign var=activityhigh value=activity_date_high_$caseID} + {assign var=activityhigh value=activity_date_high_$caseID} {$form.$activityhigh.label}
- {include file="CRM/common/jcalendar.tpl" elementName=$activityhigh} + {include file="CRM/common/jcalendar.tpl" elementName=$activityhigh} {$form.activity_type_filter_id.label}
@@ -77,120 +71,43 @@
- +
- - - - - - - - + + + + + + + +
{ts}Date{/ts}{ts}Subject{/ts}{ts}Type{/ts}{ts}With{/ts}{ts}Reporter / Assignee{/ts}{ts}Status{/ts}  {ts}Date{/ts}{ts}Subject{/ts}{ts}Type{/ts}{ts}With{/ts}{ts}Reporter{/ts}{ts}Assignee{/ts}{ts}Status{/ts} 
+ {literal} + + {/literal} - -{literal} - -{/literal} diff --git a/templates/CRM/Case/Form/CaseView.js b/templates/CRM/Case/Form/CaseView.js index eed398cd85..57e1576d9b 100644 --- a/templates/CRM/Case/Form/CaseView.js +++ b/templates/CRM/Case/Form/CaseView.js @@ -2,11 +2,7 @@ (function($, CRM) { function refresh(table) { - if (table) { - $(table).dataTable().fnDraw(); - } else { - $('#crm-main-content-wrapper').crmSnippet('refresh'); - } + $('#crm-main-content-wrapper').crmSnippet('refresh'); } function open(url, options, table) { diff --git a/templates/CRM/Case/Form/CaseView.tpl b/templates/CRM/Case/Form/CaseView.tpl index 56929a6eb4..3273107be7 100644 --- a/templates/CRM/Case/Form/CaseView.tpl +++ b/templates/CRM/Case/Form/CaseView.tpl @@ -27,222 +27,172 @@
-{* here we are showing related cases w/ jquery dialog *} -{if $showRelatedCases} - {include file="CRM/Case/Form/ViewRelatedCases.tpl"} - -{* Main case view *} -{else} - -

{ts}Summary{/ts}

- - {if $multiClient} - - - - {/if} - - {if not $multiClient} - + + + +
+ +
+ {if $hasRelatedCases} + + {/if} + + {/if} - - - - - - -
- {ts}Clients:{/ts} - {foreach from=$caseRoles.client item=client name=clients} - {$client.display_name}{if not $smarty.foreach.clients.last},   {/if} - {/foreach} - - - -
- -
- {if $hasRelatedCases} - - {/if} -
- - {foreach from=$caseRoles.client item=client} - - - - {if $client.phone} - - - - {/if} - {if $client.birth_date} - - - - {/if} + {* here we are showing related cases w/ jquery dialog *} + {if $showRelatedCases} + {include file="CRM/Case/Form/ViewRelatedCases.tpl"} + {* Main case view *} + {else} + +

{ts}Summary{/ts}

+
{$client.display_name}
{$client.phone}
{ts}DOB{/ts}: {$client.birth_date|crmDate}
+ {if $multiClient} + +
+ {ts}Clients:{/ts} + {foreach from=$caseRoles.client item=client name=clients} + {$client.display_name}{if not $smarty.foreach.clients.last},   {/if} {/foreach} -
- {if $hasRelatedCases} - - {/if} -
- {ts}Subject{/ts}: {$caseDetails.case_subject} - - {ts}Type{/ts}: {$caseDetails.case_type}  - - {ts}Status{/ts}: {$caseDetails.case_status}  - - {ts}Open Date{/ts}: {$caseDetails.case_start_date|crmDate}  - - {ts}ID{/ts}: {$caseID} -
+ + {if not $multiClient} + + + {foreach from=$caseRoles.client item=client} + + + + {if $client.phone} + + + + {/if} + {if $client.birth_date} + + + + {/if} + {/foreach} +
{$client.display_name}
{$client.phone}
{ts}DOB{/ts}: {$client.birth_date|crmDate}
+ {if $hasRelatedCases} + + {/if} + + {/if} + + {ts}Subject{/ts}: {$caseDetails.case_subject} + + + {ts}Type{/ts}: {$caseDetails.case_type}  + + + {ts}Status{/ts}: {$caseDetails.case_status}  + + + {ts}Open Date{/ts}: {$caseDetails.case_start_date|crmDate}  + + + {ts}ID{/ts}: {$caseID} + + + {if $hookCaseSummary} -
- {foreach from=$hookCaseSummary item=val key=div_id} -
{$val.value}
- {/foreach} -
+
+ {foreach from=$hookCaseSummary item=val key=div_id} +
{$val.value}
+ {/foreach} +
{/if} -
-
-

- {$form.add_activity_type_id.html} - {if $hasAccessToAllCases}   - {$form.timeline_id.html}{$form._qf_CaseView_next.html}   - {$form.report_id.html} - {/if} -

+
+
+

+ {$form.add_activity_type_id.html} + {if $hasAccessToAllCases}   + {$form.timeline_id.html}{$form._qf_CaseView_next.html}   + {$form.report_id.html} + {/if} +

+
+
+

+ {if $hasAccessToAllCases} + {ts}Print Report{/ts} + {/if} + + {if $mergeCases} + {ts}Merge Case{/ts} + {$form._qf_CaseView_next_merge_case.html} + + {$form.merge_case_id.html} + + {/if} + + {if call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))} + {ts}Assign to Another Client{/ts} + {/if} +

+
-
-

- {if $hasAccessToAllCases} - {ts}Print Report{/ts} - {/if} - {if $mergeCases} - {ts}Merge Case{/ts} - {$form._qf_CaseView_next_merge_case.html} - - {$form.merge_case_id.html} - - {/if} +

+ {include file="CRM/Case/Page/CustomDataView.tpl"} - {if call_user_func(array('CRM_Core_Permission','giveMeAllACLs'))} - {ts}Assign to Another Client{/ts} + - -
-{include file="CRM/Case/Page/CustomDataView.tpl"} - - {if $hasAccessToAllCases}
{/if} {* other relationship section ends *} -- 2.25.1