array( 'name' => ts('Edit Option'), 'url' => 'civicrm/admin/price/field/option', 'qs' => 'reset=1&action=update&oid=%%oid%%&fid=%%fid%%&sid=%%sid%%', 'title' => ts('Edit Price Option'), ), CRM_Core_Action::VIEW => array( 'name' => ts('View'), 'url' => 'civicrm/admin/price/field/option', 'qs' => 'action=view&oid=%%oid%%', 'title' => ts('View Price Option'), ), CRM_Core_Action::DISABLE => array( 'name' => ts('Disable'), 'ref' => 'crm-enable-disable', 'title' => ts('Disable Price Option'), ), CRM_Core_Action::ENABLE => array( 'name' => ts('Enable'), 'ref' => 'crm-enable-disable', 'title' => ts('Enable Price Option'), ), CRM_Core_Action::DELETE => array( 'name' => ts('Delete'), 'url' => 'civicrm/admin/price/field/option', 'qs' => 'action=delete&oid=%%oid%%', 'title' => ts('Disable Price Option'), ), ); } return self::$_actionLinks; } /** * Browse all price fields. * * @param null * * @return void */ public function browse() { $customOption = array(); CRM_Price_BAO_PriceFieldValue::getValues($this->_fid, $customOption); $config = CRM_Core_Config::singleton(); $financialType = CRM_Contribute_PseudoConstant::financialType(); $taxRate = CRM_Core_PseudoConstant::getTaxRates(); // display taxTerm for priceFields $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings'); $taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings); $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings); $getTaxDetails = FALSE; foreach ($customOption as $id => $values) { $action = array_sum(array_keys($this->actionLinks())); // Adding the required fields in the array if (isset($taxRate[$values['financial_type_id']])) { $customOption[$id]['tax_rate'] = $taxRate[$values['financial_type_id']]; if ($invoicing && isset($customOption[$id]['tax_rate'])) { $getTaxDetails = TRUE; } $taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($customOption[$id]['amount'], $customOption[$id]['tax_rate']); $customOption[$id]['tax_amount'] = $taxAmount['tax_amount']; } if (!empty($values['financial_type_id'])) { $customOption[$id]['financial_type_id'] = $financialType[$values['financial_type_id']]; } // update enable/disable links depending on price_field properties. if ($this->_isSetReserved) { $action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE; } else { if ($values['is_active']) { $action -= CRM_Core_Action::ENABLE; } else { $action -= CRM_Core_Action::DISABLE; } } if (!empty($customOption[$id]['is_default'])) { $customOption[$id]['is_default'] = ''; } else { $customOption[$id]['is_default'] = ''; } $customOption[$id]['order'] = $customOption[$id]['weight']; $customOption[$id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array( 'oid' => $id, 'fid' => $this->_fid, 'sid' => $this->_sid, ), ts('more'), FALSE, 'priceFieldValue.row.actions', 'PriceFieldValue', $id ); } // Add order changing widget to selector $returnURL = CRM_Utils_System::url('civicrm/admin/price/field/option', "action=browse&reset=1&fid={$this->_fid}&sid={$this->_sid}"); $filter = "price_field_id = {$this->_fid}"; CRM_Utils_Weight::addOrder($customOption, 'CRM_Price_DAO_PriceFieldValue', 'id', $returnURL, $filter ); $this->assign('taxTerm', $taxTerm); $this->assign('getTaxDetails', $getTaxDetails); $this->assign('customOption', $customOption); $this->assign('sid', $this->_sid); } /** * Edit custom Option. * * editing would involved modifying existing fields + adding data to new fields. * * @param string $action * The action to be invoked. * * @return void */ public function edit($action) { $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE, 0 ); $params = array(); if ($oid) { $params['oid'] = $oid; $sid = CRM_Price_BAO_PriceSet::getSetId($params); $usedBy = CRM_Price_BAO_PriceSet::getUsedBy($sid); } // set the userContext stack $session = CRM_Core_Session::singleton(); $session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field/option', "reset=1&action=browse&fid={$this->_fid}&sid={$this->_sid}" )); $controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Option', ts('Price Field Option'), $action); $controller->set('fid', $this->_fid); $controller->setEmbedded(TRUE); $controller->process(); $controller->run(); if ($action & CRM_Core_Action::DELETE) { // add breadcrumb $url = CRM_Utils_System::url('civicrm/admin/price/field/option', 'reset=1'); CRM_Utils_System::appendBreadCrumb(ts('Price Option'), $url ); $this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceFieldValue::getOptionLabel($oid)); $this->assign('usedBy', $usedBy); $comps = array( "Event" => "civicrm_event", "Contribution" => "civicrm_contribution_page", ); $priceSetContexts = array(); foreach ($comps as $name => $table) { if (array_key_exists($table, $usedBy)) { $priceSetContexts[] = $name; } } $this->assign('contexts', $priceSetContexts); } } /** * Run the page. * * This method is called after the page is created. It checks for the * type of action and executes that action. * * @param null * * @return void */ public function run() { // get the field id $this->_fid = CRM_Utils_Request::retrieve('fid', 'Positive', $this, FALSE, 0 ); //get the price set id if (!$this->_sid) { $this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive', $this); } if ($this->_sid) { CRM_Price_BAO_PriceSet::checkPermission($this->_sid); $this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved'); $this->assign('isReserved', $this->_isSetReserved); } //as url contain $sid so append breadcrumb dynamically. $breadcrumb = array( array( 'title' => ts('Price Fields'), 'url' => CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&sid=' . $this->_sid), ), ); CRM_Utils_System::appendBreadCrumb($breadcrumb); if ($this->_fid) { $fieldTitle = CRM_Price_BAO_PriceField::getTitle($this->_fid); $this->assign('fid', $this->_fid); $this->assign('fieldTitle', $fieldTitle); CRM_Utils_System::setTitle(ts('%1 - Price Options', array(1 => $fieldTitle))); $htmlType = CRM_Core_DAO::getFieldValue('CRM_Price_BAO_PriceField', $this->_fid, 'html_type'); $this->assign('addMoreFields', TRUE); //for text price field only single option present if ($htmlType == 'Text') { $this->assign('addMoreFields', FALSE); } } // get the requested action $action = CRM_Utils_Request::retrieve('action', 'String', // default to 'browse' $this, FALSE, 'browse' ); // assign vars to templates $this->assign('action', $action); $oid = CRM_Utils_Request::retrieve('oid', 'Positive', $this, FALSE, 0 ); // what action to take ? if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::VIEW | CRM_Core_Action::DELETE ) && !$this->_isSetReserved ) { // no browse for edit/update/view $this->edit($action); } else { $this->browse(); } // Call the parents run method return parent::run(); } }