3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
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.
57 * array of action links that we need to display for the browse screen
59 public function &actionLinks() {
60 // check if variable _actionsLinks is populated
61 if (!isset(self
::$_actionLinks)) {
62 // helper variable for nicer formatting
63 $deleteExtra = ts('Are you sure you want to delete this price set?');
64 $copyExtra = ts('Are you sure you want to make a copy of this price set?');
65 self
::$_actionLinks = array(
66 CRM_Core_Action
::BROWSE
=> array(
67 'name' => ts('View and Edit Price Fields'),
68 'url' => 'civicrm/admin/price/field',
69 'qs' => 'reset=1&action=browse&sid=%%sid%%',
70 'title' => ts('View and Edit Price Fields'),
72 CRM_Core_Action
::PREVIEW
=> array(
73 'name' => ts('Preview'),
74 'url' => 'civicrm/admin/price',
75 'qs' => 'action=preview&reset=1&sid=%%sid%%',
76 'title' => ts('Preview Price Set'),
78 CRM_Core_Action
::UPDATE
=> array(
79 'name' => ts('Settings'),
80 'url' => 'civicrm/admin/price',
81 'qs' => 'action=update&reset=1&sid=%%sid%%',
82 'title' => ts('Edit Price Set'),
84 CRM_Core_Action
::DISABLE
=> array(
85 'name' => ts('Disable'),
86 'ref' => 'crm-enable-disable',
87 'title' => ts('Disable Price Set'),
89 CRM_Core_Action
::ENABLE
=> array(
90 'name' => ts('Enable'),
91 'ref' => 'crm-enable-disable',
92 'title' => ts('Enable Price Set'),
94 CRM_Core_Action
::DELETE
=> array(
95 'name' => ts('Delete'),
96 'url' => 'civicrm/admin/price',
97 'qs' => 'action=delete&reset=1&sid=%%sid%%',
98 'title' => ts('Delete Price Set'),
99 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
101 CRM_Core_Action
::COPY
=> array(
102 'name' => ts('Copy Price Set'),
103 'url' => CRM_Utils_System
::currentPath(),
104 'qs' => 'action=copy&sid=%%sid%%',
105 'title' => ts('Make a Copy of Price Set'),
106 'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
110 return self
::$_actionLinks;
116 * This method is called after the page is created. It checks for the
117 * type of action and executes that action.
118 * Finally it calls the parent's run method.
122 public function run() {
123 // get the requested action
124 $action = CRM_Utils_Request
::retrieve('action', 'String',
125 // default to 'browse'
126 $this, FALSE, 'browse'
129 // assign vars to templates
130 $this->assign('action', $action);
131 $sid = CRM_Utils_Request
::retrieve('sid', 'Positive',
136 CRM_Price_BAO_PriceSet
::checkPermission($sid);
138 // what action to take ?
139 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD
)) {
140 $this->edit($sid, $action);
142 elseif ($action & CRM_Core_Action
::PREVIEW
) {
143 $this->preview($sid);
145 elseif ($action & CRM_Core_Action
::COPY
) {
146 CRM_Core_Session
::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
151 // if action is delete do the needful.
152 if ($action & (CRM_Core_Action
::DELETE
)) {
153 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($sid);
155 if (empty($usedBy)) {
157 CRM_Core_Session
::singleton()->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
158 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
159 $controller->set('sid', $sid);
160 $controller->setEmbedded(TRUE);
161 $controller->process();
166 $url = CRM_Utils_System
::url('civicrm/admin/price', 'reset=1');
167 CRM_Utils_System
::appendBreadCrumb(ts('Price Sets'), $url);
168 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet
::getTitle($sid));
169 $this->assign('usedBy', $usedBy);
172 'Event' => 'civicrm_event',
173 'Contribution' => 'civicrm_contribution_page',
174 'EventTemplate' => 'civicrm_event_template',
176 $priceSetContexts = array();
177 foreach ($comps as $name => $table) {
178 if (array_key_exists($table, $usedBy)) {
179 $priceSetContexts[] = $name;
182 $this->assign('contexts', $priceSetContexts);
186 // finally browse the price sets
190 return parent
::run();
198 * @param string $action
199 * The action to be invoked.
203 public function edit($sid, $action) {
204 // create a simple controller for editing price sets
205 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
207 // set the userContext stack
208 $session = CRM_Core_Session
::singleton();
209 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
210 $controller->set('sid', $sid);
211 $controller->setEmbedded(TRUE);
212 $controller->process();
224 public function preview($sid) {
225 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
226 $session = CRM_Core_Session
::singleton();
227 $context = CRM_Utils_Request
::retrieve('context', 'Alphanumeric', $this);
228 if ($context == 'field') {
229 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
232 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price', 'action=browse'));
234 $controller->set('groupId', $sid);
235 $controller->setEmbedded(TRUE);
236 $controller->process();
241 * Browse all price sets.
243 * @param string $action
244 * The action to be invoked.
248 public function browse($action = NULL) {
249 // get all price sets
252 'CiviEvent' => ts('Event'),
253 'CiviContribute' => ts('Contribution'),
254 'CiviMember' => ts('Membership'),
257 $dao = new CRM_Price_DAO_PriceSet();
258 if (CRM_Price_BAO_PriceSet
::eventPriceSetDomainID()) {
259 $dao->domain_id
= CRM_Core_Config
::domainID();
261 $dao->is_quick_config
= 0;
263 while ($dao->fetch()) {
264 $priceSet[$dao->id
] = array();
265 CRM_Core_DAO
::storeValues($dao, $priceSet[$dao->id
]);
267 $compIds = explode(CRM_Core_DAO
::VALUE_SEPARATOR
,
268 CRM_Utils_Array
::value('extends', $priceSet[$dao->id
])
272 foreach ($compIds as $compId) {
273 if (!empty($comps[CRM_Core_Component
::getComponentName($compId)])) {
274 $extends[] = $comps[CRM_Core_Component
::getComponentName($compId)];
277 $priceSet[$dao->id
]['extends'] = implode(', ', $extends);
279 // form all action links
280 $action = array_sum(array_keys($this->actionLinks()));
282 // update enable/disable links depending on price_set properties.
283 if ($dao->is_reserved
) {
284 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE + CRM_Core_Action
::DELETE + CRM_Core_Action
::COPY
;
287 if ($dao->is_active
) {
288 $action -= CRM_Core_Action
::ENABLE
;
291 $action -= CRM_Core_Action
::DISABLE
;
294 $actionLinks = self
::actionLinks();
296 if ($dao->is_reserved
) {
297 $actionLinks[CRM_Core_Action
::BROWSE
]['name'] = ts('View Price Fields');
299 $priceSet[$dao->id
]['action'] = CRM_Core_Action
::formLink($actionLinks, $action,
300 array('sid' => $dao->id
),
303 'priceSet.row.actions',
308 $this->assign('rows', $priceSet);
312 * make a copy of a price set, including
313 * all the fields in the page
317 public function copy() {
318 $id = CRM_Utils_Request
::retrieve('sid', 'Positive',
319 $this, TRUE, 0, 'GET'
322 CRM_Price_BAO_PriceSet
::copy($id);
324 CRM_Utils_System
::redirect(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1'));