Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 | 2 | /** |
6a488035 | 3 | * @package CRM |
ca5cec67 | 4 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 | 5 | * |
d5864876 ARW |
6 | * Generated from {$table.sourceFile} |
7 | * {$generated} | |
a8950859 | 8 | * (GenCodeChecksum:{$genCodeChecksum}) |
6a488035 | 9 | */ |
513ae7e3 | 10 | {if isset($useHelper)}{$useHelper}{/if} |
f41f0342 | 11 | /** |
c3fc2621 | 12 | * Database access object for the {$table.entity} entity. |
f41f0342 | 13 | */ |
6a488035 TO |
14 | class {$table.className} extends CRM_Core_DAO {ldelim} |
15 | ||
4b4cf875 CW |
16 | const EXT = {$ext}; |
17 | const TABLE_ADDED = '{$table.add}'; | |
d31fb4e3 | 18 | {if !empty($table.component)}const COMPONENT = '{$table.component}';{/if} |
4b4cf875 | 19 | |
6a488035 | 20 | /** |
f41f0342 | 21 | * Static instance to hold the table name. |
6a488035 TO |
22 | * |
23 | * @var string | |
6a488035 | 24 | */ |
fa45b5b9 | 25 | public static $_tableName = '{$table.name}'; |
6a488035 | 26 | |
eda5da74 CW |
27 | {* Only print this variable if it's different than the default in CRM_Core_DAO *} |
28 | {if count($table.primaryKey.field) !== 1 || $table.primaryKey.field.0 !== 'id'} | |
29 | /** | |
30 | * Primary key field(s). | |
31 | * | |
32 | * @var string[] | |
33 | */ | |
34 | public static $_primaryKey = [{if $table.primaryKey.field}'{"', '"|implode:$table.primaryKey.field}'{/if}]; | |
35 | {/if} | |
36 | ||
449c4e6b CW |
37 | {if $table.icon} |
38 | /** | |
39 | * Icon associated with this entity. | |
40 | * | |
41 | * @var string | |
42 | */ | |
43 | public static $_icon = '{$table.icon}'; | |
44 | {/if} | |
8ab43c93 CW |
45 | |
46 | {if $table.labelField} | |
47 | /** | |
48 | * Field to show when displaying a record. | |
49 | * | |
50 | * @var string | |
51 | */ | |
52 | public static $_labelField = '{$table.labelField}'; | |
53 | {/if} | |
6a488035 | 54 | /** |
f41f0342 | 55 | * Should CiviCRM log any modifications to this table in the civicrm_log table. |
6a488035 | 56 | * |
c3fc2621 | 57 | * @var bool |
6a488035 | 58 | */ |
fa45b5b9 | 59 | public static $_log = {$table.log|strtoupper}; |
a7bd99ff CW |
60 | {if $table.paths} |
61 | /** | |
62 | * Paths for accessing this entity in the UI. | |
63 | * | |
64 | * @var string[] | |
65 | */ | |
66 | protected static $_paths = {$table.paths|@print_array}; | |
67 | {/if} | |
6a488035 TO |
68 | |
69 | {foreach from=$table.fields item=field} | |
70 | /** | |
71 | {if $field.comment} | |
fb607354 | 72 | * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "} |
6a488035 | 73 | * |
c3fc2621 | 74 | {/if} |
6a488035 TO |
75 | * @var {$field.phpType} |
76 | */ | |
77 | public ${$field.name}; | |
78 | ||
79 | {/foreach} {* table.fields *} | |
80 | ||
81 | /** | |
f41f0342 | 82 | * Class constructor. |
6a488035 | 83 | */ |
c3fc2621 | 84 | public function __construct( ) {ldelim} |
6a488035 TO |
85 | $this->__table = '{$table.name}'; |
86 | ||
87 | parent::__construct( ); | |
88 | {rdelim} | |
89 | ||
449c4e6b CW |
90 | /** |
91 | * Returns localized title of this entity. | |
7b66c3b5 AH |
92 | * |
93 | * @param bool $plural | |
94 | * Whether to return the plural version of the title. | |
449c4e6b | 95 | */ |
7b66c3b5 AH |
96 | public static function getEntityTitle($plural = FALSE) {ldelim} |
97 | return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}'); | |
449c4e6b CW |
98 | {rdelim} |
99 | ||
2562d09a CW |
100 | {if !empty($table.description)} |
101 | /** | |
102 | * Returns user-friendly description of this entity. | |
103 | * | |
104 | * @return string | |
105 | */ | |
106 | public static function getEntityDescription() {ldelim} | |
107 | return {$tsFunctionName}('{$table.description|replace:"'":"\'"}'); | |
108 | {rdelim} | |
109 | {/if} | |
449c4e6b CW |
110 | |
111 | ||
1832ba99 | 112 | {if !empty($table.foreignKey) || !empty($table.dynamicForeignKey)} |
6a488035 | 113 | /** |
f41f0342 | 114 | * Returns foreign keys and entity references. |
6a488035 | 115 | * |
b6e60008 CW |
116 | * @return array |
117 | * [CRM_Core_Reference_Interface] | |
6a488035 | 118 | */ |
c3fc2621 | 119 | public static function getReferenceColumns() {ldelim} |
740dd877 TO |
120 | if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim} |
121 | Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__); | |
1832ba99 | 122 | {if isset($table.foreignKey)} |
6a488035 | 123 | {foreach from=$table.foreignKey item=foreign} |
740dd877 | 124 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}'); |
71e5aa5c | 125 | {/foreach} |
1832ba99 SL |
126 | {/if} |
127 | {if isset($table.dynamicForeignKey)} | |
71e5aa5c | 128 | {foreach from=$table.dynamicForeignKey item=foreign} |
740dd877 | 129 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}'); |
6a488035 | 130 | {/foreach} |
1832ba99 | 131 | {/if} |
740dd877 | 132 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); |
71e5aa5c | 133 | {rdelim} |
740dd877 | 134 | return Civi::$statics[__CLASS__]['links']; |
6a488035 TO |
135 | {rdelim} |
136 | {/if} {* table.foreignKey *} | |
137 | ||
138 | /** | |
b6e60008 | 139 | * Returns all the column names of this table |
6a488035 | 140 | * |
6a488035 TO |
141 | * @return array |
142 | */ | |
c3fc2621 | 143 | public static function &fields( ) {ldelim} |
740dd877 | 144 | if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim} |
c3fc2621 | 145 | Civi::$statics[__CLASS__]['fields'] = array( |
6a488035 TO |
146 | {foreach from=$table.fields item=field} |
147 | ||
148 | {if $field.uniqueName} | |
3cef3c00 | 149 | '{$field.uniqueName}' |
6a488035 TO |
150 | {else} |
151 | '{$field.name}' | |
152 | {/if} | |
153 | => array( | |
3cef3c00 | 154 | 'name' => '{$field.name}', |
6a488035 TO |
155 | 'type' => {$field.crmType}, |
156 | {if $field.title} | |
8af97d90 | 157 | 'title' => {$tsFunctionName}('{$field.title}'), |
6a488035 | 158 | {/if} |
5c7169eb | 159 | {if $field.comment} |
8af97d90 | 160 | 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'), |
5c7169eb | 161 | {/if} |
6a488035 | 162 | {if $field.required} |
c3fc2621 | 163 | 'required' => {$field.required|strtoupper}, |
6a488035 | 164 | {/if} {* field.required *} |
1832ba99 | 165 | {if isset($field.length)} |
6a488035 TO |
166 | 'maxlength' => {$field.length}, |
167 | {/if} {* field.length *} | |
1832ba99 | 168 | {if isset($field.precision)} |
ac5f2ccd TO |
169 | 'precision' => array({$field.precision}), |
170 | {/if} | |
1832ba99 | 171 | {if isset($field.size)} |
6a488035 TO |
172 | 'size' => {$field.size}, |
173 | {/if} {* field.size *} | |
1832ba99 | 174 | {if isset($field.rows)} |
6a488035 TO |
175 | 'rows' => {$field.rows}, |
176 | {/if} {* field.rows *} | |
1832ba99 | 177 | {if isset($field.cols)} |
6a488035 TO |
178 | 'cols' => {$field.cols}, |
179 | {/if} {* field.cols *} | |
180 | ||
181 | {if $field.import} | |
c3fc2621 | 182 | 'import' => {$field.import|strtoupper}, |
bf144e74 | 183 | |
6a488035 | 184 | {/if} {* field.import *} |
bf144e74 | 185 | 'where' => '{$table.name}.{$field.name}', |
186 | {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if} | |
187 | {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if} | |
6a488035 | 188 | {if $field.export} |
c3fc2621 | 189 | 'export' => {$field.export|strtoupper}, |
6a488035 | 190 | {/if} {* field.export *} |
f5c0f096 CW |
191 | {if $field.contactType} |
192 | 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if}, | |
193 | {/if} | |
6a488035 TO |
194 | {if $field.rule} |
195 | 'rule' => '{$field.rule}', | |
196 | {/if} {* field.rule *} | |
1713a0ec CW |
197 | {if !empty($field.permission)} |
198 | 'permission' => {$field.permission|@print_array}, | |
042043f1 | 199 | {/if} |
45a83e42 | 200 | {if $field.default || $field.default === '0'} |
5fb0de1f | 201 | {capture assign=unquotedDefault}{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}{/capture} |
202 | 'default' => {if ($unquotedDefault==='NULL')}NULL{else}'{$unquotedDefault}'{/if}, | |
6a488035 | 203 | {/if} {* field.default *} |
3cef3c00 | 204 | 'table_name' => '{$table.name}', |
205 | 'entity' => '{$table.entity}', | |
206 | 'bao' => '{$table.bao}', | |
fbdb9a4d | 207 | 'localizable' => {if $field.localizable}1{else}0{/if}, |
1832ba99 | 208 | {if isset($field.localize_context)}'localize_context' => '{$field.localize_context}',{/if} |
6a488035 | 209 | |
1832ba99 | 210 | {if isset($field.FKClassName)} |
6a488035 | 211 | 'FKClassName' => '{$field.FKClassName}', |
2a5c9b4d | 212 | {/if} |
88c31c05 CW |
213 | {if !empty($field.component)} |
214 | 'component' => '{$field.component}', | |
215 | {/if} | |
2a5c9b4d CW |
216 | {if $field.serialize} |
217 | 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper}, | |
218 | {/if} | |
74db51d3 | 219 | {if $field.uniqueTitle} |
220 | 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'), | |
221 | {/if} | |
5e545f38 | 222 | {if $field.html} |
4361de53 CW |
223 | 'html' => array( |
224 | {foreach from=$field.html item=val key=key} | |
8af97d90 | 225 | '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if}, |
4361de53 CW |
226 | {/foreach} |
227 | ), | |
228 | {/if} | |
6a488035 | 229 | {if $field.pseudoconstant} |
800d9240 | 230 | 'pseudoconstant' => {$field.pseudoconstant|@print_array}, |
34745448 CW |
231 | {/if} |
232 | {if $field.readonly || $field.name === $table.primaryKey.name} | |
233 | 'readonly' => TRUE, | |
a9d0587b CW |
234 | {/if} |
235 | 'add' => {if $field.add}'{$field.add}'{else}NULL{/if}, | |
236 | ), | |
6a488035 TO |
237 | {/foreach} {* table.fields *} |
238 | ); | |
740dd877 | 239 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); |
6a488035 | 240 | {rdelim} |
740dd877 | 241 | return Civi::$statics[__CLASS__]['fields']; |
6a488035 TO |
242 | {rdelim} |
243 | ||
66abbb6d | 244 | /** |
787b31c7 | 245 | * Return a mapping from field-name to the corresponding key (as used in fields()). |
66abbb6d | 246 | * |
66abbb6d | 247 | * @return array |
787b31c7 | 248 | * Array(string $name => string $uniqueName). |
66abbb6d | 249 | */ |
c3fc2621 | 250 | public static function &fieldKeys( ) {ldelim} |
787b31c7 TO |
251 | if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim} |
252 | Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); | |
253 | {rdelim} | |
254 | return Civi::$statics[__CLASS__]['fieldKeys']; | |
66abbb6d AS |
255 | {rdelim} |
256 | ||
6a488035 | 257 | /** |
b6e60008 | 258 | * Returns the names of this table |
6a488035 | 259 | * |
6a488035 TO |
260 | * @return string |
261 | */ | |
c3fc2621 | 262 | public static function getTableName( ) {ldelim} |
6a488035 TO |
263 | {if $table.localizable} |
264 | return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); | |
265 | {else} | |
266 | return self::$_tableName; | |
267 | {/if} | |
268 | {rdelim} | |
269 | ||
270 | /** | |
b6e60008 | 271 | * Returns if this table needs to be logged |
6a488035 | 272 | * |
c3fc2621 | 273 | * @return bool |
6a488035 | 274 | */ |
c3fc2621 | 275 | public function getLog( ) {ldelim} |
6a488035 TO |
276 | return self::$_log; |
277 | {rdelim} | |
278 | ||
279 | /** | |
b6e60008 CW |
280 | * Returns the list of fields that can be imported |
281 | * | |
282 | * @param bool $prefix | |
6a488035 | 283 | * |
b6e60008 | 284 | * @return array |
6a488035 | 285 | */ |
c3fc2621 | 286 | public static function &import( $prefix = FALSE ) {ldelim} |
84a0493c | 287 | $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array( |
1832ba99 | 288 | {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign} |
84a0493c TO |
289 | {if $foreign.import}'{$foreign.className}',{/if} |
290 | {/foreach}{/if} | |
291 | )); | |
292 | return $r; | |
6a488035 TO |
293 | {rdelim} |
294 | ||
295 | /** | |
b6e60008 CW |
296 | * Returns the list of fields that can be exported |
297 | * | |
298 | * @param bool $prefix | |
299 | * | |
300 | * @return array | |
301 | */ | |
c3fc2621 | 302 | public static function &export( $prefix = FALSE ) {ldelim} |
84a0493c | 303 | $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array( |
1832ba99 | 304 | {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign} |
84a0493c TO |
305 | {if $foreign.export}'{$foreign.className}',{/if} |
306 | {/foreach}{/if} | |
307 | )); | |
308 | return $r; | |
6a488035 TO |
309 | {rdelim} |
310 | ||
6b86d84f AS |
311 | /** |
312 | * Returns the list of indices | |
c3fc2621 CW |
313 | * |
314 | * @param bool $localize | |
315 | * | |
316 | * @return array | |
6b86d84f AS |
317 | */ |
318 | public static function indices($localize = TRUE) {ldelim} | |
319 | $indices = {$indicesPhp}; | |
320 | return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; | |
321 | {rdelim} | |
c3fc2621 | 322 | |
6a488035 | 323 | {rdelim} |