Improved caching system.
[com.zyxware.civiwci.git] / CRM / Wci / DAO / WidgetCache.php
CommitLineData
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 * @package CRM
30 * @copyright CiviCRM LLC (c) 2004-2013
31 */
32class CRM_Wci_DAO_WidgetCache extends CRM_Core_DAO
33{
34 /**
35 * static instance to hold the table name
36 *
37 * @var string
38 * @static
39 */
40 static $_tableName = 'civicrm_wci_widget_cache';
41 /**
42 * static instance to hold the field values
43 *
44 * @var array
45 * @static
46 */
47 static $_fields = null;
48 /**
49 * static instance to hold the keys used in $_fields for each field.
50 *
51 * @var array
52 * @static
53 */
54 static $_fieldKeys = null;
55 /**
56 * static instance to hold the FK relationships
57 *
58 * @var string
59 * @static
60 */
61 static $_links = null;
62 /**
63 * static instance to hold the values that can
64 * be imported
65 *
66 * @var array
67 * @static
68 */
69 static $_import = null;
70 /**
71 * static instance to hold the values that can
72 * be exported
73 *
74 * @var array
75 * @static
76 */
77 static $_export = null;
78 /**
79 * static value to see if we should log any modifications to
80 * this table in the civicrm_log table
81 *
82 * @var boolean
83 * @static
84 */
85 static $_log = true;
86 /**
87 * cache id
88 *
89 * @var int unsigned
90 */
91 public $id;
92 /**
93 * widget code
94 *
95 * @var string
96 */
97 public $widget_code;
98 /**
99 * widget id
100 *
101 * @var float
102 */
103 public $widget_id;
104 /**
105 * time stamp
106 *
107 * @var float
108 */
109 public $ts;
110
111 function __construct()
112 {
113 $this->__table = 'civicrm_wci_widget_cache';
114 parent::__construct();
115 }
116 /**
117 * return foreign keys and entity references
118 *
119 * @static
120 * @access public
121 * @return array of CRM_Core_EntityReference
122 */
123 static function getReferenceColumns()
124 {
125 return self::$_links;
126 }
127 /**
128 * returns all the column names of this table
129 *
130 * @access public
131 * @return array
132 */
133 static function &fields()
134 {
135 if (!(self::$_fields)) {
136 self::$_fields = array(
1008246f
J
137 'widget_id' => array(
138 'name' => 'widget_id',
139 'type' => CRM_Utils_Type::T_INT,
3ebd2f4b 140 'required' => true,
1008246f
J
141 ) ,
142 'widget_code' => array(
143 'name' => 'widget_code',
144 'type' => CRM_Utils_Type::T_TEXT,
145 'title' => ts('widget code', array('domain' => 'org.civicrm.wci')) ,
146 'required' => false,
147 ) ,
3ebd2f4b 148 'expire' => array(
1008246f 149 'name' => 'ts',
3ebd2f4b 150 'type' => CRM_Utils_Type::T_INT,
1008246f
J
151 'title' => ts('timestamp', array('domain' => 'org.civicrm.wci')) ,
152 'required' => false,
1008246f
J
153 ) ,
154
155
156 );
157 }
158 return self::$_fields;
159 }
160 /**
161 * Returns an array containing, for each field, the arary key used for that
162 * field in self::$_fields.
163 *
164 * @access public
165 * @return array
166 */
167 static function &fieldKeys()
168 {
169 if (!(self::$_fieldKeys)) {
170 self::$_fieldKeys = array(
1008246f
J
171 'widget_id' => 'widget_id',
172 'widget_code' => 'widget_code',
3ebd2f4b 173 'expire' => 'expire',
1008246f
J
174 );
175 }
176 return self::$_fieldKeys;
177 }
178 /**
179 * returns the names of this table
180 *
181 * @access public
182 * @static
183 * @return string
184 */
185 static function getTableName()
186 {
187 return self::$_tableName;
188 }
189 /**
190 * returns if this table needs to be logged
191 *
192 * @access public
193 * @return boolean
194 */
195 function getLog()
196 {
197 return self::$_log;
198 }
199 /**
200 * returns the list of fields that can be imported
201 *
202 * @access public
203 * return array
204 * @static
205 */
206 static function &import($prefix = false)
207 {
208 if (!(self::$_import)) {
209 self::$_import = array();
210 $fields = self::fields();
211 foreach($fields as $name => $field) {
212 if (CRM_Utils_Array::value('import', $field)) {
213 if ($prefix) {
214 self::$_import['wci_progress_bar'] = & $fields[$name];
215 } else {
216 self::$_import[$name] = & $fields[$name];
217 }
218 }
219 }
220 }
221 return self::$_import;
222 }
223 /**
224 * returns the list of fields that can be exported
225 *
226 * @access public
227 * return array
228 * @static
229 */
230 static function &export($prefix = false)
231 {
232 if (!(self::$_export)) {
233 self::$_export = array();
234 $fields = self::fields();
235 foreach($fields as $name => $field) {
236 if (CRM_Utils_Array::value('export', $field)) {
237 if ($prefix) {
238 self::$_export['wci_progress_bar'] = & $fields[$name];
239 } else {
240 self::$_export[$name] = & $fields[$name];
241 }
242 }
243 }
244 }
245 return self::$_export;
246 }
247}