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
{
42 * static instance to hold the table name
47 static $_tableName = 'civicrm_price_field';
49 * static instance to hold the field values
54 static $_fields = NULL;
56 * static instance to hold the FK relationships
61 static $_links = NULL;
63 * static instance to hold the values that can
69 static $_import = NULL;
71 * static instance to hold the values that can
77 static $_export = NULL;
79 * static value to see if we should log any modifications to
80 * this table in the civicrm_log table
93 * FK to civicrm_price_set
99 * Variable name/programmatic handle for this field.
105 * Text for form field label (also friendly name for administering this field).
112 * @var enum('Text', 'Select', 'Radio', 'CheckBox')
116 * Enter a quantity for this field?
120 public $is_enter_qty;
122 * Description and/or help text to display before this field.
128 * Description and/or help text to display after this field.
134 * Order in which the fields should appear
140 * Should the price be displayed next to the label for each option?
144 public $is_display_amounts;
146 * number of options per line for checkbox and radio
150 public $options_per_line;
152 * Is this price field active
158 * Is this price field required (value must be > 1)
164 * If non-zero, do not show this field before the date specified
170 * If non-zero, do not show this field after the date specified
176 * Optional scripting attributes for field
182 * Implicit FK to civicrm_option_group with name = \'visibility\'
186 public $visibility_id;
191 * @return \CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field
193 public function __construct() {
194 $this->__table
= 'civicrm_price_field';
195 parent
::__construct();
199 * return foreign links
203 public function links() {
204 if (!(self
::$_links)) {
205 self
::$_links = array(
206 'price_set_id' => 'civicrm_price_set:id',
209 return self
::$_links;
213 * returns all the column names of this table
217 static function &fields() {
218 if (!(self
::$_fields)) {
219 self
::$_fields = array(
222 'type' => CRM_Utils_Type
::T_INT
,
225 'price_set_id' => array(
226 'name' => 'price_set_id',
227 'type' => CRM_Utils_Type
::T_INT
,
229 'FKClassName' => 'Snapshot_v4p2_Price_DAO_Set',
233 'type' => CRM_Utils_Type
::T_STRING
,
234 'title' => ts('Name'),
237 'size' => CRM_Utils_Type
::HUGE
,
241 'type' => CRM_Utils_Type
::T_STRING
,
242 'title' => ts('Label'),
245 'size' => CRM_Utils_Type
::HUGE
,
247 'html_type' => array(
248 'name' => 'html_type',
249 'type' => CRM_Utils_Type
::T_ENUM
,
250 'title' => ts('Html Type'),
252 'enumValues' => 'Text, Select, Radio, CheckBox',
254 'is_enter_qty' => array(
255 'name' => 'is_enter_qty',
256 'type' => CRM_Utils_Type
::T_BOOLEAN
,
259 'name' => 'help_pre',
260 'type' => CRM_Utils_Type
::T_TEXT
,
261 'title' => ts('Help Pre'),
265 'help_post' => array(
266 'name' => 'help_post',
267 'type' => CRM_Utils_Type
::T_TEXT
,
268 'title' => ts('Help Post'),
274 'type' => CRM_Utils_Type
::T_INT
,
275 'title' => ts('Weight'),
278 'is_display_amounts' => array(
279 'name' => 'is_display_amounts',
280 'type' => CRM_Utils_Type
::T_BOOLEAN
,
283 'options_per_line' => array(
284 'name' => 'options_per_line',
285 'type' => CRM_Utils_Type
::T_INT
,
286 'title' => ts('Options Per Line'),
289 'is_active' => array(
290 'name' => 'is_active',
291 'type' => CRM_Utils_Type
::T_BOOLEAN
,
294 'is_required' => array(
295 'name' => 'is_required',
296 'type' => CRM_Utils_Type
::T_BOOLEAN
,
299 'active_on' => array(
300 'name' => 'active_on',
301 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
302 'title' => ts('Active On'),
305 'expire_on' => array(
306 'name' => 'expire_on',
307 'type' => CRM_Utils_Type
::T_DATE + CRM_Utils_Type
::T_TIME
,
308 'title' => ts('Expire On'),
311 'javascript' => array(
312 'name' => 'javascript',
313 'type' => CRM_Utils_Type
::T_STRING
,
314 'title' => ts('Javascript'),
316 'size' => CRM_Utils_Type
::HUGE
,
318 'visibility_id' => array(
319 'name' => 'visibility_id',
320 'type' => CRM_Utils_Type
::T_INT
,
325 return self
::$_fields;
329 * returns the names of this table
334 public static function getTableName() {
335 return CRM_Core_DAO
::getLocaleTableName(self
::$_tableName);
339 * returns if this table needs to be logged
343 public function getLog() {
348 * returns the list of fields that can be imported
353 static function &import($prefix = FALSE) {
354 if (!(self
::$_import)) {
355 self
::$_import = array();
356 $fields = self
::fields();
357 foreach ($fields as $name => $field) {
358 if (!empty($field['import'])) {
360 self
::$_import['price_field'] = &$fields[$name];
363 self
::$_import[$name] = &$fields[$name];
368 return self
::$_import;
372 * returns the list of fields that can be exported
377 static function &export($prefix = FALSE) {
378 if (!(self
::$_export)) {
379 self
::$_export = array();
380 $fields = self
::fields();
381 foreach ($fields as $name => $field) {
382 if (!empty($field['export'])) {
384 self
::$_export['price_field'] = &$fields[$name];
387 self
::$_export[$name] = &$fields[$name];
392 return self
::$_export;
396 * returns an array containing the enum fields of the civicrm_price_field table
399 * (reference) the array of enum fields
401 static function &getEnums() {
402 static $enums = array(
409 * returns a ts()-translated enum value for display purposes
411 * @param string $field
412 * The enum field in question.
413 * @param string $value
414 * The enum value up for translation.
417 * the display value of the enum
419 public static function tsEnum($field, $value) {
420 static $translations = NULL;
421 if (!$translations) {
422 $translations = array(
423 'html_type' => array(
424 'Text' => ts('Text'),
425 'Select' => ts('Select'),
426 'Radio' => ts('Radio'),
427 'CheckBox' => ts('CheckBox'),
431 return $translations[$field][$value];
435 * adds $value['foo_display'] for each $value['foo'] enum from civicrm_price_field
437 * @param array $values
438 * (reference) the array up for enhancing.
441 public static function addDisplayEnums(&$values) {
442 $enumFields = &Snapshot_v4p2_Price_DAO_Field
::getEnums();
443 foreach ($enumFields as $enum) {
444 if (isset($values[$enum])) {
445 $values[$enum . '_display'] = Snapshot_v4p2_Price_DAO_Field
::tsEnum($enum, $values[$enum]);