3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
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-2019
34 require_once 'CRM/Core/DAO.php';
35 require_once 'CRM/Utils/Type.php';
38 * Class CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
40 class CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
extends CRM_Core_DAO
{
42 * static instance to hold the table name
46 static $_tableName = 'civicrm_price_field';
48 * static instance to hold the field values
52 static $_fields = NULL;
54 * static instance to hold the FK relationships
58 static $_links = NULL;
60 * static instance to hold the values that can
65 static $_import = NULL;
67 * static instance to hold the values that can
72 static $_export = NULL;
74 * static value to see if we should log any modifications to
75 * this table in the civicrm_log table
87 * FK to civicrm_price_set
93 * Variable name/programmatic handle for this field.
99 * Text for form field label (also friendly name for administering this field).
106 * @var enum('Text', 'Select', 'Radio', 'CheckBox')
110 * Enter a quantity for this field?
114 public $is_enter_qty;
116 * Description and/or help text to display before this field.
122 * Description and/or help text to display after this field.
128 * Order in which the fields should appear
134 * Should the price be displayed next to the label for each option?
138 public $is_display_amounts;
140 * number of options per line for checkbox and radio
144 public $options_per_line;
146 * Is this price field active
152 * Is this price field required (value must be > 1)
158 * If non-zero, do not show this field before the date specified
164 * If non-zero, do not show this field after the date specified
170 * Optional scripting attributes for field
176 * Implicit FK to civicrm_option_group with name = \'visibility\'
180 public $visibility_id;
185 * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
187 public function __construct() {
188 $this->__table
= 'civicrm_price_field';
189 parent
::__construct();
193 * Return foreign links.
197 public function links() {
198 if (!(self
::$_links)) {
199 self
::$_links = array(
200 'price_set_id' => 'civicrm_price_set:id',
203 return self
::$_links;
207 * Returns all the column names of this table.
211 public static function &fields() {
212 if (!(self
::$_fields)) {
213 self
::$_fields = array(
216 'type' => CRM_Utils_Type
::T_INT
,
219 'price_set_id' => array(
220 'name' => 'price_set_id',
221 'type' => CRM_Utils_Type
::T_INT
,
223 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set',
227 'type' => CRM_Utils_Type
::T_STRING
,
228 'title' => ts('Name'),
231 'size' => CRM_Utils_Type
::HUGE
,
235 'type' => CRM_Utils_Type
::T_STRING
,
236 'title' => ts('Label'),
239 'size' => CRM_Utils_Type
::HUGE
,
241 'html_type' => array(
242 'name' => 'html_type',
243 'type' => CRM_Utils_Type
::T_ENUM
,
244 'title' => ts('Html Type'),
246 'enumValues' => 'Text, Select, Radio, CheckBox',
248 'is_enter_qty' => array(
249 'name' => 'is_enter_qty',
250 'type' => CRM_Utils_Type
::T_BOOLEAN
,
253 'name' => 'help_pre',
254 'type' => CRM_Utils_Type
::T_TEXT
,
255 'title' => ts('Help Pre'),
259 'help_post' => array(
260 'name' => 'help_post',
261 'type' => CRM_Utils_Type
::T_TEXT
,
262 'title' => ts('Help Post'),
268 'type' => CRM_Utils_Type
::T_INT
,
269 'title' => ts('Weight'),
272 'is_display_amounts' => array(
273 'name' => 'is_display_amounts',
274 'type' => CRM_Utils_Type
::T_BOOLEAN
,
277 'options_per_line' => array(
278 'name' => 'options_per_line',
279 'type' => CRM_Utils_Type
::T_INT
,
280 'title' => ts('Options Per Line'),
283 'is_active' => array(
284 'name' => 'is_active',
285 'type' => CRM_Utils_Type
::T_BOOLEAN
,
288 'is_required' => array(
289 'name' => 'is_required',
290 'type' => CRM_Utils_Type
::T_BOOLEAN
,
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'),
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'),
305 'javascript' => array(
306 'name' => 'javascript',
307 'type' => CRM_Utils_Type
::T_STRING
,
308 'title' => ts('Javascript'),
310 'size' => CRM_Utils_Type
::HUGE
,
312 'visibility_id' => array(
313 'name' => 'visibility_id',
314 'type' => CRM_Utils_Type
::T_INT
,
319 return self
::$_fields;
323 * returns the names of this table.
327 public static function getTableName() {
328 return CRM_Core_DAO
::getLocaleTableName(self
::$_tableName);
332 * returns if this table needs to be logged.
336 public function getLog() {
341 * returns the list of fields that can be imported.
343 * @param bool $prefix
347 public static function &import($prefix = FALSE) {
348 if (!(self
::$_import)) {
349 self
::$_import = array();
350 $fields = self
::fields();
351 foreach ($fields as $name => $field) {
352 if (!empty($field['import'])) {
354 self
::$_import['price_field'] = &$fields[$name];
357 self
::$_import[$name] = &$fields[$name];
362 return self
::$_import;
366 * Returns the list of fields that can be exported.
368 * @param bool $prefix
372 public static function &export($prefix = FALSE) {
373 if (!(self
::$_export)) {
374 self
::$_export = array();
375 $fields = self
::fields();
376 foreach ($fields as $name => $field) {
377 if (!empty($field['export'])) {
379 self
::$_export['price_field'] = &$fields[$name];
382 self
::$_export[$name] = &$fields[$name];
387 return self
::$_export;
391 * returns an array containing the enum fields of the civicrm_price_field table.
394 * (reference) the array of enum fields
396 public static function &getEnums() {
397 static $enums = array(
404 * returns a ts()-translated enum value for display purposes
406 * @param string $field
407 * The enum field in question.
408 * @param string $value
409 * The enum value up for translation.
412 * the display value of the enum
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'),
426 return $translations[$field][$value];
430 * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
432 * @param array $values
433 * (reference) the array up for enhancing.
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]);