3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2014
32 * Generated from {$table.sourceFile}
36 require_once 'CRM/Core/DAO.php';
37 require_once 'CRM/Utils/Type.php';
39 {if $table.foreignKey}
40 {foreach from=$table.foreignKey item=foreign}
42 require_once '{$foreign.fileName}';
47 class {$table.className} extends CRM_Core_DAO {ldelim}
50 * static instance to hold the table name
54 static $_tableName = '{$table.name}';
57 * static instance to hold the field values
61 static $_fields = null;
64 * static instance to hold the keys used in $_fields for each field.
68 static $_fieldKeys = null;
71 * static instance to hold the FK relationships
75 static $_links = null;
78 * static instance to hold the values that can
83 static $_import = null;
86 * static instance to hold the values that can
91 static $_export = null;
94 * static value to see if we should log any modifications to
95 * this table in the civicrm_log table
99 static $_log = {$table.log};
101 {foreach from=$table.fields item=field}
107 * @var {$field.phpType}
109 public ${$field.name};
111 {/foreach} {* table.fields *}
116 * @return {$table.name}
118 function __construct( ) {ldelim}
119 $this->__table = '{$table.name}';
121 parent::__construct( );
124 {if $table.foreignKey || $table.dynamicForeignKey}
126 * Returns foreign keys and entity references
129 * [CRM_Core_Reference_Interface]
131 static function getReferenceColumns() {ldelim}
132 if (!self::$_links) {ldelim}
133 self::$_links = static::createReferenceColumns(__CLASS__);
134 {foreach from=$table.foreignKey item=foreign}
135 self::$_links[] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}');
138 {foreach from=$table.dynamicForeignKey item=foreign}
139 self::$_links[] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}');
142 return self::$_links;
144 {/if} {* table.foreignKey *}
147 * Returns all the column names of this table
151 static function &fields( ) {ldelim}
152 if ( ! ( self::$_fields ) ) {ldelim}
153 self::$_fields = array (
154 {foreach from=$table.fields item=field}
156 {if $field.uniqueName}
157 '{$field.uniqueName}'
162 'name' => '{$field.name}',
163 'type' => {$field.crmType},
165 'title' => ts('{$field.title}'),
168 'required' => {$field.required},
169 {/if} {* field.required *}
171 'maxlength' => {$field.length},
172 {/if} {* field.length *}
173 {if $field.precision}
174 'precision' => array({$field.precision}),
177 'size' => {$field.size},
178 {/if} {* field.size *}
180 'rows' => {$field.rows},
181 {/if} {* field.rows *}
183 'cols' => {$field.cols},
184 {/if} {* field.cols *}
187 'import' => {$field.import},
188 'where' => '{$table.name}.{$field.name}',
189 'headerPattern' => '{$field.headerPattern}',
190 'dataPattern' => '{$field.dataPattern}',
191 {/if} {* field.import *}
193 'export' => {$field.export},
195 'where' => '{$table.name}.{$field.name}',
196 'headerPattern' => '{$field.headerPattern}',
197 'dataPattern' => '{$field.dataPattern}',
199 {/if} {* field.export *}
201 'rule' => '{$field.rule}',
202 {/if} {* field.rule *}
204 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
205 {/if} {* field.default *}
207 {if $field.FKClassName}
208 'FKClassName' => '{$field.FKClassName}',
209 {/if} {* field.FKClassName *}
211 {assign var=htmlOptions value=$field.html}
213 {*{$htmlOptions|@print_array}*}
214 {foreach from=$htmlOptions key=optionKey item=optionValue}
215 '{$optionKey}' => '{$optionValue}',
218 {/if} {* field.html *}
219 {if $field.pseudoconstant}
220 {assign var=pseudoOptions value=$field.pseudoconstant}
221 'pseudoconstant' => array(
222 {*{$pseudoOptions|@print_array}*}
223 {foreach from=$pseudoOptions key=optionKey item=optionValue}
224 '{$optionKey}' => '{$optionValue}',
227 {/if} {* field.pseudoconstant *} ),
228 {/foreach} {* table.fields *}
231 return self::$_fields;
235 * Returns an array containing, for each field, the arary key used for that
236 * field in self::$_fields.
240 static function &fieldKeys( ) {ldelim}
241 if ( ! ( self::$_fieldKeys ) ) {ldelim}
242 self::$_fieldKeys = array (
243 {foreach from=$table.fields item=field}
245 {if $field.uniqueName}
246 '{$field.uniqueName}'
251 {/foreach} {* table.fields *}
254 return self::$_fieldKeys;
258 * Returns the names of this table
262 static function getTableName( ) {ldelim}
263 {if $table.localizable}
264 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
266 return self::$_tableName;
271 * Returns if this table needs to be logged
275 function getLog( ) {ldelim}
280 * Returns the list of fields that can be imported
282 * @param bool $prefix
286 static function &import( $prefix = false ) {ldelim}
287 if ( ! ( self::$_import ) ) {ldelim}
288 self::$_import = array ( );
289 $fields = self::fields( );
290 foreach ( $fields as $name => $field ) {ldelim}
291 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
292 if ( $prefix ) {ldelim}
293 self::$_import['{$table.labelName}'] =& $fields[$name];
294 {rdelim} else {ldelim}
295 self::$_import[$name] =& $fields[$name];
299 {if $table.foreignKey}
300 {foreach from=$table.foreignKey item=foreign}
302 self::$_import = array_merge( self::$_import,
303 {$foreign.className}::import( true ) );
308 return self::$_import;
312 * Returns the list of fields that can be exported
314 * @param bool $prefix
318 static function &export( $prefix = false ) {ldelim}
319 if ( ! ( self::$_export ) ) {ldelim}
320 self::$_export = array ( );
321 $fields = self::fields( );
322 foreach ( $fields as $name => $field ) {ldelim}
323 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
324 if ( $prefix ) {ldelim}
325 self::$_export['{$table.labelName}'] =& $fields[$name];
326 {rdelim} else {ldelim}
327 self::$_export[$name] =& $fields[$name];
331 {if $table.foreignKey}
332 {foreach from=$table.foreignKey item=foreign}
334 self::$_export = array_merge( self::$_export,
335 {$foreign.className}::export( true ) );
340 return self::$_export;