4 +--------------------------------------------------------------------+
5 | CiviCRM version 4.3 |
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 FK relationships
73 static $_links = null;
76 * static instance to hold the values that can
82 static $_import = null;
85 * 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
100 static $_log = {$table.log};
102 {foreach from=$table.fields item=field}
108 * @var {$field.phpType}
110 public ${$field.name};
112 {/foreach} {* table.fields *}
118 * @return {$table.name}
120 function __construct( ) {ldelim}
121 $this->__table = '{$table.name}';
123 parent::__construct( );
126 {if $table.foreignKey}
128 * return foreign links
133 function links( ) {ldelim}
134 if ( ! ( self::$_links ) ) {ldelim}
135 self::$_links = array(
136 {foreach from=$table.foreignKey item=foreign}
137 '{$foreign.name}' => '{$foreign.table}:{$foreign.key}',
141 return self::$_links;
143 {/if} {* table.foreignKey *}
146 * 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 *}
174 'size' => {$field.size},
175 {/if} {* field.size *}
177 'rows' => {$field.rows},
178 {/if} {* field.rows *}
180 'cols' => {$field.cols},
181 {/if} {* field.cols *}
184 'import' => {$field.import},
185 'where' => '{$table.name}.{$field.name}',
186 'headerPattern' => '{$field.headerPattern}',
187 'dataPattern' => '{$field.dataPattern}',
188 {/if} {* field.import *}
190 'export' => {$field.export},
192 'where' => '{$table.name}.{$field.name}',
193 'headerPattern' => '{$field.headerPattern}',
194 'dataPattern' => '{$field.dataPattern}',
196 {/if} {* field.export *}
198 'rule' => '{$field.rule}',
199 {/if} {* field.rule *}
201 'default' => '{$field.default|substring:1:-1}',
202 {/if} {* field.default *}
203 {if $field.enumValues}
204 'enumValues' => '{$field.enumValues}',
205 {/if} {* field.enumValues *}
207 {if $field.FKClassName}
208 'FKClassName' => '{$field.FKClassName}',
209 {/if} {* field.FKClassName *}
210 {if $field.pseudoconstant}
211 {assign var=pseudoOptions value=$field.pseudoconstant}
212 'pseudoconstant' => array(
213 {*{$pseudoOptions|@print_array}*}
214 {foreach from=$pseudoOptions key=optionKey item=optionValue}
215 '{$optionKey}' => '{$optionValue}',
218 {/if} {* field.pseudoconstant *} ),
219 {/foreach} {* table.fields *}
222 return self::$_fields;
226 * returns the names of this table
232 static function getTableName( ) {ldelim}
233 {if $table.localizable}
234 return CRM_Core_DAO::getLocaleTableName( self::$_tableName );
236 return self::$_tableName;
241 * returns if this table needs to be logged
246 function getLog( ) {ldelim}
251 * returns the list of fields that can be imported
257 static function &import( $prefix = false ) {ldelim}
258 if ( ! ( self::$_import ) ) {ldelim}
259 self::$_import = array ( );
260 $fields = self::fields( );
261 foreach ( $fields as $name => $field ) {ldelim}
262 if ( CRM_Utils_Array::value( 'import', $field ) ) {ldelim}
263 if ( $prefix ) {ldelim}
264 self::$_import['{$table.labelName}'] =& $fields[$name];
265 {rdelim} else {ldelim}
266 self::$_import[$name] =& $fields[$name];
270 {if $table.foreignKey}
271 {foreach from=$table.foreignKey item=foreign}
273 self::$_import = array_merge( self::$_import,
274 {$foreign.className}::import( true ) );
279 return self::$_import;
283 * returns the list of fields that can be exported
289 static function &export( $prefix = false ) {ldelim}
290 if ( ! ( self::$_export ) ) {ldelim}
291 self::$_export = array ( );
292 $fields = self::fields( );
293 foreach ( $fields as $name => $field ) {ldelim}
294 if ( CRM_Utils_Array::value( 'export', $field ) ) {ldelim}
295 if ( $prefix ) {ldelim}
296 self::$_export['{$table.labelName}'] =& $fields[$name];
297 {rdelim} else {ldelim}
298 self::$_export[$name] =& $fields[$name];
302 {if $table.foreignKey}
303 {foreach from=$table.foreignKey item=foreign}
305 self::$_export = array_merge( self::$_export,
306 {$foreign.className}::export( true ) );
311 return self::$_export;
316 * returns an array containing the enum fields of the {$table.name} table
318 * @return array (reference) the array of enum fields
320 static function &getEnums() {ldelim}
321 static $enums = array(
322 {foreach from=$table.fields item=field}
323 {if $field.crmType == 'CRM_Utils_Type::T_ENUM'}
332 * returns a ts()-translated enum value for display purposes
334 * @param string $field the enum field in question
335 * @param string $value the enum value up for translation
337 * @return string the display value of the enum
339 static function tsEnum($field, $value) {ldelim}
340 static $translations = null;
341 if (!$translations) {ldelim}
342 $translations = array(
343 {foreach from=$table.fields item=field}
344 {if $field.crmType == 'CRM_Utils_Type::T_ENUM'}
345 '{$field.name}' => array(
346 {foreach from=$field.values item=value}
347 '{$value}' => ts('{$value}'),
354 return $translations[$field][$value];
358 * adds $value['foo_display'] for each $value['foo'] enum from {$table.name}
360 * @param array $values (reference) the array up for enhancing
363 static function addDisplayEnums(&$values) {ldelim}
364 $enumFields =& {$table.className}::getEnums();
365 foreach ($enumFields as $enum) {ldelim}
366 if (isset($values[$enum])) {ldelim}
367 $values[$enum.'_display'] = {$table.className}::tsEnum($enum, $values[$enum]);