Commit ce9d78e1 authored by colemanw's avatar colemanw
Browse files

CRM-20830 - Trinary activity status types

parent 760ac501
......@@ -36,6 +36,14 @@
*/
class CRM_Activity_BAO_Activity extends CRM_Activity_DAO_Activity {
/**
* Activity status types
*/
const
INCOMPLETE = 0,
COMPLETED = 1,
CANCELLED = 2;
/**
* Static field for all the activity information that we can potentially export.
*
......@@ -2437,37 +2445,31 @@ AND cl.modified_id = c.id
}
/**
* Return list of activity statuses that are considered "completed".
* Return list of activity statuses of a given type.
*
* Note: activity status options use the "grouping" field to distinguish complete from incomplete statuses.
* Note: activity status options use the "grouping" field to distinguish status types.
* Types are defined in class constants INCOMPLETE, COMPLETED, CANCELLED
*
* @param int $type
*
* @return array
*/
public static function getCompletedStatuses() {
public static function getStatusesByType($type) {
if (!isset(Civi::$statics[__CLASS__][__FUNCTION__])) {
$statuses = civicrm_api3('OptionValue', 'get', array(
'option_group_id' => "activity_status",
'filter' => 1,
'return' => array('value'),
'sequential' => 1,
'return' => array('value', 'name', 'filter'),
'options' => array('limit' => 0),
));
Civi::$statics[__CLASS__][__FUNCTION__] = CRM_Utils_Array::collect('value', $statuses['values']);
Civi::$statics[__CLASS__][__FUNCTION__] = $statuses['values'];
}
return Civi::$statics[__CLASS__][__FUNCTION__];
$ret = array();
foreach (Civi::$statics[__CLASS__][__FUNCTION__] as $status) {
if ($status['filter'] == $type) {
$ret[$status['value']] = $status['name'];
}
/**
* Check if status_id is completed.
*
* Note: activity status options use the "grouping" field to distinguish complete from incomplete statuses.
*
* @param int $statusId
*
* @return bool
*/
public static function isCompleted($statusId) {
return in_array($statusId, self::getCompletedStatuses());
}
return $ret;
}
/**
......@@ -2478,7 +2480,7 @@ AND cl.modified_id = c.id
* @return bool
*/
public static function isOverdue($activity) {
return !self::isCompleted($activity['status_id']) && CRM_Utils_Date::overdue($activity['activity_date_time']);
return array_key_exists($activity['status_id'], self::getStatusesByType(self::INCOMPLETE)) && CRM_Utils_Date::overdue($activity['activity_date_time']);
}
/**
......
......@@ -226,7 +226,11 @@ class CRM_Admin_Form_Options extends CRM_Admin_Form {
$this->add('select',
'filter',
ts('Status Type'),
array(ts('Incomplete'), ts('Completed'))
array(
CRM_Activity_BAO_Activity::INCOMPLETE => ts('Incomplete'),
CRM_Activity_BAO_Activity::COMPLETED => ts('Completed'),
CRM_Activity_BAO_Activity::CANCELLED => ts('Cancelled'),
)
);
}
if ($this->_gName == 'redaction_rule') {
......
......@@ -14,7 +14,13 @@ VALUES
-- CRM-20387
UPDATE `civicrm_contribution` SET `invoice_number` = `invoice_id` WHERE `invoice_id` LIKE CONCAT('%', `id`);
-- CRM-20830
UPDATE `civicrm_option_value`
SET filter = 1
WHERE option_group_id = (SELECT id FROM civicrm_option_group WHERE name = 'activity_status')
AND name IN ('Completed', 'Cancelled', 'Unreachable', 'Not Required', 'No-show');
AND name = 'Completed';
UPDATE `civicrm_option_value`
SET filter = 2
WHERE option_group_id = (SELECT id FROM civicrm_option_group WHERE name = 'activity_status')
AND name IN ('Cancelled', 'Unreachable', 'Not Required', 'No-show');
......@@ -336,13 +336,13 @@ function civicrm_api3_activity_get($params) {
// Handle is_overdue filter
if (isset($params['is_overdue'])) {
$completedStatuses = implode(',', CRM_Activity_BAO_Activity::getCompletedStatuses());
$incomplete = implode(',', array_keys(CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::INCOMPLETE)));
if ($params['is_overdue']) {
$sql->where('a.activity_date_time < NOW()');
$sql->where("a.status_id NOT IN ($completedStatuses)");
$sql->where("a.status_id IN ($incomplete)");
}
else {
$sql->where("(a.activity_date_time >= NOW() OR a.status_id IN ($completedStatuses))");
$sql->where("(a.activity_date_time >= NOW() OR a.status_id NOT IN ($incomplete))");
}
}
......@@ -355,8 +355,8 @@ function civicrm_api3_activity_get($params) {
// Get sort field and direction
list($sortField, $dir) = array_pad(explode(' ', $sortString), 2, 'ASC');
if ($sortField == 'is_overdue') {
$completedStatuses = implode(',', CRM_Activity_BAO_Activity::getCompletedStatuses());
$sql->orderBy("IF((a.activity_date_time >= NOW() OR a.status_id IN ($completedStatuses)), 0, 1) $dir", NULL, $index);
$incomplete = implode(',', array_keys(CRM_Activity_BAO_Activity::getStatusesByType(CRM_Activity_BAO_Activity::INCOMPLETE)));
$sql->orderBy("IF((a.activity_date_time >= NOW() OR a.status_id NOT IN ($incomplete)), 0, 1) $dir", NULL, $index);
$sortString = '(1)';
}
}
......
This diff is collapsed.
......@@ -641,12 +641,12 @@ VALUES
(@option_group_id_acs, '{ts escape="sql"}Scheduled{/ts}', 1, 'Scheduled', NULL, 0, 1, 1, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Completed{/ts}', 2, 'Completed', NULL, 1, NULL, 2, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Cancelled{/ts}', 3, 'Cancelled', NULL, 1, NULL, 3, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Cancelled{/ts}', 3, 'Cancelled', NULL, 2, NULL, 3, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Left Message{/ts}', 4, 'Left Message', NULL, 0, NULL, 4, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Unreachable{/ts}', 5, 'Unreachable', NULL, 1, NULL, 5, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Not Required{/ts}', 6, 'Not Required', NULL, 1, NULL, 6, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Unreachable{/ts}', 5, 'Unreachable', NULL, 2, NULL, 5, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Not Required{/ts}', 6, 'Not Required', NULL, 2, NULL, 6, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}Available{/ts}', 7, 'Available', NULL, 0, NULL, 7, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}No-show{/ts}', 8, 'No_show', NULL, 1, NULL, 8, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_acs, '{ts escape="sql"}No-show{/ts}', 8, 'No_show', NULL, 2, NULL, 8, NULL, 0, 0, 1, NULL, NULL, NULL),
(@option_group_id_cas, '{ts escape="sql"}Ongoing{/ts}' , 1, 'Open' , 'Opened', 0, 1, 1, NULL, 0, 1, 1, NULL, NULL, NULL),
(@option_group_id_cas, '{ts escape="sql"}Resolved{/ts}', 2, 'Closed', 'Closed', 0, NULL, 2, NULL, 0, 1, 1, NULL, NULL, NULL),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment