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 !empty($table.foreignKey) || !empty($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 {if isset($table.foreignKey)}
103 {foreach from=$table.foreignKey item=foreign}
104 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
107 {if isset($table.dynamicForeignKey)}
108 {foreach from=$table.dynamicForeignKey item=foreign}
109 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
112 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
114 return Civi::$statics[__CLASS__]['links'];
116 {/if} {* table.foreignKey *}
119 * Returns all the column names of this table
123 public static function &fields( ) {ldelim}
124 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
125 Civi::$statics[__CLASS__]['fields'] = array(
126 {foreach from=$table.fields item=field}
128 {if $field.uniqueName}
129 '{$field.uniqueName}'
134 'name' => '{$field.name}',
135 'type' => {$field.crmType},
137 'title' => {$tsFunctionName}('{$field.title}'),
140 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
143 'required' => {$field.required|strtoupper},
144 {/if} {* field.required *}
145 {if isset($field.length)}
146 'maxlength' => {$field.length},
147 {/if} {* field.length *}
148 {if isset($field.precision)}
149 'precision' => array({$field.precision}),
151 {if isset($field.size)}
152 'size' => {$field.size},
153 {/if} {* field.size *}
154 {if isset($field.rows)}
155 'rows' => {$field.rows},
156 {/if} {* field.rows *}
157 {if isset($field.cols)}
158 'cols' => {$field.cols},
159 {/if} {* field.cols *}
162 'import' => {$field.import|strtoupper},
164 {/if} {* field.import *}
165 'where' => '{$table.name}.{$field.name}',
166 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
167 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
169 'export' => {$field.export|strtoupper},
170 {/if} {* field.export *}
171 {if $field.contactType}
172 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
175 'rule' => '{$field.rule}',
176 {/if} {* field.rule *}
177 {if !empty($field.permission)}
178 'permission' => {$field.permission|@print_array},
180 {if $field.default || $field.default === '0'}
181 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
182 {/if} {* field.default *}
183 'table_name' => '{$table.name}',
184 'entity' => '{$table.entity}',
185 'bao' => '{$table.bao}',
186 'localizable' => {if $field.localizable}1{else}0{/if},
187 {if isset($field.localize_context)}'localize_context' => '{$field.localize_context}',{/if}
189 {if isset($field.FKClassName)}
190 'FKClassName' => '{$field.FKClassName}',
192 {if !empty($field.component)}
193 'component' => '{$field.component}',
195 {if $field.serialize}
196 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
198 {if $field.uniqueTitle}
199 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
203 {foreach from=$field.html item=val key=key}
204 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
208 {if $field.pseudoconstant}
209 'pseudoconstant' => {$field.pseudoconstant|@print_array},
211 {if $field.readonly || $field.name === $table.primaryKey.name}
214 'add' => {if $field.add}'{$field.add}'{else}NULL{/if},
216 {/foreach} {* table.fields *}
218 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
220 return Civi::$statics[__CLASS__]['fields'];
224 * Return a mapping from field-name to the corresponding key (as used in fields()).
227 * Array(string $name => string $uniqueName).
229 public static function &fieldKeys( ) {ldelim}
230 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
231 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
233 return Civi::$statics[__CLASS__]['fieldKeys'];
237 * Returns the names of this table
241 public static function getTableName( ) {ldelim}
242 {if $table.localizable}
243 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
245 return self::$_tableName;
250 * Returns if this table needs to be logged
254 public function getLog( ) {ldelim}
259 * Returns the list of fields that can be imported
261 * @param bool $prefix
265 public static function &import( $prefix = FALSE ) {ldelim}
266 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
267 {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
268 {if $foreign.import}'{$foreign.className}',{/if}
275 * Returns the list of fields that can be exported
277 * @param bool $prefix
281 public static function &export( $prefix = FALSE ) {ldelim}
282 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
283 {if isset($table.foreignKey)}{foreach from=$table.foreignKey item=foreign}
284 {if $foreign.export}'{$foreign.className}',{/if}
291 * Returns the list of indices
293 * @param bool $localize
297 public static function indices($localize = TRUE) {ldelim}
298 $indices = {$indicesPhp};
299 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;