Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
81621fee | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
201f27ba | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
6a488035 | 29 | * @package CRM |
201f27ba | 30 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 | 31 | * |
d5864876 ARW |
32 | * Generated from {$table.sourceFile} |
33 | * {$generated} | |
a8950859 | 34 | * (GenCodeChecksum:{$genCodeChecksum}) |
6a488035 TO |
35 | */ |
36 | ||
37 | require_once 'CRM/Core/DAO.php'; | |
38 | require_once 'CRM/Utils/Type.php'; | |
39 | ||
6a488035 TO |
40 | class {$table.className} extends CRM_Core_DAO {ldelim} |
41 | ||
42 | /** | |
43 | * static instance to hold the table name | |
44 | * | |
45 | * @var string | |
6a488035 TO |
46 | */ |
47 | static $_tableName = '{$table.name}'; | |
48 | ||
6a488035 TO |
49 | /** |
50 | * static value to see if we should log any modifications to | |
51 | * this table in the civicrm_log table | |
52 | * | |
53 | * @var boolean | |
6a488035 TO |
54 | */ |
55 | static $_log = {$table.log}; | |
56 | ||
57 | {foreach from=$table.fields item=field} | |
58 | /** | |
59 | {if $field.comment} | |
60 | * {$field.comment} | |
61 | {/if} | |
62 | * | |
63 | * @var {$field.phpType} | |
64 | */ | |
65 | public ${$field.name}; | |
66 | ||
67 | {/foreach} {* table.fields *} | |
68 | ||
69 | /** | |
70 | * class constructor | |
71 | * | |
6a488035 TO |
72 | * @return {$table.name} |
73 | */ | |
74 | function __construct( ) {ldelim} | |
75 | $this->__table = '{$table.name}'; | |
76 | ||
77 | parent::__construct( ); | |
78 | {rdelim} | |
79 | ||
71e5aa5c | 80 | {if $table.foreignKey || $table.dynamicForeignKey} |
6a488035 | 81 | /** |
b6e60008 | 82 | * Returns foreign keys and entity references |
6a488035 | 83 | * |
b6e60008 CW |
84 | * @return array |
85 | * [CRM_Core_Reference_Interface] | |
6a488035 | 86 | */ |
71e5aa5c | 87 | static function getReferenceColumns() {ldelim} |
740dd877 TO |
88 | if (!isset(Civi::$statics[__CLASS__]['links'])) {ldelim} |
89 | Civi::$statics[__CLASS__]['links'] = static::createReferenceColumns(__CLASS__); | |
6a488035 | 90 | {foreach from=$table.foreignKey item=foreign} |
740dd877 | 91 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Basic(self::getTableName(), '{$foreign.name}', '{$foreign.table}', '{$foreign.key}'); |
71e5aa5c ARW |
92 | {/foreach} |
93 | ||
94 | {foreach from=$table.dynamicForeignKey item=foreign} | |
740dd877 | 95 | Civi::$statics[__CLASS__]['links'][] = new CRM_Core_Reference_Dynamic(self::getTableName(), '{$foreign.idColumn}', NULL, '{$foreign.key|default:'id'}', '{$foreign.typeColumn}'); |
6a488035 | 96 | {/foreach} |
740dd877 | 97 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'links_callback', Civi::$statics[__CLASS__]['links']); |
71e5aa5c | 98 | {rdelim} |
740dd877 | 99 | return Civi::$statics[__CLASS__]['links']; |
6a488035 TO |
100 | {rdelim} |
101 | {/if} {* table.foreignKey *} | |
102 | ||
103 | /** | |
b6e60008 | 104 | * Returns all the column names of this table |
6a488035 | 105 | * |
6a488035 TO |
106 | * @return array |
107 | */ | |
108 | static function &fields( ) {ldelim} | |
740dd877 TO |
109 | if ( ! isset(Civi::$statics[__CLASS__]['fields']) ) {ldelim} |
110 | Civi::$statics[__CLASS__]['fields'] = array ( | |
6a488035 TO |
111 | {foreach from=$table.fields item=field} |
112 | ||
113 | {if $field.uniqueName} | |
114 | '{$field.uniqueName}' | |
115 | {else} | |
116 | '{$field.name}' | |
117 | {/if} | |
118 | => array( | |
119 | 'name' => '{$field.name}', | |
120 | 'type' => {$field.crmType}, | |
121 | {if $field.title} | |
122 | 'title' => ts('{$field.title}'), | |
123 | {/if} | |
5c7169eb CW |
124 | {if $field.comment} |
125 | 'description' => '{$field.comment|replace:"'":"\'"}', | |
126 | {/if} | |
6a488035 TO |
127 | {if $field.required} |
128 | 'required' => {$field.required}, | |
129 | {/if} {* field.required *} | |
130 | {if $field.length} | |
131 | 'maxlength' => {$field.length}, | |
132 | {/if} {* field.length *} | |
ac5f2ccd TO |
133 | {if $field.precision} |
134 | 'precision' => array({$field.precision}), | |
135 | {/if} | |
6a488035 TO |
136 | {if $field.size} |
137 | 'size' => {$field.size}, | |
138 | {/if} {* field.size *} | |
139 | {if $field.rows} | |
140 | 'rows' => {$field.rows}, | |
141 | {/if} {* field.rows *} | |
142 | {if $field.cols} | |
143 | 'cols' => {$field.cols}, | |
144 | {/if} {* field.cols *} | |
145 | ||
146 | {if $field.import} | |
147 | 'import' => {$field.import}, | |
148 | 'where' => '{$table.name}.{$field.name}', | |
149 | 'headerPattern' => '{$field.headerPattern}', | |
150 | 'dataPattern' => '{$field.dataPattern}', | |
151 | {/if} {* field.import *} | |
152 | {if $field.export} | |
153 | 'export' => {$field.export}, | |
154 | {if ! $field.import} | |
155 | 'where' => '{$table.name}.{$field.name}', | |
156 | 'headerPattern' => '{$field.headerPattern}', | |
157 | 'dataPattern' => '{$field.dataPattern}', | |
158 | {/if} | |
159 | {/if} {* field.export *} | |
160 | {if $field.rule} | |
161 | 'rule' => '{$field.rule}', | |
162 | {/if} {* field.rule *} | |
163 | {if $field.default} | |
9e1ed301 | 164 | 'default' => '{if ($field.default[0]=="'" or $field.default[0]=='"')}{$field.default|substring:1:-1}{else}{$field.default}{/if}', |
6a488035 | 165 | {/if} {* field.default *} |
6a488035 TO |
166 | |
167 | {if $field.FKClassName} | |
168 | 'FKClassName' => '{$field.FKClassName}', | |
169 | {/if} {* field.FKClassName *} | |
5e545f38 CW |
170 | {if $field.html} |
171 | {assign var=htmlOptions value=$field.html} | |
172 | 'html' => array( | |
173 | {*{$htmlOptions|@print_array}*} | |
174 | {foreach from=$htmlOptions key=optionKey item=optionValue} | |
175 | '{$optionKey}' => '{$optionValue}', | |
176 | {/foreach} | |
177 | ), | |
178 | {/if} {* field.html *} | |
6a488035 TO |
179 | {if $field.pseudoconstant} |
180 | {assign var=pseudoOptions value=$field.pseudoconstant} | |
181 | 'pseudoconstant' => array( | |
182 | {*{$pseudoOptions|@print_array}*} | |
183 | {foreach from=$pseudoOptions key=optionKey item=optionValue} | |
184 | '{$optionKey}' => '{$optionValue}', | |
185 | {/foreach} | |
186 | ) | |
187 | {/if} {* field.pseudoconstant *} ), | |
188 | {/foreach} {* table.fields *} | |
189 | ); | |
740dd877 | 190 | CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); |
6a488035 | 191 | {rdelim} |
740dd877 | 192 | return Civi::$statics[__CLASS__]['fields']; |
6a488035 TO |
193 | {rdelim} |
194 | ||
66abbb6d | 195 | /** |
787b31c7 | 196 | * Return a mapping from field-name to the corresponding key (as used in fields()). |
66abbb6d | 197 | * |
66abbb6d | 198 | * @return array |
787b31c7 | 199 | * Array(string $name => string $uniqueName). |
66abbb6d AS |
200 | */ |
201 | static function &fieldKeys( ) {ldelim} | |
787b31c7 TO |
202 | if (!isset(Civi::$statics[__CLASS__]['fieldKeys'])) {ldelim} |
203 | Civi::$statics[__CLASS__]['fieldKeys'] = array_flip(CRM_Utils_Array::collect('name', self::fields())); | |
204 | {rdelim} | |
205 | return Civi::$statics[__CLASS__]['fieldKeys']; | |
66abbb6d AS |
206 | {rdelim} |
207 | ||
6a488035 | 208 | /** |
b6e60008 | 209 | * Returns the names of this table |
6a488035 | 210 | * |
6a488035 TO |
211 | * @return string |
212 | */ | |
213 | static function getTableName( ) {ldelim} | |
214 | {if $table.localizable} | |
215 | return CRM_Core_DAO::getLocaleTableName( self::$_tableName ); | |
216 | {else} | |
217 | return self::$_tableName; | |
218 | {/if} | |
219 | {rdelim} | |
220 | ||
221 | /** | |
b6e60008 | 222 | * Returns if this table needs to be logged |
6a488035 | 223 | * |
6a488035 TO |
224 | * @return boolean |
225 | */ | |
226 | function getLog( ) {ldelim} | |
227 | return self::$_log; | |
228 | {rdelim} | |
229 | ||
230 | /** | |
b6e60008 CW |
231 | * Returns the list of fields that can be imported |
232 | * | |
233 | * @param bool $prefix | |
6a488035 | 234 | * |
b6e60008 | 235 | * @return array |
6a488035 TO |
236 | */ |
237 | static function &import( $prefix = false ) {ldelim} | |
84a0493c TO |
238 | $r = CRM_Core_DAO_AllCoreTables::getImports(__CLASS__, '{$table.labelName}', $prefix, array( |
239 | {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign} | |
240 | {if $foreign.import}'{$foreign.className}',{/if} | |
241 | {/foreach}{/if} | |
242 | )); | |
243 | return $r; | |
6a488035 TO |
244 | {rdelim} |
245 | ||
246 | /** | |
b6e60008 CW |
247 | * Returns the list of fields that can be exported |
248 | * | |
249 | * @param bool $prefix | |
250 | * | |
251 | * @return array | |
252 | */ | |
6a488035 | 253 | static function &export( $prefix = false ) {ldelim} |
84a0493c TO |
254 | $r = CRM_Core_DAO_AllCoreTables::getExports(__CLASS__, '{$table.labelName}', $prefix, array( |
255 | {if $table.foreignKey}{foreach from=$table.foreignKey item=foreign} | |
256 | {if $foreign.export}'{$foreign.className}',{/if} | |
257 | {/foreach}{/if} | |
258 | )); | |
259 | return $r; | |
6a488035 TO |
260 | {rdelim} |
261 | ||
6a488035 TO |
262 | {rdelim} |
263 | ||
264 |