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_Reference_Interface
142 static function getReferenceColumns() {ldelim}
143 if (!self::$_links) {ldelim}
144 self::$_links = static::createReferenceColumns(__CLASS__);
145 {foreach from=$table.foreignKey item=foreign}
146 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
149 {foreach from=$table.dynamicForeignKey item=foreign}
150 self::$_links[] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
153 return self::$_links;
155 {/if} {* table.foreignKey *}
158 * returns all the column names of this table
163 static function &fields( ) {ldelim}
164 if ( ! ( self::$_fields ) ) {ldelim}
165 self::$_fields = array (
166 {foreach from=$table.fields item=field}
168 {if $field.uniqueName}
169 '{$field.uniqueName}'
174 'name' => '{$field.name}',
175 'type' => {$field.crmType},
177 'title' => ts('{$field.title}'),
180 'required' => {$field.required},
181 {/if} {* field.required *}
183 'maxlength' => {$field.length},
184 {/if} {* field.length *}
185 {if $field.precision}
186 'precision' => array({$field.precision}),
189 'size' => {$field.size},
190 {/if} {* field.size *}
192 'rows' => {$field.rows},
193 {/if} {* field.rows *}
195 'cols' => {$field.cols},
196 {/if} {* field.cols *}
199 'import' => {$field.import},
200 'where' => '{$table.name}.{$field.name}',
201 'headerPattern' => '{$field.headerPattern}',
202 'dataPattern' => '{$field.dataPattern}',
203 {/if} {* field.import *}
205 'export' => {$field.export},
207 'where' => '{$table.name}.{$field.name}',
208 'headerPattern' => '{$field.headerPattern}',
209 'dataPattern' => '{$field.dataPattern}',
211 {/if} {* field.export *}
213 'rule' => '{$field.rule}',
214 {/if} {* field.rule *}
216 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
217 {/if} {* field.default *}
219 {if $field.FKClassName}
220 'FKClassName' => '{$field.FKClassName}',
221 {/if} {* field.FKClassName *}
223 {assign var=htmlOptions value=$field.html}
225 {*{$htmlOptions|@print_array}*}
226 {foreach from=$htmlOptions key=optionKey item=optionValue}
227 '{$optionKey}' => '{$optionValue}',
230 {/if} {* field.html *}
231 {if $field.pseudoconstant}
232 {assign var=pseudoOptions value=$field.pseudoconstant}
233 'pseudoconstant' => array(
234 {*{$pseudoOptions|@print_array}*}
235 {foreach from=$pseudoOptions key=optionKey item=optionValue}
236 '{$optionKey}' => '{$optionValue}',
239 {/if} {* field.pseudoconstant *} ),
240 {/foreach} {* table.fields *}
243 return self::$_fields;
247 * Returns an array containing, for each field, the arary key used for that
248 * field in self::$_fields.
253 static function &fieldKeys( ) {ldelim}
254 if ( ! ( self::$_fieldKeys ) ) {ldelim}
255 self::$_fieldKeys = array (
256 {foreach from=$table.fields item=field}
258 {if $field.uniqueName}
259 '{$field.uniqueName}'
264 {/foreach} {* table.fields *}
267 return self::$_fieldKeys;
271 * returns the names of this table
277 static function getTableName( ) {ldelim}
278 {if $table.localizable}
279 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
281 return self::$_tableName;
286 * returns if this table needs to be logged
291 function getLog( ) {ldelim}
296 * returns the list of fields that can be imported
302 static function &import( $prefix = false ) {ldelim}
303 if ( ! ( self::$_import ) ) {ldelim}
304 self::$_import = array ( );
305 $fields = self::fields( );
306 foreach ( $fields as $name => $field ) {ldelim}
307 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
308 if ( $prefix ) {ldelim}
309 self::$_import['{$table.labelName}'] =& $fields[$name];
310 {rdelim} else {ldelim}
311 self::$_import[$name] =& $fields[$name];
315 {if $table.foreignKey}
316 {foreach from=$table.foreignKey item=foreign}
318 self::$_import = array_merge( self::$_import,
319 {$foreign.className}::import( true ) );
324 return self::$_import;
328 * returns the list of fields that can be exported
334 static function &export( $prefix = false ) {ldelim}
335 if ( ! ( self::$_export ) ) {ldelim}
336 self::$_export = array ( );
337 $fields = self::fields( );
338 foreach ( $fields as $name => $field ) {ldelim}
339 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
340 if ( $prefix ) {ldelim}
341 self::$_export['{$table.labelName}'] =& $fields[$name];
342 {rdelim} else {ldelim}
343 self::$_export[$name] =& $fields[$name];
347 {if $table.foreignKey}
348 {foreach from=$table.foreignKey item=foreign}
350 self::$_export = array_merge( self::$_export,
351 {$foreign.className}::export( true ) );
356 return self::$_export;