3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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
56 * The field id of the option
63 * The price set is reserved or not
67 protected $_isSetReserved = false;
70 * The action links that we need to display for the browse screen
74 private static $_actionLinks;
77 * Get the action links for this page.
81 * @return array array of action links that we need to display for the browse screen
82 */ function &actionLinks() {
83 if (!isset(self
::$_actionLinks)) {
84 self
::$_actionLinks = array(
85 CRM_Core_Action
::UPDATE
=> array(
86 'name' => ts('Edit Option'),
87 'url' => 'civicrm/admin/price/field/option',
88 'qs' => 'reset=1&action=update&oid=%%oid%%&fid=%%fid%%&sid=%%sid%%',
89 'title' => ts('Edit Price Option'),
91 CRM_Core_Action
::VIEW
=> array(
93 'url' => 'civicrm/admin/price/field/option',
94 'qs' => 'action=view&oid=%%oid%%',
95 'title' => ts('View Price Option'),
97 CRM_Core_Action
::DISABLE
=> array(
98 'name' => ts('Disable'),
99 'ref' => 'crm-enable-disable',
100 'title' => ts('Disable Price Option'),
102 CRM_Core_Action
::ENABLE
=> array(
103 'name' => ts('Enable'),
104 'ref' => 'crm-enable-disable',
105 'title' => ts('Enable Price Option'),
107 CRM_Core_Action
::DELETE
=> array(
108 'name' => ts('Delete'),
109 'url' => 'civicrm/admin/price/field/option',
110 'qs' => 'action=delete&oid=%%oid%%',
111 'title' => ts('Disable Price Option'),
115 return self
::$_actionLinks;
119 * Browse all price fields.
125 public function browse() {
126 $customOption = array();
127 CRM_Price_BAO_PriceFieldValue
::getValues($this->_fid
, $customOption);
128 $config = CRM_Core_Config
::singleton();
129 $financialType = CRM_Contribute_PseudoConstant
::financialType();
130 $taxRate = CRM_Core_PseudoConstant
::getTaxRates();
131 // display taxTerm for priceFields
132 $invoiceSettings = CRM_Core_BAO_Setting
::getItem(CRM_Core_BAO_Setting
::CONTRIBUTE_PREFERENCES_NAME
,'contribution_invoice_settings');
133 $taxTerm = CRM_Utils_Array
::value('tax_term', $invoiceSettings);
134 $invoicing = CRM_Utils_Array
::value('invoicing', $invoiceSettings);
135 $getTaxDetails = FALSE;
136 foreach ($customOption as $id => $values) {
137 $action = array_sum(array_keys($this->actionLinks()));
138 // Adding the required fields in the array
139 if (isset($taxRate[$values['financial_type_id']])) {
140 $customOption[$id]['tax_rate'] = $taxRate[$values['financial_type_id']];
141 if ($invoicing && isset($customOption[$id]['tax_rate'])) {
142 $getTaxDetails = TRUE;
144 $taxAmount = CRM_Contribute_BAO_Contribution_Utils
::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']);
145 $customOption[$id]['tax_amount'] = $taxAmount['tax_amount'];
147 if (!empty($values['financial_type_id'])){
148 $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']];
150 // update enable/disable links depending on price_field properties.
151 if ($this->_isSetReserved
) {
152 $action -= CRM_Core_Action
::UPDATE + CRM_Core_Action
::DELETE + CRM_Core_Action
::DISABLE + CRM_Core_Action
::ENABLE
;
155 if ($values['is_active']) {
156 $action -= CRM_Core_Action
::ENABLE
;
159 $action -= CRM_Core_Action
::DISABLE
;
162 if (!empty($customOption[$id]['is_default'])) {
163 $customOption[$id]['is_default'] = '<img src="' . $config->resourceBase
. 'i/check.gif" />';
166 $customOption[$id]['is_default'] = '';
168 $customOption[$id]['order'] = $customOption[$id]['weight'];
169 $customOption[$id]['action'] = CRM_Core_Action
::formLink(self
::actionLinks(), $action,
172 'fid' => $this->_fid
,
173 'sid' => $this->_sid
,
177 'priceFieldValue.row.actions',
182 // Add order changing widget to selector
183 $returnURL = CRM_Utils_System
::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}");
184 $filter = "price_field_id = {$this->_fid}";
185 CRM_Utils_Weight
::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue',
186 'id', $returnURL, $filter
189 $this->assign('taxTerm', $taxTerm);
190 $this->assign('getTaxDetails', $getTaxDetails);
191 $this->assign('customOption', $customOption);
192 $this->assign('sid', $this->_sid
);
196 * Edit custom Option.
198 * editing would involved modifying existing fields + adding data to new fields.
200 * @param string $action the action to be invoked
204 public function edit($action) {
205 $oid = CRM_Utils_Request
::retrieve('oid', 'Positive',
210 $params['oid'] = $oid;
211 $sid = CRM_Price_BAO_PriceSet
::getSetId($params);
213 $usedBy = CRM_Price_BAO_PriceSet
::getUsedBy($sid);
215 // set the userContext stack
216 $session = CRM_Core_Session
::singleton();
218 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin/price/field/option',
219 "reset=1&action=browse&fid={$this->_fid}&sid={$this->_sid}"
221 $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Option', ts('Price Field Option'), $action);
222 $controller->set('fid', $this->_fid
);
223 $controller->setEmbedded(TRUE);
224 $controller->process();
227 if ($action & CRM_Core_Action
::DELETE
) {
229 $url = CRM_Utils_System
::url('civicrm/admin/price/field/option', 'reset=1');
230 CRM_Utils_System
::appendBreadCrumb(ts('Price Option'),
233 $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceFieldValue
::getOptionLabel($oid));
234 $this->assign('usedBy', $usedBy);
236 "Event" => "civicrm_event",
237 "Contribution" => "civicrm_contribution_page",
239 $priceSetContexts = array();
240 foreach ($comps as $name => $table) {
241 if (array_key_exists($table, $usedBy)) {
242 $priceSetContexts[] = $name;
245 $this->assign('contexts', $priceSetContexts);
252 * This method is called after the page is created. It checks for the
253 * type of action and executes that action.
259 public function run() {
262 $this->_fid
= CRM_Utils_Request
::retrieve('fid', 'Positive',
265 //get the price set id
267 $this->_sid
= CRM_Utils_Request
::retrieve('sid', 'Positive', $this);
271 CRM_Price_BAO_PriceSet
::checkPermission($this->_sid
);
272 $this->_isSetReserved
= CRM_Core_DAO
::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid
, 'is_reserved');
273 $this->assign('isReserved', $this->_isSetReserved
);
275 //as url contain $sid so append breadcrumb dynamically.
276 $breadcrumb = array(array('title' => ts('Price Fields'),
277 'url' => CRM_Utils_System
::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid
),
279 CRM_Utils_System
::appendBreadCrumb($breadcrumb);
282 $fieldTitle = CRM_Price_BAO_PriceField
::getTitle($this->_fid
);
283 $this->assign('fid', $this->_fid
);
284 $this->assign('fieldTitle', $fieldTitle);
285 CRM_Utils_System
::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle)));
287 $htmlType = CRM_Core_DAO
::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid
, 'html_type');
288 $this->assign('addMoreFields', TRUE);
289 //for text price field only single option present
290 if ($htmlType == 'Text') {
291 $this->assign('addMoreFields', FALSE);
295 // get the requested action
296 $action = CRM_Utils_Request
::retrieve('action', 'String',
297 // default to 'browse'
298 $this, FALSE, 'browse'
301 // assign vars to templates
302 $this->assign('action', $action);
304 $oid = CRM_Utils_Request
::retrieve('oid', 'Positive',
307 // what action to take ?
308 if ($action & (CRM_Core_Action
::UPDATE | CRM_Core_Action
::ADD |
309 CRM_Core_Action
::VIEW | CRM_Core_Action
::DELETE
310 ) && !$this->_isSetReserved
) {
311 // no browse for edit/update/view
312 $this->edit($action);
317 // Call the parents run method
318 return parent
::run();