From 067986a077221f2d71674f49a836138eb90f1886 Mon Sep 17 00:00:00 2001 From: sunil Date: Fri, 31 Jul 2015 17:32:15 +0530 Subject: [PATCH] Getting started for 4.6 removed unwanted code getting started should available for new users Getting started changes Getting started changes --- CRM/Core/BAO/Dashboard.php | 17 +- CRM/Core/xml/Menu/Contact.xml | 5 + CRM/Dashlet/Page/GettingStarted.php | 152 ++++++++++++++++++ CRM/Upgrade/Incremental/php/FourSix.php | 34 ++++ templates/CRM/Dashlet/Page/GettingStarted.tpl | 27 ++++ xml/templates/civicrm_navigation.tpl | 2 + 6 files changed, 230 insertions(+), 7 deletions(-) create mode 100644 CRM/Dashlet/Page/GettingStarted.php create mode 100644 templates/CRM/Dashlet/Page/GettingStarted.tpl diff --git a/CRM/Core/BAO/Dashboard.php b/CRM/Core/BAO/Dashboard.php index c7dcd923da..0daa5b75df 100644 --- a/CRM/Core/BAO/Dashboard.php +++ b/CRM/Core/BAO/Dashboard.php @@ -164,13 +164,16 @@ class CRM_Core_BAO_Dashboard extends CRM_Core_DAO_Dashboard { $contactID = CRM_Core_Session::singleton()->get('userID'); $allDashlets = CRM_Utils_Array::index(array('name'), $getDashlets['values']); $defaultDashlets = array(); - if (!empty($allDashlets['blog'])) { - $defaultDashlets['blog'] = array( - 'dashboard_id' => $allDashlets['blog']['id'], - 'is_active' => 1, - 'column_no' => 1, - 'contact_id' => $contactID, - ); + $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)) { diff --git a/CRM/Core/xml/Menu/Contact.xml b/CRM/Core/xml/Menu/Contact.xml index 729452ed1a..ed9c7ecf0d 100644 --- a/CRM/Core/xml/Menu/Contact.xml +++ b/CRM/Core/xml/Menu/Contact.xml @@ -250,6 +250,11 @@ CiviCRM Blog CRM_Dashlet_Page_Blog + + civicrm/dashlet/getting-started + CiviCRM Getting Started + CRM_Dashlet_Page_GettingStarted + civicrm/ajax/relation CRM_Contact_Page_AJAX::relationship diff --git a/CRM/Dashlet/Page/GettingStarted.php b/CRM/Dashlet/Page/GettingStarted.php new file mode 100644 index 0000000000..362fd74f7c --- /dev/null +++ b/CRM/Dashlet/Page/GettingStarted.php @@ -0,0 +1,152 @@ + array( + 'configbackend' => 'civicrm/admin/configtask', + ), + ); + + /** + * Get the final, usable URL string (after interpolating any variables) + * + * @return FALSE|string + */ + public function gettingStartedUrl() { + // Note: We use "*default*" as the default (rather than self::GETTING_STARTED_URL) so that future + // developers can change GETTING_STARTED_URL without needing to update {civicrm_setting}. + $url = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'gettingStartedUrl', NULL, '*default*'); + if ($url === '*default*') { + $url = self::GETTING_STARTED_URL; + } + return CRM_Utils_System::evalUrl($url); + } + + /** + * List gettingStarted page as dashlet. + */ + public function run() { + $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'dashlet'); + $this->assign('context', $context); + + $this->assign('gettingStarted', $this->_gettingStarted()); + + return parent::run(); + } + + /** + * Load gettingStarted page from cache. + * Refresh cache if expired + * + * @return array + */ + private function _gettingStarted() { + // Fetch data from cache + $cache = CRM_Core_DAO::executeQuery("SELECT data, created_date FROM civicrm_cache + WHERE group_name = 'dashboard' AND path = 'gettingStarted'"); + if ($cache->fetch()) { + $expire = time() - (60 * 60 * 24 * self::CACHE_DAYS); + // Refresh data after CACHE_DAYS + if (strtotime($cache->created_date) < $expire) { + $new_data = $this->_getHtml($this->gettingStartedUrl()); + // If fetching the new html was successful, return it + // Otherwise use the old cached data - it's better than nothing + if ($new_data) { + return $new_data; + } + } + return unserialize($cache->data); + } + return $this->_getHtml($this->gettingStartedUrl()); + } + + /** + * Get html and cache results. + * + * @param $url + * + * @return array|NULL + * array of gettingStarted items; or NULL if not available + */ + public function _getHtml($url) { + + $httpClient = new CRM_Utils_HttpClient(self::CHECK_TIMEOUT); + list ($status, $html) = $httpClient->get($url); + if ($status !== CRM_Utils_HttpClient::STATUS_OK) { + return NULL; + } + + $tokensList = CRM_Utils_Token::getTokens($html); + $this->replaceLinkToken($tokensList, $html); + if ($html) { + CRM_Core_BAO_Cache::setItem($html, 'dashboard', 'gettingStarted'); + } + return $html; + } + + + /** + * @param array $tokensList + * @param string $str + * + */ + public function replaceLinkToken($tokensList, &$str) { + foreach ($tokensList as $categories => $tokens) { + foreach ($tokens as $token) { + $value = ''; + if (!empty(self::$_tokens[$categories][$token])) { + $value = self::$_tokens[$categories][$token]; + if ($categories == 'crmurl') { + $value = CRM_Utils_System::url($value, "reset=1", FALSE, NULL, TRUE, TRUE); + } + } + CRM_Utils_Token::token_replace($categories, $token, $value, $str); + } + } + } + +} diff --git a/CRM/Upgrade/Incremental/php/FourSix.php b/CRM/Upgrade/Incremental/php/FourSix.php index d3ad74d7c8..41a34c8f03 100644 --- a/CRM/Upgrade/Incremental/php/FourSix.php +++ b/CRM/Upgrade/Incremental/php/FourSix.php @@ -258,4 +258,38 @@ class CRM_Upgrade_Incremental_php_FourSix { return TRUE; } + + /** + * Upgrade function. + * + * @param string $rev + */ + public function upgrade_4_6_12($rev) { + $this->addTask(ts('Add Getting Started dashlet to %1: SQL', array(1 => $rev)), ' addGettingStartedDashlet', $rev); + } + + /** + * Add Getting Started dashlet to dashboard + * + * @param \CRM_Queue_TaskContext $ctx + * + * @return bool + */ + public function addGettingStartedDashlet(CRM_Queue_TaskContext $ctx) { + $sql = "SELECT count(*) FROM civicrm_dashboard WHERE name='gettingStarted'"; + $res = CRM_Core_DAO::singleValueQuery($sql); + $domainId = CRM_Core_Config::domainID(); + if ($res <= 0) { + $sql = "INSERT INTO `civicrm_dashboard` + ( `domain_id`, `name`, `label`, `url`, `permission`, `permission_operator`, `column_no`, `is_minimized`, `is_active`, `weight`, `fullscreen_url`, `is_fullscreen`, `is_reserved`) VALUES ( {$domainId}, 'getting-started', 'Getting Started', 'civicrm/dashlet/getting-started?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/getting-started?reset=1&snippet=5&context=dashletFullscreen', 1, 1)"; + CRM_Core_DAO::executeQuery($sql); + // Add default position for Getting Started Dashlet ( left column) + $sql = "INSERT INTO `civicrm_dashboard_contact` (dashboard_id, contact_id, column_no, is_active) +SELECT (SELECT MAX(id) FROM `civicrm_dashboard`), contact_id, 0, IF (SUM(is_active) > 0, 1, 0) +FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; + CRM_Core_DAO::executeQuery($sql); + } + return TRUE; + } + } diff --git a/templates/CRM/Dashlet/Page/GettingStarted.tpl b/templates/CRM/Dashlet/Page/GettingStarted.tpl new file mode 100644 index 0000000000..7da8e5a18c --- /dev/null +++ b/templates/CRM/Dashlet/Page/GettingStarted.tpl @@ -0,0 +1,27 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.6 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2015 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU Affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} + +
{$gettingStarted}
diff --git a/xml/templates/civicrm_navigation.tpl b/xml/templates/civicrm_navigation.tpl index 28f275b1a0..f74bc307e3 100644 --- a/xml/templates/civicrm_navigation.tpl +++ b/xml/templates/civicrm_navigation.tpl @@ -100,6 +100,8 @@ INSERT INTO `civicrm_dashboard` ( `domain_id`, `name`, `label`, `url`, `permission`, `permission_operator`, `column_no`, `is_minimized`, `is_active`, `weight`, `fullscreen_url`, `is_fullscreen`, `is_reserved`) VALUES ( @domainID, 'blog', '{ts escape="sql"}CiviCRM News{/ts}', 'civicrm/dashlet/blog?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/blog?reset=1&snippet=5&context=dashletFullscreen', 1, 1), + ( @domainID, 'getting-started', '{ts escape="sql"}Getting Started{/ts}', 'civicrm/dashlet/getting-started?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/getting-started?reset=1&snippet=5&context=dashletFullscreen', 1, 1), + ( @domainID, 'activity', '{ts escape="sql"}Activities{/ts}', 'civicrm/dashlet/activity?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 1, 'civicrm/dashlet/activity?reset=1&snippet=5&context=dashletFullscreen', 1, 1), ( @domainID, 'myCases', '{ts escape="sql"}My Cases{/ts}', 'civicrm/dashlet/myCases?reset=1&snippet=5', 'access my cases and activities', NULL , 0, 0, 1, 2, 'civicrm/dashlet/myCases?reset=1&snippet=5&context=dashletFullscreen', 1, 1), ( @domainID, 'allCases', '{ts escape="sql"}All Cases{/ts}', 'civicrm/dashlet/allCases?reset=1&snippet=5', 'access all cases and activities', NULL , 0, 0, 1, 3, 'civicrm/dashlet/allCases?reset=1&snippet=5&context=dashletFullscreen', 1, 1), -- 2.25.1