CRM-20799: make activity filter user preference an optional setting
authordeb.monish <monish.deb@jmaconsulting.biz>
Sat, 1 Jul 2017 11:34:44 +0000 (17:04 +0530)
committerdeb.monish <monish.deb@jmaconsulting.biz>
Sat, 1 Jul 2017 19:28:09 +0000 (00:58 +0530)
CRM/Activity/Form/ActivityFilter.php
CRM/Activity/Page/AJAX.php
CRM/Admin/Form/Preferences/Display.php
settings/Core.setting.php
templates/CRM/Activity/Selector/Selector.tpl
templates/CRM/Admin/Form/Preferences/Display.tpl
templates/CRM/Core/DateRange.tpl
tests/phpunit/CRM/Activity/BAO/ActivityTest.php

index bcfaede42931e47d78a51bb2e9e00f09a87cf16e..b843dc2a0e7aa63d4a67e4fac9d05ab627de3a4c 100644 (file)
@@ -67,8 +67,7 @@ class CRM_Activity_Form_ActivityFilter extends CRM_Core_Form {
   public function setDefaultValues() {
     // CRM-11761 retrieve user's activity filter preferences
     $defaults = array();
-    $userID = CRM_Core_Session::getLoggedInContactID();
-    if ($userID) {
+    if (Civi::settings()->get('preserve_activity_tab_filter') && ($userID = CRM_Core_Session::getLoggedInContactID())) {
       $defaults = Civi::service('settings_manager')
         ->getBagByContact(NULL, $userID)
         ->get('activity_tab_filter');
index b3a1c786021f138f592ace0a3e8ecfd4a0ec7ac1..a7fab121825ed8c3cc3d0fc855ac5e6a5eedd4f8 100644 (file)
@@ -433,13 +433,22 @@ class CRM_Activity_Page_AJAX {
     }
 
     // store the activity filter preference CRM-11761
-    $session = CRM_Core_Session::singleton();
-    $userID = $session->get('userID');
-    if ($userID) {
-      $activityFilter = array(
-        'activity_type_filter_id' => empty($params['activity_type_id']) ? '' : CRM_Utils_Type::escape($params['activity_type_id'], 'Integer'),
-        'activity_type_exclude_filter_id' => empty($params['activity_type_exclude_id']) ? '' : CRM_Utils_Type::escape($params['activity_type_exclude_id'], 'Integer'),
-      );
+    if (Civi::settings()->get('preserve_activity_tab_filter') && ($userID = CRM_Core_Session::getLoggedInContactID())) {
+      unset($optionalParameters['context']);
+      foreach ($optionalParameters as $searchField => $dataType) {
+        if (!empty($params[$searchField])) {
+          $activityFilter[$searchField] = CRM_Utils_Type::escape($params[$searchField], $dataType);
+          if (in_array($searchField, array('activity_date_low', 'activity_date_high'))) {
+            $activityFilter['activity_date_relative'] = 0;
+          }
+          elseif ($searchField == 'activity_status_id') {
+            $activityFilter['status_id'] = explode(',', $activityFilter[$searchField]);
+          }
+        }
+        elseif (in_array($searchField, array('activity_type_id', 'activity_type_exclude_id'))) {
+          $activityFilter[$searchField] = '';
+        }
+      }
 
       /**
        * @var \Civi\Core\SettingsBag $cSettings
index c6d1d13fbd54c8be54cfdb2555b882851826cc1b..bc678af44497ca8b5aeb346a6569244e79d13e07 100644 (file)
@@ -70,34 +70,39 @@ class CRM_Admin_Form_Preferences_Display extends CRM_Admin_Form_Preferences {
           'title' => ts('Include ICal Invite to Activity Assignees'),
           'weight' => 6,
         ),
+        'preserve_activity_tab_filter' => array(
+          'html_type' => 'checkbox',
+          'title' => ts('Preserve activity filters as a user preference'),
+          'weight' => 7,
+        ),
         'contact_ajax_check_similar' => array(
           'html_type' => 'checkbox',
           'title' => ts('Check for Similar Contacts'),
-          'weight' => 7,
+          'weight' => 8,
         ),
         'user_dashboard_options' => array(
           'html_type' => 'checkboxes',
           'title' => ts('Contact Dashboard'),
-          'weight' => 8,
+          'weight' => 9,
         ),
         'display_name_format' => array(
           'html_type' => 'textarea',
           'title' => ts('Individual Display Name Format'),
-          'weight' => 9,
+          'weight' => 10,
         ),
         'sort_name_format' => array(
           'html_type' => 'textarea',
           'title' => ts('Individual Sort Name Format'),
-          'weight' => 10,
+          'weight' => 11,
         ),
         'editor_id' => array(
           'html_type' => NULL,
-          'weight' => 11,
+          'weight' => 12,
         ),
         'ajaxPopupsEnabled' => array(
           'html_type' => 'checkbox',
           'title' => ts('Enable Popup Forms'),
-          'weight' => 12,
+          'weight' => 13,
         ),
       ),
     );
index b2c8940e3900de3840d1c1b7f32d05ac185ede48..d09cc36c45185ca9ade19463f99288aa87f4e868 100644 (file)
@@ -953,4 +953,18 @@ return array(
     'description' => 'If enabled, then CMS email id will be syncronised with CiviCRM contacts\'s primary email.',
     'help_text' => NULL,
   ),
+  'preserve_activity_tab_filter' => array(
+    'group_name' => 'CiviCRM Preferences',
+    'group' => 'core',
+    'name' => 'preserve_activity_tab_filter',
+    'type' => 'String',
+    'html_type' => 'Text',
+    'default' => '0',
+    'add' => '4.7',
+    'title' => 'Preserve activity filters as a user preference',
+    'is_domain' => 1,
+    'is_contact' => 0,
+    'description' => 'When enabled, any filter settings a user selects on the contact\'s Activity tab will be remembered as they visit other contacts',
+    'help_text' => NULL,
+  ),
 );
index 471fdc3fdfad2a597b5181cdfdbf68204b655dc7..d934a36b55a13c4e17b7bf0df12c27772d8edf6d 100644 (file)
@@ -39,7 +39,7 @@
           </td>
           {include file="CRM/Core/DateRange.tpl" fieldName="activity_date" from='_low' to='_high' label='Date'}
           <td class="crm-contact-form-block-activity_status_filter_id crm-inline-edit-field">
-            {ts}Status{/ts}: {$form.status_id.html|crmAddClass:medium}
+            {ts}Status{/ts}<br /> {$form.status_id.html|crmAddClass:medium}
           </td>
         </tr>
       </table>
index ae5831e80ad61189aad5a315dc75a632f7ac0c91..fe6e16231d94cd0344050079984673a57ff227c6 100644 (file)
       </td>
     </tr>
 
+    <tr class="crm-preferences-display-form-block-preserve_activity_tab_filter">
+      <td class="label"></td>
+      <td>{$form.preserve_activity_tab_filter.html} {$form.preserve_activity_tab_filter.label}</td>
+    </tr>
+    <tr class="crm-preferences-display-form-block-description">
+      <td>&nbsp;</td>
+      <td class="description">{ts}When enabled, any filter settings a user selects on the contact's Activity tab will be remembered as they visit other contacts.{/ts}
+      </td>
+    </tr>
+
     <tr class="crm-preferences-display-form-block-user_dashboard_options">
       <td class="label">{$form.user_dashboard_options.label}</td>
       <td>{$form.user_dashboard_options.html}<span id="invoice_help">  {help id="id-invoices_id"}</span></td>
index 8e30142669b5cd682a26cec8fdf46e13b0d3c99b..723f3286fc7fa73d0d1ac32165dc72236ddedc24 100644 (file)
@@ -27,7 +27,7 @@
 {assign var=relativeName   value=$fieldName|cat:"_relative"}
 <td colspan=2>
   {if $label}
-   {ts}{$label}{/ts}
+   {ts}{$label}{/ts}<br />
   {/if}
   {$form.$relativeName.html}<br />
   <span class="crm-absolute-date-range">
index 97ffec5904badf91b0cf579df2e59845e526898f..27089d02543469f05418fab0606bb14c6daa3401 100644 (file)
@@ -745,20 +745,20 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
     // activity IDs catagorised by date
     $lastWeekActivities = array(1, 2, 3);
     $todayActivities = array(4, 5, 6, 7);
-    $lastMonthActivities = array(8, 9, 10, 11);
+    $lastTwoMonthsActivities = array(8, 9, 10, 11);
     $lastYearActivties = array(12, 13, 14, 15, 16);
 
     // date values later used to set activity date value
     $lastWeekDate = date('YmdHis', strtotime('1 week ago'));
     $today = date('YmdHis');
-    $lastMonthDate = date('YmdHis', strtotime('1 month ago'));
+    $lastTwoMonthAgoDate = date('YmdHis', strtotime('2 months ago'));
     $lastYearDate = date('YmdHis', strtotime('1 year ago'));
     for ($i = 1; $i <= 16; $i++) {
       if (in_array($i, $lastWeekActivities)) {
         $date = $lastWeekDate;
       }
-      elseif (in_array($i, $lastMonthActivities)) {
-        $date = $lastMonthDate;
+      elseif (in_array($i, $lastTwoMonthsActivities)) {
+        $date = $lastTwoMonthAgoDate;
       }
       elseif (in_array($i, $lastYearActivties)) {
         $date = $lastYearDate;
@@ -814,13 +814,13 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
           'sort' => NULL,
         ),
       ),
-      'last-month-activity' => array(
+      'this-quarter-activity' => array(
         'params' => array(
           'contact_id' => 1,
           'admin' => TRUE,
           'caseId' => NULL,
           'context' => 'activity',
-          'activity_date_relative' => 'previous.month',
+          'activity_date_relative' => 'this.quarter',
           'activity_type_id' => NULL,
           'offset' => 0,
           'rowCount' => 0,
@@ -871,10 +871,10 @@ class CRM_Activity_BAO_ActivityTest extends CiviUnitTestCase {
         $this->assertEquals(count($lastWeekActivities), count($activitiesDep));
         $this->checkArrayEquals($lastWeekActivities, $activityIDs);
       }
-      elseif ($caseName == 'last-month-activity') {
-        $this->assertEquals(count($lastMonthActivities), $activityCount);
-        $this->assertEquals(count($lastMonthActivities), count($activitiesDep));
-        $this->checkArrayEquals($lastMonthActivities, $activityIDs);
+      elseif ($caseName == 'lhis-quarter-activity') {
+        $this->assertEquals(count($lastTwoMonthsActivities), $activityCount);
+        $this->assertEquals(count($lastTwoMonthsActivities), count($activitiesDep));
+        $this->checkArrayEquals($lastTwoMonthsActivities, $activityIDs);
       }
       elseif ($caseName == 'last-year-activity') {
         $this->assertEquals(count($lastYearActivties), $activityCount);