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 * Should CiviCRM log any modifications to this table in the civicrm_log table.
40 public static $_log = {$table.log|strtoupper};
43 * Paths for accessing this entity in the UI.
47 protected static $_paths = {$table.paths|@print_array};
50 {foreach from=$table.fields item=field}
53 * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "}
56 * @var {$field.phpType}
58 public ${$field.name};
60 {/foreach} {* table.fields *}
65 public function __construct( ) {ldelim}
66 $this->__table = '{$table.name}';
68 parent::__construct( );
72 * Returns localized title of this entity.
75 * Whether to return the plural version of the title.
77 public static function getEntityTitle($plural = FALSE) {ldelim}
78 return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}');
83 {if $table.foreignKey || $table.dynamicForeignKey}
85 * Returns foreign keys and entity references.
88 * [CRM_Core_Reference_Interface]
90 public static function getReferenceColumns() {ldelim}
91 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
92 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
93 {foreach from=$table.foreignKey item=foreign}
94 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
97 {foreach from=$table.dynamicForeignKey item=foreign}
98 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
100 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
102 return Civi::$statics[__CLASS__]['links'];
104 {/if} {* table.foreignKey *}
107 * Returns all the column names of this table
111 public static function &fields( ) {ldelim}
112 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
113 Civi::$statics[__CLASS__]['fields'] = array(
114 {foreach from=$table.fields item=field}
116 {if $field.uniqueName}
117 '{$field.uniqueName}'
122 'name' => '{$field.name}',
123 'type' => {$field.crmType},
125 'title' => {$tsFunctionName}('{$field.title}'),
128 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
131 'required' => {$field.required|strtoupper},
132 {/if} {* field.required *}
134 'maxlength' => {$field.length},
135 {/if} {* field.length *}
136 {if $field.precision}
137 'precision' => array({$field.precision}),
140 'size' => {$field.size},
141 {/if} {* field.size *}
143 'rows' => {$field.rows},
144 {/if} {* field.rows *}
146 'cols' => {$field.cols},
147 {/if} {* field.cols *}
150 'import' => {$field.import|strtoupper},
152 {/if} {* field.import *}
153 'where' => '{$table.name}.{$field.name}',
154 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
155 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
157 'export' => {$field.export|strtoupper},
158 {/if} {* field.export *}
159 {if $field.contactType}
160 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
163 'rule' => '{$field.rule}',
164 {/if} {* field.rule *}
165 {if !empty($field.permission)}
166 'permission' => {$field.permission|@print_array},
168 {if $field.default || $field.default === '0'}
169 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
170 {/if} {* field.default *}
171 'table_name' => '{$table.name}',
172 'entity' => '{$table.entity}',
173 'bao' => '{$table.bao}',
174 'localizable' => {if $field.localizable}1{else}0{/if},
175 {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if}
177 {if $field.FKClassName}
178 'FKClassName' => '{$field.FKClassName}',
180 {if $field.serialize}
181 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
183 {if $field.uniqueTitle}
184 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
188 {foreach from=$field.html item=val key=key}
189 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
193 {if $field.pseudoconstant}
194 'pseudoconstant' => {$field.pseudoconstant|@print_array},
196 'add' => {if $field.add}'{$field.add}'{else}NULL{/if},
198 {/foreach} {* table.fields *}
200 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
202 return Civi::$statics[__CLASS__]['fields'];
206 * Return a mapping from field-name to the corresponding key (as used in fields()).
209 * Array(string $name => string $uniqueName).
211 public static function &fieldKeys( ) {ldelim}
212 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
213 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
215 return Civi::$statics[__CLASS__]['fieldKeys'];
219 * Returns the names of this table
223 public static function getTableName( ) {ldelim}
224 {if $table.localizable}
225 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
227 return self::$_tableName;
232 * Returns if this table needs to be logged
236 public function getLog( ) {ldelim}
241 * Returns the list of fields that can be imported
243 * @param bool $prefix
247 public static function &import( $prefix = FALSE ) {ldelim}
248 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
249 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
250 {if $foreign.import}'{$foreign.className}',{/if}
257 * Returns the list of fields that can be exported
259 * @param bool $prefix
263 public static function &export( $prefix = FALSE ) {ldelim}
264 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
265 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
266 {if $foreign.export}'{$foreign.className}',{/if}
273 * Returns the list of indices
275 * @param bool $localize
279 public static function indices($localize = TRUE) {ldelim}
280 $indices = {$indicesPhp};
281 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;