| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | +--------------------------------------------------------------------+ |
| 5 | | CiviCRM version 4.5 | |
| 6 | +--------------------------------------------------------------------+ |
| 7 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 8 | +--------------------------------------------------------------------+ |
| 9 | | This file is a part of CiviCRM. | |
| 10 | | | |
| 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. | |
| 14 | | | |
| 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. | |
| 19 | | | |
| 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 | +--------------------------------------------------------------------+ |
| 27 | */ |
| 28 | |
| 29 | /** |
| 30 | * |
| 31 | * @package CRM |
| 32 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 33 | * |
| 34 | * Generated from {$table.sourceFile} |
| 35 | * {$generated} |
| 36 | */ |
| 37 | |
| 38 | require_once 'CRM/Core/DAO.php'; |
| 39 | require_once 'CRM/Utils/Type.php'; |
| 40 | |
| 41 | {if $table.foreignKey} |
| 42 | {foreach from=$table.foreignKey item=foreign} |
| 43 | {if $foreign.import} |
| 44 | require_once '{$foreign.fileName}'; |
| 45 | {/if} |
| 46 | {/foreach} |
| 47 | {/if} |
| 48 | |
| 49 | class {$table.className} extends CRM_Core_DAO {ldelim} |
| 50 | |
| 51 | /** |
| 52 | * static instance to hold the table name |
| 53 | * |
| 54 | * @var string |
| 55 | * @static |
| 56 | */ |
| 57 | static $_tableName = '{$table.name}'; |
| 58 | |
| 59 | /** |
| 60 | * static instance to hold the field values |
| 61 | * |
| 62 | * @var array |
| 63 | * @static |
| 64 | */ |
| 65 | static $_fields = null; |
| 66 | |
| 67 | /** |
| 68 | * static instance to hold the keys used in $_fields for each field. |
| 69 | * |
| 70 | * @var array |
| 71 | * @static |
| 72 | */ |
| 73 | static $_fieldKeys = null; |
| 74 | |
| 75 | /** |
| 76 | * static instance to hold the FK relationships |
| 77 | * |
| 78 | * @var string |
| 79 | * @static |
| 80 | */ |
| 81 | static $_links = null; |
| 82 | |
| 83 | /** |
| 84 | * static instance to hold the values that can |
| 85 | * be imported |
| 86 | * |
| 87 | * @var array |
| 88 | * @static |
| 89 | */ |
| 90 | static $_import = null; |
| 91 | |
| 92 | /** |
| 93 | * static instance to hold the values that can |
| 94 | * be exported |
| 95 | * |
| 96 | * @var array |
| 97 | * @static |
| 98 | */ |
| 99 | static $_export = null; |
| 100 | |
| 101 | /** |
| 102 | * static value to see if we should log any modifications to |
| 103 | * this table in the civicrm_log table |
| 104 | * |
| 105 | * @var boolean |
| 106 | * @static |
| 107 | */ |
| 108 | static $_log = {$table.log}; |
| 109 | |
| 110 | {foreach from=$table.fields item=field} |
| 111 | /** |
| 112 | {if $field.comment} |
| 113 | * {$field.comment} |
| 114 | {/if} |
| 115 | * |
| 116 | * @var {$field.phpType} |
| 117 | */ |
| 118 | public ${$field.name}; |
| 119 | |
| 120 | {/foreach} {* table.fields *} |
| 121 | |
| 122 | /** |
| 123 | * class constructor |
| 124 | * |
| 125 | * @access public |
| 126 | * @return {$table.name} |
| 127 | */ |
| 128 | function __construct( ) {ldelim} |
| 129 | $this->__table = '{$table.name}'; |
| 130 | |
| 131 | parent::__construct( ); |
| 132 | {rdelim} |
| 133 | |
| 134 | {if $table.foreignKey || $table.dynamicForeignKey} |
| 135 | /** |
| 136 | * return foreign keys and entity references |
| 137 | * |
| 138 | * @static |
| 139 | * @access public |
| 140 | * @return array of CRM_Core_Reference_Interface |
| 141 | */ |
| 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}'); |
| 147 | {/foreach} |
| 148 | |
| 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}'); |
| 151 | {/foreach} |
| 152 | {rdelim} |
| 153 | return self::$_links; |
| 154 | {rdelim} |
| 155 | {/if} {* table.foreignKey *} |
| 156 | |
| 157 | /** |
| 158 | * returns all the column names of this table |
| 159 | * |
| 160 | * @access public |
| 161 | * @return array |
| 162 | */ |
| 163 | static function &fields( ) {ldelim} |
| 164 | if ( ! ( self::$_fields ) ) {ldelim} |
| 165 | self::$_fields = array ( |
| 166 | {foreach from=$table.fields item=field} |
| 167 | |
| 168 | {if $field.uniqueName} |
| 169 | '{$field.uniqueName}' |
| 170 | {else} |
| 171 | '{$field.name}' |
| 172 | {/if} |
| 173 | => array( |
| 174 | 'name' => '{$field.name}', |
| 175 | 'type' => {$field.crmType}, |
| 176 | {if $field.title} |
| 177 | 'title' => ts('{$field.title}'), |
| 178 | {/if} |
| 179 | {if $field.required} |
| 180 | 'required' => {$field.required}, |
| 181 | {/if} {* field.required *} |
| 182 | {if $field.length} |
| 183 | 'maxlength' => {$field.length}, |
| 184 | {/if} {* field.length *} |
| 185 | {if $field.precision} |
| 186 | 'precision' => array({$field.precision}), |
| 187 | {/if} |
| 188 | {if $field.size} |
| 189 | 'size' => {$field.size}, |
| 190 | {/if} {* field.size *} |
| 191 | {if $field.rows} |
| 192 | 'rows' => {$field.rows}, |
| 193 | {/if} {* field.rows *} |
| 194 | {if $field.cols} |
| 195 | 'cols' => {$field.cols}, |
| 196 | {/if} {* field.cols *} |
| 197 | |
| 198 | {if $field.import} |
| 199 | 'import' => {$field.import}, |
| 200 | 'where' => '{$table.name}.{$field.name}', |
| 201 | 'headerPattern' => '{$field.headerPattern}', |
| 202 | 'dataPattern' => '{$field.dataPattern}', |
| 203 | {/if} {* field.import *} |
| 204 | {if $field.export} |
| 205 | 'export' => {$field.export}, |
| 206 | {if ! $field.import} |
| 207 | 'where' => '{$table.name}.{$field.name}', |
| 208 | 'headerPattern' => '{$field.headerPattern}', |
| 209 | 'dataPattern' => '{$field.dataPattern}', |
| 210 | {/if} |
| 211 | {/if} {* field.export *} |
| 212 | {if $field.rule} |
| 213 | 'rule' => '{$field.rule}', |
| 214 | {/if} {* field.rule *} |
| 215 | {if $field.default} |
| 216 | 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', |
| 217 | {/if} {* field.default *} |
| 218 | |
| 219 | {if $field.FKClassName} |
| 220 | 'FKClassName' => '{$field.FKClassName}', |
| 221 | {/if} {* field.FKClassName *} |
| 222 | {if $field.html} |
| 223 | {assign var=htmlOptions value=$field.html} |
| 224 | 'html' => array( |
| 225 | {*{$htmlOptions|@print_array}*} |
| 226 | {foreach from=$htmlOptions key=optionKey item=optionValue} |
| 227 | '{$optionKey}' => '{$optionValue}', |
| 228 | {/foreach} |
| 229 | ), |
| 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}', |
| 237 | {/foreach} |
| 238 | ) |
| 239 | {/if} {* field.pseudoconstant *} ), |
| 240 | {/foreach} {* table.fields *} |
| 241 | ); |
| 242 | {rdelim} |
| 243 | return self::$_fields; |
| 244 | {rdelim} |
| 245 | |
| 246 | /** |
| 247 | * Returns an array containing, for each field, the arary key used for that |
| 248 | * field in self::$_fields. |
| 249 | * |
| 250 | * @access public |
| 251 | * @return array |
| 252 | */ |
| 253 | static function &fieldKeys( ) {ldelim} |
| 254 | if ( ! ( self::$_fieldKeys ) ) {ldelim} |
| 255 | self::$_fieldKeys = array ( |
| 256 | {foreach from=$table.fields item=field} |
| 257 | '{$field.name}' => |
| 258 | {if $field.uniqueName} |
| 259 | '{$field.uniqueName}' |
| 260 | {else} |
| 261 | '{$field.name}' |
| 262 | {/if}, |
| 263 | |
| 264 | {/foreach} {* table.fields *} |
| 265 | ); |
| 266 | {rdelim} |
| 267 | return self::$_fieldKeys; |
| 268 | {rdelim} |
| 269 | |
| 270 | /** |
| 271 | * returns the names of this table |
| 272 | * |
| 273 | * @access public |
| 274 | * @static |
| 275 | * @return string |
| 276 | */ |
| 277 | static function getTableName( ) {ldelim} |
| 278 | {if $table.localizable} |
| 279 | return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); |
| 280 | {else} |
| 281 | return self::$_tableName; |
| 282 | {/if} |
| 283 | {rdelim} |
| 284 | |
| 285 | /** |
| 286 | * returns if this table needs to be logged |
| 287 | * |
| 288 | * @access public |
| 289 | * @return boolean |
| 290 | */ |
| 291 | function getLog( ) {ldelim} |
| 292 | return self::$_log; |
| 293 | {rdelim} |
| 294 | |
| 295 | /** |
| 296 | * returns the list of fields that can be imported |
| 297 | * |
| 298 | * @access public |
| 299 | * return array |
| 300 | * @static |
| 301 | */ |
| 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]; |
| 312 | {rdelim} |
| 313 | {rdelim} |
| 314 | {rdelim} |
| 315 | {if $table.foreignKey} |
| 316 | {foreach from=$table.foreignKey item=foreign} |
| 317 | {if $foreign.import} |
| 318 | self::$_import = array_merge( self::$_import, |
| 319 | {$foreign.className}::import( true ) ); |
| 320 | {/if} |
| 321 | {/foreach} |
| 322 | {/if} |
| 323 | {rdelim} |
| 324 | return self::$_import; |
| 325 | {rdelim} |
| 326 | |
| 327 | /** |
| 328 | * returns the list of fields that can be exported |
| 329 | * |
| 330 | * @access public |
| 331 | * return array |
| 332 | * @static |
| 333 | */ |
| 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]; |
| 344 | {rdelim} |
| 345 | {rdelim} |
| 346 | {rdelim} |
| 347 | {if $table.foreignKey} |
| 348 | {foreach from=$table.foreignKey item=foreign} |
| 349 | {if $foreign.export} |
| 350 | self::$_export = array_merge( self::$_export, |
| 351 | {$foreign.className}::export( true ) ); |
| 352 | {/if} |
| 353 | {/foreach} |
| 354 | {/if} |
| 355 | {rdelim} |
| 356 | return self::$_export; |
| 357 | {rdelim} |
| 358 | |
| 359 | {rdelim} |
| 360 | |
| 361 | |