From 2db35bf6ee39bf6d611681a9163515fa89115765 Mon Sep 17 00:00:00 2001 From: Alice Frumin Date: Tue, 11 Jul 2017 17:29:39 -0400 Subject: [PATCH] CRM-12167: Start Implementation of Visibility per Price Option template updates php updates adding column to upgrader and xml some improvements from comparing to current price field visibility id approach --- CRM/Price/BAO/PriceField.php | 15 +++++++++++- CRM/Price/DAO/PriceFieldValue.php | 24 ++++++++++++++++++++ CRM/Price/Form/Field.php | 9 ++++++++ CRM/Price/Form/Option.php | 4 ++++ CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl | 4 ++++ templates/CRM/Price/Form/Option.tpl | 5 +++- templates/CRM/Price/Form/OptionFields.tpl | 6 +++-- templates/CRM/Price/Form/PriceSet.tpl | 9 ++++++++ xml/schema/Price/PriceFieldValue.xml | 15 +++++++++++- 9 files changed, 86 insertions(+), 5 deletions(-) mode change 100644 => 100755 CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl diff --git a/CRM/Price/BAO/PriceField.php b/CRM/Price/BAO/PriceField.php index 6e9de163d6..4a5c4649b5 100644 --- a/CRM/Price/BAO/PriceField.php +++ b/CRM/Price/BAO/PriceField.php @@ -147,6 +147,7 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { 'is_default' => CRM_Utils_Array::value($params['option_weight'][$index], $defaultArray) ? $defaultArray[$params['option_weight'][$index]] : 0, 'membership_num_terms' => NULL, 'non_deductible_amount' => CRM_Utils_Array::value('non_deductible_amount', $params), + 'visibility_id' => $params['option_visibility_id'][$index], ); if ($options['membership_type_id']) { @@ -431,11 +432,18 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { $count = CRM_Utils_Array::value('count', $opt, ''); $max_value = CRM_Utils_Array::value('max_value', $opt, ''); $priceVal = implode($seperator, array($opt[$valueFieldName] + $taxAmount, $count, $max_value)); + if (isset($opt['visibility_id'])) { + $visibility_id = $opt['visibility_id']; + } + else { + $visibility_id = 1; + } $extra = array( 'price' => json_encode(array($elementName, $priceVal)), 'data-amount' => $opt[$valueFieldName], 'data-currency' => $currencyName, 'data-price-field-values' => json_encode($customOption), + 'visibility' => $visibility_id, ); if (!empty($qf->_quickConfig) && $field->name == 'contribution_amount') { $extra += array('onclick' => 'clearAmountOther();'); @@ -536,7 +544,12 @@ class CRM_Price_BAO_PriceField extends CRM_Price_DAO_PriceField { $qf->add('text', 'txt-' . $elementName, $label, array('size' => '4')); } } - + if (isset($opt['visibility_id'])) { + $visibility_id = $opt['visibility_id']; + } + else { + $visibility_id = 1; + } $element = &$qf->add('select', $elementName, $label, array( '' => ts('- select -'), diff --git a/CRM/Price/DAO/PriceFieldValue.php b/CRM/Price/DAO/PriceFieldValue.php index 2b3a301f8a..c51f08380c 100644 --- a/CRM/Price/DAO/PriceFieldValue.php +++ b/CRM/Price/DAO/PriceFieldValue.php @@ -152,6 +152,12 @@ class CRM_Price_DAO_PriceFieldValue extends CRM_Core_DAO { * @var float */ public $non_deductible_amount; + /** + * Implicit FK to civicrm_option_group with name = \'visibility\' + * + * @var int unsigned + */ + public $visibility_id; /** * Class constructor. */ @@ -434,6 +440,24 @@ class CRM_Price_DAO_PriceFieldValue extends CRM_Core_DAO { 'type' => 'Text', ) , ) , + 'visibility_id' => array( + 'name' => 'visibility_id', + 'type' => CRM_Utils_Type::T_INT, + 'title' => ts('Price Field Option Visibility') , + 'description' => 'Implicit FK to civicrm_option_group with name = \'visibility\'', + 'default' => '1', + 'table_name' => 'civicrm_price_field_value', + 'entity' => 'PriceFieldValue', + 'bao' => 'CRM_Price_BAO_PriceFieldValue', + 'localizable' => 0, + 'html' => array( + 'type' => 'Select', + ) , + 'pseudoconstant' => array( + 'optionGroupName' => 'visibility', + 'optionEditPath' => 'civicrm/admin/options/visibility', + ), + ) , ); CRM_Core_DAO_AllCoreTables::invoke(__CLASS__, 'fields_callback', Civi::$statics[__CLASS__]['fields']); } diff --git a/CRM/Price/Form/Field.php b/CRM/Price/Form/Field.php index d694510d1d..ac32ccff26 100644 --- a/CRM/Price/Form/Field.php +++ b/CRM/Price/Form/Field.php @@ -132,6 +132,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form { for ($i = 1; $i <= self::NUM_OPTION; $i++) { $defaults['option_status[' . $i . ']'] = 1; $defaults['option_weight[' . $i . ']'] = $i; + $defaults['option_visibility_id[' . $i . ']'] = 1; } } @@ -191,6 +192,11 @@ class CRM_Price_Form_Field extends CRM_Core_Form { if (count($financialType)) { $this->assign('financialType', $financialType); } + + //Visibility Type Options + $visibilityType = CRM_Core_PseudoConstant::visibility(); + $this->assign('visibilityType', $visibilityType); + $enabledComponents = CRM_Core_Component::getEnabledComponents(); $eventComponentId = $memberComponentId = NULL; if (array_key_exists('CiviEvent', $enabledComponents)) { @@ -302,6 +308,7 @@ class CRM_Price_Form_Field extends CRM_Core_Form { // is active ? $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?')); + $this->add('select', 'option_visibility_id[' . $i . ']', ts('Visibility'), array('' => ts('- select -')) + $visibilityType); $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i); //for checkbox handling of default option @@ -651,6 +658,8 @@ class CRM_Price_Form_Field extends CRM_Core_Form { //$params['option_description'] = array( 1 => $params['description'] ); $params['option_weight'] = array(1 => $params['weight']); $params['option_financial_type_id'] = array(1 => $params['financial_type_id']); + $params['option_visibility_id'] = array(1 => CRM_Utils_Array::value('visibility_id', $params)); + $params['is_active'] = array(1 => 1); } if ($this->_fid) { diff --git a/CRM/Price/Form/Option.php b/CRM/Price/Form/Option.php index 0bd160b25c..fbb2048714 100644 --- a/CRM/Price/Form/Option.php +++ b/CRM/Price/Form/Option.php @@ -229,6 +229,9 @@ class CRM_Price_Form_Option extends CRM_Core_Form { // is active ? $this->add('checkbox', 'is_active', ts('Active?')); + // is public? + $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility()); + //is default $this->add('checkbox', 'is_default', ts('Default')); @@ -319,6 +322,7 @@ class CRM_Price_Form_Option extends CRM_Core_Form { $params['price_field_id'] = $this->_fid; $params['is_default'] = CRM_Utils_Array::value('is_default', $params, FALSE); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); + $params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE); $ids = array(); if ($this->_oid) { $ids['id'] = $this->_oid; diff --git a/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl b/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl old mode 100644 new mode 100755 index dbedca1b2f..55dede9e34 --- a/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl +++ b/CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl @@ -41,3 +41,7 @@ ON price_field.price_field_id = cpf.id LEFT JOIN civicrm_price_set ps ON ps.id = cpf.price_set_id SET cpf.is_active = 1 WHERE ps.is_quick_config = 1 AND cpf.is_active = 0; + +-- CRM-12167 +ALTER TABLE `civicrm_price_field_value` +ADD COLUMN `visibility_id` int(10); diff --git a/templates/CRM/Price/Form/Option.tpl b/templates/CRM/Price/Form/Option.tpl index a52d23666b..addfdc2df7 100644 --- a/templates/CRM/Price/Form/Option.tpl +++ b/templates/CRM/Price/Form/Option.tpl @@ -106,6 +106,10 @@ {$form.is_default.html} {/if} + + {$form.visibility_id.label} +  {$form.visibility_id.html} {help id="id-visibility"} + {literal} @@ -130,4 +134,3 @@ - diff --git a/templates/CRM/Price/Form/OptionFields.tpl b/templates/CRM/Price/Form/OptionFields.tpl index 753392b1c1..0b11d28bbc 100644 --- a/templates/CRM/Price/Form/OptionFields.tpl +++ b/templates/CRM/Price/Form/OptionFields.tpl @@ -48,7 +48,8 @@ {ts}Max Participant{/ts} {help id="id-participant-max"} {/if} {ts}Order{/ts} - {ts}Active?{/ts} + {ts}Visibility{/ts} + {ts}Active?{/ts} {section name=rowLoop start=1 loop=16} @@ -80,7 +81,8 @@ {$form.option_max_value.$index.html} {/if} {$form.option_weight.$index.html} - {$form.option_status.$index.html} + {$form.option_visibility_id.$index.html} + {$form.option_status.$index.html} {/section} diff --git a/templates/CRM/Price/Form/PriceSet.tpl b/templates/CRM/Price/Form/PriceSet.tpl index 4979744ab1..87210e0a22 100644 --- a/templates/CRM/Price/Form/PriceSet.tpl +++ b/templates/CRM/Price/Form/PriceSet.tpl @@ -61,6 +61,15 @@ {/if} {/if} {/foreach} + {literal} + + {/literal} {if $element.help_post}
{$element.help_post}
{/if} diff --git a/xml/schema/Price/PriceFieldValue.xml b/xml/schema/Price/PriceFieldValue.xml index cd6ba61a1b..b68992a1b4 100644 --- a/xml/schema/Price/PriceFieldValue.xml +++ b/xml/schema/Price/PriceFieldValue.xml @@ -221,5 +221,18 @@ Text + + visibility_id + Price Field Option Visibility + int unsigned + 1 + Implicit FK to civicrm_option_group with name = 'visibility' + 4.7 + + visibility + + + Select + + - -- 2.25.1