3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
43 * static instance to hold the table name
48 static $_tableName = 'civicrm_price_field';
50 * static instance to hold the field values
55 static $_fields = null;
57 * static instance to hold the FK relationships
62 static $_links = null;
64 * static instance to hold the values that can
70 static $_import = null;
72 * static instance to hold the values that can
78 static $_export = null;
80 * static value to see if we should log any modifications to
81 * this table in the civicrm_log table
94 * FK to civicrm_price_set
100 * Variable name/programmatic handle for this field.
106 * Text for form field label (also friendly name for administering this field).
113 * @var enum('Text', 'Select', 'Radio', 'CheckBox')
117 * Enter a quantity for this field?
121 public $is_enter_qty;
123 * Description and/or help text to display before this field.
129 * Description and/or help text to display after this field.
135 * Order in which the fields should appear
141 * Should the price be displayed next to the label for each option?
145 public $is_display_amounts;
147 * number of options per line for checkbox and radio
151 public $options_per_line;
153 * Is this price field active
159 * Is this price field required (value must be > 1)
165 * If non-zero, do not show this field before the date specified
171 * If non-zero, do not show this field after the date specified
177 * Optional scripting attributes for field
183 * Implicit FK to civicrm_option_group with name = \'visibility\'
187 public $visibility_id;
193 * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
195 function __construct()
197 $this->__table
= 'civicrm_price_field';
198 parent
::__construct();
201 * return foreign links
208 if (!(self
::$_links)) {
209 self
::$_links = array(
210 'price_set_id' => 'civicrm_price_set:id',
213 return self
::$_links;
216 * returns all the column names of this table
221 static function &fields()
223 if (!(self
::$_fields)) {
224 self
::$_fields = array(
227 'type' => CRM_Utils_Type
::T_INT
,
230 'price_set_id' => array(
231 'name' => 'price_set_id',
232 'type' => CRM_Utils_Type
::T_INT
,
234 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set',
238 'type' => CRM_Utils_Type
::T_STRING
,
239 'title' => ts('Name') ,
242 'size' => CRM_Utils_Type
::HUGE
,
246 'type' => CRM_Utils_Type
::T_STRING
,
247 'title' => ts('Label') ,
250 'size' => CRM_Utils_Type
::HUGE
,
252 'html_type' => array(
253 'name' => 'html_type',
254 'type' => CRM_Utils_Type
::T_ENUM
,
255 'title' => ts('Html Type') ,
257 'enumValues' => 'Text, Select, Radio, CheckBox',
259 'is_enter_qty' => array(
260 'name' => 'is_enter_qty',
261 'type' => CRM_Utils_Type
::T_BOOLEAN
,
264 'name' => 'help_pre',
265 'type' => CRM_Utils_Type
::T_TEXT
,
266 'title' => ts('Help Pre') ,
270 'help_post' => array(
271 'name' => 'help_post',
272 'type' => CRM_Utils_Type
::T_TEXT
,
273 'title' => ts('Help Post') ,
279 'type' => CRM_Utils_Type
::T_INT
,
280 'title' => ts('Weight') ,
283 'is_display_amounts' => array(
284 'name' => 'is_display_amounts',
285 'type' => CRM_Utils_Type
::T_BOOLEAN
,
288 'options_per_line' => array(
289 'name' => 'options_per_line',
290 'type' => CRM_Utils_Type
::T_INT
,
291 'title' => ts('Options Per Line') ,
294 'is_active' => array(
295 'name' => 'is_active',
296 'type' => CRM_Utils_Type
::T_BOOLEAN
,
299 'is_required' => array(
300 'name' => 'is_required',
301 'type' => CRM_Utils_Type
::T_BOOLEAN
,
304 'active_on' => array(
305 'name' => 'active_on',
306 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
307 'title' => ts('Active On') ,
310 'expire_on' => array(
311 'name' => 'expire_on',
312 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
313 'title' => ts('Expire On') ,
316 'javascript' => array(
317 'name' => 'javascript',
318 'type' => CRM_Utils_Type
::T_STRING
,
319 'title' => ts('Javascript') ,
321 'size' => CRM_Utils_Type
::HUGE
,
323 'visibility_id' => array(
324 'name' => 'visibility_id',
325 'type' => CRM_Utils_Type
::T_INT
,
330 return self
::$_fields;
333 * returns the names of this table
339 static function getTableName()
341 return CRM_Core_DAO
::getLocaleTableName(self
::$_tableName);
344 * returns if this table needs to be logged
354 * returns the list of fields that can be imported
360 static function &import($prefix = false)
362 if (!(self
::$_import)) {
363 self
::$_import = array();
364 $fields = self
::fields();
365 foreach($fields as $name => $field) {
366 if (!empty($field['import'])) {
368 self
::$_import['price_field'] = & $fields[$name];
370 self
::$_import[$name] = & $fields[$name];
375 return self
::$_import;
378 * returns the list of fields that can be exported
384 static function &export($prefix = false)
386 if (!(self
::$_export)) {
387 self
::$_export = array();
388 $fields = self
::fields();
389 foreach($fields as $name => $field) {
390 if (!empty($field['export'])) {
392 self
::$_export['price_field'] = & $fields[$name];
394 self
::$_export[$name] = & $fields[$name];
399 return self
::$_export;
402 * returns an array containing the enum fields of the civicrm_price_field table
404 * @return array (reference) the array of enum fields
406 static function &getEnums()
408 static $enums = array(
414 * returns a ts()-translated enum value for display purposes
416 * @param string $field the enum field in question
417 * @param string $value the enum value up for translation
419 * @return string the display value of the enum
421 static function tsEnum($field, $value)
423 static $translations = null;
424 if (!$translations) {
425 $translations = array(
426 'html_type' => array(
427 'Text' => ts('Text') ,
428 'Select' => ts('Select') ,
429 'Radio' => ts('Radio') ,
430 'CheckBox' => ts('CheckBox') ,
434 return $translations[$field][$value];
437 * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
439 * @param array $values (reference) the array up for enhancing
442 static function addDisplayEnums(&$values)
444 $enumFields = & Snapshot_v4p2_Price_DAO_Field
::getEnums();
445 foreach($enumFields as $enum) {
446 if (isset($values[$enum])) {
447 $values[$enum . '_display'] = Snapshot_v4p2_Price_DAO_Field
::tsEnum($enum, $values[$enum]);