Skip to content

Commit

Permalink
CRM-12167: Start Implementation of Visibility per Price Option
Browse files Browse the repository at this point in the history
template updates
php updates
adding column to upgrader and xml
some improvements from comparing to current price field visibility id approach
  • Loading branch information
alifrumin authored and MiyaNoctem committed Sep 25, 2017
1 parent c2e75ad commit 2db35bf
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 5 deletions.
15 changes: 14 additions & 1 deletion CRM/Price/BAO/PriceField.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public static function create(&$params) {
'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']) {
Expand Down Expand Up @@ -431,11 +432,18 @@ public static function addQuickFormElement(
$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();');
Expand Down Expand Up @@ -536,7 +544,12 @@ public static function addQuickFormElement(
$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 -'),
Expand Down
24 changes: 24 additions & 0 deletions CRM/Price/DAO/PriceFieldValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -434,6 +440,24 @@ static function &fields() {
'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']);
}
Expand Down
9 changes: 9 additions & 0 deletions CRM/Price/Form/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ public function setDefaultValues() {
for ($i = 1; $i <= self::NUM_OPTION; $i++) {
$defaults['option_status[' . $i . ']'] = 1;
$defaults['option_weight[' . $i . ']'] = $i;
$defaults['option_visibility_id[' . $i . ']'] = 1;
}
}

Expand Down Expand Up @@ -191,6 +192,11 @@ public function buildQuickForm() {
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)) {
Expand Down Expand Up @@ -302,6 +308,7 @@ public function buildQuickForm() {
// 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
Expand Down Expand Up @@ -651,6 +658,8 @@ public function postProcess() {
//$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) {
Expand Down
4 changes: 4 additions & 0 deletions CRM/Price/Form/Option.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ public function buildQuickForm() {
// 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'));

Expand Down Expand Up @@ -319,6 +322,7 @@ public function postProcess() {
$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;
Expand Down
4 changes: 4 additions & 0 deletions CRM/Upgrade/Incremental/sql/4.7.23.mysql.tpl
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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);
5 changes: 4 additions & 1 deletion templates/CRM/Price/Form/Option.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@
<td>{$form.is_default.html}</td>
</tr>
{/if}
<tr class="crm-price-field-form-block-visibility_id">
<td class="label">{$form.visibility_id.label}</td>
<td>&nbsp;{$form.visibility_id.html} {help id="id-visibility"}</td>
</tr>
</table>

{literal}
Expand All @@ -130,4 +134,3 @@
</div>

</div>

6 changes: 4 additions & 2 deletions templates/CRM/Price/Form/OptionFields.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
<th>{ts}Max Participant{/ts} {help id="id-participant-max"}</th>
{/if}
<th>{ts}Order{/ts}</th>
<th>{ts}Active?{/ts}</th>
<th>{ts}Visibility{/ts}</th>
<th>{ts}Active?{/ts}</th>
</tr>

{section name=rowLoop start=1 loop=16}
Expand Down Expand Up @@ -80,7 +81,8 @@
<td>{$form.option_max_value.$index.html}</td>
{/if}
<td> {$form.option_weight.$index.html}</td>
<td> {$form.option_status.$index.html}</td>
<td> {$form.option_visibility_id.$index.html}</td>
<td> {$form.option_status.$index.html}</td>
</tr>
{/section}
</table>
Expand Down
9 changes: 9 additions & 0 deletions templates/CRM/Price/Form/PriceSet.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
{/if}
{/if}
{/foreach}
{literal}
<script>
cj('input').each(function(){
if (cj(this).attr('visibility') == 2 && typeof adminpage=='undefined'){
cj(this).parent().hide();
}
});
</script>
{/literal}
{if $element.help_post}
<div class="description">{$element.help_post}</div>
{/if}
Expand Down
15 changes: 14 additions & 1 deletion xml/schema/Price/PriceFieldValue.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,18 @@
<type>Text</type>
</html>
</field>
<field>
<name>visibility_id</name>
<title>Price Field Option Visibility</title>
<type>int unsigned</type>
<default>1</default>
<comment>Implicit FK to civicrm_option_group with name = 'visibility'</comment>
<add>4.7</add>
<pseudoconstant>
<optionGroupName>visibility</optionGroupName>
</pseudoconstant>
<html>
<type>Select</type>
</html>
</field>
</table>

0 comments on commit 2db35bf

Please sign in to comment.