From a2b33bc5c2119079aca9ec64cc777e176c06ab73 Mon Sep 17 00:00:00 2001 From: Vimal Joseph Date: Fri, 21 Nov 2014 00:31:58 +0530 Subject: [PATCH] Modified cache system. For static content - ie content with out progress bar, System will cache it till the widget is modified. --- CRM/Wci/BAO/WidgetCache.php | 13 ++++++++----- CRM/Wci/WidgetCode.php | 18 +++++++++++++----- templates/CRM/Wci/Form/WCISettings.tpl | 2 +- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/CRM/Wci/BAO/WidgetCache.php b/CRM/Wci/BAO/WidgetCache.php index bb4899d..7de9a9c 100644 --- a/CRM/Wci/BAO/WidgetCache.php +++ b/CRM/Wci/BAO/WidgetCache.php @@ -34,17 +34,20 @@ class CRM_Wci_BAO_WidgetCache extends CRM_Wci_DAO_WidgetCache { - public static function setWidgetCache($widgetId, $code) { - $cacheTime = civicrm_api3('setting', 'getValue', - array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); + public static function setWidgetCache($widgetId, $widget) { $timenow = time(); - $expire_on = $timenow + ($cacheTime * 60); + $expire_on = PHP_INT_MAX; + if ($widget['dynamic'] == TRUE) { + $cacheTime = civicrm_api3('setting', 'getValue', + array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); + $expire_on = $timenow + ($cacheTime * 60); + } $query = "INSERT INTO civicrm_wci_widget_cache (widget_id, widget_code, expire, createdtime) VALUES (%1, %2, %3, %4) ON DUPLICATE KEY UPDATE widget_id = %1, widget_code = %2, expire = %3, createdtime = %4"; $params = array( 1 => array($widgetId, 'Integer'), - 2 => array($code, 'String'), + 2 => array($widget['code'], 'String'), 3 => array($expire_on, 'Integer'), 4 => array($timenow, 'Integer') ); diff --git a/CRM/Wci/WidgetCode.php b/CRM/Wci/WidgetCode.php index e53c460..e870456 100644 --- a/CRM/Wci/WidgetCode.php +++ b/CRM/Wci/WidgetCode.php @@ -4,6 +4,8 @@ require_once '../wci-helper-functions.php'; class CRM_Wci_WidgetCode { static function generate_widget_code($widgetId, $preview = 0) { + $code = ''; + $dynamic_content = FALSE; $data = CRM_Wci_BAO_Widget::getWidgetData($widgetId); $template = CRM_Core_Smarty::singleton(); $template->assign('wciform', $data); @@ -16,23 +18,29 @@ class CRM_Wci_WidgetCode { } else { $wcidata = $template->fetch('string:' . html_entity_decode($data['custom_template'])); } + $code = json_encode($wcidata); - return $code; + + if ($data['progress_bar_id'] != 0) { + $dynamic_content = TRUE; + } + return array('dynamic' => $dynamic_content, 'code' => $code); } static function get_widget_code($embedId, $preview = 0) { $code = ''; if ($preview) { - return CRM_Wci_WidgetCode::generate_widget_code($embedId, $preview); + $widget = CRM_Wci_WidgetCode::generate_widget_code($embedId, $preview); + return $widget['code']; } else { $widgetId = CRM_Wci_BAO_EmbedCode::getWidgetId($embedId); $code = CRM_Wci_BAO_WidgetCache::getWidgetCache($widgetId); } - if (!$code) { - $code = CRM_Wci_WidgetCode::generate_widget_code($widgetId); - CRM_Wci_BAO_WidgetCache::setWidgetCache($widgetId, $code); + $widget = CRM_Wci_WidgetCode::generate_widget_code($widgetId); + CRM_Wci_BAO_WidgetCache::setWidgetCache($widgetId, $widget); + $code = $widget['code']; } return $code; diff --git a/templates/CRM/Wci/Form/WCISettings.tpl b/templates/CRM/Wci/Form/WCISettings.tpl index 66ffc52..e1b89cf 100644 --- a/templates/CRM/Wci/Form/WCISettings.tpl +++ b/templates/CRM/Wci/Form/WCISettings.tpl @@ -14,7 +14,7 @@
Enter public profile id where user can signup for newsletter. User's mail id will be added to the group configured for the widget when they click subscribe button.'
{/if} {if "widget_cache_timeout" == $form.$elementName.id} -
Cache will be cleared after specified minites.
+
Cache will be cleared after specified minutes. Widgets with static content (with out a progress bar) will be cached till it is modified.
{/if}
-- 2.25.1