Commit | Line | Data |
---|---|---|
1008246f J |
1 | <?php |
2 | require_once '../wci-helper-functions.php'; | |
3 | ||
4 | class CRM_Wci_WidgetCode { | |
5 | ||
6 | static function get_widget_realtime_code($widgetId) { | |
7 | $data = CRM_Wci_BAO_Widget::getWidgetData($widgetId); | |
8 | $template = CRM_Core_Smarty::singleton(); | |
9 | $template->assign('wciform', $data); | |
10 | $template->assign('cpageId', $data['button_link_to']); | |
11 | // $template->assign('preview', $preview); | |
12 | ||
13 | if ($data["override"] == '0') { | |
14 | $template->template_dir[] = getWciWidgetTemplatePath(); | |
15 | $wcidata = $template->fetch('wciwidget.tpl'); | |
16 | } else { | |
17 | $wcidata = $template->fetch('string:' . html_entity_decode($data['custom_template'])); | |
18 | } | |
19 | $code = json_encode($wcidata); | |
20 | CRM_Wci_BAO_WidgetCache::setWidgetCache($widgetId, $code); | |
21 | return $code; | |
22 | } | |
23 | ||
24 | static function get_widget_code($embedId, $preview=0) { | |
25 | ||
26 | if($preview) { | |
27 | /**On preview time controller is called from create widget | |
28 | form so id will be widget id */ | |
29 | $code = CRM_Wci_WidgetCode::get_widget_realtime_code($embedId); | |
30 | } else { | |
31 | $widgetId = CRM_Wci_BAO_EmbedCode::getWidgetId($embedId); | |
32 | $code = CRM_Wci_BAO_WidgetCache::getWidgetCache($widgetId); | |
33 | ||
34 | $tsDiff = CRM_Wci_BAO_WidgetCache::getCurrentTsDiff($widgetId); | |
35 | $cacheTime = civicrm_api3('setting', 'getValue', | |
36 | array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); | |
37 | if(($tsDiff > $cacheTime)||(empty($code))) { | |
38 | $code = CRM_Wci_WidgetCode::get_widget_realtime_code($widgetId); | |
39 | } | |
40 | } | |
41 | return $code; | |
42 | } | |
43 | } | |
44 |