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 | */ |
fbb7b4d8 | 10 | {$useHelper} |
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 | |
449c4e6b CW |
27 | {if $table.icon} |
28 | /** | |
29 | * Icon associated with this entity. | |
30 | * | |
31 | * @var string | |
32 | */ | |
33 | public static $_icon = '{$table.icon}'; | |
34 | {/if} | |
6a488035 | 35 | /** |
f41f0342 | 36 | * Should CiviCRM log any modifications to this table in the civicrm_log table. |
6a488035 | 37 | * |
c3fc2621 | 38 | * @var bool |
6a488035 | 39 | */ |
fa45b5b9 | 40 | public static $_log = {$table.log|strtoupper}; |
a7bd99ff CW |
41 | {if $table.paths} |
42 | /** | |
43 | * Paths for accessing this entity in the UI. | |
44 | * | |
45 | * @var string[] | |
46 | */ | |
47 | protected static $_paths = {$table.paths|@print_array}; | |
48 | {/if} | |
6a488035 TO |
49 | |
50 | {foreach from=$table.fields item=field} | |
51 | /** | |
52 | {if $field.comment} | |
fb607354 | 53 | * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "} |
6a488035 | 54 | * |
c3fc2621 | 55 | {/if} |
6a488035 TO |
56 | * @var {$field.phpType} |
57 | */ | |
58 | public ${$field.name}; | |
59 | ||
60 | {/foreach} {* table.fields *} | |
61 | ||
62 | /** | |
f41f0342 | 63 | * Class constructor. |
6a488035 | 64 | */ |
c3fc2621 | 65 | public function __construct( ) {ldelim} |
6a488035 TO |
66 | $this->__table = '{$table.name}'; |
67 | ||
68 | parent::__construct( ); | |
69 | {rdelim} | |
70 | ||
449c4e6b CW |
71 | /** |
72 | * Returns localized title of this entity. | |
7b66c3b5 AH |
73 | * |
74 | * @param bool $plural | |
75 | * Whether to return the plural version of the title. | |
449c4e6b | 76 | */ |
7b66c3b5 AH |
77 | public static function getEntityTitle($plural = FALSE) {ldelim} |
78 | return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}'); | |
449c4e6b CW |
79 | {rdelim} |
80 | ||
81 | ||
82 | ||
71e5aa5c | 83 | {if $table.foreignKey || $table.dynamicForeignKey} |
6a488035 | 84 | /** |
f41f0342 | 85 | * Returns foreign keys and entity references. |
6a488035 | 86 | * |
b6e60008 CW |
87 | * @return array |
88 | * [CRM_Core_Reference_Interface] | |
6a488035 | 89 | */ |
c3fc2621 | 90 | public static function getReferenceColumns() {ldelim} |
740dd877 TO |
91 | if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim} |
92 | Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__); | |
6a488035 | 93 | {foreach from=$table.foreignKey item=foreign} |
740dd877 | 94 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}'); |
71e5aa5c ARW |
95 | {/foreach} |
96 | ||
97 | {foreach from=$table.dynamicForeignKey item=foreign} | |
740dd877 | 98 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}'); |
6a488035 | 99 | {/foreach} |
740dd877 | 100 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); |
71e5aa5c | 101 | {rdelim} |
740dd877 | 102 | return Civi::$statics[__CLASS__]['links']; |
6a488035 TO |
103 | {rdelim} |
104 | {/if} {* table.foreignKey *} | |
105 | ||
106 | /** | |
b6e60008 | 107 | * Returns all the column names of this table |
6a488035 | 108 | * |
6a488035 TO |
109 | * @return array |
110 | */ | |
c3fc2621 | 111 | public static function &fields( ) {ldelim} |
740dd877 | 112 | if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim} |
c3fc2621 | 113 | Civi::$statics[__CLASS__]['fields'] = array( |
6a488035 TO |
114 | {foreach from=$table.fields item=field} |
115 | ||
116 | {if $field.uniqueName} | |
3cef3c00 | 117 | '{$field.uniqueName}' |
6a488035 TO |
118 | {else} |
119 | '{$field.name}' | |
120 | {/if} | |
121 | => array( | |
3cef3c00 | 122 | 'name' => '{$field.name}', |
6a488035 TO |
123 | 'type' => {$field.crmType}, |
124 | {if $field.title} | |
8af97d90 | 125 | 'title' => {$tsFunctionName}('{$field.title}'), |
6a488035 | 126 | {/if} |
5c7169eb | 127 | {if $field.comment} |
8af97d90 | 128 | 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'), |
5c7169eb | 129 | {/if} |
6a488035 | 130 | {if $field.required} |
c3fc2621 | 131 | 'required' => {$field.required|strtoupper}, |
6a488035 TO |
132 | {/if} {* field.required *} |
133 | {if $field.length} | |
134 | 'maxlength' => {$field.length}, | |
135 | {/if} {* field.length *} | |
ac5f2ccd TO |
136 | {if $field.precision} |
137 | 'precision' => array({$field.precision}), | |
138 | {/if} | |
6a488035 TO |
139 | {if $field.size} |
140 | 'size' => {$field.size}, | |
141 | {/if} {* field.size *} | |
142 | {if $field.rows} | |
143 | 'rows' => {$field.rows}, | |
144 | {/if} {* field.rows *} | |
145 | {if $field.cols} | |
146 | 'cols' => {$field.cols}, | |
147 | {/if} {* field.cols *} | |
148 | ||
149 | {if $field.import} | |
c3fc2621 | 150 | 'import' => {$field.import|strtoupper}, |
bf144e74 | 151 | |
6a488035 | 152 | {/if} {* field.import *} |
bf144e74 | 153 | 'where' => '{$table.name}.{$field.name}', |
154 | {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if} | |
155 | {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if} | |
6a488035 | 156 | {if $field.export} |
c3fc2621 | 157 | 'export' => {$field.export|strtoupper}, |
6a488035 | 158 | {/if} {* field.export *} |
f5c0f096 CW |
159 | {if $field.contactType} |
160 | 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if}, | |
161 | {/if} | |
6a488035 TO |
162 | {if $field.rule} |
163 | 'rule' => '{$field.rule}', | |
164 | {/if} {* field.rule *} | |
1713a0ec CW |
165 | {if !empty($field.permission)} |
166 | 'permission' => {$field.permission|@print_array}, | |
042043f1 | 167 | {/if} |
45a83e42 | 168 | {if $field.default || $field.default === '0'} |
9e1ed301 | 169 | 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', |
6a488035 | 170 | {/if} {* field.default *} |
3cef3c00 | 171 | 'table_name' => '{$table.name}', |
172 | 'entity' => '{$table.entity}', | |
173 | 'bao' => '{$table.bao}', | |
fbdb9a4d | 174 | 'localizable' => {if $field.localizable}1{else}0{/if}, |
65c86f7d | 175 | {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if} |
6a488035 TO |
176 | |
177 | {if $field.FKClassName} | |
178 | 'FKClassName' => '{$field.FKClassName}', | |
2a5c9b4d CW |
179 | {/if} |
180 | {if $field.serialize} | |
181 | 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper}, | |
182 | {/if} | |
74db51d3 | 183 | {if $field.uniqueTitle} |
184 | 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'), | |
185 | {/if} | |
5e545f38 | 186 | {if $field.html} |
4361de53 CW |
187 | 'html' => array( |
188 | {foreach from=$field.html item=val key=key} | |
8af97d90 | 189 | '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if}, |
4361de53 CW |
190 | {/foreach} |
191 | ), | |
192 | {/if} | |
6a488035 | 193 | {if $field.pseudoconstant} |
800d9240 | 194 | 'pseudoconstant' => {$field.pseudoconstant|@print_array}, |
a9d0587b CW |
195 | {/if} |
196 | 'add' => {if $field.add}'{$field.add}'{else}NULL{/if}, | |
197 | ), | |
6a488035 TO |
198 | {/foreach} {* table.fields *} |
199 | ); | |
740dd877 | 200 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); |
6a488035 | 201 | {rdelim} |
740dd877 | 202 | return Civi::$statics[__CLASS__]['fields']; |
6a488035 TO |
203 | {rdelim} |
204 | ||
66abbb6d | 205 | /** |
787b31c7 | 206 | * Return a mapping from field-name to the corresponding key (as used in fields()). |
66abbb6d | 207 | * |
66abbb6d | 208 | * @return array |
787b31c7 | 209 | * Array(string $name => string $uniqueName). |
66abbb6d | 210 | */ |
c3fc2621 | 211 | public static function &fieldKeys( ) {ldelim} |
787b31c7 TO |
212 | if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim} |
213 | Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); | |
214 | {rdelim} | |
215 | return Civi::$statics[__CLASS__]['fieldKeys']; | |
66abbb6d AS |
216 | {rdelim} |
217 | ||
6a488035 | 218 | /** |
b6e60008 | 219 | * Returns the names of this table |
6a488035 | 220 | * |
6a488035 TO |
221 | * @return string |
222 | */ | |
c3fc2621 | 223 | public static function getTableName( ) {ldelim} |
6a488035 TO |
224 | {if $table.localizable} |
225 | return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); | |
226 | {else} | |
227 | return self::$_tableName; | |
228 | {/if} | |
229 | {rdelim} | |
230 | ||
231 | /** | |
b6e60008 | 232 | * Returns if this table needs to be logged |
6a488035 | 233 | * |
c3fc2621 | 234 | * @return bool |
6a488035 | 235 | */ |
c3fc2621 | 236 | public function getLog( ) {ldelim} |
6a488035 TO |
237 | return self::$_log; |
238 | {rdelim} | |
239 | ||
240 | /** | |
b6e60008 CW |
241 | * Returns the list of fields that can be imported |
242 | * | |
243 | * @param bool $prefix | |
6a488035 | 244 | * |
b6e60008 | 245 | * @return array |
6a488035 | 246 | */ |
c3fc2621 | 247 | public static function &import( $prefix = FALSE ) {ldelim} |
84a0493c TO |
248 | $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array( |
249 | {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign} | |
250 | {if $foreign.import}'{$foreign.className}',{/if} | |
251 | {/foreach}{/if} | |
252 | )); | |
253 | return $r; | |
6a488035 TO |
254 | {rdelim} |
255 | ||
256 | /** | |
b6e60008 CW |
257 | * Returns the list of fields that can be exported |
258 | * | |
259 | * @param bool $prefix | |
260 | * | |
261 | * @return array | |
262 | */ | |
c3fc2621 | 263 | public static function &export( $prefix = FALSE ) {ldelim} |
84a0493c TO |
264 | $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array( |
265 | {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign} | |
266 | {if $foreign.export}'{$foreign.className}',{/if} | |
267 | {/foreach}{/if} | |
268 | )); | |
269 | return $r; | |
6a488035 TO |
270 | {rdelim} |
271 | ||
6b86d84f AS |
272 | /** |
273 | * Returns the list of indices | |
c3fc2621 CW |
274 | * |
275 | * @param bool $localize | |
276 | * | |
277 | * @return array | |
6b86d84f AS |
278 | */ |
279 | public static function indices($localize = TRUE) {ldelim} | |
280 | $indices = {$indicesPhp}; | |
281 | return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices; | |
282 | {rdelim} | |
c3fc2621 | 283 | |
6a488035 | 284 | {rdelim} |