4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.5 |
6 +--------------------------------------------------------------------+
7 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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 *}
186 {if $field.precision}
187 'precision' => array({$field.precision}),
190 'size' => {$field.size},
191 {/if} {* field.size *}
193 'rows' => {$field.rows},
194 {/if} {* field.rows *}
196 'cols' => {$field.cols},
197 {/if} {* field.cols *}
200 'import' => {$field.import},
201 'where' => '{$table.name}.{$field.name}',
202 'headerPattern' => '{$field.headerPattern}',
203 'dataPattern' => '{$field.dataPattern}',
204 {/if} {* field.import *}
206 'export' => {$field.export},
208 'where' => '{$table.name}.{$field.name}',
209 'headerPattern' => '{$field.headerPattern}',
210 'dataPattern' => '{$field.dataPattern}',
212 {/if} {* field.export *}
214 'rule' => '{$field.rule}',
215 {/if} {* field.rule *}
217 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
218 {/if} {* field.default *}
220 {if $field.FKClassName}
221 'FKClassName' => '{$field.FKClassName}',
222 {/if} {* field.FKClassName *}
224 {assign var=htmlOptions value=$field.html}
226 {*{$htmlOptions|@print_array}*}
227 {foreach from=$htmlOptions key=optionKey item=optionValue}
228 '{$optionKey}' => '{$optionValue}',
231 {/if} {* field.html *}
232 {if $field.pseudoconstant}
233 {assign var=pseudoOptions value=$field.pseudoconstant}
234 'pseudoconstant' => array(
235 {*{$pseudoOptions|@print_array}*}
236 {foreach from=$pseudoOptions key=optionKey item=optionValue}
237 '{$optionKey}' => '{$optionValue}',
240 {/if} {* field.pseudoconstant *} ),
241 {/foreach} {* table.fields *}
244 return self::$_fields;
248 * Returns an array containing, for each field, the arary key used for that
249 * field in self::$_fields.
254 static function &fieldKeys( ) {ldelim}
255 if ( ! ( self::$_fieldKeys ) ) {ldelim}
256 self::$_fieldKeys = array (
257 {foreach from=$table.fields item=field}
259 {if $field.uniqueName}
260 '{$field.uniqueName}'
265 {/foreach} {* table.fields *}
268 return self::$_fieldKeys;
272 * returns the names of this table
278 static function getTableName( ) {ldelim}
279 {if $table.localizable}
280 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
282 return self::$_tableName;
287 * returns if this table needs to be logged
292 function getLog( ) {ldelim}
297 * returns the list of fields that can be imported
303 static function &import( $prefix = false ) {ldelim}
304 if ( ! ( self::$_import ) ) {ldelim}
305 self::$_import = array ( );
306 $fields = self::fields( );
307 foreach ( $fields as $name => $field ) {ldelim}
308 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
309 if ( $prefix ) {ldelim}
310 self::$_import['{$table.labelName}'] =& $fields[$name];
311 {rdelim} else {ldelim}
312 self::$_import[$name] =& $fields[$name];
316 {if $table.foreignKey}
317 {foreach from=$table.foreignKey item=foreign}
319 self::$_import = array_merge( self::$_import,
320 {$foreign.className}::import( true ) );
325 return self::$_import;
329 * returns the list of fields that can be exported
335 static function &export( $prefix = false ) {ldelim}
336 if ( ! ( self::$_export ) ) {ldelim}
337 self::$_export = array ( );
338 $fields = self::fields( );
339 foreach ( $fields as $name => $field ) {ldelim}
340 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
341 if ( $prefix ) {ldelim}
342 self::$_export['{$table.labelName}'] =& $fields[$name];
343 {rdelim} else {ldelim}
344 self::$_export[$name] =& $fields[$name];
348 {if $table.foreignKey}
349 {foreach from=$table.foreignKey item=foreign}
351 self::$_export = array_merge( self::$_export,
352 {$foreign.className}::export( true ) );
357 return self::$_export;