/**
  * Get details of each dashlets.
  *
  * @param int $dashletID
  *   Widget ID.
  *
  * @return array
  *   associted array title and content
  */
 public static function getDashletInfo($dashletID)
 {
     $dashletInfo = array();
     $params = array(1 => array($dashletID, 'Integer'));
     $query = "SELECT name, label, url, fullscreen_url, is_fullscreen FROM civicrm_dashboard WHERE id = %1";
     $dashboadDAO = CRM_Core_DAO::executeQuery($query, $params);
     $dashboadDAO->fetch();
     // build the content
     $dao = new CRM_Contact_DAO_DashboardContact();
     $session = CRM_Core_Session::singleton();
     $dao->contact_id = $session->get('userID');
     $dao->dashboard_id = $dashletID;
     $dao->find(TRUE);
     //reset content based on the cache time set in config
     $createdDate = strtotime($dao->created_date);
     $dateDiff = round(abs(time() - $createdDate) / 60);
     $config = CRM_Core_Config::singleton();
     if ($config->dashboardCacheTimeout <= $dateDiff) {
         $dao->content = NULL;
     }
     // if content is empty and url is set, retrieve it from url
     if (!$dao->content && $dashboadDAO->url) {
         $url = $dashboadDAO->url;
         // CRM-7087
         // -lets use relative url for internal use.
         // -make sure relative url should not be htmlize.
         if (substr($dashboadDAO->url, 0, 4) != 'http') {
             $urlParam = explode('?', $dashboadDAO->url);
             $url = CRM_Utils_System::url($urlParam[0], $urlParam[1], TRUE, NULL, FALSE);
         }
         //get content from url
         $dao->content = CRM_Utils_System::getServerResponse($url);
         $dao->created_date = date("YmdHis");
         $dao->save();
     }
     $dashletInfo = array('title' => $dashboadDAO->label, 'name' => $dashboadDAO->name, 'content' => $dao->content);
     if ($dashboadDAO->is_fullscreen) {
         $fullscreenUrl = $dashboadDAO->fullscreen_url;
         if (substr($fullscreenUrl, 0, 4) != 'http') {
             $urlParam = explode('?', $dashboadDAO->fullscreen_url);
             $fullscreenUrl = CRM_Utils_System::url($urlParam[0], $urlParam[1], TRUE, NULL, FALSE);
         }
         $dashletInfo['fullscreenUrl'] = $fullscreenUrl;
     }
     return $dashletInfo;
 }
Example #2
0
 /**
  * Function to get the list of dashlets for a contact
  * and if there are no dashlets for contact return default dashlets and update 
  * contact's preference entry
  *  
  * @param int $contactID contactID
  *
  * @return array $dashlets  array of dashlets
  * @access public
  * @static
  */
 static function getContactDashlets($flatFormat = false)
 {
     $dashlets = array();
     $session = CRM_Core_Session::singleton();
     $contactID = $session->get('userID');
     // get contact dashboard dashlets
     $hasDashlets = false;
     require_once 'CRM/Contact/DAO/DashboardContact.php';
     $dao = new CRM_Contact_DAO_DashboardContact();
     $dao->contact_id = $contactID;
     $dao->orderBy('column_no asc, weight asc');
     $dao->find();
     while ($dao->fetch()) {
         if (!$flatFormat) {
             $hasDashlets = true;
             if (!$dao->is_active) {
                 continue;
             }
             // 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;
         }
     }
     if ($flatFormat) {
         return $dashlets;
     }
     // if empty then make entry in contact dashboard for this contact
     if (empty($dashlets) && !$hasDashlets) {
         $defaultDashlets = self::getDashlets();
         //now you need make dashlet entries for logged in contact
         // need to optimize this sql
         foreach ($defaultDashlets as $key => $values) {
             $valuesArray[] = " ( {$key}, {$contactID} )";
         }
         if (!empty($defaultDashlets)) {
             $valuesString = implode(',', $valuesArray);
             $query = "\n                    INSERT INTO civicrm_dashboard_contact ( dashboard_id, contact_id )\n                    VALUES {$valuesString}";
             CRM_Core_DAO::executeQuery($query);
         }
     }
     return $dashlets;
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  * @static
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['dashboard_contact'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }