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}';
20 * Static instance to hold the table name.
24 public static $_tableName = '{$table.name}';
28 * Icon associated with this entity.
32 public static $_icon = '{$table.icon}';
35 * Should CiviCRM log any modifications to this table in the civicrm_log table.
39 public static $_log = {$table.log|strtoupper};
41 {foreach from=$table.fields item=field}
44 * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "}
47 * @var {$field.phpType}
49 public ${$field.name};
51 {/foreach} {* table.fields *}
56 public function __construct( ) {ldelim}
57 $this->__table = '{$table.name}';
59 parent::__construct( );
63 * Returns localized title of this entity.
66 * Whether to return the plural version of the title.
68 public static function getEntityTitle($plural = FALSE) {ldelim}
69 return $plural ? {$tsFunctionName}('{$table.titlePlural}') : {$tsFunctionName}('{$table.title}');
74 {if $table.foreignKey || $table.dynamicForeignKey}
76 * Returns foreign keys and entity references.
79 * [CRM_Core_Reference_Interface]
81 public static function getReferenceColumns() {ldelim}
82 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
83 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
84 {foreach from=$table.foreignKey item=foreign}
85 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
88 {foreach from=$table.dynamicForeignKey item=foreign}
89 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
91 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
93 return Civi::$statics[__CLASS__]['links'];
95 {/if} {* table.foreignKey *}
98 * Returns all the column names of this table
102 public static function &fields( ) {ldelim}
103 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
104 Civi::$statics[__CLASS__]['fields'] = array(
105 {foreach from=$table.fields item=field}
107 {if $field.uniqueName}
108 '{$field.uniqueName}'
113 'name' => '{$field.name}',
114 'type' => {$field.crmType},
116 'title' => {$tsFunctionName}('{$field.title}'),
119 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
122 'required' => {$field.required|strtoupper},
123 {/if} {* field.required *}
125 'maxlength' => {$field.length},
126 {/if} {* field.length *}
127 {if $field.precision}
128 'precision' => array({$field.precision}),
131 'size' => {$field.size},
132 {/if} {* field.size *}
134 'rows' => {$field.rows},
135 {/if} {* field.rows *}
137 'cols' => {$field.cols},
138 {/if} {* field.cols *}
141 'import' => {$field.import|strtoupper},
143 {/if} {* field.import *}
144 'where' => '{$table.name}.{$field.name}',
145 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
146 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
148 'export' => {$field.export|strtoupper},
149 {/if} {* field.export *}
150 {if $field.contactType}
151 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
154 'rule' => '{$field.rule}',
155 {/if} {* field.rule *}
156 {if !empty($field.permission)}
157 'permission' => {$field.permission|@print_array},
159 {if $field.default || $field.default === '0'}
160 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
161 {/if} {* field.default *}
162 'table_name' => '{$table.name}',
163 'entity' => '{$table.entity}',
164 'bao' => '{$table.bao}',
165 'localizable' => {if $field.localizable}1{else}0{/if},
166 {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if}
168 {if $field.FKClassName}
169 'FKClassName' => '{$field.FKClassName}',
171 {if $field.serialize}
172 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
174 {if $field.uniqueTitle}
175 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
179 {foreach from=$field.html item=val key=key}
180 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
184 {if $field.pseudoconstant}
185 'pseudoconstant' => {$field.pseudoconstant|@print_array},
187 'add' => {if $field.add}'{$field.add}'{else}NULL{/if},
189 {/foreach} {* table.fields *}
191 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
193 return Civi::$statics[__CLASS__]['fields'];
197 * Return a mapping from field-name to the corresponding key (as used in fields()).
200 * Array(string $name => string $uniqueName).
202 public static function &fieldKeys( ) {ldelim}
203 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
204 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
206 return Civi::$statics[__CLASS__]['fieldKeys'];
210 * Returns the names of this table
214 public static function getTableName( ) {ldelim}
215 {if $table.localizable}
216 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
218 return self::$_tableName;
223 * Returns if this table needs to be logged
227 public function getLog( ) {ldelim}
232 * Returns the list of fields that can be imported
234 * @param bool $prefix
238 public static function &import( $prefix = FALSE ) {ldelim}
239 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
240 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
241 {if $foreign.import}'{$foreign.className}',{/if}
248 * Returns the list of fields that can be exported
250 * @param bool $prefix
254 public static function &export( $prefix = FALSE ) {ldelim}
255 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
256 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
257 {if $foreign.export}'{$foreign.className}',{/if}
264 * Returns the list of indices
266 * @param bool $localize
270 public static function indices($localize = TRUE) {ldelim}
271 $indices = {$indicesPhp};
272 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;