3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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;
192 * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
194 public function __construct()
196 $this->__table
= 'civicrm_price_field';
197 parent
::__construct();
200 * return foreign links
204 public function links()
206 if (!(self
::$_links)) {
207 self
::$_links = array(
208 'price_set_id' => 'civicrm_price_set:id',
211 return self
::$_links;
214 * returns all the column names of this table
218 static function &fields()
220 if (!(self
::$_fields)) {
221 self
::$_fields = array(
224 'type' => CRM_Utils_Type
::T_INT
,
227 'price_set_id' => array(
228 'name' => 'price_set_id',
229 'type' => CRM_Utils_Type
::T_INT
,
231 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set',
235 'type' => CRM_Utils_Type
::T_STRING
,
236 'title' => ts('Name') ,
239 'size' => CRM_Utils_Type
::HUGE
,
243 'type' => CRM_Utils_Type
::T_STRING
,
244 'title' => ts('Label') ,
247 'size' => CRM_Utils_Type
::HUGE
,
249 'html_type' => array(
250 'name' => 'html_type',
251 'type' => CRM_Utils_Type
::T_ENUM
,
252 'title' => ts('Html Type') ,
254 'enumValues' => 'Text, Select, Radio, CheckBox',
256 'is_enter_qty' => array(
257 'name' => 'is_enter_qty',
258 'type' => CRM_Utils_Type
::T_BOOLEAN
,
261 'name' => 'help_pre',
262 'type' => CRM_Utils_Type
::T_TEXT
,
263 'title' => ts('Help Pre') ,
267 'help_post' => array(
268 'name' => 'help_post',
269 'type' => CRM_Utils_Type
::T_TEXT
,
270 'title' => ts('Help Post') ,
276 'type' => CRM_Utils_Type
::T_INT
,
277 'title' => ts('Weight') ,
280 'is_display_amounts' => array(
281 'name' => 'is_display_amounts',
282 'type' => CRM_Utils_Type
::T_BOOLEAN
,
285 'options_per_line' => array(
286 'name' => 'options_per_line',
287 'type' => CRM_Utils_Type
::T_INT
,
288 'title' => ts('Options Per Line') ,
291 'is_active' => array(
292 'name' => 'is_active',
293 'type' => CRM_Utils_Type
::T_BOOLEAN
,
296 'is_required' => array(
297 'name' => 'is_required',
298 'type' => CRM_Utils_Type
::T_BOOLEAN
,
301 'active_on' => array(
302 'name' => 'active_on',
303 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
304 'title' => ts('Active On') ,
307 'expire_on' => array(
308 'name' => 'expire_on',
309 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
310 'title' => ts('Expire On') ,
313 'javascript' => array(
314 'name' => 'javascript',
315 'type' => CRM_Utils_Type
::T_STRING
,
316 'title' => ts('Javascript') ,
318 'size' => CRM_Utils_Type
::HUGE
,
320 'visibility_id' => array(
321 'name' => 'visibility_id',
322 'type' => CRM_Utils_Type
::T_INT
,
327 return self
::$_fields;
330 * returns the names of this table
335 public static function getTableName()
337 return CRM_Core_DAO
::getLocaleTableName(self
::$_tableName);
340 * returns if this table needs to be logged
344 public function getLog()
349 * returns the list of fields that can be imported
354 static function &import($prefix = false)
356 if (!(self
::$_import)) {
357 self
::$_import = array();
358 $fields = self
::fields();
359 foreach($fields as $name => $field) {
360 if (!empty($field['import'])) {
362 self
::$_import['price_field'] = & $fields[$name];
364 self
::$_import[$name] = & $fields[$name];
369 return self
::$_import;
372 * returns the list of fields that can be exported
377 static function &export($prefix = false)
379 if (!(self
::$_export)) {
380 self
::$_export = array();
381 $fields = self
::fields();
382 foreach($fields as $name => $field) {
383 if (!empty($field['export'])) {
385 self
::$_export['price_field'] = & $fields[$name];
387 self
::$_export[$name] = & $fields[$name];
392 return self
::$_export;
395 * returns an array containing the enum fields of the civicrm_price_field table
397 * @return array (reference) the array of enum fields
399 static function &getEnums()
401 static $enums = array(
407 * returns a ts()-translated enum value for display purposes
409 * @param string $field the enum field in question
410 * @param string $value the enum value up for translation
412 * @return string the display value of the enum
414 public static function tsEnum($field, $value)
416 static $translations = null;
417 if (!$translations) {
418 $translations = array(
419 'html_type' => array(
420 'Text' => ts('Text') ,
421 'Select' => ts('Select') ,
422 'Radio' => ts('Radio') ,
423 'CheckBox' => ts('CheckBox') ,
427 return $translations[$field][$value];
430 * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
432 * @param array $values (reference) the array up for enhancing
435 public static function addDisplayEnums(&$values)
437 $enumFields = & Snapshot_v4p2_Price_DAO_Field
::getEnums();
438 foreach($enumFields as $enum) {
439 if (isset($values[$enum])) {
440 $values[$enum . '_display'] = Snapshot_v4p2_Price_DAO_Field
::tsEnum($enum, $values[$enum]);