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'] = $htmlTypes[$priceField[$priceFieldBAO->id
]['html_type']];
174 $priceField[$priceFieldBAO->id
]['order'] = $priceField[$priceFieldBAO->id
]['weight'];
175 $priceField[$priceFieldBAO->id
]['action'] = CRM_Core_Action
::formLink(
179 'fid' => $priceFieldBAO->id
,
180 'sid' => $this->_sid
,
184 'priceField.row.actions',
190 $returnURL = CRM_Utils_System
::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
191 $filter = "price_set_id = {$this->_sid}";
192 CRM_Utils_Weight
::addOrder($priceField, 'CRM_Price_DAO_PriceField',
193 'id', $returnURL, $filter
195 $this->assign('priceField', $priceField);
201 * editing would involved modifying existing fields + adding data to new fields.
203 * @param string $action the action to be invoked
209 function edit($action) {
210 // create a simple controller for editing price data
211 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Field', ts('Price Field'), $action);
213 // set the userContext stack
214 $session = CRM_Core_Session
::singleton();
215 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
217 $controller->set('sid', $this->_sid
);
218 $controller->setEmbedded(TRUE);
219 $controller->process();
226 * This method is called after the page is created. It checks for the
227 * type of action and executes that action.
237 $this->_sid
= CRM_Utils_Request
::retrieve('sid', 'Positive',
240 $fid = CRM_Utils_Request
::retrieve('fid', 'Positive',
243 $action = CRM_Utils_Request
::retrieve('action', 'String',
244 // default to 'browse'
245 $this, FALSE, 'browse'
249 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($this->_sid
);
250 $this->assign('usedBy', $usedBy);
251 $this->_isSetReserved
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid
, 'is_reserved');
252 $this->assign('isReserved', $this->_isSetReserved
);
254 CRM_Price_BAO_PriceSet
::checkPermission($this->_sid
);
256 'Event' => 'civicrm_event',
257 'Contribution' => 'civicrm_contribution_page',
258 'EventTemplate' => 'civicrm_event_template'
260 $priceSetContexts = array();
261 foreach ($comps as $name => $table) {
262 if (array_key_exists($table, $usedBy)) {
263 $priceSetContexts[] = $name;
266 $this->assign('contexts', $priceSetContexts);
269 if ($action & (CRM_Core_Action
::DELETE
) && !$this->_isSetReserved
) {
270 if (empty($usedBy)) {
272 $session = CRM_Core_Session
::singleton();
273 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
274 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
275 $controller->set('fid', $fid);
276 $controller->setEmbedded(TRUE);
277 $controller->process();
282 $url = CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1');
283 CRM_Utils_System
::appendBreadCrumb(ts('Price'),
286 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField
::getTitle($fid));
291 $groupTitle = CRM_Price_BAO_PriceSet
::getTitle($this->_sid
);
292 $this->assign('sid', $this->_sid
);
293 $this->assign('groupTitle', $groupTitle);
294 CRM_Utils_System
::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
297 // assign vars to templates
298 $this->assign('action', $action);
300 // what action to take ?
301 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
) && !$this->_isSetReserved
) {
302 // no browse for edit/update/view
303 $this->edit($action);
305 elseif ($action & CRM_Core_Action
::PREVIEW
) {
306 $this->preview($fid);
312 // Call the parents run method
313 return parent
::run();
317 * Preview price field
319 * @param int $id price field id
324 function preview($fid) {
325 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Form Field'), CRM_Core_Action
::PREVIEW
);
326 $session = CRM_Core_Session
::singleton();
327 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid
));
328 $controller->set('fieldId', $fid);
329 $controller->set('groupId', $this->_sid
);
330 $controller->setEmbedded(TRUE);
331 $controller->process();