Merge pull request #13731 from eileenmcnaughton/5.11
[civicrm-core.git] / CRM / Upgrade / Snapshot / V4p2 / Price / DAO / Field.php
CommitLineData
6a488035
TO
1<?php
2/*
3+--------------------------------------------------------------------+
fee14197 4| CiviCRM version 5 |
6a488035 5+--------------------------------------------------------------------+
6b83d5bd 6| Copyright CiviCRM LLC (c) 2004-2019 |
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+--------------------------------------------------------------------+
5e2d78f1 26 */
6a488035
TO
27/**
28 *
29 * @package CRM
6b83d5bd 30 * @copyright CiviCRM LLC (c) 2004-2019
6a488035
TO
31 * $Id$
32 *
33 */
34require_once 'CRM/Core/DAO.php';
35require_once 'CRM/Utils/Type.php';
624e56fa
EM
36
37/**
38 * Class CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
39 */
353ffa53
TO
40class CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field extends CRM_Core_DAO {
41 /**
42 * static instance to hold the table name
43 *
44 * @var string
353ffa53
TO
45 */
46 static $_tableName = 'civicrm_price_field';
47 /**
48 * static instance to hold the field values
49 *
50 * @var array
353ffa53
TO
51 */
52 static $_fields = NULL;
53 /**
54 * static instance to hold the FK relationships
55 *
56 * @var string
353ffa53
TO
57 */
58 static $_links = NULL;
59 /**
60 * static instance to hold the values that can
61 * be imported
62 *
63 * @var array
353ffa53
TO
64 */
65 static $_import = NULL;
66 /**
67 * static instance to hold the values that can
68 * be exported
69 *
70 * @var array
353ffa53
TO
71 */
72 static $_export = NULL;
73 /**
74 * static value to see if we should log any modifications to
75 * this table in the civicrm_log table
76 *
5e2d78f1 77 * @var bool
353ffa53
TO
78 */
79 static $_log = TRUE;
80 /**
81 * Price Field
82 *
83 * @var int unsigned
84 */
85 public $id;
86 /**
87 * FK to civicrm_price_set
88 *
89 * @var int unsigned
90 */
91 public $price_set_id;
92 /**
93 * Variable name/programmatic handle for this field.
94 *
95 * @var string
96 */
97 public $name;
98 /**
99 * Text for form field label (also friendly name for administering this field).
100 *
101 * @var string
102 */
103 public $label;
104 /**
105 *
106 * @var enum('Text', 'Select', 'Radio', 'CheckBox')
107 */
108 public $html_type;
109 /**
110 * Enter a quantity for this field?
111 *
5e2d78f1 112 * @var bool
353ffa53
TO
113 */
114 public $is_enter_qty;
115 /**
116 * Description and/or help text to display before this field.
117 *
118 * @var text
119 */
120 public $help_pre;
121 /**
122 * Description and/or help text to display after this field.
123 *
124 * @var text
125 */
126 public $help_post;
127 /**
128 * Order in which the fields should appear
129 *
130 * @var int
131 */
132 public $weight;
133 /**
134 * Should the price be displayed next to the label for each option?
135 *
136 * @var boolean
137 */
138 public $is_display_amounts;
139 /**
140 * number of options per line for checkbox and radio
141 *
142 * @var int unsigned
143 */
144 public $options_per_line;
145 /**
146 * Is this price field active
147 *
148 * @var boolean
149 */
150 public $is_active;
151 /**
152 * Is this price field required (value must be > 1)
153 *
154 * @var boolean
155 */
156 public $is_required;
157 /**
158 * If non-zero, do not show this field before the date specified
159 *
160 * @var datetime
161 */
162 public $active_on;
163 /**
164 * If non-zero, do not show this field after the date specified
165 *
166 * @var datetime
167 */
168 public $expire_on;
169 /**
170 * Optional scripting attributes for field
171 *
172 * @var string
173 */
174 public $javascript;
175 /**
176 * Implicit FK to civicrm_option_group with name = \'visibility\'
177 *
178 * @var int unsigned
179 */
180 public $visibility_id;
77b97be7
EM
181
182 /**
fe482240 183 * Class constructor.
77b97be7 184 *
77b97be7
EM
185 * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
186 */
353ffa53
TO
187 public function __construct() {
188 $this->__table = 'civicrm_price_field';
189 parent::__construct();
190 }
191
192 /**
fe482240 193 * Return foreign links.
353ffa53
TO
194 *
195 * @return array
196 */
197 public function links() {
198 if (!(self::$_links)) {
199 self::$_links = array(
200 'price_set_id' => 'civicrm_price_set:id',
201 );
6a488035 202 }
353ffa53
TO
203 return self::$_links;
204 }
205
206 /**
fe482240 207 * Returns all the column names of this table.
353ffa53
TO
208 *
209 * @return array
210 */
1e1ed556 211 public static function &fields() {
353ffa53
TO
212 if (!(self::$_fields)) {
213 self::$_fields = array(
214 'id' => array(
215 'name' => 'id',
216 'type' => CRM_Utils_Type::T_INT,
217 'required' => TRUE,
218 ),
219 'price_set_id' => array(
220 'name' => 'price_set_id',
221 'type' => CRM_Utils_Type::T_INT,
222 'required' => TRUE,
223 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set',
224 ),
225 'name' => array(
226 'name' => 'name',
227 'type' => CRM_Utils_Type::T_STRING,
228 'title' => ts('Name'),
229 'required' => TRUE,
230 'maxlength' => 255,
231 'size' => CRM_Utils_Type::HUGE,
232 ),
233 'label' => array(
234 'name' => 'label',
235 'type' => CRM_Utils_Type::T_STRING,
236 'title' => ts('Label'),
237 'required' => TRUE,
238 'maxlength' => 255,
239 'size' => CRM_Utils_Type::HUGE,
240 ),
241 'html_type' => array(
242 'name' => 'html_type',
243 'type' => CRM_Utils_Type::T_ENUM,
244 'title' => ts('Html Type'),
245 'required' => TRUE,
246 'enumValues' => 'Text, Select, Radio, CheckBox',
247 ),
248 'is_enter_qty' => array(
249 'name' => 'is_enter_qty',
250 'type' => CRM_Utils_Type::T_BOOLEAN,
251 ),
252 'help_pre' => array(
253 'name' => 'help_pre',
254 'type' => CRM_Utils_Type::T_TEXT,
255 'title' => ts('Help Pre'),
256 'rows' => 4,
257 'cols' => 80,
258 ),
259 'help_post' => array(
260 'name' => 'help_post',
261 'type' => CRM_Utils_Type::T_TEXT,
262 'title' => ts('Help Post'),
263 'rows' => 4,
264 'cols' => 80,
265 ),
266 'weight' => array(
267 'name' => 'weight',
268 'type' => CRM_Utils_Type::T_INT,
269 'title' => ts('Weight'),
270 'default' => '',
271 ),
272 'is_display_amounts' => array(
273 'name' => 'is_display_amounts',
274 'type' => CRM_Utils_Type::T_BOOLEAN,
275 'default' => '',
276 ),
277 'options_per_line' => array(
278 'name' => 'options_per_line',
279 'type' => CRM_Utils_Type::T_INT,
280 'title' => ts('Options Per Line'),
281 'default' => '',
282 ),
283 'is_active' => array(
284 'name' => 'is_active',
285 'type' => CRM_Utils_Type::T_BOOLEAN,
286 'default' => '',
287 ),
288 'is_required' => array(
289 'name' => 'is_required',
290 'type' => CRM_Utils_Type::T_BOOLEAN,
291 'default' => '',
292 ),
293 'active_on' => array(
294 'name' => 'active_on',
295 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
296 'title' => ts('Active On'),
297 'default' => 'UL',
298 ),
299 'expire_on' => array(
300 'name' => 'expire_on',
301 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
302 'title' => ts('Expire On'),
303 'default' => 'UL',
304 ),
305 'javascript' => array(
306 'name' => 'javascript',
307 'type' => CRM_Utils_Type::T_STRING,
308 'title' => ts('Javascript'),
309 'maxlength' => 255,
310 'size' => CRM_Utils_Type::HUGE,
311 ),
312 'visibility_id' => array(
313 'name' => 'visibility_id',
314 'type' => CRM_Utils_Type::T_INT,
315 'default' => '',
316 ),
317 );
6a488035 318 }
353ffa53
TO
319 return self::$_fields;
320 }
321
322 /**
fe482240 323 * returns the names of this table.
353ffa53 324 *
353ffa53
TO
325 * @return string
326 */
327 public static function getTableName() {
328 return CRM_Core_DAO::getLocaleTableName(self::$_tableName);
329 }
330
331 /**
fe482240 332 * returns if this table needs to be logged.
353ffa53 333 *
5e2d78f1 334 * @return bool
353ffa53
TO
335 */
336 public function getLog() {
337 return self::$_log;
338 }
339
340 /**
fe482240 341 * returns the list of fields that can be imported.
353ffa53 342 *
ea3ddccf 343 * @param bool $prefix
344 *
76e7a76c 345 * @return array
353ffa53 346 */
5e2d78f1 347 public static function &import($prefix = FALSE) {
353ffa53
TO
348 if (!(self::$_import)) {
349 self::$_import = array();
350 $fields = self::fields();
351 foreach ($fields as $name => $field) {
352 if (!empty($field['import'])) {
353 if ($prefix) {
354 self::$_import['price_field'] = &$fields[$name];
355 }
356 else {
357 self::$_import[$name] = &$fields[$name];
358 }
6a488035 359 }
353ffa53 360 }
6a488035 361 }
353ffa53
TO
362 return self::$_import;
363 }
364
365 /**
54957108 366 * Returns the list of fields that can be exported.
367 *
368 * @param bool $prefix
353ffa53 369 *
76e7a76c 370 * @return array
353ffa53 371 */
5e2d78f1 372 public static function &export($prefix = FALSE) {
353ffa53
TO
373 if (!(self::$_export)) {
374 self::$_export = array();
375 $fields = self::fields();
376 foreach ($fields as $name => $field) {
377 if (!empty($field['export'])) {
378 if ($prefix) {
379 self::$_export['price_field'] = &$fields[$name];
380 }
381 else {
382 self::$_export[$name] = &$fields[$name];
383 }
6a488035 384 }
353ffa53 385 }
6a488035 386 }
353ffa53
TO
387 return self::$_export;
388 }
389
390 /**
fe482240 391 * returns an array containing the enum fields of the civicrm_price_field table.
353ffa53
TO
392 *
393 * @return array
a6c01b45 394 * (reference) the array of enum fields
353ffa53 395 */
5e2d78f1 396 public static function &getEnums() {
353ffa53
TO
397 static $enums = array(
398 'html_type',
399 );
400 return $enums;
401 }
402
403 /**
404 * returns a ts()-translated enum value for display purposes
405 *
406 * @param string $field
407 * The enum field in question.
408 * @param string $value
409 * The enum value up for translation.
410 *
411 * @return string
a6c01b45 412 * the display value of the enum
353ffa53
TO
413 */
414 public static function tsEnum($field, $value) {
415 static $translations = NULL;
416 if (!$translations) {
417 $translations = array(
418 'html_type' => array(
419 'Text' => ts('Text'),
420 'Select' => ts('Select'),
421 'Radio' => ts('Radio'),
422 'CheckBox' => ts('CheckBox'),
423 ),
424 );
6a488035 425 }
353ffa53
TO
426 return $translations[$field][$value];
427 }
428
429 /**
430 * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
431 *
432 * @param array $values
433 * (reference) the array up for enhancing.
353ffa53
TO
434 */
435 public static function addDisplayEnums(&$values) {
436 $enumFields = &Snapshot_v4p2_Price_DAO_Field::getEnums();
437 foreach ($enumFields as $enum) {
438 if (isset($values[$enum])) {
439 $values[$enum . '_display'] = Snapshot_v4p2_Price_DAO_Field::tsEnum($enum, $values[$enum]);
440 }
6a488035 441 }
353ffa53 442 }
5e2d78f1 443
6a488035 444}