Add configuration options to adjust the behavior of recent items stack: 1.) Define...
authorNiels Heinemann <heinemann@kompetenzz.de>
Tue, 12 Jan 2016 15:22:39 +0000 (16:22 +0100)
committerNiels Heinemann <heinemann@kompetenzz.de>
Fri, 20 May 2016 09:42:27 +0000 (11:42 +0200)
CRM/Admin/Form/Setting/Miscellaneous.php
CRM/Utils/Recent.php
settings/Core.setting.php
templates/CRM/Admin/Form/Setting/Miscellaneous.tpl

index 897ccef971811a6f73204c9a882c5e5d1e3c7788..9f8b189d841f067452a082c2d009ba74f02bb7b8 100644 (file)
@@ -50,6 +50,8 @@ class CRM_Admin_Form_Setting_Miscellaneous extends CRM_Admin_Form_Setting {
     'recaptchaPublicKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
     'recaptchaPrivateKey' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
     'wkhtmltopdfPath' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+    'recentItemsMaxCount' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+    'recentItemsProviders' => CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
   );
 
   public $_uploadMaxSize;
index 25de25889d585078dbe3db9ec90d6abde0768797..0206a2fa0a968f9a28312d32b2285cd4479eb7a5 100644 (file)
 class CRM_Utils_Recent {
 
   /**
-   * Max number of items in queue.
+   * Store name
    *
-   * @var int
+   * @var string
    */
-  const MAX_ITEMS = 10, STORE_NAME = 'CRM_Utils_Recent';
+  const STORE_NAME = 'CRM_Utils_Recent';
 
   /**
    * The list of recently viewed items.
@@ -49,10 +49,20 @@ class CRM_Utils_Recent {
    */
   static private $_recent = NULL;
 
+  /**
+   * Maximum stack size
+   * @var int
+   */
+  static private $_maxItems = 20;
+  
   /**
    * Initialize this class and set the static variables.
    */
   public static function initialize() {
+    $maxItemsSetting = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'recentItemsMaxCount');
+    if (isset($maxItemsSetting) && $maxItemsSetting > 0 && $maxItemsSetting < 100)
+        self::$_maxItems = $maxItemsSetting;
+    
     if (!self::$_recent) {
       $session = CRM_Core_Session::singleton();
       self::$_recent = $session->get(self::STORE_NAME);
@@ -97,6 +107,10 @@ class CRM_Utils_Recent {
     $others = array()
   ) {
     self::initialize();
+    
+    if (!self::isProviderEnabled($type))
+        return;
+    
     $session = CRM_Core_Session::singleton();
 
     // make sure item is not already present in list
@@ -127,7 +141,8 @@ class CRM_Utils_Recent {
         'delete_url' => CRM_Utils_Array::value('deleteUrl', $others),
       )
     );
-    if (count(self::$_recent) > self::MAX_ITEMS) {
+    error_log("FOOOO: " . self::$_maxItems);
+    if (count(self::$_recent) > self::$_maxItems) {
       array_pop(self::$_recent);
     }
 
@@ -188,4 +203,70 @@ class CRM_Utils_Recent {
     $session->set(self::STORE_NAME, self::$_recent);
   }
 
+  /**
+   * Check if a provider is allowed to add stuff.
+   * If correspondig setting is empty, all are allowed
+   * 
+   * @param string $providerName
+   */
+  public static function isProviderEnabled($providerName) {
+      
+      // Join contact types to providerName 'Contact'
+      $contactTypes = CRM_Contact_BAO_ContactType::contactTypes(TRUE);
+      if (in_array($providerName, $contactTypes))
+         $providerName = 'Contact';
+      
+      $allowed = true;
+      
+      // Use core setting recentItemsProviders if configured
+      $providersPermitted = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'recentItemsProviders');
+      if ($providersPermitted)
+          $allowed = in_array($providerName, $providersPermitted);
+      
+      // Else allow
+      return $allowed;
+  }
+
+  /**
+   * Gets the list of available providers to civi's recent items stack
+   */
+  public static function getProviders() {
+      $providers = array(
+          'Contact' => ts('Contacts'),
+          'Relationship' => ts('Relationships'),
+          'Activity' => ts('Activities'),
+          'Note' => ts('Notes'),
+          'Group' => ts('Groups'),
+          'Case' => ts('Cases'),
+          'Contribution' => ts('Contributions'),
+          'Participant' => ts('Participants'),
+          'Grant' => ts('Grants'),
+          'Membership' => ts('Memberships'),
+          'Pledge' => ts('Pledges'),
+          'Event' => ts('Events'),
+          'Campaign' => ts('Campaigns'),
+      );
+      
+      /** We may strip off disabled components **/
+//            $enabledComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array());
+//      if (!$enabledComponents) 
+//          return $providers;
+//      
+//      foreach ($enabledComponents as $component) {
+//          switch ($component) {
+//              case 'CiviEvent': => ts('CiviEvent'),
+//              'Participants' => ts('Participants'),
+//              'CiviContribute' => ts('CiviContribute'),
+//              'CiviMember' => ts('CiviMember'),
+//              'CiviMail' => ts('CiviMail'),
+//              'CiviReport' => ts('CiviReport'),
+//              'CiviPledge' => ts('CiviPledge'),
+//              'CiviCase' => ts('CiviCase'),
+//              'CiviCampaign' => ts('CiviCampaign'),
+//              'CiviGrant' => ts('CiviGrant')
+//          }
+//      }
+
+      return $providers;
+  }
 }
index ce2c88fa9b58a4d7bb9ca45a3180343938f15830..77bc4975e27ad91ef1229d552a492e74f5da72ba 100644 (file)
@@ -823,4 +823,45 @@ return array(
     'description' => NULL,
     'help_text' => NULL,
   ),
+  'recentItemsMaxCount' => array(
+    'group_name' => 'CiviCRM Preferences',
+    'group' => 'core',
+    'name' => 'recentItemsMaxCount',
+    'type' => 'Integer',
+    'quick_form_type' => 'Element',
+    'html_type' => 'text',
+    'html_attributes' => array(
+      'size' => 2,
+      'maxlength' => 3
+    ),
+    'default' => 20,
+    'add' => '4.7',
+    'title' => 'Size of "Recent Items" stack',
+    'is_domain' => 1,
+    'is_contact' => 0,
+    'description' => 'How many items should CiviCRM store in it\'s "Recently viewed" list.',
+    'help_text' => NULL,
+  ),
+  'recentItemsProviders' => array(
+    'group_name' => 'CiviCRM Preferences',
+    'group' => 'core',
+    'name' => 'recentItemsProviders',
+    'type' => 'Array',
+    'html_type' => 'Select',
+    'quick_form_type' => 'Select',
+    'html_attributes' => array(
+      'multiple' => 1,
+      'class' => 'crm-select2',
+    ),
+    'default' => '',
+    'add' => '4.7',
+    'title' => 'Recent Items Providers',
+    'is_domain' => 1,
+    'is_contact' => 0,
+    'description' => 'What providers may save views in CiviCRM\'s "Recently viewed" list. If empty, all are in.',
+    'help_text' => NULL,
+    'pseudoconstant' => array(
+      'callback' => 'CRM_Utils_Recent::getProviders'
+    ),
+  ),
 );
index e42d69b13017a1ebbab933f6693043a0a864f7cd..04db77c290d6496de105ea81904008534891e636 100644 (file)
@@ -82,8 +82,8 @@
             <td>{$form.max_attachments.html}<br />
                 <span class="description">{ts}Maximum number of files (documents, images, etc.) which can attached to emails or activities.{/ts}</span></td>
         </tr>
-  <tr class="crm-miscellaneous-form-block-maxFileSize">
-      <td class="label">{$form.maxFileSize.label}</td>
+        <tr class="crm-miscellaneous-form-block-maxFileSize">
+            <td class="label">{$form.maxFileSize.label}</td>
             <td>{$form.maxFileSize.html}<br />
                 <span class="description">{$maxFileSize_description}</span></td>
         </tr>
                 <p class="description">{ts}If enabled, contacts with the permission to edit a related contact will inherit that contact's permission to edit other related contacts.{/ts}</p>
             </td>
         </tr>
+        <tr class="crm-miscellaneous-form-block-recentItemsMaxCount">
+            <td class="label">{$form.recentItemsMaxCount.label}</td>
+            <td>{$form.recentItemsMaxCount.html}<br />
+                <span class="description">{$recentItemsMaxCount_description}</span></td>
+        </tr>
+        <tr class="crm-miscellaneous-form-block-recentItemsProviders">
+            <td class="label">{$form.recentItemsProviders.label}</td>
+            <td>{$form.recentItemsProviders.html}<br />
+                <span class="description">{$recentItemsProviders_description}</span></td>
+        </tr>
 
     </table>
 <h3>{ts}reCAPTCHA Keys{/ts}</h3>