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