Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
0f03f337 | 6 | | Copyright CiviCRM LLC (c) 2004-2017 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
0f03f337 | 31 | * @copyright CiviCRM LLC (c) 2004-2017 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for previewing custom data | |
38 | * | |
39 | * It delegates the work to lower level subclasses and integrates the changes | |
40 | * back in. It also uses a lot of functionality with the CRM API's, so any change | |
41 | * made here could potentially affect the API etc. Be careful, be aware, use unit tests. | |
42 | * | |
43 | */ | |
44 | class CRM_Price_Form_Preview extends CRM_Core_Form { | |
45 | ||
46 | /** | |
fe482240 | 47 | * The group tree data. |
6a488035 TO |
48 | * |
49 | * @var array | |
50 | */ | |
51 | protected $_groupTree; | |
52 | ||
53 | /** | |
100fef9d | 54 | * Pre processing work done here. |
6a488035 TO |
55 | * |
56 | * gets session variables for group or field id | |
57 | * | |
6a488035 | 58 | * @return void |
95ea96be | 59 | */ |
bed98343 | 60 | public function preProcess() { |
6a488035 TO |
61 | // get the controller vars |
62 | $groupId = $this->get('groupId'); | |
63 | $fieldId = $this->get('fieldId'); | |
64 | ||
65 | if ($fieldId) { | |
9da8dc8c | 66 | $groupTree = CRM_Price_BAO_PriceSet::getSetDetail($groupId); |
6a488035 TO |
67 | $this->_groupTree[$groupId]['fields'][$fieldId] = $groupTree[$groupId]['fields'][$fieldId]; |
68 | $this->assign('preview_type', 'field'); | |
69 | $url = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$groupId}"); | |
353ffa53 TO |
70 | $breadCrumb = array( |
71 | array( | |
72 | 'title' => ts('Price Set Fields'), | |
6a488035 | 73 | 'url' => $url, |
bed98343 | 74 | ), |
353ffa53 | 75 | ); |
6a488035 TO |
76 | } |
77 | else { | |
78 | // group preview | |
9da8dc8c | 79 | $this->_groupTree = CRM_Price_BAO_PriceSet::getSetDetail($groupId); |
6a488035 | 80 | $this->assign('preview_type', 'group'); |
9da8dc8c | 81 | $this->assign('setTitle', CRM_Price_BAO_PriceSet::getTitle($groupId)); |
6a488035 | 82 | $url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1'); |
353ffa53 TO |
83 | $breadCrumb = array( |
84 | array( | |
85 | 'title' => ts('Price Sets'), | |
6a488035 | 86 | 'url' => $url, |
bed98343 | 87 | ), |
353ffa53 | 88 | ); |
6a488035 TO |
89 | } |
90 | CRM_Utils_System::appendBreadCrumb($breadCrumb); | |
91 | } | |
92 | ||
93 | /** | |
fe482240 | 94 | * Set the default form values. |
6a488035 | 95 | * |
a6c01b45 CW |
96 | * @return array |
97 | * the default array reference | |
6a488035 | 98 | */ |
00be9182 | 99 | public function setDefaultValues() { |
6a488035 | 100 | $defaults = array(); |
353ffa53 TO |
101 | $groupId = $this->get('groupId'); |
102 | $fieldId = $this->get('fieldId'); | |
a7488080 | 103 | if (!empty($this->_groupTree[$groupId]['fields'])) { |
6a488035 TO |
104 | foreach ($this->_groupTree[$groupId]['fields'] as $key => $val) { |
105 | foreach ($val['options'] as $keys => $values) { | |
106 | if ($values['is_default']) { | |
107 | if ($val['html_type'] == 'CheckBox') { | |
108 | $defaults["price_{$key}"][$keys] = 1; | |
109 | } | |
110 | else { | |
111 | $defaults["price_{$key}"] = $keys; | |
112 | } | |
113 | } | |
114 | } | |
115 | } | |
116 | } | |
117 | return $defaults; | |
118 | } | |
119 | ||
120 | /** | |
fe482240 | 121 | * Build the form object. |
6a488035 | 122 | * |
6a488035 | 123 | * @return void |
6a488035 TO |
124 | */ |
125 | public function buildQuickForm() { | |
126 | $this->assign('groupTree', $this->_groupTree); | |
127 | ||
128 | // add the form elements | |
129 | ||
130 | foreach ($this->_groupTree as $group) { | |
131 | if (is_array($group['fields']) && !empty($group['fields'])) { | |
132 | foreach ($group['fields'] as $field) { | |
133 | $fieldId = $field['id']; | |
134 | $elementName = 'price_' . $fieldId; | |
1019b2fe SL |
135 | if (!empty($field['options'])) { |
136 | CRM_Price_BAO_PriceField::addQuickFormElement($this, $elementName, $fieldId, FALSE, $field['is_required']); | |
137 | } | |
6a488035 TO |
138 | } |
139 | } | |
140 | } | |
141 | ||
142 | $this->addButtons(array( | |
c5c263ca AH |
143 | array( |
144 | 'type' => 'cancel', | |
145 | 'name' => ts('Done with Preview'), | |
146 | 'isDefault' => TRUE, | |
147 | ), | |
148 | )); | |
6a488035 | 149 | } |
96025800 | 150 | |
6a488035 | 151 | } |