3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2013
37 * Create a page for displaying Price Fields.
39 * Heart of this class is the run method which checks
40 * for action type and then displays the appropriate
44 class CRM_Price_Page_Field
extends CRM_Core_Page
{
47 * The price set group id of the field
55 * The action links that we need to display for the browse screen
60 private static $_actionLinks;
63 * The price set is reserved or not
68 protected $_isSetReserved = false;
71 * Get the action links for this page.
75 * @return array array of action links that we need to display for the browse screen
77 */ function &actionLinks() {
78 if (!isset(self
::$_actionLinks)) {
79 // helper variable for nicer formatting
80 $deleteExtra = ts('Are you sure you want to delete this price field?');
81 self
::$_actionLinks = array(
82 CRM_Core_Action
::UPDATE
=> array(
83 'name' => ts('Edit Price Field'),
84 'url' => 'civicrm/admin/price/field',
85 'qs' => 'action=update&reset=1&sid=%%sid%%&fid=%%fid%%',
86 'title' => ts('Edit Price'),
88 CRM_Core_Action
::PREVIEW
=> array(
89 'name' => ts('Preview Field'),
90 'url' => 'civicrm/admin/price/field',
91 'qs' => 'action=preview&reset=1&sid=%%sid%%&fid=%%fid%%',
92 'title' => ts('Preview Price'),
94 CRM_Core_Action
::DISABLE
=> array(
95 'name' => ts('Disable'),
96 'extra' => 'onclick = "enableDisable( %%fid%%,\'' . 'CRM_Price_BAO_PriceField' . '\',\'' . 'enable-disable' . '\' );"',
97 'ref' => 'disable-action',
98 'title' => ts('Disable Price'),
100 CRM_Core_Action
::ENABLE
=> array(
101 'name' => ts('Enable'),
102 'extra' => 'onclick = "enableDisable( %%fid%%,\'' . 'CRM_Price_BAO_PriceField' . '\',\'' . 'disable-enable' . '\' );"',
103 'ref' => 'enable-action',
104 'title' => ts('Enable Price'),
106 CRM_Core_Action
::DELETE
=> array(
107 'name' => ts('Delete'),
108 'url' => 'civicrm/admin/price/field',
109 'qs' => 'action=delete&reset=1&sid=%%sid%%&fid=%%fid%%',
110 'title' => ts('Delete Price'),
111 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
115 return self
::$_actionLinks;
119 * Browse all price set fields.
127 $priceField = array();
128 $priceFieldBAO = new CRM_Price_BAO_PriceField();
131 $priceFieldBAO->price_set_id
= $this->_sid
;
132 $priceFieldBAO->orderBy('weight, label');
133 $priceFieldBAO->find();
135 while ($priceFieldBAO->fetch()) {
136 $priceField[$priceFieldBAO->id
] = array();
137 CRM_Core_DAO
::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id
]);
139 // get price if it's a text field
140 if ($priceFieldBAO->html_type
== 'Text') {
141 $optionValues = array();
142 $params = array('price_field_id' => $priceFieldBAO->id
);
144 CRM_Price_BAO_PriceFieldValue
::retrieve($params, $optionValues);
146 $priceField[$priceFieldBAO->id
]['price'] = CRM_Utils_Array
::value('amount', $optionValues);
149 $action = array_sum(array_keys($this->actionLinks()));
151 if ($this->_isSetReserved
) {
152 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DISABLE
;
155 if ($priceFieldBAO->is_active
) {
156 $action -= CRM_Core_Action
::ENABLE
;
159 $action -= CRM_Core_Action
::DISABLE
;
163 if ($priceFieldBAO->active_on
== '0000-00-00 00:00:00') {
164 $priceField[$priceFieldBAO->id
]['active_on'] = '';
167 if ($priceFieldBAO->expire_on
== '0000-00-00 00:00:00') {
168 $priceField[$priceFieldBAO->id
]['expire_on'] = '';
171 // need to translate html types from the db
172 $htmlTypes = CRM_Price_BAO_PriceField
::htmlTypes();
173 $priceField[$priceFieldBAO->id
]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id
]['html_type']];
174 $priceField[$priceFieldBAO->id
]['order'] = $priceField[$priceFieldBAO->id
]['weight'];
175 $priceField[$priceFieldBAO->id
]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
177 'fid' => $priceFieldBAO->id
,
178 'sid' => $this->_sid
,
183 $returnURL = CRM_Utils_System
::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
184 $filter = "price_set_id = {$this->_sid}";
185 CRM_Utils_Weight
::addOrder($priceField, 'CRM_Price_DAO_PriceField',
186 'id', $returnURL, $filter
188 $this->assign('priceField', $priceField);
194 * editing would involved modifying existing fields + adding data to new fields.
196 * @param string $action the action to be invoked
202 function edit($action) {
203 // create a simple controller for editing price data
204 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Field', ts('Price Field'), $action);
206 // set the userContext stack
207 $session = CRM_Core_Session
::singleton();
208 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
210 $controller->set('sid', $this->_sid
);
211 $controller->setEmbedded(TRUE);
212 $controller->process();
219 * This method is called after the page is created. It checks for the
220 * type of action and executes that action.
230 $this->_sid
= CRM_Utils_Request
::retrieve('sid', 'Positive',
233 $fid = CRM_Utils_Request
::retrieve('fid', 'Positive',
236 $action = CRM_Utils_Request
::retrieve('action', 'String',
237 // default to 'browse'
238 $this, FALSE, 'browse'
242 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($this->_sid
);
243 $this->assign('usedBy', $usedBy);
244 $this->_isSetReserved
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid
, 'is_reserved');
245 $this->assign('isReserved', $this->_isSetReserved
);
247 CRM_Price_BAO_PriceSet
::checkPermission($this->_sid
);
249 'Event' => 'civicrm_event',
250 'Contribution' => 'civicrm_contribution_page',
251 'EventTemplate' => 'civicrm_event_template'
253 $priceSetContexts = array();
254 foreach ($comps as $name => $table) {
255 if (array_key_exists($table, $usedBy)) {
256 $priceSetContexts[] = $name;
259 $this->assign('contexts', $priceSetContexts);
262 if ($action & (CRM_Core_Action
::DELETE
) && !$this->_isSetReserved
) {
263 if (empty($usedBy)) {
265 $session = CRM_Core_Session
::singleton();
266 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
267 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
268 $controller->set('fid', $fid);
269 $controller->setEmbedded(TRUE);
270 $controller->process();
275 $url = CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1');
276 CRM_Utils_System
::appendBreadCrumb(ts('Price'),
279 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField
::getTitle($fid));
284 $groupTitle = CRM_Price_BAO_PriceSet
::getTitle($this->_sid
);
285 $this->assign('sid', $this->_sid
);
286 $this->assign('groupTitle', $groupTitle);
287 CRM_Utils_System
::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
290 // assign vars to templates
291 $this->assign('action', $action);
293 // what action to take ?
294 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
) && !$this->_isSetReserved
) {
295 // no browse for edit/update/view
296 $this->edit($action);
298 elseif ($action & CRM_Core_Action
::PREVIEW
) {
299 $this->preview($fid);
305 // Call the parents run method
306 return parent
::run();
310 * Preview price field
312 * @param int $id price field id
317 function preview($fid) {
318 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Form Field'), CRM_Core_Action
::PREVIEW
);
319 $session = CRM_Core_Session
::singleton();
320 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
321 $controller->set('fieldId', $fid);
322 $controller->set('groupId', $this->_sid
);
323 $controller->setEmbedded(TRUE);
324 $controller->process();