31603 progress bar update not clearing widget cache
[com.zyxware.civiwci.git] / CRM / Wci / BAO / WidgetCache.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM Widget Creation Interface (WCI) Version 1.0 |
5 +--------------------------------------------------------------------+
6 | Copyright Zyxware Technologies (c) 2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM WCI. |
9 | |
10 | CiviCRM WCI is free software; you can copy, modify, and distribute |
11 | it under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007. |
13 | |
14 | CiviCRM WCI is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License along with this program; if not, contact Zyxware |
21 | Technologies at info[AT]zyxware[DOT]com. |
22 +--------------------------------------------------------------------+
23 */
24
25 /**
26 *
27 * @package CRM
28 * @copyright CiviCRM LLC (c) 2004-2013
29 *
30 */
31
32 class CRM_Wci_BAO_WidgetCache extends CRM_Wci_DAO_WidgetCache {
33
34 public static function setWidgetCache($widgetId, $widget) {
35 $timenow = time();
36 $expire_on = PHP_INT_MAX;
37 if ($widget['dynamic'] == TRUE) {
38 $cacheTime = civicrm_api3('setting', 'getValue',
39 array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout'));
40 $expire_on = $timenow + ($cacheTime * 60);
41 }
42 $query = "INSERT INTO civicrm_wci_widget_cache (widget_id, widget_code, expire, createdtime)
43 VALUES (%1, %2, %3, %4)
44 ON DUPLICATE KEY UPDATE widget_id = %1, widget_code = %2, expire = %3, createdtime = %4";
45 $params = array(
46 1 => array($widgetId, 'Integer'),
47 2 => array($widget['code'], 'String'),
48 3 => array($expire_on, 'Integer'),
49 4 => array($timenow, 'Integer')
50 );
51 CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_WidgetCache');
52 }
53
54 public static function getWidgetCache($widgetId) {
55 $code = "";
56 $query = "SELECT widget_code FROM civicrm_wci_widget_cache where widget_id = %1
57 AND expire >= %2";
58 $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($widgetId, 'Integer'),
59 2 => array(time(), 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache');
60 if ($dao->fetch()) {
61 $code = $dao->widget_code;
62 }
63 return $code;
64 }
65
66 public static function deleteWidgetCache($widgetId) {
67 $code = "";
68 $query = "DELETE FROM civicrm_wci_widget_cache where widget_id = %1";
69 $dao = CRM_Core_DAO::executeQuery($query,
70 array(1 => array($widgetId, 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache');
71 }
72
73 public static function clearCache($pbId) {
74 $query = "SELECT wc.widget_id FROM civicrm_wci_widget_cache as wc INNER JOIN civicrm_wci_widget w on w.id = wc.widget_id WHERE w.progress_bar_id =%1";
75 $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($pbId, 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache');
76 if ($dao->fetch()) {
77 $widget_id = $dao->widget_id;
78 CRM_Wci_BAO_WidgetCache::deleteWidgetCache($widget_id);
79 }
80 }
81 }