- * 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;
- }
-
- /**
- * Save changes made by use to the Dashlet.