4 * @copyright CiviCRM LLC (c) 2004-2018
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 static $_tableName = '{$table.name}';
24 * Should CiviCRM log any modifications to this table in the civicrm_log table.
28 static $_log = {$table.log|strtoupper};
30 {foreach from=$table.fields item=field}
36 * @var {$field.phpType}
38 public ${$field.name};
40 {/foreach} {* table.fields *}
45 public function __construct( ) {ldelim}
46 $this->__table = '{$table.name}';
48 parent::__construct( );
51 {if $table.foreignKey || $table.dynamicForeignKey}
53 * Returns foreign keys and entity references.
56 * [CRM_Core_Reference_Interface]
58 public static function getReferenceColumns() {ldelim}
59 if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim}
60 Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__);
61 {foreach from=$table.foreignKey item=foreign}
62 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
65 {foreach from=$table.dynamicForeignKey item=foreign}
66 Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
68 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']);
70 return Civi::$statics[__CLASS__]['links'];
72 {/if} {* table.foreignKey *}
75 * Returns all the column names of this table
79 public static function &fields( ) {ldelim}
80 if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim}
81 Civi::$statics[__CLASS__]['fields'] = array(
82 {foreach from=$table.fields item=field}
84 {if $field.uniqueName}
90 'name' => '{$field.name}',
91 'type' => {$field.crmType},
93 'title' => ts('{$field.title}'),
96 'description' => '{$field.comment|replace:"'":"\'"}',
99 'required' => {$field.required|strtoupper},
100 {/if} {* field.required *}
102 'maxlength' => {$field.length},
103 {/if} {* field.length *}
104 {if $field.precision}
105 'precision' => array({$field.precision}),
108 'size' => {$field.size},
109 {/if} {* field.size *}
111 'rows' => {$field.rows},
112 {/if} {* field.rows *}
114 'cols' => {$field.cols},
115 {/if} {* field.cols *}
118 'import' => {$field.import|strtoupper},
119 'where' => '{$table.name}.{$field.name}',
120 'headerPattern' => '{$field.headerPattern}',
121 'dataPattern' => '{$field.dataPattern}',
122 {/if} {* field.import *}
124 'export' => {$field.export|strtoupper},
126 'where' => '{$table.name}.{$field.name}',
127 'headerPattern' => '{$field.headerPattern}',
128 'dataPattern' => '{$field.dataPattern}',
130 {/if} {* field.export *}
132 'rule' => '{$field.rule}',
133 {/if} {* field.rule *}
134 {if $field.default || $field.default === '0'}
135 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
136 {/if} {* field.default *}
137 'table_name' => '{$table.name}',
138 'entity' => '{$table.entity}',
139 'bao' => '{$table.bao}',
140 'localizable' => {if $field.localizable}1{else}0{/if},
142 {if $field.FKClassName}
143 'FKClassName' => '{$field.FKClassName}',
145 {if $field.serialize}
146 'serialize' => self::SERIALIZE_{$field.serialize|strtoupper},
150 {foreach from=$field.html item=val key=key}
151 '{$key}' => {if $key eq 'label'}ts("{$val}"){else}'{$val}'{/if},
155 {if $field.pseudoconstant}
156 'pseudoconstant' => {$field.pseudoconstant|@print_array}
157 {/if} {* field.pseudoconstant *} ),
158 {/foreach} {* table.fields *}
160 CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']);
162 return Civi::$statics[__CLASS__]['fields'];
166 * Return a mapping from field-name to the corresponding key (as used in fields()).
169 * Array(string $name => string $uniqueName).
171 public static function &fieldKeys( ) {ldelim}
172 if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim}
173 Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields()));
175 return Civi::$statics[__CLASS__]['fieldKeys'];
179 * Returns the names of this table
183 public static function getTableName( ) {ldelim}
184 {if $table.localizable}
185 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
187 return self::$_tableName;
192 * Returns if this table needs to be logged
196 public function getLog( ) {ldelim}
201 * Returns the list of fields that can be imported
203 * @param bool $prefix
207 public static function &import( $prefix = FALSE ) {ldelim}
208 $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array(
209 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
210 {if $foreign.import}'{$foreign.className}',{/if}
217 * Returns the list of fields that can be exported
219 * @param bool $prefix
223 public static function &export( $prefix = FALSE ) {ldelim}
224 $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array(
225 {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign}
226 {if $foreign.export}'{$foreign.className}',{/if}
233 * Returns the list of indices
235 * @param bool $localize
239 public static function indices($localize = TRUE) {ldelim}
240 $indices = {$indicesPhp};
241 return ($localize && !empty($indices)) ? CRM_Core_DAO_AllCoreTables::multilingualize(__CLASS__, $indices) : $indices;