CRM-19883 - Activity Priority Field is Not Included in Advanced Search or Activity...
authoryashodha <yashodha.chaku@webaccessglobal.com>
Mon, 16 Jan 2017 09:25:54 +0000 (14:55 +0530)
committeryashodha <yashodha.chaku@webaccessglobal.com>
Tue, 17 Jan 2017 07:04:48 +0000 (12:34 +0530)
CRM/Activity/BAO/Activity.php
CRM/Activity/BAO/Query.php
CRM/Activity/Form/Search.php
CRM/Contact/BAO/Query.php
CRM/Contact/Form/Search/Advanced.php
CRM/Report/Form/Activity.php
CRM/Report/Form/ActivitySummary.php
templates/CRM/Activity/Form/Search/Common.tpl

index b990e3d7a8493d9d27e7219b3a1a234da35f1d2f..05e5d09de9b7d69b28adff8f47b87602d41ce31f 100644 (file)
@@ -2175,6 +2175,12 @@ AND cl.modified_id  = c.id
             '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);
       }
index 00b314727ef0491d87a75f7e903f4f8ce942a704..042276c9c85a3350285e7d92d384285756f4920f 100644 (file)
@@ -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;
@@ -54,7 +54,7 @@ class CRM_Activity_BAO_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;
@@ -63,19 +63,19 @@ class CRM_Activity_BAO_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;
@@ -84,8 +84,8 @@ class CRM_Activity_BAO_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;
@@ -94,31 +94,31 @@ class CRM_Activity_BAO_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;
     }
@@ -152,6 +152,15 @@ class CRM_Activity_BAO_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;
+    }
   }
 
   /**
@@ -192,6 +201,7 @@ class CRM_Activity_BAO_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':
@@ -200,7 +210,7 @@ class CRM_Activity_BAO_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);
         }
@@ -221,6 +231,7 @@ class CRM_Activity_BAO_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));
@@ -379,6 +390,12 @@ class CRM_Activity_BAO_Query {
                                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;
@@ -444,6 +461,11 @@ class CRM_Activity_BAO_Query {
     $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) {
@@ -531,6 +553,7 @@ class CRM_Activity_BAO_Query {
         'activity_location' => 1,
         'activity_details' => 1,
         'activity_status' => 1,
+        'activity_priority' => 1,
         'source_contact' => 1,
         'source_record_id' => 1,
         'activity_is_test' => 1,
index 91917d117972c770ae818887512906c2481c63eb..1ed11f3ddf5b43c6c7b91c3452f5a00764c2a48a 100644 (file)
@@ -195,9 +195,14 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
       $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);
     }
 
index 2cbacac170ccfd818426a83295b044194e5f4684..07f7ce6ab47d7a47d2900d0870e5d32ce0b27a4b 100644 (file)
@@ -1883,6 +1883,8 @@ class CRM_Contact_BAO_Query {
       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':
@@ -2659,6 +2661,7 @@ class CRM_Contact_BAO_Query {
         case 'parent_id':
         case 'civicrm_activity_contact':
         case 'source_contact':
+        case 'activity_priority':
           $from .= CRM_Activity_BAO_Query::from($name, $mode, $side);
           continue;
 
index 3e2b7fcf54d6357dd5cdf2d365df8de19a79a21c..d1710683878675470bf7f48817a6d870ccf87a2a 100644 (file)
@@ -347,6 +347,7 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       'contribution_trxn_id',
       'activity_type_id',
       'status_id',
+      'priority_id',
       'activity_subject',
       'activity_details',
       'contribution_page_id',
@@ -356,7 +357,10 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       '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);
index 1447ce56b7c98dee580627bda96a334872657061..346d943b11b8d593557517797bed71b5a4160442 100644 (file)
@@ -256,6 +256,11 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
           '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(
index e6041b1901657abca67426fc2fe70c83b5a458f3..e1a1049a90777b522a4579026fd9ecf26098ea57 100644 (file)
@@ -125,6 +125,11 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
             '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,
@@ -672,6 +677,7 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
     $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
@@ -762,6 +768,13 @@ class CRM_Report_Form_ActivitySummary extends CRM_Report_Form {
         }
       }
 
+      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'];
index 73c0320a8a3458227129f4c99123682753b903f0..df9923c00f140544934c133e2dd81a1932a1458b 100644 (file)
   </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}