3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class generates form components for previewing custom data
21 * It delegates the work to lower level subclasses and integrates the changes
22 * back in. It also uses a lot of functionality with the CRM API's, so any change
23 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
26 class CRM_Price_Form_Preview
extends CRM_Core_Form
{
29 * The group tree data.
33 protected $_groupTree;
36 * Pre processing work done here.
38 * gets session variables for group or field id
42 public function preProcess() {
43 // get the controller vars
44 $groupId = $this->get('groupId');
45 $fieldId = $this->get('fieldId');
48 $groupTree = CRM_Price_BAO_PriceSet
::getSetDetail($groupId);
49 $this->_groupTree
[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId];
50 $this->assign('preview_type', 'field');
51 $url = CRM_Utils_System
::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$groupId}");
54 'title' => ts('Price Set Fields'),
61 $this->_groupTree
= CRM_Price_BAO_PriceSet
::getSetDetail($groupId);
62 $this->assign('preview_type', 'group');
63 $this->assign('setTitle', CRM_Price_BAO_PriceSet
::getTitle($groupId));
64 $url = CRM_Utils_System
::url('civicrm/admin/price', 'reset=1');
67 'title' => ts('Price Sets'),
72 CRM_Utils_System
::appendBreadCrumb($breadCrumb);
76 * Set the default form values.
79 * the default array reference
81 public function setDefaultValues() {
83 $groupId = $this->get('groupId');
84 $fieldId = $this->get('fieldId');
85 if (!empty($this->_groupTree
[$groupId]['fields'])) {
86 foreach ($this->_groupTree
[$groupId]['fields'] as $key => $val) {
87 foreach ($val['options'] as $keys => $values) {
88 if ($values['is_default']) {
89 if ($val['html_type'] == 'CheckBox') {
90 $defaults["price_{$key}"][$keys] = 1;
93 $defaults["price_{$key}"] = $keys;
103 * Build the form object.
107 public function buildQuickForm() {
108 $this->assign('groupTree', $this->_groupTree
);
110 // add the form elements
112 foreach ($this->_groupTree
as $group) {
113 if (is_array($group['fields']) && !empty($group['fields'])) {
114 foreach ($group['fields'] as $field) {
115 $fieldId = $field['id'];
116 $elementName = 'price_' . $fieldId;
117 if (!empty($field['options'])) {
118 CRM_Price_BAO_PriceField
::addQuickFormElement($this, $elementName, $fieldId, FALSE, $field['is_required']);
127 'name' => ts('Done with Preview'),