Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
6a488035 TO |
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 | /** | |
6a488035 | 29 | * @package CRM |
e7112fa7 | 30 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 | 31 | * |
d5864876 ARW |
32 | * Generated from {$table.sourceFile} |
33 | * {$generated} | |
6a488035 TO |
34 | */ |
35 | ||
36 | require_once 'CRM/Core/DAO.php'; | |
37 | require_once 'CRM/Utils/Type.php'; | |
38 | ||
39 | {if $table.foreignKey} | |
40 | {foreach from=$table.foreignKey item=foreign} | |
41 | {if $foreign.import} | |
42 | require_once '{$foreign.fileName}'; | |
43 | {/if} | |
44 | {/foreach} | |
45 | {/if} | |
46 | ||
47 | class {$table.className} extends CRM_Core_DAO {ldelim} | |
48 | ||
49 | /** | |
50 | * static instance to hold the table name | |
51 | * | |
52 | * @var string | |
6a488035 TO |
53 | */ |
54 | static $_tableName = '{$table.name}'; | |
55 | ||
56 | /** | |
57 | * static instance to hold the field values | |
58 | * | |
59 | * @var array | |
6a488035 TO |
60 | */ |
61 | static $_fields = null; | |
62 | ||
66abbb6d AS |
63 | /** |
64 | * static instance to hold the keys used in $_fields for each field. | |
65 | * | |
66 | * @var array | |
66abbb6d AS |
67 | */ |
68 | static $_fieldKeys = null; | |
69 | ||
6a488035 TO |
70 | /** |
71 | * static instance to hold the FK relationships | |
72 | * | |
73 | * @var string | |
6a488035 TO |
74 | */ |
75 | static $_links = null; | |
76 | ||
77 | /** | |
78 | * static instance to hold the values that can | |
79 | * be imported | |
80 | * | |
81 | * @var array | |
6a488035 TO |
82 | */ |
83 | static $_import = null; | |
84 | ||
85 | /** | |
86 | * static instance to hold the values that can | |
87 | * be exported | |
88 | * | |
89 | * @var array | |
6a488035 TO |
90 | */ |
91 | static $_export = null; | |
92 | ||
93 | /** | |
94 | * static value to see if we should log any modifications to | |
95 | * this table in the civicrm_log table | |
96 | * | |
97 | * @var boolean | |
6a488035 TO |
98 | */ |
99 | static $_log = {$table.log}; | |
100 | ||
101 | {foreach from=$table.fields item=field} | |
102 | /** | |
103 | {if $field.comment} | |
104 | * {$field.comment} | |
105 | {/if} | |
106 | * | |
107 | * @var {$field.phpType} | |
108 | */ | |
109 | public ${$field.name}; | |
110 | ||
111 | {/foreach} {* table.fields *} | |
112 | ||
113 | /** | |
114 | * class constructor | |
115 | * | |
6a488035 TO |
116 | * @return {$table.name} |
117 | */ | |
118 | function __construct( ) {ldelim} | |
119 | $this->__table = '{$table.name}'; | |
120 | ||
121 | parent::__construct( ); | |
122 | {rdelim} | |
123 | ||
71e5aa5c | 124 | {if $table.foreignKey || $table.dynamicForeignKey} |
6a488035 | 125 | /** |
b6e60008 | 126 | * Returns foreign keys and entity references |
6a488035 | 127 | * |
b6e60008 CW |
128 | * @return array |
129 | * [CRM_Core_Reference_Interface] | |
6a488035 | 130 | */ |
71e5aa5c ARW |
131 | static function getReferenceColumns() {ldelim} |
132 | if (!self::$_links) {ldelim} | |
ffcef054 | 133 | self::$_links = static::createReferenceColumns(__CLASS__); |
6a488035 | 134 | {foreach from=$table.foreignKey item=foreign} |
ffcef054 | 135 | self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}'); |
71e5aa5c ARW |
136 | {/foreach} |
137 | ||
138 | {foreach from=$table.dynamicForeignKey item=foreign} | |
ffcef054 | 139 | self::$_links[] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}'); |
6a488035 | 140 | {/foreach} |
71e5aa5c ARW |
141 | {rdelim} |
142 | return self::$_links; | |
6a488035 TO |
143 | {rdelim} |
144 | {/if} {* table.foreignKey *} | |
145 | ||
146 | /** | |
b6e60008 | 147 | * Returns all the column names of this table |
6a488035 | 148 | * |
6a488035 TO |
149 | * @return array |
150 | */ | |
151 | static function &fields( ) {ldelim} | |
152 | if ( ! ( self::$_fields ) ) {ldelim} | |
153 | self::$_fields = array ( | |
154 | {foreach from=$table.fields item=field} | |
155 | ||
156 | {if $field.uniqueName} | |
157 | '{$field.uniqueName}' | |
158 | {else} | |
159 | '{$field.name}' | |
160 | {/if} | |
161 | => array( | |
162 | 'name' => '{$field.name}', | |
163 | 'type' => {$field.crmType}, | |
164 | {if $field.title} | |
165 | 'title' => ts('{$field.title}'), | |
166 | {/if} | |
5c7169eb CW |
167 | {if $field.comment} |
168 | 'description' => '{$field.comment|replace:"'":"\'"}', | |
169 | {/if} | |
6a488035 TO |
170 | {if $field.required} |
171 | 'required' => {$field.required}, | |
172 | {/if} {* field.required *} | |
173 | {if $field.length} | |
174 | 'maxlength' => {$field.length}, | |
175 | {/if} {* field.length *} | |
ac5f2ccd TO |
176 | {if $field.precision} |
177 | 'precision' => array({$field.precision}), | |
178 | {/if} | |
6a488035 TO |
179 | {if $field.size} |
180 | 'size' => {$field.size}, | |
181 | {/if} {* field.size *} | |
182 | {if $field.rows} | |
183 | 'rows' => {$field.rows}, | |
184 | {/if} {* field.rows *} | |
185 | {if $field.cols} | |
186 | 'cols' => {$field.cols}, | |
187 | {/if} {* field.cols *} | |
188 | ||
189 | {if $field.import} | |
190 | 'import' => {$field.import}, | |
191 | 'where' => '{$table.name}.{$field.name}', | |
192 | 'headerPattern' => '{$field.headerPattern}', | |
193 | 'dataPattern' => '{$field.dataPattern}', | |
194 | {/if} {* field.import *} | |
195 | {if $field.export} | |
196 | 'export' => {$field.export}, | |
197 | {if ! $field.import} | |
198 | 'where' => '{$table.name}.{$field.name}', | |
199 | 'headerPattern' => '{$field.headerPattern}', | |
200 | 'dataPattern' => '{$field.dataPattern}', | |
201 | {/if} | |
202 | {/if} {* field.export *} | |
203 | {if $field.rule} | |
204 | 'rule' => '{$field.rule}', | |
205 | {/if} {* field.rule *} | |
206 | {if $field.default} | |
9e1ed301 | 207 | 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', |
6a488035 | 208 | {/if} {* field.default *} |
6a488035 TO |
209 | |
210 | {if $field.FKClassName} | |
211 | 'FKClassName' => '{$field.FKClassName}', | |
212 | {/if} {* field.FKClassName *} | |
5e545f38 CW |
213 | {if $field.html} |
214 | {assign var=htmlOptions value=$field.html} | |
215 | 'html' => array( | |
216 | {*{$htmlOptions|@print_array}*} | |
217 | {foreach from=$htmlOptions key=optionKey item=optionValue} | |
218 | '{$optionKey}' => '{$optionValue}', | |
219 | {/foreach} | |
220 | ), | |
221 | {/if} {* field.html *} | |
6a488035 TO |
222 | {if $field.pseudoconstant} |
223 | {assign var=pseudoOptions value=$field.pseudoconstant} | |
224 | 'pseudoconstant' => array( | |
225 | {*{$pseudoOptions|@print_array}*} | |
226 | {foreach from=$pseudoOptions key=optionKey item=optionValue} | |
227 | '{$optionKey}' => '{$optionValue}', | |
228 | {/foreach} | |
229 | ) | |
230 | {/if} {* field.pseudoconstant *} ), | |
231 | {/foreach} {* table.fields *} | |
232 | ); | |
233 | {rdelim} | |
234 | return self::$_fields; | |
235 | {rdelim} | |
236 | ||
66abbb6d AS |
237 | /** |
238 | * Returns an array containing, for each field, the arary key used for that | |
239 | * field in self::$_fields. | |
240 | * | |
66abbb6d AS |
241 | * @return array |
242 | */ | |
243 | static function &fieldKeys( ) {ldelim} | |
244 | if ( ! ( self::$_fieldKeys ) ) {ldelim} | |
245 | self::$_fieldKeys = array ( | |
246 | {foreach from=$table.fields item=field} | |
247 | '{$field.name}' => | |
248 | {if $field.uniqueName} | |
249 | '{$field.uniqueName}' | |
250 | {else} | |
251 | '{$field.name}' | |
252 | {/if}, | |
253 | ||
254 | {/foreach} {* table.fields *} | |
255 | ); | |
256 | {rdelim} | |
257 | return self::$_fieldKeys; | |
258 | {rdelim} | |
259 | ||
6a488035 | 260 | /** |
b6e60008 | 261 | * Returns the names of this table |
6a488035 | 262 | * |
6a488035 TO |
263 | * @return string |
264 | */ | |
265 | static function getTableName( ) {ldelim} | |
266 | {if $table.localizable} | |
267 | return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); | |
268 | {else} | |
269 | return self::$_tableName; | |
270 | {/if} | |
271 | {rdelim} | |
272 | ||
273 | /** | |
b6e60008 | 274 | * Returns if this table needs to be logged |
6a488035 | 275 | * |
6a488035 TO |
276 | * @return boolean |
277 | */ | |
278 | function getLog( ) {ldelim} | |
279 | return self::$_log; | |
280 | {rdelim} | |
281 | ||
282 | /** | |
b6e60008 CW |
283 | * Returns the list of fields that can be imported |
284 | * | |
285 | * @param bool $prefix | |
6a488035 | 286 | * |
b6e60008 | 287 | * @return array |
6a488035 TO |
288 | */ |
289 | static function &import( $prefix = false ) {ldelim} | |
290 | if ( ! ( self::$_import ) ) {ldelim} | |
291 | self::$_import = array ( ); | |
292 | $fields = self::fields( ); | |
293 | foreach ( $fields as $name => $field ) {ldelim} | |
294 | if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim} | |
295 | if ( $prefix ) {ldelim} | |
296 | self::$_import['{$table.labelName}'] =& $fields[$name]; | |
297 | {rdelim} else {ldelim} | |
298 | self::$_import[$name] =& $fields[$name]; | |
299 | {rdelim} | |
300 | {rdelim} | |
301 | {rdelim} | |
302 | {if $table.foreignKey} | |
303 | {foreach from=$table.foreignKey item=foreign} | |
304 | {if $foreign.import} | |
305 | self::$_import = array_merge( self::$_import, | |
306 | {$foreign.className}::import( true ) ); | |
307 | {/if} | |
308 | {/foreach} | |
309 | {/if} | |
310 | {rdelim} | |
311 | return self::$_import; | |
312 | {rdelim} | |
313 | ||
314 | /** | |
b6e60008 CW |
315 | * Returns the list of fields that can be exported |
316 | * | |
317 | * @param bool $prefix | |
318 | * | |
319 | * @return array | |
320 | */ | |
6a488035 TO |
321 | static function &export( $prefix = false ) {ldelim} |
322 | if ( ! ( self::$_export ) ) {ldelim} | |
323 | self::$_export = array ( ); | |
324 | $fields = self::fields( ); | |
325 | foreach ( $fields as $name => $field ) {ldelim} | |
326 | if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim} | |
327 | if ( $prefix ) {ldelim} | |
328 | self::$_export['{$table.labelName}'] =& $fields[$name]; | |
329 | {rdelim} else {ldelim} | |
330 | self::$_export[$name] =& $fields[$name]; | |
331 | {rdelim} | |
332 | {rdelim} | |
333 | {rdelim} | |
334 | {if $table.foreignKey} | |
335 | {foreach from=$table.foreignKey item=foreign} | |
336 | {if $foreign.export} | |
337 | self::$_export = array_merge( self::$_export, | |
338 | {$foreign.className}::export( true ) ); | |
339 | {/if} | |
340 | {/foreach} | |
341 | {/if} | |
342 | {rdelim} | |
343 | return self::$_export; | |
344 | {rdelim} | |
345 | ||
6a488035 TO |
346 | {rdelim} |
347 | ||
348 |