Rename activity search field from status_id to activity_status_id
authoreileen <emcnaughton@wikimedia.org>
Sun, 24 Nov 2019 22:04:09 +0000 (11:04 +1300)
committereileen <emcnaughton@wikimedia.org>
Sun, 24 Nov 2019 22:12:41 +0000 (11:12 +1300)
Currently this is on the form as 'status_id' but as soon as it's submitted the value is renamed - I think
we might not even need to change the smart group for this one.

The other field that is being renamed is 'priority_id'. Unless we have an appetite to
add a uniqueName for this field (which I kind of feel like not doing more of for some
cycles), I think we could stop renaming it & rely on the default where handling for the
where clause. From what I can see the reason for prefixing is not about
uniqueness but rather about adding a prefix so it gets handled by
Activity_BAO_Query - but in fact Contact_BAO_Query should handle it just fine
based on metadata

CRM/Activity/BAO/Query.php
CRM/Activity/Form/Search.php
CRM/Contact/Form/Search/Advanced.php
CRM/Contact/Form/Search/Custom/ActivitySearch.php
CRM/Core/Form/Search.php
templates/CRM/Activity/Form/Search/Common.tpl

index 5eea3826846ea3347af13abcd0242f5e60da2133..4ffdd8963e6dc9c71f9e16d2eb38d51889e573d7 100644 (file)
@@ -443,11 +443,12 @@ class CRM_Activity_BAO_Query {
   /**
    * Get the metadata for fields to be included on the activity search form.
    *
+   * @throws \CiviCRM_API3_Exception
    * @todo ideally this would be a trait included on the activity search & advanced search
    * rather than a static function.
    */
   public static function getSearchFieldMetadata() {
-    $fields = ['activity_type_id', 'activity_date_time', 'priority_id', 'activity_location'];
+    $fields = ['activity_type_id', 'activity_date_time', 'priority_id', 'activity_location', 'activity_status_id'];
     $metadata = civicrm_api3('Activity', 'getfields', [])['values'];
     $metadata = array_intersect_key($metadata, array_flip($fields));
     $metadata['activity_text'] = [
@@ -462,6 +463,9 @@ class CRM_Activity_BAO_Query {
    * Add all the elements shared between case activity search and advanced search.
    *
    * @param CRM_Core_Form_Search $form
+   *
+   * @throws \CiviCRM_API3_Exception
+   * @throws \CRM_Core_Exception
    */
   public static function buildSearchForm(&$form) {
     $form->addSearchFieldMetadata(['Activity' => self::getSearchFieldMetadata()]);
@@ -484,21 +488,13 @@ class CRM_Activity_BAO_Query {
       'flip' => 1,
       'labelColumn' => 'name',
     ]);
-    $form->addSelect('status_id',
-      [
-        'entity' => 'activity',
-        'multiple' => 'multiple',
-        'option_url' => NULL,
-        'placeholder' => ts('- any -'),
-      ]
-    );
     $ssID = $form->get('ssID');
     $status = [$activityStatus['Completed'], $activityStatus['Scheduled']];
     //If status is saved in smart group.
     if (!empty($ssID) && !empty($form->_formValues['activity_status_id'])) {
       $status = $form->_formValues['activity_status_id'];
     }
-    $form->setDefaults(['status_id' => $status]);
+    $form->setDefaults(['activity_status_id' => $status]);
 
     $form->addElement('text', 'activity_text', ts('Activity Text'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
 
index 480fdc7639f301bfe79e6664f0e6e04df352de14..5724ba411958dd385daab16098045e86447205ee 100644 (file)
@@ -173,6 +173,8 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
    *
    * The processing consists of using a Selector / Controller framework for getting the
    * search results.
+   *
+   * @throws \CRM_Core_Exception
    */
   public function postProcess() {
     if ($this->_done) {
@@ -184,11 +186,9 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
     if (!empty($_POST)) {
       $specialParams = [
         'activity_type_id',
-        'status_id',
         'priority_id',
       ];
       $changeNames = [
-        'status_id' => 'activity_status_id',
         'priority_id' => 'activity_priority_id',
       ];
 
index aa901bb825b8f1652a5764f51a48a2f89f727c8c..74479bfeffd49752d9a5fcb894f03684a55c1c53 100644 (file)
@@ -323,7 +323,6 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       'participant_status_id',
       'contribution_trxn_id',
       'activity_type_id',
-      'status_id',
       'priority_id',
       'contribution_product_id',
       'payment_instrument_id',
@@ -332,7 +331,6 @@ class CRM_Contact_Form_Search_Advanced extends CRM_Contact_Form_Search {
       'preferred_communication_method',
     ];
     $changeNames = [
-      'status_id' => 'activity_status_id',
       'priority_id' => 'activity_priority_id',
     ];
     CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, $specialParams, $changeNames);
index c2a2578f588a2ebb04c6b6651c97b7aaf6ec9e25..b0456e2f321b7c7e5d5c3873c71ed53d256efb08 100644 (file)
@@ -24,6 +24,8 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea
    * Class constructor.
    *
    * @param array $formValues
+   *
+   * @throws \CRM_Core_Exception
    */
   public function __construct(&$formValues) {
     $this->_formValues = self::formatSavedSearchFields($formValues);
@@ -145,6 +147,7 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea
    * @param bool $justIDs
    *
    * @return string
+   * @throws \CRM_Core_Exception
    */
   public function all(
     $offset = 0, $rowcount = 0, $sort = NULL,
@@ -188,7 +191,7 @@ class CRM_Contact_Form_Search_Custom_ActivitySearch extends CRM_Contact_Form_Sea
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Activity');
 
     foreach ($groupTree as $key) {
-      if (!empty($key['extends']) && $key['extends'] == 'Activity') {
+      if (!empty($key['extends']) && $key['extends'] === 'Activity') {
         $select .= ", " . $key['table_name'] . ".*";
         $from .= " LEFT JOIN " . $key['table_name'] . " ON " . $key['table_name'] . ".entity_id = activity.id";
       }
@@ -348,6 +351,8 @@ ORDER BY contact_a.sort_name';
 
   /**
    * @inheritDoc
+   *
+   * @throws \CRM_Core_Exception
    */
   public function count() {
     $sql = $this->all();
index 0553ae91690d5e1d0ada50d218cca4e5dc1ab198..855ab66045820873ecc4e5354728b02acd24a9cb 100644 (file)
@@ -143,7 +143,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
   /**
    * Set the form values based on input and preliminary processing.
    *
-   * @throws \Exception
+   * @throws \CRM_Core_Exception
    */
   protected function setFormValues() {
     $this->_formValues = $this->getFormValues();
index a4d3b8a4fe002dc6398d3942a13c37d57789e30d..954984a9fc0e837a62795384cd3d4fcc4ed05aed 100644 (file)
@@ -80,8 +80,8 @@
     {$form.activity_option.html}<br/>
   </td>
   <td colspan="2">
-    {$form.status_id.label}<br/>
-    {$form.status_id.html}
+    {$form.activity_status_id.label}<br/>
+    {$form.activity_status_id.html}
   </td>
 </tr>
 <tr>