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
19 * Create a page for displaying Price Sets.
21 * Heart of this class is the run method which checks
22 * for action type and then displays the appropriate
26 class CRM_Price_Page_Set
extends CRM_Core_Page
{
29 * The action links that we need to display for the browse screen.
33 private static $_actionLinks;
36 * Get the action links for this page.
39 * array of action links that we need to display for the browse screen
41 public function &actionLinks() {
42 // check if variable _actionsLinks is populated
43 if (!isset(self
::$_actionLinks)) {
44 // helper variable for nicer formatting
45 $deleteExtra = ts('Are you sure you want to delete this price set?');
46 $copyExtra = ts('Are you sure you want to make a copy of this price set?');
47 self
::$_actionLinks = [
48 CRM_Core_Action
::BROWSE
=> [
49 'name' => ts('View and Edit Price Fields'),
50 'url' => 'civicrm/admin/price/field',
51 'qs' => 'reset=1&action=browse&sid=%%sid%%',
52 'title' => ts('View and Edit Price Fields'),
54 CRM_Core_Action
::PREVIEW
=> [
55 'name' => ts('Preview'),
56 'url' => 'civicrm/admin/price',
57 'qs' => 'action=preview&reset=1&sid=%%sid%%',
58 'title' => ts('Preview Price Set'),
60 CRM_Core_Action
::UPDATE
=> [
61 'name' => ts('Settings'),
62 'url' => 'civicrm/admin/price',
63 'qs' => 'action=update&reset=1&sid=%%sid%%',
64 'title' => ts('Edit Price Set'),
66 CRM_Core_Action
::DISABLE
=> [
67 'name' => ts('Disable'),
68 'ref' => 'crm-enable-disable',
69 'title' => ts('Disable Price Set'),
71 CRM_Core_Action
::ENABLE
=> [
72 'name' => ts('Enable'),
73 'ref' => 'crm-enable-disable',
74 'title' => ts('Enable Price Set'),
76 CRM_Core_Action
::DELETE
=> [
77 'name' => ts('Delete'),
78 'url' => 'civicrm/admin/price',
79 'qs' => 'action=delete&reset=1&sid=%%sid%%',
80 'title' => ts('Delete Price Set'),
81 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
83 CRM_Core_Action
::COPY
=> [
84 'name' => ts('Copy Price Set'),
85 'url' => CRM_Utils_System
::currentPath(),
86 'qs' => 'action=copy&sid=%%sid%%',
87 'title' => ts('Make a Copy of Price Set'),
88 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
92 return self
::$_actionLinks;
98 * This method is called after the page is created. It checks for the
99 * type of action and executes that action.
100 * Finally it calls the parent's run method.
104 public function run() {
105 // get the requested action
106 $action = CRM_Utils_Request
::retrieve('action', 'String',
107 // default to 'browse'
108 $this, FALSE, 'browse'
111 // assign vars to templates
112 $this->assign('action', $action);
113 $sid = CRM_Utils_Request
::retrieve('sid', 'Positive',
118 CRM_Price_BAO_PriceSet
::checkPermission($sid);
120 // what action to take ?
121 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
122 $this->edit($sid, $action);
124 elseif ($action & CRM_Core_Action
::PREVIEW
) {
125 $this->preview($sid);
127 elseif ($action & CRM_Core_Action
::COPY
) {
128 CRM_Core_Session
::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
133 // if action is delete do the needful.
134 if ($action & (CRM_Core_Action
::DELETE
)) {
135 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($sid);
137 if (empty($usedBy)) {
139 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
140 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
141 $controller->set('sid', $sid);
142 $controller->setEmbedded(TRUE);
143 $controller->process();
148 $url = CRM_Utils_System
::url('civicrm/admin/price', 'reset=1');
149 CRM_Utils_System
::appendBreadCrumb(ts('Price Sets'), $url);
150 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet
::getTitle($sid));
151 $this->assign('usedBy', $usedBy);
154 'Event' => 'civicrm_event',
155 'Contribution' => 'civicrm_contribution_page',
156 'EventTemplate' => 'civicrm_event_template',
158 $priceSetContexts = [];
159 foreach ($comps as $name => $table) {
160 if (array_key_exists($table, $usedBy)) {
161 $priceSetContexts[] = $name;
164 $this->assign('contexts', $priceSetContexts);
168 // finally browse the price sets
172 return parent
::run();
180 * @param string $action
181 * The action to be invoked.
185 public function edit($sid, $action) {
186 // create a simple controller for editing price sets
187 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
189 // set the userContext stack
190 $session = CRM_Core_Session
::singleton();
191 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
192 $controller->set('sid', $sid);
193 $controller->setEmbedded(TRUE);
194 $controller->process();
206 public function preview($sid) {
207 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
208 $session = CRM_Core_Session
::singleton();
209 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
210 if ($context == 'field') {
211 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
214 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
216 $controller->set('groupId', $sid);
217 $controller->setEmbedded(TRUE);
218 $controller->process();
223 * Browse all price sets.
225 * @param string $action
226 * The action to be invoked.
230 public function browse($action = NULL) {
231 // get all price sets
234 'CiviEvent' => ts('Event'),
235 'CiviContribute' => ts('Contribution'),
236 'CiviMember' => ts('Membership'),
239 $dao = new CRM_Price_DAO_PriceSet();
240 if (CRM_Price_BAO_PriceSet
::eventPriceSetDomainID()) {
241 $dao->domain_id
= CRM_Core_Config
::domainID();
243 $dao->is_quick_config
= 0;
245 while ($dao->fetch()) {
246 $priceSet[$dao->id
] = [];
247 CRM_Core_DAO
::storeValues($dao, $priceSet[$dao->id
]);
249 $compIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
250 CRM_Utils_Array
::value('extends', $priceSet[$dao->id
])
254 foreach ($compIds as $compId) {
255 if (!empty($comps[CRM_Core_Component
::getComponentName($compId)])) {
256 $extends[] = $comps[CRM_Core_Component
::getComponentName($compId)];
259 $priceSet[$dao->id
]['extends'] = implode(', ', $extends);
261 // form all action links
262 $action = array_sum(array_keys($this->actionLinks()));
264 // update enable/disable links depending on price_set properties.
265 if ($dao->is_reserved
) {
266 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DELETE + CRM_Core_Action
::COPY
;
269 if ($dao->is_active
) {
270 $action -= CRM_Core_Action
::ENABLE
;
273 $action -= CRM_Core_Action
::DISABLE
;
276 $actionLinks = self
::actionLinks();
278 if ($dao->is_reserved
) {
279 $actionLinks[CRM_Core_Action
::BROWSE
]['name'] = ts('View Price Fields');
281 $priceSet[$dao->id
]['action'] = CRM_Core_Action
::formLink($actionLinks, $action,
285 'priceSet.row.actions',
290 $this->assign('rows', $priceSet);
294 * make a copy of a price set, including
295 * all the fields in the page
299 public function copy() {
300 $id = CRM_Utils_Request
::retrieve('sid', 'Positive',
301 $this, TRUE, 0, 'GET'
304 CRM_Price_BAO_PriceSet
::copy($id);
306 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));