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 Custom Options.
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_Option
extends CRM_Core_Page
{
46 public $useLivePageJS = TRUE;
49 * The field id of the option
57 * The field id of the option
65 * The price set is reserved or not
70 protected $_isSetReserved = false;
73 * The action links that we need to display for the browse screen
78 private static $_actionLinks;
81 * Get the action links for this page.
85 * @return array array of action links that we need to display for the browse screen
87 */ function &actionLinks() {
88 if (!isset(self
::$_actionLinks)) {
89 self
::$_actionLinks = array(
90 CRM_Core_Action
::UPDATE
=> array(
91 'name' => ts('Edit Option'),
92 'url' => 'civicrm/admin/price/field/option',
93 'qs' => 'reset=1&action=update&oid=%%oid%%&fid=%%fid%%&sid=%%sid%%',
94 'title' => ts('Edit Price Option'),
96 CRM_Core_Action
::VIEW
=> array(
98 'url' => 'civicrm/admin/price/field/option',
99 'qs' => 'action=view&oid=%%oid%%',
100 'title' => ts('View Price Option'),
102 CRM_Core_Action
::DISABLE
=> array(
103 'name' => ts('Disable'),
104 'ref' => 'crm-enable-disable',
105 'title' => ts('Disable Price Option'),
107 CRM_Core_Action
::ENABLE
=> array(
108 'name' => ts('Enable'),
109 'ref' => 'crm-enable-disable',
110 'title' => ts('Enable Price Option'),
112 CRM_Core_Action
::DELETE
=> array(
113 'name' => ts('Delete'),
114 'url' => 'civicrm/admin/price/field/option',
115 'qs' => 'action=delete&oid=%%oid%%',
116 'title' => ts('Disable Price Option'),
120 return self
::$_actionLinks;
124 * Browse all price fields.
132 $customOption = array();
133 CRM_Price_BAO_PriceFieldValue
::getValues($this->_fid
, $customOption);
134 $config = CRM_Core_Config
::singleton();
135 $financialType = CRM_Contribute_PseudoConstant
::financialType();
136 $taxRate = CRM_Core_PseudoConstant
::getTaxRates();
137 // display taxTerm for priceFields
138 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,'contribution_invoice_settings');
139 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
140 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
141 $getTaxDetails = FALSE;
142 foreach ($customOption as $id => $values) {
143 $action = array_sum(array_keys($this->actionLinks()));
144 // Adding the required fields in the array
145 if (isset($taxRate[$values['financial_type_id']])) {
146 $customOption[$id]['tax_rate'] = $taxRate[$values['financial_type_id']];
147 if ($invoicing && isset($customOption[$id]['tax_rate'])) {
148 $getTaxDetails = TRUE;
150 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']);
151 $customOption[$id]['tax_amount'] = $taxAmount['tax_amount'];
153 if (!empty($values['financial_type_id'])){
154 $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']];
156 // update enable/disable links depending on price_field properties.
157 if ($this->_isSetReserved
) {
158 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE
;
161 if ($values['is_active']) {
162 $action -= CRM_Core_Action
::ENABLE
;
165 $action -= CRM_Core_Action
::DISABLE
;
168 if (!empty($customOption[$id]['is_default'])) {
169 $customOption[$id]['is_default'] = '<img src="' . $config->resourceBase
. 'i/check.gif" />';
172 $customOption[$id]['is_default'] = '';
174 $customOption[$id]['order'] = $customOption[$id]['weight'];
175 $customOption[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
178 'fid' => $this->_fid
,
179 'sid' => $this->_sid
,
183 'priceFieldValue.row.actions',
188 // Add order changing widget to selector
189 $returnURL = CRM_Utils_System
::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}");
190 $filter = "price_field_id = {$this->_fid}";
191 CRM_Utils_Weight
::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue',
192 'id', $returnURL, $filter
195 $this->assign('taxTerm', $taxTerm);
196 $this->assign('getTaxDetails', $getTaxDetails);
197 $this->assign('customOption', $customOption);
198 $this->assign('sid', $this->_sid
);
202 * Edit custom Option.
204 * editing would involved modifying existing fields + adding data to new fields.
206 * @param string $action the action to be invoked
211 function edit($action) {
212 $oid = CRM_Utils_Request
::retrieve('oid', 'Positive',
217 $params['oid'] = $oid;
218 $sid = CRM_Price_BAO_PriceSet
::getSetId($params);
220 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($sid);
222 // set the userContext stack
223 $session = CRM_Core_Session
::singleton();
225 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field/option',
226 "reset=1&action=browse&fid={$this->_fid}&sid={$this->_sid}"
228 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Option', ts('Price Field Option'), $action);
229 $controller->set('fid', $this->_fid
);
230 $controller->setEmbedded(TRUE);
231 $controller->process();
234 if ($action & CRM_Core_Action
::DELETE
) {
236 $url = CRM_Utils_System
::url('civicrm/admin/price/field/option', 'reset=1');
237 CRM_Utils_System
::appendBreadCrumb(ts('Price Option'),
240 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceFieldValue
::getOptionLabel($oid));
241 $this->assign('usedBy', $usedBy);
243 "Event" => "civicrm_event",
244 "Contribution" => "civicrm_contribution_page",
246 $priceSetContexts = array();
247 foreach ($comps as $name => $table) {
248 if (array_key_exists($table, $usedBy)) {
249 $priceSetContexts[] = $name;
252 $this->assign('contexts', $priceSetContexts);
259 * This method is called after the page is created. It checks for the
260 * type of action and executes that action.
270 $this->_fid
= CRM_Utils_Request
::retrieve('fid', 'Positive',
273 //get the price set id
275 $this->_sid
= CRM_Utils_Request
::retrieve('sid', 'Positive', $this);
279 CRM_Price_BAO_PriceSet
::checkPermission($this->_sid
);
280 $this->_isSetReserved
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid
, 'is_reserved');
281 $this->assign('isReserved', $this->_isSetReserved
);
283 //as url contain $sid so append breadcrumb dynamically.
284 $breadcrumb = array(array('title' => ts('Price Fields'),
285 'url' => CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid
),
287 CRM_Utils_System
::appendBreadCrumb($breadcrumb);
290 $fieldTitle = CRM_Price_BAO_PriceField
::getTitle($this->_fid
);
291 $this->assign('fid', $this->_fid
);
292 $this->assign('fieldTitle', $fieldTitle);
293 CRM_Utils_System
::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
295 $htmlType = CRM_Core_DAO
::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid
, 'html_type');
296 $this->assign('addMoreFields', TRUE);
297 //for text price field only single option present
298 if ($htmlType == 'Text') {
299 $this->assign('addMoreFields', FALSE);
303 // get the requested action
304 $action = CRM_Utils_Request
::retrieve('action', 'String',
305 // default to 'browse'
306 $this, FALSE, 'browse'
309 // assign vars to templates
310 $this->assign('action', $action);
312 $oid = CRM_Utils_Request
::retrieve('oid', 'Positive',
315 // what action to take ?
316 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD |
317 CRM_Core_Action
::VIEW | CRM_Core_Action
::DELETE
318 ) && !$this->_isSetReserved
) {
319 // no browse for edit/update/view
320 $this->edit($action);
325 // Call the parents run method
326 return parent
::run();