4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.4 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2013 |
8 +--------------------------------------------------------------------+
9 | This file is a part of CiviCRM. |
11 | CiviCRM is free software; you can copy, modify, and distribute it |
12 | under the terms of the GNU Affero General Public License |
13 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
15 | CiviCRM is distributed in the hope that it will be useful, but |
16 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. |
20 | You should have received a copy of the GNU Affero General Public |
21 | License and the CiviCRM Licensing Exception along |
22 | with this program; if not, contact CiviCRM LLC |
23 | at info[AT]civicrm[DOT]org. If you have questions about the |
24 | GNU Affero General Public License or the licensing of CiviCRM, |
25 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
26 +--------------------------------------------------------------------+
32 * @copyright CiviCRM LLC (c) 2004-2013
34 * Generated from {$table.sourceFile}
38 require_once 'CRM/Core/DAO.php';
39 require_once 'CRM/Utils/Type.php';
41 {if $table.foreignKey}
42 {foreach from=$table.foreignKey item=foreign}
44 require_once '{$foreign.fileName}';
49 class {$table.className} extends CRM_Core_DAO {ldelim}
52 * static instance to hold the table name
57 static $_tableName = '{$table.name}';
60 * static instance to hold the field values
65 static $_fields = null;
68 * static instance to hold the keys used in $_fields for each field.
73 static $_fieldKeys = null;
76 * static instance to hold the FK relationships
81 static $_links = null;
84 * static instance to hold the values that can
90 static $_import = null;
93 * static instance to hold the values that can
99 static $_export = null;
102 * static value to see if we should log any modifications to
103 * this table in the civicrm_log table
108 static $_log = {$table.log};
110 {foreach from=$table.fields item=field}
116 * @var {$field.phpType}
118 public ${$field.name};
120 {/foreach} {* table.fields *}
126 * @return {$table.name}
128 function __construct( ) {ldelim}
129 $this->__table = '{$table.name}';
131 parent::__construct( );
134 {if $table.foreignKey || $table.dynamicForeignKey}
136 * return foreign keys and entity references
140 * @return array of CRM_Core_EntityReference
142 static function getReferenceColumns() {ldelim}
143 if (!self::$_links) {ldelim}
144 self::$_links = array(
145 {foreach from=$table.foreignKey item=foreign}
146 new CRM_Core_EntityReference(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}'),
149 {foreach from=$table.dynamicForeignKey item=foreign}
150 new CRM_Core_EntityReference(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}'),
154 return self::$_links;
156 {/if} {* table.foreignKey *}
159 * returns all the column names of this table
164 static function &fields( ) {ldelim}
165 if ( ! ( self::$_fields ) ) {ldelim}
166 self::$_fields = array (
167 {foreach from=$table.fields item=field}
169 {if $field.uniqueName}
170 '{$field.uniqueName}'
175 'name' => '{$field.name}',
176 'type' => {$field.crmType},
178 'title' => ts('{$field.title}'),
181 'required' => {$field.required},
182 {/if} {* field.required *}
184 'maxlength' => {$field.length},
185 {/if} {* field.length *}
187 'size' => {$field.size},
188 {/if} {* field.size *}
190 'rows' => {$field.rows},
191 {/if} {* field.rows *}
193 'cols' => {$field.cols},
194 {/if} {* field.cols *}
197 'import' => {$field.import},
198 'where' => '{$table.name}.{$field.name}',
199 'headerPattern' => '{$field.headerPattern}',
200 'dataPattern' => '{$field.dataPattern}',
201 {/if} {* field.import *}
203 'export' => {$field.export},
205 'where' => '{$table.name}.{$field.name}',
206 'headerPattern' => '{$field.headerPattern}',
207 'dataPattern' => '{$field.dataPattern}',
209 {/if} {* field.export *}
211 'rule' => '{$field.rule}',
212 {/if} {* field.rule *}
214 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
215 {/if} {* field.default *}
216 {if $field.enumValues}
217 'enumValues' => '{$field.enumValues}',
218 {/if} {* field.enumValues *}
220 {if $field.FKClassName}
221 'FKClassName' => '{$field.FKClassName}',
222 {/if} {* field.FKClassName *}
223 {if $field.pseudoconstant}
224 {assign var=pseudoOptions value=$field.pseudoconstant}
225 'pseudoconstant' => array(
226 {*{$pseudoOptions|@print_array}*}
227 {foreach from=$pseudoOptions key=optionKey item=optionValue}
228 '{$optionKey}' => '{$optionValue}',
231 {/if} {* field.pseudoconstant *} ),
232 {/foreach} {* table.fields *}
235 return self::$_fields;
239 * Returns an array containing, for each field, the arary key used for that
240 * field in self::$_fields.
245 static function &fieldKeys( ) {ldelim}
246 if ( ! ( self::$_fieldKeys ) ) {ldelim}
247 self::$_fieldKeys = array (
248 {foreach from=$table.fields item=field}
250 {if $field.uniqueName}
251 '{$field.uniqueName}'
256 {/foreach} {* table.fields *}
259 return self::$_fieldKeys;
263 * returns the names of this table
269 static function getTableName( ) {ldelim}
270 {if $table.localizable}
271 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
273 return self::$_tableName;
278 * returns if this table needs to be logged
283 function getLog( ) {ldelim}
288 * returns the list of fields that can be imported
294 static function &import( $prefix = false ) {ldelim}
295 if ( ! ( self::$_import ) ) {ldelim}
296 self::$_import = array ( );
297 $fields = self::fields( );
298 foreach ( $fields as $name => $field ) {ldelim}
299 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
300 if ( $prefix ) {ldelim}
301 self::$_import['{$table.labelName}'] =& $fields[$name];
302 {rdelim} else {ldelim}
303 self::$_import[$name] =& $fields[$name];
307 {if $table.foreignKey}
308 {foreach from=$table.foreignKey item=foreign}
310 self::$_import = array_merge( self::$_import,
311 {$foreign.className}::import( true ) );
316 return self::$_import;
320 * returns the list of fields that can be exported
326 static function &export( $prefix = false ) {ldelim}
327 if ( ! ( self::$_export ) ) {ldelim}
328 self::$_export = array ( );
329 $fields = self::fields( );
330 foreach ( $fields as $name => $field ) {ldelim}
331 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
332 if ( $prefix ) {ldelim}
333 self::$_export['{$table.labelName}'] =& $fields[$name];
334 {rdelim} else {ldelim}
335 self::$_export[$name] =& $fields[$name];
339 {if $table.foreignKey}
340 {foreach from=$table.foreignKey item=foreign}
342 self::$_export = array_merge( self::$_export,
343 {$foreign.className}::export( true ) );
348 return self::$_export;
353 * returns an array containing the enum fields of the {$table.name} table
355 * @return array (reference) the array of enum fields
357 static function &getEnums() {ldelim}
358 static $enums = array(
359 {foreach from=$table.fields item=field}
360 {if $field.crmType == 'CRM_Utils_Type::T_ENUM'}
369 * returns a ts()-translated enum value for display purposes
371 * @param string $field the enum field in question
372 * @param string $value the enum value up for translation
374 * @return string the display value of the enum
376 static function tsEnum($field, $value) {ldelim}
377 static $translations = null;
378 if (!$translations) {ldelim}
379 $translations = array(
380 {foreach from=$table.fields item=field}
381 {if $field.crmType == 'CRM_Utils_Type::T_ENUM'}
382 '{$field.name}' => array(
383 {foreach from=$field.values item=value}
384 '{$value}' => ts('{$value}'),
391 return $translations[$field][$value];
395 * adds $value['foo_display'] for each $value['foo'] enum from {$table.name}
397 * @param array $values (reference) the array up for enhancing
400 static function addDisplayEnums(&$values) {ldelim}
401 $enumFields =& {$table.className}::getEnums();
402 foreach ($enumFields as $enum) {ldelim}
403 if (isset($values[$enum])) {ldelim}
404 $values[$enum.'_display'] = {$table.className}::tsEnum($enum, $values[$enum]);