3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
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 'description' => '{$field.comment|replace:"'":"\'"}',
171 'required' => {$field.required},
172 {/if} {* field.required *}
174 'maxlength' => {$field.length},
175 {/if} {* field.length *}
176 {if $field.precision}
177 'precision' => array({$field.precision}),
180 'size' => {$field.size},
181 {/if} {* field.size *}
183 'rows' => {$field.rows},
184 {/if} {* field.rows *}
186 'cols' => {$field.cols},
187 {/if} {* field.cols *}
190 'import' => {$field.import},
191 'where' => '{$table.name}.{$field.name}',
192 'headerPattern' => '{$field.headerPattern}',
193 'dataPattern' => '{$field.dataPattern}',
194 {/if} {* field.import *}
196 'export' => {$field.export},
198 'where' => '{$table.name}.{$field.name}',
199 'headerPattern' => '{$field.headerPattern}',
200 'dataPattern' => '{$field.dataPattern}',
202 {/if} {* field.export *}
204 'rule' => '{$field.rule}',
205 {/if} {* field.rule *}
207 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}',
208 {/if} {* field.default *}
210 {if $field.FKClassName}
211 'FKClassName' => '{$field.FKClassName}',
212 {/if} {* field.FKClassName *}
214 {assign var=htmlOptions value=$field.html}
216 {*{$htmlOptions|@print_array}*}
217 {foreach from=$htmlOptions key=optionKey item=optionValue}
218 '{$optionKey}' => '{$optionValue}',
221 {/if} {* field.html *}
222 {if $field.pseudoconstant}
223 {assign var=pseudoOptions value=$field.pseudoconstant}
224 'pseudoconstant' => array(
225 {*{$pseudoOptions|@print_array}*}
226 {foreach from=$pseudoOptions key=optionKey item=optionValue}
227 '{$optionKey}' => '{$optionValue}',
230 {/if} {* field.pseudoconstant *} ),
231 {/foreach} {* table.fields *}
234 return self::$_fields;
238 * Returns an array containing, for each field, the arary key used for that
239 * field in self::$_fields.
243 static function &fieldKeys( ) {ldelim}
244 if ( ! ( self::$_fieldKeys ) ) {ldelim}
245 self::$_fieldKeys = array (
246 {foreach from=$table.fields item=field}
248 {if $field.uniqueName}
249 '{$field.uniqueName}'
254 {/foreach} {* table.fields *}
257 return self::$_fieldKeys;
261 * Returns the names of this table
265 static function getTableName( ) {ldelim}
266 {if $table.localizable}
267 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
269 return self::$_tableName;
274 * Returns if this table needs to be logged
278 function getLog( ) {ldelim}
283 * Returns the list of fields that can be imported
285 * @param bool $prefix
289 static function &import( $prefix = false ) {ldelim}
290 if ( ! ( self::$_import ) ) {ldelim}
291 self::$_import = array ( );
292 $fields = self::fields( );
293 foreach ( $fields as $name => $field ) {ldelim}
294 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
295 if ( $prefix ) {ldelim}
296 self::$_import['{$table.labelName}'] =& $fields[$name];
297 {rdelim} else {ldelim}
298 self::$_import[$name] =& $fields[$name];
302 {if $table.foreignKey}
303 {foreach from=$table.foreignKey item=foreign}
305 self::$_import = array_merge( self::$_import,
306 {$foreign.className}::import( true ) );
311 return self::$_import;
315 * Returns the list of fields that can be exported
317 * @param bool $prefix
321 static function &export( $prefix = false ) {ldelim}
322 if ( ! ( self::$_export ) ) {ldelim}
323 self::$_export = array ( );
324 $fields = self::fields( );
325 foreach ( $fields as $name => $field ) {ldelim}
326 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
327 if ( $prefix ) {ldelim}
328 self::$_export['{$table.labelName}'] =& $fields[$name];
329 {rdelim} else {ldelim}
330 self::$_export[$name] =& $fields[$name];
334 {if $table.foreignKey}
335 {foreach from=$table.foreignKey item=foreign}
337 self::$_export = array_merge( self::$_export,
338 {$foreign.className}::export( true ) );
343 return self::$_export;