3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
21 * Create a page for displaying Price Sets.
23 * Heart of this class is the run method which checks
24 * for action type and then displays the appropriate
28 class CRM_Price_Page_Set
extends CRM_Core_Page
{
31 * The action links that we need to display for the browse screen.
35 private static $_actionLinks;
38 * Get the action links for this page.
41 * array of action links that we need to display for the browse screen
43 public function &actionLinks() {
44 // check if variable _actionsLinks is populated
45 if (!isset(self
::$_actionLinks)) {
46 // helper variable for nicer formatting
47 $deleteExtra = ts('Are you sure you want to delete this price set?');
48 $copyExtra = ts('Are you sure you want to make a copy of this price set?');
49 self
::$_actionLinks = [
50 CRM_Core_Action
::BROWSE
=> [
51 'name' => ts('View and Edit Price Fields'),
52 'url' => 'civicrm/admin/price/field',
53 'qs' => 'reset=1&action=browse&sid=%%sid%%',
54 'title' => ts('View and Edit Price Fields'),
56 CRM_Core_Action
::PREVIEW
=> [
57 'name' => ts('Preview'),
58 'url' => 'civicrm/admin/price',
59 'qs' => 'action=preview&reset=1&sid=%%sid%%',
60 'title' => ts('Preview Price Set'),
62 CRM_Core_Action
::UPDATE
=> [
63 'name' => ts('Settings'),
64 'url' => 'civicrm/admin/price',
65 'qs' => 'action=update&reset=1&sid=%%sid%%',
66 'title' => ts('Edit Price Set'),
68 CRM_Core_Action
::DISABLE
=> [
69 'name' => ts('Disable'),
70 'ref' => 'crm-enable-disable',
71 'title' => ts('Disable Price Set'),
73 CRM_Core_Action
::ENABLE
=> [
74 'name' => ts('Enable'),
75 'ref' => 'crm-enable-disable',
76 'title' => ts('Enable Price Set'),
78 CRM_Core_Action
::DELETE
=> [
79 'name' => ts('Delete'),
80 'url' => 'civicrm/admin/price',
81 'qs' => 'action=delete&reset=1&sid=%%sid%%',
82 'title' => ts('Delete Price Set'),
83 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
85 CRM_Core_Action
::COPY
=> [
86 'name' => ts('Copy Price Set'),
87 'url' => CRM_Utils_System
::currentPath(),
88 'qs' => 'action=copy&sid=%%sid%%',
89 'title' => ts('Make a Copy of Price Set'),
90 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
94 return self
::$_actionLinks;
100 * This method is called after the page is created. It checks for the
101 * type of action and executes that action.
102 * Finally it calls the parent's run method.
106 public function run() {
107 // get the requested action
108 $action = CRM_Utils_Request
::retrieve('action', 'String',
109 // default to 'browse'
110 $this, FALSE, 'browse'
113 // assign vars to templates
114 $this->assign('action', $action);
115 $sid = CRM_Utils_Request
::retrieve('sid', 'Positive',
120 CRM_Price_BAO_PriceSet
::checkPermission($sid);
122 // what action to take ?
123 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
124 $this->edit($sid, $action);
126 elseif ($action & CRM_Core_Action
::PREVIEW
) {
127 $this->preview($sid);
129 elseif ($action & CRM_Core_Action
::COPY
) {
130 CRM_Core_Session
::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
135 // if action is delete do the needful.
136 if ($action & (CRM_Core_Action
::DELETE
)) {
137 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($sid);
139 if (empty($usedBy)) {
141 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
142 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
143 $controller->set('sid', $sid);
144 $controller->setEmbedded(TRUE);
145 $controller->process();
150 $url = CRM_Utils_System
::url('civicrm/admin/price', 'reset=1');
151 CRM_Utils_System
::appendBreadCrumb(ts('Price Sets'), $url);
152 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet
::getTitle($sid));
153 $this->assign('usedBy', $usedBy);
156 'Event' => 'civicrm_event',
157 'Contribution' => 'civicrm_contribution_page',
158 'EventTemplate' => 'civicrm_event_template',
160 $priceSetContexts = [];
161 foreach ($comps as $name => $table) {
162 if (array_key_exists($table, $usedBy)) {
163 $priceSetContexts[] = $name;
166 $this->assign('contexts', $priceSetContexts);
170 // finally browse the price sets
174 return parent
::run();
182 * @param string $action
183 * The action to be invoked.
187 public function edit($sid, $action) {
188 // create a simple controller for editing price sets
189 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
191 // set the userContext stack
192 $session = CRM_Core_Session
::singleton();
193 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
194 $controller->set('sid', $sid);
195 $controller->setEmbedded(TRUE);
196 $controller->process();
208 public function preview($sid) {
209 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
210 $session = CRM_Core_Session
::singleton();
211 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
212 if ($context == 'field') {
213 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
216 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
218 $controller->set('groupId', $sid);
219 $controller->setEmbedded(TRUE);
220 $controller->process();
225 * Browse all price sets.
227 * @param string $action
228 * The action to be invoked.
232 public function browse($action = NULL) {
233 // get all price sets
236 'CiviEvent' => ts('Event'),
237 'CiviContribute' => ts('Contribution'),
238 'CiviMember' => ts('Membership'),
241 $dao = new CRM_Price_DAO_PriceSet();
242 if (CRM_Price_BAO_PriceSet
::eventPriceSetDomainID()) {
243 $dao->domain_id
= CRM_Core_Config
::domainID();
245 $dao->is_quick_config
= 0;
247 while ($dao->fetch()) {
248 $priceSet[$dao->id
] = [];
249 CRM_Core_DAO
::storeValues($dao, $priceSet[$dao->id
]);
251 $compIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
252 CRM_Utils_Array
::value('extends', $priceSet[$dao->id
])
256 foreach ($compIds as $compId) {
257 if (!empty($comps[CRM_Core_Component
::getComponentName($compId)])) {
258 $extends[] = $comps[CRM_Core_Component
::getComponentName($compId)];
261 $priceSet[$dao->id
]['extends'] = implode(', ', $extends);
263 // form all action links
264 $action = array_sum(array_keys($this->actionLinks()));
266 // update enable/disable links depending on price_set properties.
267 if ($dao->is_reserved
) {
268 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DELETE + CRM_Core_Action
::COPY
;
271 if ($dao->is_active
) {
272 $action -= CRM_Core_Action
::ENABLE
;
275 $action -= CRM_Core_Action
::DISABLE
;
278 $actionLinks = self
::actionLinks();
280 if ($dao->is_reserved
) {
281 $actionLinks[CRM_Core_Action
::BROWSE
]['name'] = ts('View Price Fields');
283 $priceSet[$dao->id
]['action'] = CRM_Core_Action
::formLink($actionLinks, $action,
287 'priceSet.row.actions',
292 $this->assign('rows', $priceSet);
296 * make a copy of a price set, including
297 * all the fields in the page
301 public function copy() {
302 $id = CRM_Utils_Request
::retrieve('sid', 'Positive',
303 $this, TRUE, 0, 'GET'
306 CRM_Price_BAO_PriceSet
::copy($id);
308 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));