Esempio n. 1
0
 /**
  * Setup default dashlets for new users.
  *
  * When a user accesses their dashboard for the first time, set up
  * the default dashlets.
  *
  * @param bool $flatFormat
  *
  * @return array
  *    Array of dashboard_id's
  * @throws \CiviCRM_API3_Exception
  */
 public static function initializeDashlets($flatFormat = FALSE)
 {
     $dashlets = array();
     $getDashlets = civicrm_api3("Dashboard", "get", array('domain_id' => CRM_Core_Config::domainID(), 'option.limit' => 0));
     $contactID = CRM_Core_Session::singleton()->getLoggedInContactID();
     $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']);
     $defaultDashlets = array();
     $defaults = array('blog' => 1, 'getting-started' => '0');
     foreach ($defaults as $name => $column) {
         if (!empty($allDashlets[$name])) {
             $defaultDashlets[$name] = array('dashboard_id' => $allDashlets[$name]['id'], 'is_active' => 1, 'column_no' => $column, 'contact_id' => $contactID);
         }
     }
     CRM_Utils_Hook::dashboard_defaults($allDashlets, $defaultDashlets);
     if (is_array($defaultDashlets) && !empty($defaultDashlets)) {
         foreach ($defaultDashlets as $id => $defaultDashlet) {
             $dashboard_id = $defaultDashlet['dashboard_id'];
             if (!self::checkPermission($getDashlets['values'][$dashboard_id]['permission'], CRM_Utils_Array::value('permission_operator', $getDashlets['values'][$dashboard_id]))) {
                 continue;
             } else {
                 $assignDashlets = civicrm_api3("dashboard_contact", "create", $defaultDashlet);
                 if (!$flatFormat) {
                     $values = $assignDashlets['values'][$assignDashlets['id']];
                     $dashlets[$values['column_no']][$values['weight'] - $values['dashboard_id']] = $values['is_minimized'];
                 } else {
                     $dashlets[$dashboard_id] = $defaultDashlet['dashboard_id'];
                 }
             }
         }
     }
     return $dashlets;
 }
Esempio n. 2
0
 /**
  * @param $hasDashlets
  *
  * @return bool
  * @throws CiviCRM_API3_Exception
  */
 static function initializeDashlets($hasDashlets)
 {
     $getDashlets = civicrm_api3("Dashboard", "get", array('domain_id' => CRM_Core_Config::domainID()));
     $contactID = CRM_Core_Session::singleton()->get('userID');
     $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']);
     $defaultDashlets = array();
     if (!$hasDashlets && !empty($allDashlets['blog'])) {
         $defaultDashlets['blog'] = array('dashboard_id' => $allDashlets['blog']['id'], 'is_active' => 1, 'column_no' => 1, 'contact_id' => $contactID, 'domain_id' => CRM_Core_Config::domainID());
     }
     CRM_Utils_Hook::dashboard_defaults($allDashlets, $defaultDashlets);
     if (is_array($defaultDashlets) && !empty($defaultDashlets)) {
         foreach ($defaultDashlets as $defaultDashlet) {
             if (!self::checkPermission($getDashlets['values'][$defaultDashlet['dashboard_id']]['permission'], $getDashlets['values'][$defaultDashlet['dashboard_id']]['permission_operator'])) {
                 unset($defaultDashlets[$defaultDashlet]);
                 continue;
             } else {
                 $assignDashlets = civicrm_api3("dashboard_contact", "create", $defaultDashlet);
                 $dashlets[$defaultDashlet['dashboard_id']] = $defaultDashlet['dashboard_id'];
             }
         }
         return $dashlets;
     }
     return FALSE;
 }