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 *}
217 {if $field.FKClassName}
218 'FKClassName' => '{$field.FKClassName}',
219 {/if} {* field.FKClassName *}
221 {assign var=htmlOptions value=$field.html}
223 {*{$htmlOptions|@print_array}*}
224 {foreach from=$htmlOptions key=optionKey item=optionValue}
225 '{$optionKey}' => '{$optionValue}',
228 {/if} {* field.html *}
229 {if $field.pseudoconstant}
230 {assign var=pseudoOptions value=$field.pseudoconstant}
231 'pseudoconstant' => array(
232 {*{$pseudoOptions|@print_array}*}
233 {foreach from=$pseudoOptions key=optionKey item=optionValue}
234 '{$optionKey}' => '{$optionValue}',
237 {/if} {* field.pseudoconstant *} ),
238 {/foreach} {* table.fields *}
241 return self::$_fields;
245 * Returns an array containing, for each field, the arary key used for that
246 * field in self::$_fields.
251 static function &fieldKeys( ) {ldelim}
252 if ( ! ( self::$_fieldKeys ) ) {ldelim}
253 self::$_fieldKeys = array (
254 {foreach from=$table.fields item=field}
256 {if $field.uniqueName}
257 '{$field.uniqueName}'
262 {/foreach} {* table.fields *}
265 return self::$_fieldKeys;
269 * returns the names of this table
275 static function getTableName( ) {ldelim}
276 {if $table.localizable}
277 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
279 return self::$_tableName;
284 * returns if this table needs to be logged
289 function getLog( ) {ldelim}
294 * returns the list of fields that can be imported
300 static function &import( $prefix = false ) {ldelim}
301 if ( ! ( self::$_import ) ) {ldelim}
302 self::$_import = array ( );
303 $fields = self::fields( );
304 foreach ( $fields as $name => $field ) {ldelim}
305 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
306 if ( $prefix ) {ldelim}
307 self::$_import['{$table.labelName}'] =& $fields[$name];
308 {rdelim} else {ldelim}
309 self::$_import[$name] =& $fields[$name];
313 {if $table.foreignKey}
314 {foreach from=$table.foreignKey item=foreign}
316 self::$_import = array_merge( self::$_import,
317 {$foreign.className}::import( true ) );
322 return self::$_import;
326 * returns the list of fields that can be exported
332 static function &export( $prefix = false ) {ldelim}
333 if ( ! ( self::$_export ) ) {ldelim}
334 self::$_export = array ( );
335 $fields = self::fields( );
336 foreach ( $fields as $name => $field ) {ldelim}
337 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
338 if ( $prefix ) {ldelim}
339 self::$_export['{$table.labelName}'] =& $fields[$name];
340 {rdelim} else {ldelim}
341 self::$_export[$name] =& $fields[$name];
345 {if $table.foreignKey}
346 {foreach from=$table.foreignKey item=foreign}
348 self::$_export = array_merge( self::$_export,
349 {$foreign.className}::export( true ) );
354 return self::$_export;