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}
77 public ${$field.name};
79 {/foreach} {* table.fields *}
84 public function __construct( ) {ldelim}
85 $this->__table = '{$table.name}';
87 parent::__construct( );
91 * Returns localized title of this entity.
94 * Whether to return the plural version of the title.
96 public static function getEntityTitle($plural = FALSE) {ldelim}
97 return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}');
100 {if !empty($table.description)}
102 * Returns user-friendly description of this entity.
106 public static function getEntityDescription() {ldelim}
107 return {$tsFunctionName}('{$table.description|replace:"'":"\'"}');
112 {if !empty($table.foreignKey) || !empty($table.dynamicForeignKey)}
114 * Returns foreign keys and entity references.
117 * [CRM_Core_Reference_Interface]
119 public static function getReferenceColumns() {ldelim}
120 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
121 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
122 {if isset($table.foreignKey)}
123 {foreach from=$table.foreignKey item=foreign}
124 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
127 {if isset($table.dynamicForeignKey)}
128 {foreach from=$table.dynamicForeignKey item=foreign}
129 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
132 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
134 return Civi::$statics[__CLASS__]['links'];
136 {/if} {* table.foreignKey *}
139 * Returns all the column names of this table
143 public static function &fields( ) {ldelim}
144 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
145 Civi::$statics[__CLASS__]['fields'] = array(
146 {foreach from=$table.fields item=field}
148 {if $field.uniqueName}
149 '{$field.uniqueName}'
154 'name' => '{$field.name}',
155 'type' => {$field.crmType},
157 'title' => {$tsFunctionName}('{$field.title}'),
160 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
163 'required' => {$field.required|strtoupper},
164 {/if} {* field.required *}
165 {if isset($field.length)}
166 'maxlength' => {$field.length},
167 {/if} {* field.length *}
168 {if isset($field.precision)}
169 'precision' => array({$field.precision}),
171 {if isset($field.size)}
172 'size' => {$field.size},
173 {/if} {* field.size *}
174 {if isset($field.rows)}
175 'rows' => {$field.rows},
176 {/if} {* field.rows *}
177 {if isset($field.cols)}
178 'cols' => {$field.cols},
179 {/if} {* field.cols *}
182 'import' => {$field.import|strtoupper},
184 {/if} {* field.import *}
185 'where' => '{$table.name}.{$field.name}',
186 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
187 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
189 'export' => {$field.export|strtoupper},
190 {/if} {* field.export *}
191 {if $field.contactType}
192 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
195 'rule' => '{$field.rule}',
196 {/if} {* field.rule *}
197 {if !empty($field.permission)}
198 'permission' => {$field.permission|@print_array},
200 {if $field.default || $field.default === '0'}
201 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
202 {/if} {* field.default *}
203 'table_name' => '{$table.name}',
204 'entity' => '{$table.entity}',
205 'bao' => '{$table.bao}',
206 'localizable' => {if $field.localizable}1{else}0{/if},
207 {if isset($field.localize_context)}'localize_context' => '{$field.localize_context}',{/if}
209 {if isset($field.FKClassName)}
210 'FKClassName' => '{$field.FKClassName}',
212 {if !empty($field.component)}
213 'component' => '{$field.component}',
215 {if $field.serialize}
216 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
218 {if $field.uniqueTitle}
219 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
223 {foreach from=$field.html item=val key=key}
224 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
228 {if $field.pseudoconstant}
229 'pseudoconstant' => {$field.pseudoconstant|@print_array},
231 {if $field.readonly || $field.name === $table.primaryKey.name}
234 'add' => {if $field.add}'{$field.add}'{else}NULL{/if},
236 {/foreach} {* table.fields *}
238 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
240 return Civi::$statics[__CLASS__]['fields'];
244 * Return a mapping from field-name to the corresponding key (as used in fields()).
247 * Array(string $name => string $uniqueName).
249 public static function &fieldKeys( ) {ldelim}
250 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
251 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
253 return Civi::$statics[__CLASS__]['fieldKeys'];
257 * Returns the names of this table
261 public static function getTableName( ) {ldelim}
262 {if $table.localizable}
263 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
265 return self::$_tableName;
270 * Returns if this table needs to be logged
274 public function getLog( ) {ldelim}
279 * Returns the list of fields that can be imported
281 * @param bool $prefix
285 public static function &import( $prefix = FALSE ) {ldelim}
286 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
287 {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
288 {if $foreign.import}'{$foreign.className}',{/if}
295 * Returns the list of fields that can be exported
297 * @param bool $prefix
301 public static function &export( $prefix = FALSE ) {ldelim}
302 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
303 {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
304 {if $foreign.export}'{$foreign.className}',{/if}
311 * Returns the list of indices
313 * @param bool $localize
317 public static function indices($localize = TRUE) {ldelim}
318 $indices = {$indicesPhp};
319 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;