Commit | Line | Data |
---|---|---|
1008246f J |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.4 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | 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 and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
32 | * | |
33 | */ | |
34 | ||
35 | class CRM_Wci_BAO_WidgetCache extends CRM_Wci_DAO_WidgetCache { | |
36 | ||
a2b33bc5 | 37 | public static function setWidgetCache($widgetId, $widget) { |
96beafc6 | 38 | $timenow = time(); |
a2b33bc5 VJ |
39 | $expire_on = PHP_INT_MAX; |
40 | if ($widget['dynamic'] == TRUE) { | |
41 | $cacheTime = civicrm_api3('setting', 'getValue', | |
42 | array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout')); | |
43 | $expire_on = $timenow + ($cacheTime * 60); | |
44 | } | |
96beafc6 J |
45 | $query = "INSERT INTO civicrm_wci_widget_cache (widget_id, widget_code, expire, createdtime) |
46 | VALUES (%1, %2, %3, %4) | |
47 | ON DUPLICATE KEY UPDATE widget_id = %1, widget_code = %2, expire = %3, createdtime = %4"; | |
3ebd2f4b VJ |
48 | $params = array( |
49 | 1 => array($widgetId, 'Integer'), | |
a2b33bc5 | 50 | 2 => array($widget['code'], 'String'), |
96beafc6 J |
51 | 3 => array($expire_on, 'Integer'), |
52 | 4 => array($timenow, 'Integer') | |
3ebd2f4b | 53 | ); |
1008246f J |
54 | CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_WidgetCache'); |
55 | } | |
1008246f J |
56 | |
57 | public static function getWidgetCache($widgetId) { | |
58 | $code = ""; | |
3ebd2f4b VJ |
59 | $query = "SELECT widget_code FROM civicrm_wci_widget_cache where widget_id = %1 |
60 | AND expire >= %2"; | |
3ebd2f4b | 61 | $dao = CRM_Core_DAO::executeQuery($query, array(1 => array($widgetId, 'Integer'), |
96beafc6 | 62 | 2 => array(time(), 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache'); |
1008246f J |
63 | if ($dao->fetch()) { |
64 | $code = $dao->widget_code; | |
65 | } | |
66 | return $code; | |
67 | } | |
3ebd2f4b VJ |
68 | |
69 | public static function deleteWidgetCache($widgetId) { | |
70 | $code = ""; | |
71 | $query = "DELETE FROM civicrm_wci_widget_cache where widget_id = %1"; | |
72 | $dao = CRM_Core_DAO::executeQuery($query, | |
73 | array(1 => array($widgetId, 'Integer')), TRUE, 'CRM_Wci_DAO_WidgetCache'); | |
74 | } | |
1008246f | 75 | } |