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 * Static instance to hold the table name.
21 public static $_tableName = '{$table.name}';
25 * Icon associated with this entity.
29 public static $_icon = '{$table.icon}';
32 * Should CiviCRM log any modifications to this table in the civicrm_log table.
36 public static $_log = {$table.log|strtoupper};
38 {foreach from=$table.fields item=field}
41 * {$field.comment|regex_replace:"/\n[ ]*/":"\n* "}
44 * @var {$field.phpType}
46 public ${$field.name};
48 {/foreach} {* table.fields *}
53 public function __construct( ) {ldelim}
54 $this->__table = '{$table.name}';
56 parent::__construct( );
60 * Returns localized title of this entity.
62 public static function getEntityTitle() {ldelim}
63 return ts('{$table.title}');
68 {if $table.foreignKey || $table.dynamicForeignKey}
70 * Returns foreign keys and entity references.
73 * [CRM_Core_Reference_Interface]
75 public static function getReferenceColumns() {ldelim}
76 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
77 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
78 {foreach from=$table.foreignKey item=foreign}
79 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
82 {foreach from=$table.dynamicForeignKey item=foreign}
83 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
85 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
87 return Civi::$statics[__CLASS__]['links'];
89 {/if} {* table.foreignKey *}
92 * Returns all the column names of this table
96 public static function &fields( ) {ldelim}
97 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
98 Civi::$statics[__CLASS__]['fields'] = array(
99 {foreach from=$table.fields item=field}
101 {if $field.uniqueName}
102 '{$field.uniqueName}'
107 'name' => '{$field.name}',
108 'type' => {$field.crmType},
110 'title' => {$tsFunctionName}('{$field.title}'),
113 'description' => {$tsFunctionName}('{$field.comment|replace:"'":"\'"}'),
116 'required' => {$field.required|strtoupper},
117 {/if} {* field.required *}
119 'maxlength' => {$field.length},
120 {/if} {* field.length *}
121 {if $field.precision}
122 'precision' => array({$field.precision}),
125 'size' => {$field.size},
126 {/if} {* field.size *}
128 'rows' => {$field.rows},
129 {/if} {* field.rows *}
131 'cols' => {$field.cols},
132 {/if} {* field.cols *}
135 'import' => {$field.import|strtoupper},
137 {/if} {* field.import *}
138 'where' => '{$table.name}.{$field.name}',
139 {if $field.headerPattern}'headerPattern' => '{$field.headerPattern}',{/if}
140 {if $field.dataPattern}'dataPattern' => '{$field.dataPattern}',{/if}
142 'export' => {$field.export|strtoupper},
143 {/if} {* field.export *}
144 {if $field.contactType}
145 'contactType' => {if $field.contactType == 'null'}NULL{else}'{$field.contactType}'{/if},
148 'rule' => '{$field.rule}',
149 {/if} {* field.rule *}
150 {if !empty($field.permission)}
151 'permission' => {$field.permission|@print_array},
153 {if $field.default || $field.default === '0'}
154 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
155 {/if} {* field.default *}
156 'table_name' => '{$table.name}',
157 'entity' => '{$table.entity}',
158 'bao' => '{$table.bao}',
159 'localizable' => {if $field.localizable}1{else}0{/if},
160 {if $field.localize_context}'localize_context' => '{$field.localize_context}',{/if}
162 {if $field.FKClassName}
163 'FKClassName' => '{$field.FKClassName}',
165 {if $field.serialize}
166 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
168 {if $field.uniqueTitle}
169 'unique_title' => {$tsFunctionName}('{$field.uniqueTitle}'),
173 {foreach from=$field.html item=val key=key}
174 '{$key}' => {if $key eq 'label'}{$tsFunctionName}("{$val}"){else}'{$val}'{/if},
178 {if $field.pseudoconstant}
179 'pseudoconstant' => {$field.pseudoconstant|@print_array},
180 {/if} {* field.pseudoconstant *} ),
181 {/foreach} {* table.fields *}
183 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
185 return Civi::$statics[__CLASS__]['fields'];
189 * Return a mapping from field-name to the corresponding key (as used in fields()).
192 * Array(string $name => string $uniqueName).
194 public static function &fieldKeys( ) {ldelim}
195 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
196 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
198 return Civi::$statics[__CLASS__]['fieldKeys'];
202 * Returns the names of this table
206 public static function getTableName( ) {ldelim}
207 {if $table.localizable}
208 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
210 return self::$_tableName;
215 * Returns if this table needs to be logged
219 public function getLog( ) {ldelim}
224 * Returns the list of fields that can be imported
226 * @param bool $prefix
230 public static function &import( $prefix = FALSE ) {ldelim}
231 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
232 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
233 {if $foreign.import}'{$foreign.className}',{/if}
240 * Returns the list of fields that can be exported
242 * @param bool $prefix
246 public static function &export( $prefix = FALSE ) {ldelim}
247 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
248 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
249 {if $foreign.export}'{$foreign.className}',{/if}
256 * Returns the list of indices
258 * @param bool $localize
262 public static function indices($localize = TRUE) {ldelim}
263 $indices = {$indicesPhp};
264 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;