$adminFieldVisible = TRUE;
}
+ $hideAdminValues = TRUE;
+ if (CRM_Core_Permission::check('edit event participants')) {
+ $hideAdminValues = FALSE;
+ }
+
foreach ($form->_feeBlock as $field) {
// public AND admin visibility fields are included for back-office registration and back-office change selections
if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
//user might modified w/ hook.
$options = CRM_Utils_Array::value('options', $field);
+ $formClasses = array('CRM_Event_Form_Participant', 'CRM_Event_Form_ParticipantFeeSelection');
+
if (!is_array($options)) {
continue;
}
+ elseif ($hideAdminValues && !in_array($className, $formClasses)) {
+ foreach ($options as $key => $currentOption) {
+ if ($currentOption['visibility_id'] == CRM_Price_BAO_PriceField::getVisibilityOptionID('admin')) {
+ unset($options[$key]);
+ }
+ }
+ }
$optionFullIds = CRM_Utils_Array::value('option_full_ids', $field, array());
protected $_options;
+ /**
+ * List of visibility option ID's, of the form name => ID
+ *
+ * @var array
+ */
+ private static $visibilityOptionsKeys;
+
/**
* Takes an associative array and creates a price field object.
*
* (reference) an assoc array of name/value pairs.
*
* @return CRM_Price_DAO_PriceField
+ * @throws \CRM_Core_Exception
*/
public static function create(&$params) {
if (empty($params['id']) && empty($params['name'])) {
'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],
+ 'visibility_id' => CRM_Utils_Array::value($index, CRM_Utils_Array::value('option_visibility_id', $params), self::getVisibilityOptionID('public')),
);
if ($options['membership_type_id']) {
$visibility_id = $opt['visibility_id'];
}
else {
- $visibility_id = 1;
+ $visibility_id = self::getVisibilityOptionID('public');
}
$extra = array(
'price' => json_encode(array($elementName, $priceVal)),
$visibility_id = $opt['visibility_id'];
}
else {
- $visibility_id = 1;
+ $visibility_id = self::getVisibilityOptionID('public');
}
$element = &$qf->add('select', $elementName, $label,
array(
'price' => json_encode(array($opt['id'], $priceVal)),
'data-amount' => $opt[$valueFieldName],
'data-currency' => $currencyName,
+ 'visibility' => $opt['visibility_id'],
)
);
if ($is_pay_later) {
return $label;
}
+ /**
+ * Given the name of a visibility option, returns its ID.
+ *
+ * @param string $visibilityName
+ *
+ * @return int
+ */
+ public static function getVisibilityOptionID($visibilityName) {
+
+ if (!isset(self::$visibilityOptionsKeys)) {
+ self::$visibilityOptionsKeys = CRM_Price_BAO_PriceField::buildOptions(
+ 'visibility_id',
+ NULL,
+ array(
+ 'labelColumn' => 'name',
+ 'flip' => TRUE,
+ )
+ );
+ }
+
+ if (isset(self::$visibilityOptionsKeys[$visibilityName])) {
+ return self::$visibilityOptionsKeys[$visibilityName];
+ }
+
+ return 0;
+ }
+
}
$adminFieldVisible = TRUE;
}
+ $hideAdminValues = TRUE;
+ if (CRM_Core_Permission::check('edit contributions')) {
+ $hideAdminValues = FALSE;
+ }
+
foreach ($feeBlock as $id => $field) {
if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
(CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) ||
$form->assign('ispricelifetime', TRUE);
}
}
+
+ $formClasses = array('CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership');
+
if (!is_array($options) || !in_array($id, $validPriceFieldIds)) {
continue;
}
+ elseif ($hideAdminValues && !in_array($className, $formClasses)) {
+ foreach ($options as $key => $currentOption) {
+ if ($currentOption['visibility_id'] == CRM_Price_BAO_PriceField::getVisibilityOptionID('admin')) {
+ unset($options[$key]);
+ }
+ }
+ }
if (!empty($options)) {
CRM_Price_BAO_PriceField::addQuickFormElement($form,
'price_' . $field['id'],
if ($form->_action & CRM_Core_Action::ADD) {
if ($fields['html_type'] != 'Text') {
$countemptyrows = 0;
- $_flagOption = $_rowError = 0;
+ $publicOptionCount = $_flagOption = $_rowError = 0;
$_showHide = new CRM_Core_ShowHideBlocks('', '');
+ $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array('labelColumn' => 'name'));
for ($index = 1; $index <= self::NUM_OPTION; $index++) {
$_showHide->addHide($hideBlock);
}
+ if (!empty($fields['option_visibility_id'][$index]) && (!$noLabel || !$noAmount)) {
+ if ($visibilityOptions[$fields['option_visibility_id'][$index]] == 'public') {
+ $publicOptionCount++;
+ }
+ }
+
$_flagOption = $_emptyRow = 0;
}
$errors['option_label[1]'] = $errors['option_amount[1]'] = ts('Label and value cannot be empty.');
$_flagOption = 1;
}
+
+ if ($visibilityOptions[$fields['visibility_id']] == 'public' && $publicOptionCount == 0) {
+ $errors['visibility_id'] = ts('You have selected to make this field public but have not enabled any public price options. Please update your selections to include a public price option, or make this field admin visibility only.');
+ for ($index = 1; $index <= self::NUM_OPTION; $index++) {
+ if (!empty($fields['option_label'][$index]) || !empty($fields['option_amount'][$index])) {
+ $errors["option_visibility_id[{$index}]"] = ts('Public field should at least have one public option.');
+ }
+ }
+ }
+
+ if ($visibilityOptions[$fields['visibility_id']] == 'admin' && $publicOptionCount > 0) {
+ $errors['visibility_id'] = ts('Field with \'Admin\' visibility should only contain \'Admin\' options.');
+
+ for ($index = 1; $index <= self::NUM_OPTION; $index++) {
+
+ $isOptionSet = !empty($fields['option_label'][$index]) || !empty($fields['option_amount'][$index]);
+ $currentOptionVisibility = CRM_Utils_Array::value($fields['option_visibility_id'][$index], $visibilityOptions);
+
+ if ($isOptionSet && $currentOptionVisibility == 'public') {
+ $errors["option_visibility_id[{$index}]"] = ts('\'Admin\' field should only have \'Admin\' visibility options.');
+ }
+ }
+ }
}
elseif (!empty($fields['max_value']) &&
!empty($fields['count']) &&
) {
$errors['count'] = ts('Participant count can not be greater than max participants.');
}
+
+ $priceField = CRM_Price_BAO_PriceField::findById($fields['fieldId']);
+ $visibilityOptions = CRM_Price_BAO_PriceFieldValue::buildOptions('visibility_id', NULL, array('labelColumn' => 'name'));
+
+ $publicCount = 0;
+ $options = CRM_Price_BAO_PriceField::getOptions($priceField->id);
+ foreach ($options as $currentOption) {
+ if ($fields['optionId'] == $currentOption['id'] && $visibilityOptions[$fields['visibility_id']] == 'public') {
+ $publicCount++;
+ }
+ elseif ($fields['optionId'] != $currentOption['id'] && $visibilityOptions[$currentOption['visibility_id']] == 'public') {
+ $publicCount++;
+ }
+ }
+ if ($visibilityOptions[$priceField->visibility_id] == 'public' && $publicCount == 0) {
+ $errors['visibility_id'] = ts('All other options for this \'Public\' field have \'Admin\' visibility. There should at least be one \'Public\' option, or make the field \'Admin\' only.');
+ }
+ elseif ($visibilityOptions[$priceField->visibility_id] == 'admin' && $publicCount > 0) {
+ $errors['visibility_id'] = ts('You must choose \'Admin\' visibility for this price option, as it belongs to a field with \'Admin\' visibility.');
+ }
+
return empty($errors) ? TRUE : $errors;
}
$this->addTask('CRM-21195 - Add icon field to civicrm_navigation', 'addColumn',
'civicrm_navigation', 'icon', "varchar(255) NULL DEFAULT NULL COMMENT 'CSS class name for an icon'");
+ $this->addTask('CRM-12167 - Add visibility column to civicrm_price_field_value', 'addColumn',
+ 'civicrm_price_field_value', 'visibility_id', 'int(10) unsigned DEFAULT 1 COMMENT "Implicit FK to civicrm_option_group with name = \'visibility\'"');
}
/*
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);
}
}
+
+ var adminVisibilityID = 0;
+ cj('#visibility_id').on('change', function () {
+ if (adminVisibilityID == 0) {
+ CRM.api3('OptionValue', 'getvalue', {
+ 'sequential': 1,
+ 'return': 'value',
+ 'option_group_id': 'visibility',
+ 'name': 'admin'
+ }).done(function(result) {
+ adminVisibilityID = result.result;
+ if (cj('#visibility_id').val() == adminVisibilityID) {
+ updateVisibilitySelects(adminVisibilityID);
+ }
+ });
+ } else {
+ if (cj('#visibility_id').val() == adminVisibilityID) {
+ updateVisibilitySelects(adminVisibilityID);
+ }
+ }
+ });
+
+ function updateVisibilitySelects(value) {
+ for (var i=1; i<=15; i++) {
+ cj('#option_visibility_id_' + i).val(value);
+ }
+ }
</script>
{/literal}
<div class="crm-block crm-form-block crm-price-field-form-block">
{/if}
<tr class="crm-price-field-form-block-visibility_id">
<td class="label">{$form.visibility_id.label}</td>
- <td> {$form.visibility_id.html} {help id="id-visibility"}</td>
+ <td> {$form.visibility_id.html} {help id="id-visibility-options" file="CRM/Price/Page/Field.hlp"}</td>
</tr>
</table>
<th>{ts}Max Participant{/ts} {help id="id-participant-max"}</th>
{/if}
<th>{ts}Order{/ts}</th>
- <th>{ts}Visibility{/ts}</th>
+ <th>{ts}Visibility{/ts} {help id="id-visibility-options"}</th>
<th>{ts}Active?{/ts}</th>
</tr>
{/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}
{ts}You may enter a negative amount value if the field or option is being used to discount the total price.{/ts}
{/htxt}
+{htxt id="id-visibility-options-title"}
+ {ts}Visibility per Option{/ts}
+{/htxt}
+{htxt id="id-visibility-options"}
+ {ts}Select between Admin/Public for each option. 'Public' will show the option to all users accessing the price set. Use 'Admin' to limit the option to users with the 'CiviEvent: edit event participants’ permission (when viewing the field via the event registration pages) or the ‘CiviContribute: edit contributions’ permission (when accessing the field through a contribution page).{/ts}
+{/htxt}
+
{htxt id="id-participant-count-title"}
{ts}Participant Count{/ts}
{/htxt}
{ts}Visibility{/ts}
{/htxt}
{htxt id="id-visibility"}
- {ts}Fields with 'Public' visibility will be displayed on your Event Information page AND will be available in the online registration (self-service) form. For some events you may want to allow staff to select special options with special pricing and / or discounts (using negative price set field values). Select 'Admin' visibility for these Price Fields. They will only be included when staff or volunteers are registering participants from the back-office 'Register Event Participants' screen.{/ts}
+ {ts}Fields with 'Public' visibility will be displayed on your Event Information page AND will be available in the online registration (self-service) form. For some events you may want to allow staff to select special options with special pricing and / or discounts (using negative price set field values). Select 'Admin' visibility for these Price Fields. They will only be included when staff or volunteers are registering participants from the back-office 'Register Event Participants' screen. If the parent price field visibility is ‘Public’ then it should be possible to set individual price options as 'Admin', but it should have at least one 'Public' option. If the parent price field visibility is 'Admin', then all the price field options should be set to 'Admin', including any new options added to the form.{/ts}
{/htxt}
{htxt id="id-member-price-options-title"}
$this->assertArrayKeyExists('visibility_id', $fields);
$this->assertEquals('visibility', $fields['visibility_id']['pseudoconstant']['optionGroupName']);
}
+
}
);\r
\r
for ($index = 1; $index <= CRM_Price_Form_Field::NUM_OPTION; $index++) {\r
- $defaultParams['option_label'][$index] = null;\r
- $defaultParams['option_value'][$index] = null;\r
- $defaultParams['option_name'][$index] = null;\r
- $defaultParams['option_weight'][$index] = null;\r
- $defaultParams['option_amount'][$index] = null;\r
- $defaultParams['option_visibility_id'][$index] = null;\r
+ $defaultParams['option_label'][$index] = NULL;\r
+ $defaultParams['option_value'][$index] = NULL;\r
+ $defaultParams['option_name'][$index] = NULL;\r
+ $defaultParams['option_weight'][$index] = NULL;\r
+ $defaultParams['option_amount'][$index] = NULL;\r
+ $defaultParams['option_visibility_id'][$index] = NULL;\r
}\r
\r
return array_merge($defaultParams, $params);\r
}\r
+\r
}\r
foreach ($this->priceFieldValues as $currentField) {\r
if ($this->visibilityOptions[$currentField['visibility_id']] == 'public') {\r
$this->publicValue = $currentField;\r
- } else {\r
+ }\r
+ else {\r
$this->adminValue = $currentField;\r
}\r
}\r
-\r
}\r
+\r
}\r