4 * @copyright CiviCRM LLC https://civicrm.org/licensing
6 * Generated from {$table.sourceFile}
8 * (GenCodeChecksum:{$genCodeChecksum})
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}';
29 * Icon associated with this entity.
33 public static $_icon = '{$table.icon}';
36 {if $table.labelField}
38 * Field to show when displaying a record.
42 public static $_labelField = '{$table.labelField}';
45 * Should CiviCRM log any modifications to this table in the civicrm_log table.
49 public static $_log = {$table.log|strtoupper};
52 * Paths for accessing this entity in the UI.
56 protected static $_paths = {$table.paths|@print_array};
59 {foreach from=$table.fields item=field}
62 * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "}
65 * @var {$field.phpType}
67 public ${$field.name};
69 {/foreach} {* table.fields *}
74 public function __construct( ) {ldelim}
75 $this->__table = '{$table.name}';
77 parent::__construct( );
81 * Returns localized title of this entity.
84 * Whether to return the plural version of the title.
86 public static function getEntityTitle($plural = FALSE) {ldelim}
87 return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}');
92 {if $table.foreignKey || $table.dynamicForeignKey}
94 * Returns foreign keys and entity references.
97 * [CRM_Core_Reference_Interface]
99 public static function getReferenceColumns() {ldelim}
100 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
101 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
102 {foreach from=$table.foreignKey item=foreign}
103 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
106 {foreach from=$table.dynamicForeignKey item=foreign}
107 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
109 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
111 return Civi::$statics[__CLASS__]['links'];
113 {/if} {* table.foreignKey *}
116 * Returns all the column names of this table
120 public static function &fields( ) {ldelim}
121 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
122 Civi::$statics[__CLASS__]['fields'] = array(
123 {foreach from=$table.fields item=field}
125 {if $field.uniqueName}
126 '{$field.uniqueName}'
131 'name' => '{$field.name}',
132 'type' => {$field.crmType},
134 'title' => {$tsFunctionName}('{$field.title}'),
137 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
140 'required' => {$field.required|strtoupper},
141 {/if} {* field.required *}
143 'maxlength' => {$field.length},
144 {/if} {* field.length *}
145 {if $field.precision}
146 'precision' => array({$field.precision}),
149 'size' => {$field.size},
150 {/if} {* field.size *}
152 'rows' => {$field.rows},
153 {/if} {* field.rows *}
155 'cols' => {$field.cols},
156 {/if} {* field.cols *}
159 'import' => {$field.import|strtoupper},
161 {/if} {* field.import *}
162 'where' => '{$table.name}.{$field.name}',
163 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
164 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
166 'export' => {$field.export|strtoupper},
167 {/if} {* field.export *}
168 {if $field.contactType}
169 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
172 'rule' => '{$field.rule}',
173 {/if} {* field.rule *}
174 {if !empty($field.permission)}
175 'permission' => {$field.permission|@print_array},
177 {if $field.default || $field.default === '0'}
178 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
179 {/if} {* field.default *}
180 'table_name' => '{$table.name}',
181 'entity' => '{$table.entity}',
182 'bao' => '{$table.bao}',
183 'localizable' => {if $field.localizable}1{else}0{/if},
184 {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if}
186 {if $field.FKClassName}
187 'FKClassName' => '{$field.FKClassName}',
189 {if !empty($field.component)}
190 'component' => '{$field.component}',
192 {if $field.serialize}
193 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
195 {if $field.uniqueTitle}
196 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
200 {foreach from=$field.html item=val key=key}
201 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
205 {if $field.pseudoconstant}
206 'pseudoconstant' => {$field.pseudoconstant|@print_array},
208 {if $field.readonly || $field.name === $table.primaryKey.name}
211 'add' => {if $field.add}'{$field.add}'{else}NULL{/if},
213 {/foreach} {* table.fields *}
215 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
217 return Civi::$statics[__CLASS__]['fields'];
221 * Return a mapping from field-name to the corresponding key (as used in fields()).
224 * Array(string $name => string $uniqueName).
226 public static function &fieldKeys( ) {ldelim}
227 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
228 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
230 return Civi::$statics[__CLASS__]['fieldKeys'];
234 * Returns the names of this table
238 public static function getTableName( ) {ldelim}
239 {if $table.localizable}
240 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
242 return self::$_tableName;
247 * Returns if this table needs to be logged
251 public function getLog( ) {ldelim}
256 * Returns the list of fields that can be imported
258 * @param bool $prefix
262 public static function &import( $prefix = FALSE ) {ldelim}
263 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
264 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
265 {if $foreign.import}'{$foreign.className}',{/if}
272 * Returns the list of fields that can be exported
274 * @param bool $prefix
278 public static function &export( $prefix = FALSE ) {ldelim}
279 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
280 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
281 {if $foreign.export}'{$foreign.className}',{/if}
288 * Returns the list of indices
290 * @param bool $localize
294 public static function indices($localize = TRUE) {ldelim}
295 $indices = {$indicesPhp};
296 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;