Skip to content

Commit

Permalink
CRM-19883 - Activity Priority Field is Not Included in Advanced Searc…
Browse files Browse the repository at this point in the history
…h or Activity Reports
  • Loading branch information
yashodha committed Jan 16, 2017
1 parent 6f88f9a commit 1f22293
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 18 deletions.
6 changes: 6 additions & 0 deletions CRM/Activity/BAO/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -2175,6 +2175,12 @@ public static function &exportableFields($name = 'Activity') {
'type' => CRM_Utils_Type::T_STRING,
'searchByLabel' => TRUE,
),
'activity_priority' => array(
'title' => ts('Activity Priority'),
'name' => 'activity_priority',
'type' => CRM_Utils_Type::T_STRING,
'searchByLabel' => TRUE,
),
);
$fields = array_merge($Activityfields, $exportableFields);
}
Expand Down
51 changes: 37 additions & 14 deletions CRM/Activity/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ class CRM_Activity_BAO_Query {
*/
public static function select(&$query) {
if (!empty($query->_returnProperties['activity_id'])) {
$query->_select['activity_id'] = "civicrm_activity.id as activity_id";
$query->_select['activity_id'] = 'civicrm_activity.id as activity_id';
$query->_element['activity_id'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['activity_type_id'])) {
$query->_select['activity_type_id'] = "activity_type.value as activity_type_id";
$query->_select['activity_type_id'] = 'activity_type.value as activity_type_id';
$query->_element['activity_type_id'] = 1;
$query->_tables['civicrm_activity'] = 1;
$query->_tables['activity_type'] = 1;
Expand All @@ -54,7 +54,7 @@ public static function select(&$query) {
}

if (!empty($query->_returnProperties['activity_type'])) {
$query->_select['activity_type'] = "activity_type.label as activity_type";
$query->_select['activity_type'] = 'activity_type.label as activity_type';
$query->_element['activity_type'] = 1;
$query->_tables['civicrm_activity'] = 1;
$query->_tables['activity_type'] = 1;
Expand All @@ -63,19 +63,19 @@ public static function select(&$query) {
}

if (!empty($query->_returnProperties['activity_subject'])) {
$query->_select['activity_subject'] = "civicrm_activity.subject as activity_subject";
$query->_select['activity_subject'] = 'civicrm_activity.subject as activity_subject';
$query->_element['activity_subject'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['activity_date_time'])) {
$query->_select['activity_date_time'] = "civicrm_activity.activity_date_time as activity_date_time";
$query->_select['activity_date_time'] = 'civicrm_activity.activity_date_time as activity_date_time';
$query->_element['activity_date_time'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['activity_status_id'])) {
$query->_select['activity_status_id'] = "activity_status.value as activity_status_id";
$query->_select['activity_status_id'] = 'activity_status.value as activity_status_id';
$query->_element['activity_status_id'] = 1;
$query->_tables['civicrm_activity'] = 1;
$query->_tables['activity_status'] = 1;
Expand All @@ -84,8 +84,8 @@ public static function select(&$query) {
}

if (!empty($query->_returnProperties['activity_status'])) {
$query->_select['activity_status'] = "activity_status.label as activity_status,
civicrm_activity.status_id as status_id";
$query->_select['activity_status'] = 'activity_status.label as activity_status,
civicrm_activity.status_id as status_id';
$query->_element['activity_status'] = 1;
$query->_tables['civicrm_activity'] = 1;
$query->_tables['activity_status'] = 1;
Expand All @@ -94,31 +94,31 @@ public static function select(&$query) {
}

if (!empty($query->_returnProperties['activity_duration'])) {
$query->_select['activity_duration'] = "civicrm_activity.duration as activity_duration";
$query->_select['activity_duration'] = 'civicrm_activity.duration as activity_duration';
$query->_element['activity_duration'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['activity_location'])) {
$query->_select['activity_location'] = "civicrm_activity.location as activity_location";
$query->_select['activity_location'] = 'civicrm_activity.location as activity_location';
$query->_element['activity_location'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['activity_details'])) {
$query->_select['activity_details'] = "civicrm_activity.details as activity_details";
$query->_select['activity_details'] = 'civicrm_activity.details as activity_details';
$query->_element['activity_details'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['source_record_id'])) {
$query->_select['source_record_id'] = "civicrm_activity.source_record_id as source_record_id";
$query->_select['source_record_id'] = 'civicrm_activity.source_record_id as source_record_id';
$query->_element['source_record_id'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}

if (!empty($query->_returnProperties['activity_is_test'])) {
$query->_select['activity_is_test'] = "civicrm_activity.is_test as activity_is_test";
$query->_select['activity_is_test'] = 'civicrm_activity.is_test as activity_is_test';
$query->_element['activity_is_test'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
Expand Down Expand Up @@ -152,6 +152,15 @@ public static function select(&$query) {
$query->_whereTables['parent_id'] = 1;
$query->_element['parent_id'] = 1;
}

if (!empty($query->_returnProperties['activity_priority'])) {
$query->_select['activity_priority'] = 'activity_priority.label as activity_priority,
civicrm_activity.priority_id as priority_id';
$query->_element['activity_priority'] = 1;
$query->_tables['activity_priority'] = 1;
$query->_whereTables['activity_priority'] = 1;
$query->_tables['civicrm_activity'] = $query->_whereTables['civicrm_activity'] = 1;
}
}

/**
Expand Down Expand Up @@ -192,6 +201,7 @@ public static function whereClauseSingle(&$values, &$query) {
case 'activity_engagement_level':
case 'activity_id':
case 'activity_campaign_id':
case 'activity_priority_id':
// We no longer expect "subject" as a specific criteria (as of CRM-19447),
// but we still use activity_subject in Activity.Get API
case 'activity_subject':
Expand All @@ -200,7 +210,7 @@ public static function whereClauseSingle(&$values, &$query) {
if (in_array($name, array('activity_engagement_level', 'activity_id'))) {
$name = $qillName = str_replace('activity_', '', $name);
}
if (in_array($name, array('activity_status_id', 'activity_subject'))) {
if (in_array($name, array('activity_status_id', 'activity_subject', 'activity_priority_id'))) {
$name = str_replace('activity_', '', $name);
$qillName = str_replace('_id', '', $qillName);
}
Expand All @@ -221,6 +231,7 @@ public static function whereClauseSingle(&$values, &$query) {

case 'activity_type':
case 'activity_status':
case 'activity_priority':
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("$name.label", $op, $value, 'String');
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Activity_DAO_Activity', $name, $value, $op);
$query->_qill[$grouping][] = ts('%1 %2 %3', array(1 => $fields[$name]['title'], 2 => $op, 3 => $value));
Expand Down Expand Up @@ -379,6 +390,12 @@ public static function from($name, $mode, $side) {
AND option_group_activity_type.id = activity_type.option_group_id ) ";
break;

case 'activity_priority':
$from .= " $side JOIN civicrm_option_group option_group_activity_priority ON (option_group_activity_priority.name = 'priority')";
$from .= " $side JOIN civicrm_option_value activity_priority ON (civicrm_activity.priority_id = activity_priority.value
AND option_group_activity_priority.id = activity_priority.option_group_id ) ";
break;

case 'civicrm_activity_tag':
$from .= " $side JOIN civicrm_entity_tag as civicrm_activity_tag ON ( civicrm_activity_tag.entity_table = 'civicrm_activity' AND civicrm_activity_tag.entity_id = civicrm_activity.id ) ";
break;
Expand Down Expand Up @@ -444,6 +461,11 @@ public static function buildSearchForm(&$form) {
$form->addRadio('activity_option', '', CRM_Core_SelectValues::activityTextOptions());
$form->setDefaults(array('activity_option' => 'both'));

$priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
$form->addSelect('priority_id',
array('entity' => 'activity', 'label' => ts('Priority'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
);

$form->addYesNo('activity_test', ts('Activity is a Test?'));
$activity_tags = CRM_Core_BAO_Tag::getTags('civicrm_activity');
if ($activity_tags) {
Expand Down Expand Up @@ -531,6 +553,7 @@ public static function defaultReturnProperties($mode, $includeCustomFields = TRU
'activity_location' => 1,
'activity_details' => 1,
'activity_status' => 1,
'activity_priority' => 1,
'source_contact' => 1,
'source_record_id' => 1,
'activity_is_test' => 1,
Expand Down
7 changes: 6 additions & 1 deletion CRM/Activity/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,14 @@ public function postProcess() {
$specialParams = array(
'activity_type_id',
'status_id',
'priority_id',
'activity_text',
);
$changeNames = array('status_id' => 'activity_status_id');
$changeNames = array(
'status_id' => 'activity_status_id',
'priority_id' => 'activity_priority_id',
);

CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams, $changeNames);
}

Expand Down
3 changes: 3 additions & 0 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,8 @@ public function whereClauseSingle(&$values, $apiEntity = NULL) {
case 'activity_role':
case 'activity_status_id':
case 'activity_status':
case 'activity_priority':
case 'activity_priority_id':
case 'followup_parent_id':
case 'parent_id':
case 'source_contact_id':
Expand Down Expand Up @@ -2659,6 +2661,7 @@ public static function fromClause(&$tables, $inner = NULL, $right = NULL, $prima
case 'parent_id':
case 'civicrm_activity_contact':
case 'source_contact':
case 'activity_priority':
$from .= CRM_Activity_BAO_Query::from($name, $mode, $side);
continue;

Expand Down
6 changes: 5 additions & 1 deletion CRM/Contact/Form/Search/Advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ public function normalizeFormValues() {
'contribution_trxn_id',
'activity_type_id',
'status_id',
'priority_id',
'activity_subject',
'activity_details',
'contribution_page_id',
Expand All @@ -356,7 +357,10 @@ public function normalizeFormValues() {
'contact_tags',
'preferred_communication_method',
);
$changeNames = array('status_id' => 'activity_status_id');
$changeNames = array(
'status_id' => 'activity_status_id',
'priority_id' => 'activity_priority_id',
);
CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams, $changeNames);

$taglist = CRM_Utils_Array::value('contact_taglist', $this->_formValues);
Expand Down
5 changes: 5 additions & 0 deletions CRM/Report/Form/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ public function __construct() {
'details' => array(
'title' => ts('Activity Details'),
),
'priority_id' => array(
'title' => ts('Priority'),
'default' => TRUE,
'type' => CRM_Utils_Type::T_STRING,
),
),
'filters' => array(
'activity_date_time' => array(
Expand Down
13 changes: 13 additions & 0 deletions CRM/Report/Form/ActivitySummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ public function __construct() {
'title' => ts('Duration'),
'default' => TRUE,
),
'priority_id' => array(
'title' => ts('Priority'),
'default' => TRUE,
'type' => CRM_Utils_Type::T_STRING,
),
'id' => array(
'title' => ts('Total Activities'),
'required' => TRUE,
Expand Down Expand Up @@ -672,6 +677,7 @@ public function alterDisplay(&$rows) {
$entryFound = FALSE;
$activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
$activityStatus = CRM_Core_PseudoConstant::activityStatus();
$priority = CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id');
$onHover = ts('View Contact Summary for this Contact');
foreach ($rows as $rowNum => $row) {
// make count columns point to activity detail report
Expand Down Expand Up @@ -762,6 +768,13 @@ public function alterDisplay(&$rows) {
}
}

if (array_key_exists('civicrm_activity_priority_id', $row)) {
if ($value = $row['civicrm_activity_priority_id']) {
$rows[$rowNum]['civicrm_activity_priority_id'] = $priority[$value];
$entryFound = TRUE;
}
}

if (array_key_exists('civicrm_activity_duration', $row)) {
if ($value = $row['civicrm_activity_duration']) {
$rows[$rowNum]['civicrm_activity_duration'] = $rows[$rowNum]['civicrm_activity_duration_total'];
Expand Down
6 changes: 4 additions & 2 deletions templates/CRM/Activity/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,10 @@
</td>
</tr>
<tr>
{* td intentionally left blank to align the 'is test' widget on the right *}
<td></td>
<td>
{$form.priority_id.label}<br />
{$form.priority_id.html}
</td>
<td colspan="2">
{$form.activity_test.label} {help id="is-test" file="CRM/Contact/Form/Search/Advanced"}
&nbsp; {$form.activity_test.html}
Expand Down

0 comments on commit 1f22293

Please sign in to comment.