4 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 * Generated from {$table.sourceFile}
8 * (GenCodeChecksum:{$genCodeChecksum})
10 {if isset($useHelper)}{$useHelper}{/if}
12 * Database access object for the {$table.entity} entity.
14 class {$table.className} extends CRM_Core_DAO {ldelim}
17 const TABLE_ADDED = '{$table.add}';
18 {if !empty($table.component)}const COMPONENT = '{$table.component}';{/if}
21 * Static instance to hold the table name.
25 public static $_tableName = '{$table.name}';
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'}
30 * Primary key field(s).
34 public static $_primaryKey = [{if $table.primaryKey.field}'{"', '"|implode:$table.primaryKey.field}'{/if}];
39 * Icon associated with this entity.
43 public static $_icon = '{$table.icon}';
46 {if $table.labelField}
48 * Field to show when displaying a record.
52 public static $_labelField = '{$table.labelField}';
55 * Should CiviCRM log any modifications to this table in the civicrm_log table.
59 public static $_log = {$table.log|strtoupper};
62 * Paths for accessing this entity in the UI.
66 protected static $_paths = {$table.paths|@print_array};
69 {foreach from=$table.fields item=field}
72 * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "}
75 * @var {$field.phpType}{if $field.phpNullable}|null
78 * (SQL type: {$field.sqlType})
79 * Note that values will be retrieved from the database as a string.
81 public ${$field.name};
83 {/foreach} {* table.fields *}
88 public function __construct( ) {ldelim}
89 $this->__table = '{$table.name}';
91 parent::__construct( );
95 * Returns localized title of this entity.
98 * Whether to return the plural version of the title.
100 public static function getEntityTitle($plural = FALSE) {ldelim}
101 return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}');
104 {if !empty($table.description)}
106 * Returns user-friendly description of this entity.
110 public static function getEntityDescription() {ldelim}
111 return {$tsFunctionName}('{$table.description|replace:"'":"\'"}');
116 {if !empty($table.foreignKey) || !empty($table.dynamicForeignKey)}
118 * Returns foreign keys and entity references.
121 * [CRM_Core_Reference_Interface]
123 public static function getReferenceColumns() {ldelim}
124 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
125 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
126 {if isset($table.foreignKey)}
127 {foreach from=$table.foreignKey item=foreign}
128 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
131 {if isset($table.dynamicForeignKey)}
132 {foreach from=$table.dynamicForeignKey item=foreign}
133 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
136 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
138 return Civi::$statics[__CLASS__]['links'];
140 {/if} {* table.foreignKey *}
143 * Returns all the column names of this table
147 public static function &fields( ) {ldelim}
148 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
149 Civi::$statics[__CLASS__]['fields'] = array(
150 {foreach from=$table.fields item=field}
152 {if $field.uniqueName}
153 '{$field.uniqueName}'
158 'name' => '{$field.name}',
159 'type' => {$field.crmType},
161 'title' => {$tsFunctionName}('{$field.title}'),
164 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
167 'required' => {$field.required|strtoupper},
168 {/if} {* field.required *}
169 {if isset($field.length)}
170 'maxlength' => {$field.length},
171 {/if} {* field.length *}
172 {if isset($field.precision)}
173 'precision' => array({$field.precision}),
175 {if isset($field.size)}
176 'size' => {$field.size},
177 {/if} {* field.size *}
178 {if isset($field.rows)}
179 'rows' => {$field.rows},
180 {/if} {* field.rows *}
181 {if isset($field.cols)}
182 'cols' => {$field.cols},
183 {/if} {* field.cols *}
186 'import' => {$field.import|strtoupper},
188 {/if} {* field.import *}
189 'where' => '{$table.name}.{$field.name}',
190 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
191 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
193 'export' => {$field.export|strtoupper},
194 {/if} {* field.export *}
195 {if $field.contactType}
196 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
199 'rule' => '{$field.rule}',
200 {/if} {* field.rule *}
201 {if !empty($field.permission)}
202 'permission' => {$field.permission|@print_array},
204 {if $field.default || $field.default === '0'}
205 {capture assign=unquotedDefault}{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}{/capture}
206 'default' => {if ($unquotedDefault==='NULL')}NULL{else}'{$unquotedDefault}'{/if},
207 {/if} {* field.default *}
208 'table_name' => '{$table.name}',
209 'entity' => '{$table.entity}',
210 'bao' => '{$table.bao}',
211 'localizable' => {if $field.localizable}1{else}0{/if},
212 {if isset($field.localize_context)}'localize_context' => '{$field.localize_context}',{/if}
214 {if isset($field.FKClassName)}
215 'FKClassName' => '{$field.FKClassName}',
217 {if !empty($field.component)}
218 'component' => '{$field.component}',
220 {if $field.serialize}
221 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
223 {if $field.uniqueTitle}
224 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
228 {foreach from=$field.html item=val key=key}
229 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
233 {if $field.pseudoconstant}
234 'pseudoconstant' => {$field.pseudoconstant|@print_array},
236 {if $field.readonly || $field.name === $table.primaryKey.name}
239 'add' => {if $field.add}'{$field.add}'{else}NULL{/if},
241 {/foreach} {* table.fields *}
243 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
245 return Civi::$statics[__CLASS__]['fields'];
249 * Return a mapping from field-name to the corresponding key (as used in fields()).
252 * Array(string $name => string $uniqueName).
254 public static function &fieldKeys( ) {ldelim}
255 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
256 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
258 return Civi::$statics[__CLASS__]['fieldKeys'];
262 * Returns the names of this table
266 public static function getTableName( ) {ldelim}
267 {if $table.localizable}
268 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
270 return self::$_tableName;
275 * Returns if this table needs to be logged
279 public function getLog( ) {ldelim}
284 * Returns the list of fields that can be imported
286 * @param bool $prefix
290 public static function &import( $prefix = FALSE ) {ldelim}
291 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
292 {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
293 {if $foreign.import}'{$foreign.className}',{/if}
300 * Returns the list of fields that can be exported
302 * @param bool $prefix
306 public static function &export( $prefix = FALSE ) {ldelim}
307 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
308 {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
309 {if $foreign.export}'{$foreign.className}',{/if}
316 * Returns the list of indices
318 * @param bool $localize
322 public static function indices($localize = TRUE) {ldelim}
323 $indices = {$indicesPhp};
324 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;