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 Sets.
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_Set
extends CRM_Core_Page
{
47 * The action links that we need to display for the browse screen
51 private static $_actionLinks;
54 * Get the action links for this page.
58 * @return array array of action links that we need to display for the browse screen
60 */ function &actionLinks() {
61 // check if variable _actionsLinks is populated
62 if (!isset(self
::$_actionLinks)) {
63 // helper variable for nicer formatting
64 $deleteExtra = ts('Are you sure you want to delete this price set?');
65 $copyExtra = ts('Are you sure you want to make a copy of this price set?');
66 self
::$_actionLinks = array(
67 CRM_Core_Action
::BROWSE
=> array(
68 'name' => ts('View and Edit Price Fields'),
69 'url' => 'civicrm/admin/price/field',
70 'qs' => 'reset=1&action=browse&sid=%%sid%%',
71 'title' => ts('View and Edit Price Fields'),
73 CRM_Core_Action
::PREVIEW
=> array(
74 'name' => ts('Preview'),
75 'url' => 'civicrm/admin/price',
76 'qs' => 'action=preview&reset=1&sid=%%sid%%',
77 'title' => ts('Preview Price Set'),
79 CRM_Core_Action
::UPDATE
=> array(
80 'name' => ts('Settings'),
81 'url' => 'civicrm/admin/price',
82 'qs' => 'action=update&reset=1&sid=%%sid%%',
83 'title' => ts('Edit Price Set'),
85 CRM_Core_Action
::DISABLE
=> array(
86 'name' => ts('Disable'),
87 'ref' => 'crm-enable-disable',
88 'title' => ts('Disable Price Set'),
90 CRM_Core_Action
::ENABLE
=> array(
91 'name' => ts('Enable'),
92 'ref' => 'crm-enable-disable',
93 'title' => ts('Enable Price Set'),
95 CRM_Core_Action
::DELETE
=> array(
96 'name' => ts('Delete'),
97 'url' => 'civicrm/admin/price',
98 'qs' => 'action=delete&reset=1&sid=%%sid%%',
99 'title' => ts('Delete Price Set'),
100 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
102 CRM_Core_Action
::COPY
=> array(
103 'name' => ts('Copy Price Set'),
104 'url' => CRM_Utils_System
::currentPath(),
105 'qs' => 'action=copy&sid=%%sid%%',
106 'title' => ts('Make a Copy of Price Set'),
107 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
111 return self
::$_actionLinks;
117 * This method is called after the page is created. It checks for the
118 * type of action and executes that action.
119 * Finally it calls the parent's run method.
128 // get the requested action
129 $action = CRM_Utils_Request
::retrieve('action', 'String',
130 // default to 'browse'
131 $this, FALSE, 'browse'
134 // assign vars to templates
135 $this->assign('action', $action);
136 $sid = CRM_Utils_Request
::retrieve('sid', 'Positive',
141 CRM_Price_BAO_PriceSet
::checkPermission($sid);
143 // what action to take ?
144 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
145 $this->edit($sid, $action);
147 elseif ($action & CRM_Core_Action
::PREVIEW
) {
148 $this->preview($sid);
150 elseif ($action & CRM_Core_Action
::COPY
) {
151 $session = CRM_Core_Session
::singleton();
152 CRM_Core_Session
::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
157 // if action is delete do the needful.
158 if ($action & (CRM_Core_Action
::DELETE
)) {
159 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($sid);
161 if (empty($usedBy)) {
163 $session = CRM_Core_Session
::singleton();
164 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
165 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
166 // $id = CRM_Utils_Request::retrieve('sid', 'Positive', $this, false, 0);
167 $controller->set('sid', $sid);
168 $controller->setEmbedded(TRUE);
169 $controller->process();
174 $url = CRM_Utils_System
::url('civicrm/admin/price', 'reset=1');
175 CRM_Utils_System
::appendBreadCrumb(ts('Price Sets'), $url);
176 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet
::getTitle($sid));
177 $this->assign('usedBy', $usedBy);
180 'Event' => 'civicrm_event',
181 'Contribution' => 'civicrm_contribution_page',
182 'EventTemplate' => 'civicrm_event_template'
184 $priceSetContexts = array();
185 foreach ($comps as $name => $table) {
186 if (array_key_exists($table, $usedBy)) {
187 $priceSetContexts[] = $name;
190 $this->assign('contexts', $priceSetContexts);
194 // finally browse the price sets
198 return parent
::run();
205 * @param string $action the action to be invoked
207 * @internal param int $id price set id
211 function edit($sid, $action) {
212 // create a simple controller for editing price sets
213 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
215 // set the userContext stack
216 $session = CRM_Core_Session
::singleton();
217 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
218 $controller->set('sid', $sid);
219 $controller->setEmbedded(TRUE);
220 $controller->process();
229 * @internal param int $id price set id
234 function preview($sid) {
235 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
236 $session = CRM_Core_Session
::singleton();
237 $context = CRM_Utils_Request
::retrieve('context', 'String', $this);
238 if ($context == 'field') {
239 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
242 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
244 $controller->set('groupId', $sid);
245 $controller->setEmbedded(TRUE);
246 $controller->process();
251 * Browse all price sets
253 * @param string $action the action to be invoked
258 function browse($action = NULL) {
259 // get all price sets
261 $comps = array('CiviEvent' => ts('Event'),
262 'CiviContribute' => ts('Contribution'),
263 'CiviMember' => ts('Membership'),
266 $dao = new CRM_Price_DAO_PriceSet();
267 if (CRM_Price_BAO_PriceSet
::eventPriceSetDomainID()) {
268 $dao->domain_id
= CRM_Core_Config
::domainID();
270 $dao->is_quick_config
= 0;
272 while ($dao->fetch()) {
273 $priceSet[$dao->id
] = array();
274 CRM_Core_DAO
::storeValues($dao, $priceSet[$dao->id
]);
276 $compIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
277 CRM_Utils_Array
::value('extends', $priceSet[$dao->id
])
281 foreach ($compIds as $compId) {
282 if (!empty($comps[CRM_Core_Component
::getComponentName($compId)])) {
283 $extends[] = $comps[CRM_Core_Component
::getComponentName($compId)];
286 $priceSet[$dao->id
]['extends'] = implode(', ', $extends);
288 // form all action links
289 $action = array_sum(array_keys($this->actionLinks()));
291 // update enable/disable links depending on price_set properties.
292 if ($dao->is_reserved
) {
293 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DELETE + CRM_Core_Action
::COPY
;
296 if ($dao->is_active
) {
297 $action -= CRM_Core_Action
::ENABLE
;
300 $action -= CRM_Core_Action
::DISABLE
;
303 $actionLinks = self
::actionLinks();
305 if ($dao->is_reserved
) {
306 $actionLinks[CRM_Core_Action
::BROWSE
]['name'] = 'View Price Fields';
308 $priceSet[$dao->id
]['action'] = CRM_Core_Action
::formLink($actionLinks, $action,
309 array('sid' => $dao->id
),
312 'priceSet.row.actions',
317 $this->assign('rows', $priceSet);
321 * This function is to make a copy of a price set, including
322 * all the fields in the page
328 $id = CRM_Utils_Request
::retrieve('sid', 'Positive',
329 $this, TRUE, 0, 'GET'
332 CRM_Price_BAO_PriceSet
::copy($id);
334 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));