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