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