3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
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
{
46 public $useLivePageJS = TRUE;
49 * The price set group id of the field
57 * The action links that we need to display for the browse screen
62 private static $_actionLinks;
65 * The price set is reserved or not
70 protected $_isSetReserved = false;
73 * Get the action links for this page.
77 * @return array array of action links that we need to display for the browse screen
79 */ function &actionLinks() {
80 if (!isset(self
::$_actionLinks)) {
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 'ref' => 'crm-enable-disable',
97 'title' => ts('Disable Price'),
99 CRM_Core_Action
::ENABLE
=> array(
100 'name' => ts('Enable'),
101 'ref' => 'crm-enable-disable',
102 'title' => ts('Enable Price'),
104 CRM_Core_Action
::DELETE
=> array(
105 'name' => ts('Delete'),
106 'url' => 'civicrm/admin/price/field',
107 'qs' => 'action=delete&reset=1&sid=%%sid%%&fid=%%fid%%',
108 'title' => ts('Delete Price'),
112 return self
::$_actionLinks;
116 * Browse all price set fields.
124 $resourceManager = CRM_Core_Resources
::singleton();
125 if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled
) {
126 $resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999);
129 $priceField = array();
130 $priceFieldBAO = new CRM_Price_BAO_PriceField();
133 $priceFieldBAO->price_set_id
= $this->_sid
;
134 $priceFieldBAO->orderBy('weight, label');
135 $priceFieldBAO->find();
137 while ($priceFieldBAO->fetch()) {
138 $priceField[$priceFieldBAO->id
] = array();
139 CRM_Core_DAO
::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id
]);
141 // get price if it's a text field
142 if ($priceFieldBAO->html_type
== 'Text') {
143 $optionValues = array();
144 $params = array('price_field_id' => $priceFieldBAO->id
);
146 CRM_Price_BAO_PriceFieldValue
::retrieve($params, $optionValues);
148 $priceField[$priceFieldBAO->id
]['price'] = CRM_Utils_Array
::value('amount', $optionValues);
151 $action = array_sum(array_keys($this->actionLinks()));
153 if ($this->_isSetReserved
) {
154 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DISABLE
;
157 if ($priceFieldBAO->is_active
) {
158 $action -= CRM_Core_Action
::ENABLE
;
161 $action -= CRM_Core_Action
::DISABLE
;
165 if ($priceFieldBAO->active_on
== '0000-00-00 00:00:00') {
166 $priceField[$priceFieldBAO->id
]['active_on'] = '';
169 if ($priceFieldBAO->expire_on
== '0000-00-00 00:00:00') {
170 $priceField[$priceFieldBAO->id
]['expire_on'] = '';
173 // need to translate html types from the db
174 $htmlTypes = CRM_Price_BAO_PriceField
::htmlTypes();
175 $priceField[$priceFieldBAO->id
]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id
]['html_type']];
176 $priceField[$priceFieldBAO->id
]['order'] = $priceField[$priceFieldBAO->id
]['weight'];
177 $priceField[$priceFieldBAO->id
]['action'] = CRM_Core_Action
::formLink(
181 'fid' => $priceFieldBAO->id
,
182 'sid' => $this->_sid
,
186 'priceField.row.actions',
192 $returnURL = CRM_Utils_System
::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
193 $filter = "price_set_id = {$this->_sid}";
194 CRM_Utils_Weight
::addOrder($priceField, 'CRM_Price_DAO_PriceField',
195 'id', $returnURL, $filter
197 $this->assign('priceField', $priceField);
203 * editing would involved modifying existing fields + adding data to new fields.
205 * @param string $action the action to be invoked
211 function edit($action) {
212 // create a simple controller for editing price data
213 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Field', ts('Price Field'), $action);
215 // set the userContext stack
216 $session = CRM_Core_Session
::singleton();
217 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
219 $controller->set('sid', $this->_sid
);
220 $controller->setEmbedded(TRUE);
221 $controller->process();
228 * This method is called after the page is created. It checks for the
229 * type of action and executes that action.
239 $this->_sid
= CRM_Utils_Request
::retrieve('sid', 'Positive',
242 $fid = CRM_Utils_Request
::retrieve('fid', 'Positive',
245 $action = CRM_Utils_Request
::retrieve('action', 'String',
246 // default to 'browse'
247 $this, FALSE, 'browse'
251 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($this->_sid
);
252 $this->assign('usedBy', $usedBy);
253 $this->_isSetReserved
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid
, 'is_reserved');
254 $this->assign('isReserved', $this->_isSetReserved
);
256 CRM_Price_BAO_PriceSet
::checkPermission($this->_sid
);
258 'Event' => 'civicrm_event',
259 'Contribution' => 'civicrm_contribution_page',
260 'EventTemplate' => 'civicrm_event_template'
262 $priceSetContexts = array();
263 foreach ($comps as $name => $table) {
264 if (array_key_exists($table, $usedBy)) {
265 $priceSetContexts[] = $name;
268 $this->assign('contexts', $priceSetContexts);
271 if ($action & (CRM_Core_Action
::DELETE
) && !$this->_isSetReserved
) {
272 if (empty($usedBy)) {
274 $session = CRM_Core_Session
::singleton();
275 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
276 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
277 $controller->set('fid', $fid);
278 $controller->setEmbedded(TRUE);
279 $controller->process();
284 $url = CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1');
285 CRM_Utils_System
::appendBreadCrumb(ts('Price'),
288 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField
::getTitle($fid));
293 $groupTitle = CRM_Price_BAO_PriceSet
::getTitle($this->_sid
);
294 $this->assign('sid', $this->_sid
);
295 $this->assign('groupTitle', $groupTitle);
296 CRM_Utils_System
::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
299 // assign vars to templates
300 $this->assign('action', $action);
302 // what action to take ?
303 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
) && !$this->_isSetReserved
) {
304 // no browse for edit/update/view
305 $this->edit($action);
307 elseif ($action & CRM_Core_Action
::PREVIEW
) {
308 $this->preview($fid);
314 // Call the parents run method
315 return parent
::run();
319 * Preview price field
323 * @internal param int $id price field id
328 function preview($fid) {
329 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Form Field'), CRM_Core_Action
::PREVIEW
);
330 $session = CRM_Core_Session
::singleton();
331 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
332 $controller->set('fieldId', $fid);
333 $controller->set('groupId', $this->_sid
);
334 $controller->setEmbedded(TRUE);
335 $controller->process();