CRM-18172 only load up dashlets relevant to the current domain
authoreileenmcnaugton <eileen@fuzion.co.nz>
Mon, 7 Mar 2016 12:08:59 +0000 (01:08 +1300)
committereileenmcnaugton <eileen@fuzion.co.nz>
Mon, 7 Mar 2016 12:08:59 +0000 (01:08 +1300)
CRM/Core/BAO/Dashboard.php

index e42bf80bfab52c9a769a5f50f2c78ba5416c05e4..c8df7cbdc738afb5735363efd24ddb962cc289af 100644 (file)
@@ -107,29 +107,30 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard {
   public static function getContactDashlets($flatFormat = FALSE, $contactID = NULL) {
     $dashlets = array();
 
-    if (!$contactID) {
-      $contactID = CRM_Core_Session::singleton()->get('userID');
-    }
-
     // Get contact dashboard dashlets.
     $hasDashlets = FALSE;
     $dao = new CRM_Contact_DAO_DashboardContact();
-    $dao->contact_id = $contactID;
+    $dao->contact_id = $contactID ? $contactID : CRM_Core_Session::singleton()->getLoggedInContactID();
     $dao->orderBy('column_no asc, weight asc');
     $dao->find();
+
+    // The available list will only include those which are valid for the domain.
+    $availableDashlets = self::getDashlets();
     while ($dao->fetch()) {
       // When a dashlet is removed, it stays in the table with status disabled,
       // so even if a user decides not to have any dashlets show, they will still
       // have records in the table to indicate that we are not newly initializing.
-      $hasDashlets = TRUE;
-      if (!$flatFormat) {
-        if ($dao->is_active) {
-          // append weight so that order is preserved.
-          $dashlets[$dao->column_no]["{$dao->weight}-{$dao->dashboard_id}"] = $dao->is_minimized;
+      if ((!empty($availableDashlets[$dao->dashboard_id]) && $availableDashlets[$dao->dashboard_id]['is_active'])) {
+        $hasDashlets = TRUE;
+        if (!$flatFormat) {
+          if ($dao->is_active) {
+            // append weight so that order is preserved.
+            $dashlets[$dao->column_no]["{$dao->weight}-{$dao->dashboard_id}"] = $dao->is_minimized;
+          }
+        }
+        else {
+          $dashlets[$dao->dashboard_id] = $dao->dashboard_id;
         }
-      }
-      else {
-        $dashlets[$dao->dashboard_id] = $dao->dashboard_id;
       }
     }
 
@@ -162,7 +163,7 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard {
         'domain_id' => CRM_Core_Config::domainID(),
         'option.limit' => 0,
       ));
-    $contactID = CRM_Core_Session::singleton()->get('userID');
+    $contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
     $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']);
     $defaultDashlets = array();
     $defaults = array('blog' => 1, 'getting-started' => '0');