First commit

This commit is contained in:
Theodotos Andreou 2018-01-14 13:10:16 +00:00
commit c6e2478c40
13918 changed files with 2303184 additions and 0 deletions

View file

@ -0,0 +1,343 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Price Fields.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Price_Page_Field extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The price set group id of the field.
*
* @var int
*/
protected $_sid;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* The price set is reserved or not.
*
* @var boolean
*/
protected $_isSetReserved = FALSE;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => array(
'name' => ts('Edit Price Field'),
'url' => 'civicrm/admin/price/field',
'qs' => 'action=update&reset=1&sid=%%sid%%&fid=%%fid%%',
'title' => ts('Edit Price'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview Field'),
'url' => 'civicrm/admin/price/field',
'qs' => 'action=preview&reset=1&sid=%%sid%%&fid=%%fid%%',
'title' => ts('Preview Price'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Price'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Price'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/price/field',
'qs' => 'action=delete&reset=1&sid=%%sid%%&fid=%%fid%%',
'title' => ts('Delete Price'),
),
);
}
return self::$_actionLinks;
}
/**
* Browse all price set fields.
*/
public function browse() {
$resourceManager = CRM_Core_Resources::singleton();
if (!empty($_GET['new']) && $resourceManager->ajaxPopupsEnabled) {
$resourceManager->addScriptFile('civicrm', 'js/crm.addNew.js', 999, 'html-header');
}
$priceField = array();
$priceFieldBAO = new CRM_Price_BAO_PriceField();
// fkey is sid
$priceFieldBAO->price_set_id = $this->_sid;
$priceFieldBAO->orderBy('weight, label');
$priceFieldBAO->find();
// display taxTerm for priceFields
$invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
$taxTerm = CRM_Utils_Array::value('tax_term', $invoiceSettings);
$invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
$getTaxDetails = FALSE;
$taxRate = CRM_Core_PseudoConstant::getTaxRates();
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
while ($priceFieldBAO->fetch()) {
$priceField[$priceFieldBAO->id] = array();
CRM_Core_DAO::storeValues($priceFieldBAO, $priceField[$priceFieldBAO->id]);
// get price if it's a text field
if ($priceFieldBAO->html_type == 'Text') {
$optionValues = array();
$params = array('price_field_id' => $priceFieldBAO->id);
CRM_Price_BAO_PriceFieldValue::retrieve($params, $optionValues);
$priceField[$priceFieldBAO->id]['price'] = CRM_Utils_Array::value('amount', $optionValues);
$financialTypeId = $optionValues['financial_type_id'];
if ($invoicing && isset($taxRate[$financialTypeId])) {
$priceField[$priceFieldBAO->id]['tax_rate'] = $taxRate[$financialTypeId];
$getTaxDetails = TRUE;
}
if (isset($priceField[$priceFieldBAO->id]['tax_rate'])) {
$taxAmount = CRM_Contribute_BAO_Contribution_Utils::calculateTaxAmount($priceField[$priceFieldBAO->id]['price'], $priceField[$priceFieldBAO->id]['tax_rate'], TRUE);
$priceField[$priceFieldBAO->id]['tax_amount'] = $taxAmount['tax_amount'];
}
}
$action = array_sum(array_keys(self::actionLinks()));
if ($this->_isSetReserved) {
$action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DELETE + CRM_Core_Action::ENABLE + CRM_Core_Action::DISABLE;
}
else {
if ($priceFieldBAO->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
}
if ($priceFieldBAO->active_on == '0000-00-00 00:00:00') {
$priceField[$priceFieldBAO->id]['active_on'] = '';
}
if ($priceFieldBAO->expire_on == '0000-00-00 00:00:00') {
$priceField[$priceFieldBAO->id]['expire_on'] = '';
}
// need to translate html types from the db
$htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
$priceField[$priceFieldBAO->id]['html_type_display'] = $htmlTypes[$priceField[$priceFieldBAO->id]['html_type']];
$priceField[$priceFieldBAO->id]['order'] = $priceField[$priceFieldBAO->id]['weight'];
$priceField[$priceFieldBAO->id]['action'] = CRM_Core_Action::formLink(
self::actionLinks(),
$action,
array(
'fid' => $priceFieldBAO->id,
'sid' => $this->_sid,
),
ts('more'),
FALSE,
'priceField.row.actions',
'PriceField',
$priceFieldBAO->id
);
$this->assign('taxTerm', $taxTerm);
$this->assign('getTaxDetails', $getTaxDetails);
}
$returnURL = CRM_Utils_System::url('civicrm/admin/price/field', "reset=1&action=browse&sid={$this->_sid}");
$filter = "price_set_id = {$this->_sid}";
CRM_Utils_Weight::addOrder($priceField, 'CRM_Price_DAO_PriceField',
'id', $returnURL, $filter
);
$this->assign('priceField', $priceField);
}
/**
* Edit price data.
*
* editing would involved modifying existing fields + adding data to new fields.
*
* @param string $action
* The action to be invoked.
*/
public function edit($action) {
// create a simple controller for editing price data
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Field', ts('Price Field'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
$controller->set('sid', $this->_sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
*
* @return void
*/
public function run() {
// get the group id
$this->_sid = CRM_Utils_Request::retrieve('sid', 'Positive',
$this
);
$fid = CRM_Utils_Request::retrieve('fid', 'Positive',
$this, FALSE, 0
);
$action = CRM_Utils_Request::retrieve('action', 'String',
// default to 'browse'
$this, FALSE, 'browse'
);
if ($this->_sid) {
$usedBy = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid);
$this->assign('usedBy', $usedBy);
$this->_isSetReserved = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'is_reserved');
$this->assign('isReserved', $this->_isSetReserved);
CRM_Price_BAO_PriceSet::checkPermission($this->_sid);
$comps = array(
'Event' => 'civicrm_event',
'Contribution' => 'civicrm_contribution_page',
'EventTemplate' => 'civicrm_event_template',
);
$priceSetContexts = array();
foreach ($comps as $name => $table) {
if (array_key_exists($table, $usedBy)) {
$priceSetContexts[] = $name;
}
}
$this->assign('contexts', $priceSetContexts);
}
if ($action & (CRM_Core_Action::DELETE) && !$this->_isSetReserved) {
if (empty($usedBy)) {
// prompt to delete
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteField', 'Delete Price Field', '');
$controller->set('fid', $fid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
else {
// add breadcrumb
$url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1');
CRM_Utils_System::appendBreadCrumb(ts('Price'),
$url
);
$this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceField::getTitle($fid));
}
}
if ($action & CRM_Core_Action::DELETE) {
CRM_Utils_System::setTitle(ts('Delete Price Field'));
}
elseif ($this->_sid) {
$groupTitle = CRM_Price_BAO_PriceSet::getTitle($this->_sid);
$this->assign('sid', $this->_sid);
$this->assign('groupTitle', $groupTitle);
CRM_Utils_System::setTitle(ts('%1 - Price Fields', array(1 => $groupTitle)));
}
// assign vars to templates
$this->assign('action', $action);
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD) && !$this->_isSetReserved) {
// no browse for edit/update/view
$this->edit($action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($fid);
}
else {
$this->browse();
}
// Call the parents run method
return parent::run();
}
/**
* Preview price field.
*
* @param int $fid
*
* @internal param int $id price field id
*
* @return void
*/
public function preview($fid) {
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Form Field'), CRM_Core_Action::PREVIEW);
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid));
$controller->set('fieldId', $fid);
$controller->set('groupId', $this->_sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
}

View file

@ -0,0 +1,341 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Custom Options.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Price_Page_Option extends CRM_Core_Page {
public $useLivePageJS = TRUE;
/**
* The field id of the option.
*
* @var int
*/
protected $_fid;
/**
* The field id of the option.
*
* @var int
*/
protected $_sid;
/**
* The price set is reserved or not.
*
* @var boolean
*/
protected $_isSetReserved = FALSE;
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public static function &actionLinks() {
if (!isset(self::$_actionLinks)) {
self::$_actionLinks = array(
CRM_Core_Action::UPDATE => 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.
*
* @return void
*/
public function browse() {
$priceOptions = civicrm_api3('PriceFieldValue', 'get', array(
'price_field_id' => $this->_fid,
// Explicitly do not check permissions so we are not
// restricted by financial type, so we can change them.
'check_permissions' => FALSE,
'options' => array(
'limit' => 0,
'sort' => array('weight', 'label'),
),
));
$customOption = $priceOptions['values'];
// CRM-15378 - check if these price options are in an Event price set
$isEvent = FALSE;
$extendComponentId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_sid, 'extends', 'id');
$allComponents = explode(CRM_Core_DAO::VALUE_SEPARATOR, $extendComponentId);
$eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
if (in_array($eventComponentId, $allComponents)) {
$isEvent = TRUE;
}
$config = CRM_Core_Config::singleton();
$taxRate = CRM_Core_PseudoConstant::getTaxRates();
// display taxTerm for priceFields
$invoiceSettings = Civi::settings()->get('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(self::actionLinks()));
// Adding the required fields in the array
if (isset($taxRate[$values['financial_type_id']])) {
// Cast to float so trailing zero decimals are removed
$customOption[$id]['tax_rate'] = (float) $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'], TRUE);
$customOption[$id]['tax_amount'] = $taxAmount['tax_amount'];
}
if (!empty($values['financial_type_id'])) {
$customOption[$id]['financial_type_id'] = CRM_Contribute_PseudoConstant::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'] = '<img src="' . $config->resourceBase . 'i/check.gif" />';
}
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);
$this->assign('isEvent', $isEvent);
}
/**
* 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.
*
* @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();
}
}

View file

@ -0,0 +1,327 @@
<?php
/*
+--------------------------------------------------------------------+
| CiviCRM version 4.7 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2017 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| CiviCRM is free software; you can copy, modify, and distribute it |
| under the terms of the GNU Affero General Public License |
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
| |
| CiviCRM is distributed in the hope that it will be useful, but |
| WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| See the GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public |
| License and the CiviCRM Licensing Exception along |
| with this program; if not, contact CiviCRM LLC |
| at info[AT]civicrm[DOT]org. If you have questions about the |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC (c) 2004-2017
* $Id$
*
*/
/**
* Create a page for displaying Price Sets.
*
* Heart of this class is the run method which checks
* for action type and then displays the appropriate
* page.
*
*/
class CRM_Price_Page_Set extends CRM_Core_Page {
/**
* The action links that we need to display for the browse screen.
*
* @var array
*/
private static $_actionLinks;
/**
* Get the action links for this page.
*
* @return array
* array of action links that we need to display for the browse screen
*/
public function &actionLinks() {
// check if variable _actionsLinks is populated
if (!isset(self::$_actionLinks)) {
// helper variable for nicer formatting
$deleteExtra = ts('Are you sure you want to delete this price set?');
$copyExtra = ts('Are you sure you want to make a copy of this price set?');
self::$_actionLinks = array(
CRM_Core_Action::BROWSE => array(
'name' => ts('View and Edit Price Fields'),
'url' => 'civicrm/admin/price/field',
'qs' => 'reset=1&action=browse&sid=%%sid%%',
'title' => ts('View and Edit Price Fields'),
),
CRM_Core_Action::PREVIEW => array(
'name' => ts('Preview'),
'url' => 'civicrm/admin/price',
'qs' => 'action=preview&reset=1&sid=%%sid%%',
'title' => ts('Preview Price Set'),
),
CRM_Core_Action::UPDATE => array(
'name' => ts('Settings'),
'url' => 'civicrm/admin/price',
'qs' => 'action=update&reset=1&sid=%%sid%%',
'title' => ts('Edit Price Set'),
),
CRM_Core_Action::DISABLE => array(
'name' => ts('Disable'),
'ref' => 'crm-enable-disable',
'title' => ts('Disable Price Set'),
),
CRM_Core_Action::ENABLE => array(
'name' => ts('Enable'),
'ref' => 'crm-enable-disable',
'title' => ts('Enable Price Set'),
),
CRM_Core_Action::DELETE => array(
'name' => ts('Delete'),
'url' => 'civicrm/admin/price',
'qs' => 'action=delete&reset=1&sid=%%sid%%',
'title' => ts('Delete Price Set'),
'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
),
CRM_Core_Action::COPY => array(
'name' => ts('Copy Price Set'),
'url' => CRM_Utils_System::currentPath(),
'qs' => 'action=copy&sid=%%sid%%',
'title' => ts('Make a Copy of Price Set'),
'extra' => 'onclick = "return confirm(\'' . $copyExtra . '\');"',
),
);
}
return self::$_actionLinks;
}
/**
* Run the page.
*
* This method is called after the page is created. It checks for the
* type of action and executes that action.
* Finally it calls the parent's run method.
*
* @return void
*/
public function run() {
// 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);
$sid = CRM_Utils_Request::retrieve('sid', 'Positive',
$this, FALSE, 0
);
if ($sid) {
CRM_Price_BAO_PriceSet::checkPermission($sid);
}
// what action to take ?
if ($action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) {
$this->edit($sid, $action);
}
elseif ($action & CRM_Core_Action::PREVIEW) {
$this->preview($sid);
}
elseif ($action & CRM_Core_Action::COPY) {
CRM_Core_Session::setStatus(ts('A copy of the price set has been created'), ts('Saved'), 'success');
$this->copy();
}
else {
// if action is delete do the needful.
if ($action & (CRM_Core_Action::DELETE)) {
$usedBy = CRM_Price_BAO_PriceSet::getUsedBy($sid);
if (empty($usedBy)) {
// prompt to delete
CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_DeleteSet', 'Delete Price Set', NULL);
$controller->set('sid', $sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
else {
// add breadcrumb
$url = CRM_Utils_System::url('civicrm/admin/price', 'reset=1');
CRM_Utils_System::appendBreadCrumb(ts('Price Sets'), $url);
$this->assign('usedPriceSetTitle', CRM_Price_BAO_PriceSet::getTitle($sid));
$this->assign('usedBy', $usedBy);
$comps = array(
'Event' => 'civicrm_event',
'Contribution' => 'civicrm_contribution_page',
'EventTemplate' => 'civicrm_event_template',
);
$priceSetContexts = array();
foreach ($comps as $name => $table) {
if (array_key_exists($table, $usedBy)) {
$priceSetContexts[] = $name;
}
}
$this->assign('contexts', $priceSetContexts);
}
}
// finally browse the price sets
$this->browse();
}
// parent run
return parent::run();
}
/**
* Edit price set.
*
* @param int $sid
* Price set id.
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function edit($sid, $action) {
// create a simple controller for editing price sets
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Set', ts('Price Set'), $action);
// set the userContext stack
$session = CRM_Core_Session::singleton();
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
$controller->set('sid', $sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Preview price set.
*
* @param int $sid
* Price set id.
*
* @return void
*/
public function preview($sid) {
$controller = new CRM_Core_Controller_Simple('CRM_Price_Form_Preview', ts('Preview Price Set'), NULL);
$session = CRM_Core_Session::singleton();
$context = CRM_Utils_Request::retrieve('context', 'String', $this);
if ($context == 'field') {
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price/field', "action=browse&sid={$sid}"));
}
else {
$session->pushUserContext(CRM_Utils_System::url('civicrm/admin/price', 'action=browse'));
}
$controller->set('groupId', $sid);
$controller->setEmbedded(TRUE);
$controller->process();
$controller->run();
}
/**
* Browse all price sets.
*
* @param string $action
* The action to be invoked.
*
* @return void
*/
public function browse($action = NULL) {
// get all price sets
$priceSet = array();
$comps = array(
'CiviEvent' => ts('Event'),
'CiviContribute' => ts('Contribution'),
'CiviMember' => ts('Membership'),
);
$dao = new CRM_Price_DAO_PriceSet();
if (CRM_Price_BAO_PriceSet::eventPriceSetDomainID()) {
$dao->domain_id = CRM_Core_Config::domainID();
}
$dao->is_quick_config = 0;
$dao->find();
while ($dao->fetch()) {
$priceSet[$dao->id] = array();
CRM_Core_DAO::storeValues($dao, $priceSet[$dao->id]);
$compIds = explode(CRM_Core_DAO::VALUE_SEPARATOR,
CRM_Utils_Array::value('extends', $priceSet[$dao->id])
);
$extends = array();
//CRM-10225
foreach ($compIds as $compId) {
if (!empty($comps[CRM_Core_Component::getComponentName($compId)])) {
$extends[] = $comps[CRM_Core_Component::getComponentName($compId)];
}
}
$priceSet[$dao->id]['extends'] = implode(', ', $extends);
// form all action links
$action = array_sum(array_keys($this->actionLinks()));
// update enable/disable links depending on price_set properties.
if ($dao->is_reserved) {
$action -= CRM_Core_Action::UPDATE + CRM_Core_Action::DISABLE + CRM_Core_Action::ENABLE + CRM_Core_Action::DELETE + CRM_Core_Action::COPY;
}
else {
if ($dao->is_active) {
$action -= CRM_Core_Action::ENABLE;
}
else {
$action -= CRM_Core_Action::DISABLE;
}
}
$actionLinks = self::actionLinks();
//CRM-10117
if ($dao->is_reserved) {
$actionLinks[CRM_Core_Action::BROWSE]['name'] = 'View Price Fields';
}
$priceSet[$dao->id]['action'] = CRM_Core_Action::formLink($actionLinks, $action,
array('sid' => $dao->id),
ts('more'),
FALSE,
'priceSet.row.actions',
'PriceSet',
$dao->id
);
}
$this->assign('rows', $priceSet);
}
/**
* make a copy of a price set, including
* all the fields in the page
*
* @return void
*/
public function copy() {
$id = CRM_Utils_Request::retrieve('sid', 'Positive',
$this, TRUE, 0, 'GET'
);
CRM_Price_BAO_PriceSet::copy($id);
CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), 'reset=1'));
}
}