<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.5 |
+ | CiviCRM version 4.6 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2014 |
+--------------------------------------------------------------------+
class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet {
/**
- * static field for default price set details
+ * Static field for default price set details
*
* @var array
- * @static
*/
static $_defaultPriceSet = NULL;
/**
- * class constructor
+ * Class constructor
*/
- function __construct() {
+ public function __construct() {
parent::__construct();
}
/**
- * takes an associative array and creates a price set object
+ * Takes an associative array and creates a price set object
*
- * @param array $params (reference) an assoc array of name/value pairs
+ * @param array $params
+ * (reference) an assoc array of name/value pairs.
*
- * @return object CRM_Price_DAO_PriceSet object
- * @access public
- * @static
+ * @return CRM_Price_DAO_PriceSet
*/
- static function create(&$params) {
- if(empty($params['id']) && empty($params['name'])) {
+ public static function create(&$params) {
+ if (empty($params['id']) && empty($params['name'])) {
$params['name'] = CRM_Utils_String::munge($params['title'], '_', 242);
}
+ if (!empty($params['extends']) && is_array($params['extends'])) {
+ $params['extends'] = CRM_Utils_Array::implodePadded($params['extends']);
+ }
$priceSetBAO = new CRM_Price_BAO_PriceSet();
$priceSetBAO->copyValues($params);
if (self::eventPriceSetDomainID()) {
}
/**
- * Takes a bunch of params that are needed to match certain criteria and
- * retrieves the relevant objects. Typically the valid params are only
- * contact_id. We'll tweak this function to be more full featured over a period
- * of time. This is the inverse function of create. It also stores all the retrieved
- * values in the default array
+ * Fetch object based on array of properties
*
- * @param array $params (reference ) an assoc array of name/value pairs
- * @param array $defaults (reference ) an assoc array to hold the flattened values
+ * @param array $params
+ * (reference ) an assoc array of name/value pairs.
+ * @param array $defaults
+ * (reference ) an assoc array to hold the flattened values.
*
- * @return object CRM_Price_DAO_PriceSet object
- * @access public
- * @static
+ * @return CRM_Price_DAO_PriceSet
*/
- static function retrieve(&$params, &$defaults) {
+ public static function retrieve(&$params, &$defaults) {
return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceSet', $params, $defaults);
}
/**
- * update the is_active flag in the db
+ * Update the is_active flag in the db
*
- * @param int $id id of the database record
+ * @param int $id
+ * Id of the database record.
* @param $isActive
*
* @internal param bool $is_active value we want to set the is_active field
*
- * @return Object DAO object on sucess, null otherwise
- * @static
- * @access public
+ * @return Object
+ * DAO object on sucess, null otherwise
*/
- static function setIsActive($id, $isActive) {
+ public static function setIsActive($id, $isActive) {
return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_active', $isActive);
}
*
* @param string $entity
*
- * @return array $defaultPriceSet default price set
- *
- * @access public
- * @static
+ * @return array
+ * default price set
*
*/
public static function getDefaultPriceSet($entity = 'contribution') {
self::$_defaultPriceSet[$entity] = array();
while ($dao->fetch()) {
self::$_defaultPriceSet[$entity][$dao->priceFieldValueID] = array(
- 'setID' => $dao->setID,
- 'priceFieldID' => $dao->priceFieldID,
- 'name' => $dao->name,
- 'label' => $dao->label,
- 'priceFieldValueID' => $dao->priceFieldValueID,
- 'membership_type_id' => $dao->membership_type_id,
- 'amount' => $dao->amount,
- 'financial_type_id' => $dao->financial_type_id,
+ 'setID' => $dao->setID,
+ 'priceFieldID' => $dao->priceFieldID,
+ 'name' => $dao->name,
+ 'label' => $dao->label,
+ 'priceFieldValueID' => $dao->priceFieldValueID,
+ 'membership_type_id' => $dao->membership_type_id,
+ 'amount' => $dao->amount,
+ 'financial_type_id' => $dao->financial_type_id,
);
}
/**
* Get the price set title.
*
- * @param int $id id of price set
+ * @param int $id
+ * Id of price set.
*
- * @return string title
- *
- * @access public
- * @static
+ * @return string
+ * title
*
*/
public static function getTitle($id) {
/**
* Return a list of all forms which use this price set.
*
- * @param int $id id of price set
+ * @param int $id
+ * Id of price set.
* @param bool|string $simpleReturn - get raw data. Possible values: 'entity', 'table'
*
* @return array
/**
* Delete the price set
*
- * @param int $id Price Set id
+ * @param int $id
+ * Price Set id.
*
- * @return boolean false if fields exist for this set, true if the
- * set could be deleted
+ * @return bool
+ * false if fields exist for this set, true if the
+ * set could be deleted
*
- * @access public
- * @static
*/
public static function deleteSet($id) {
// remove from all inactive forms
* Link the price set with the specified table and id
*
* @param string $entityTable
- * @param integer $entityId
- * @param integer $priceSetId
+ * @param int $entityId
+ * @param int $priceSetId
*
* @return bool
*/
* Delete price set for the given entity and id
*
* @param string $entityTable
- * @param integer $entityId
+ * @param int $entityId
*
* @return mixed
*/
public static function removeFrom($entityTable, $entityId) {
- $dao = new CRM_Price_DAO_PriceSetEntity();
+ $dao = new CRM_Price_DAO_PriceSetEntity();
$dao->entity_table = $entityTable;
- $dao->entity_id = $entityId;
+ $dao->entity_id = $entityId;
return $dao->delete();
}
*
* @param string $entityTable
* @param int $entityId
- * @param int $usedFor ( price set that extends/used for particular component )
+ * @param int $usedFor
+ * ( price set that extends/used for particular component ).
*
* @param null $isQuickConfig
* @param null $setName
*
- * @return integer|false price_set_id, or false if none found
+ * @return int|false
+ * price_set_id, or false if none found
*/
public static function getFor($entityTable, $entityId, $usedFor = NULL, $isQuickConfig = NULL, &$setName = NULL) {
if (!$entityTable || !$entityId) {
if ($isQuickConfig) {
$sql .= ' AND ps.is_quick_config = 0 ';
}
- $params = array(1 => array($entityTable, 'String'),
- 2 => array($entityId, 'Integer'),
+ $params = array(
+ 1 => array($entityTable, 'String'),
+ 2 => array($entityId, 'Integer'),
);
if ($usedFor) {
$sql .= " AND ps.extends LIKE '%%3%' ";
/**
* Find a price_set_id associated with the given option value or field ID
*
- * @param array $params (reference) an assoc array of name/value pairs
+ * @param array $params
+ * (reference) an assoc array of name/value pairs.
* array may contain either option id or
* price field id
*
- * @return integer|NULL price set id on success, null otherwise
- * @static
- * @access public
+ * @return int|NULL
+ * price set id on success, null otherwise
*/
public static function getSetId(&$params) {
$fid = NULL;
/**
* Return an associative array of all price sets
*
- * @param bool $withInactive whether or not to include inactive entries
+ * @param bool $withInactive
+ * Whether or not to include inactive entries.
* @param bool|string $extendComponentName name of the component like 'CiviEvent','CiviContribute'
*
- * @return array associative array of id => name
+ * @return array
+ * associative array of id => name
*/
public static function getAssoc($withInactive = FALSE, $extendComponentName = FALSE) {
$query = '
*
* An array containing price set details (including price fields) is returned
*
- * @param $setID
+ * @param int $setID
* @param bool $required
* @param bool $validOnly
*
* @internal param int $setId - price set id whose details are needed
*
- * @return array $setTree - array consisting of field details
+ * @return array
+ * array consisting of field details
*/
public static function getSetDetail($setID, $required = TRUE, $validOnly = FALSE) {
// create a new tree
$select = 'SELECT ' . implode(',', $priceFields);
$from = ' FROM civicrm_price_field';
- $params = array();
+ $params = array();
$params[1] = array($setID, 'Integer');
- $where = '
+ $where = '
WHERE price_set_id = %1
AND is_active = 1
';
* @throws CRM_Core_Exception
* @return int
*/
- static function getOnlyPriceFieldID(array $priceSet) {
- if(count($priceSet['fields']) > 1) {
+ public static function getOnlyPriceFieldID(array $priceSet) {
+ if (count($priceSet['fields']) > 1) {
throw new CRM_Core_Exception(ts('expected only one price field to be in priceset but multiple are present'));
}
return (int) implode('_', array_keys($priceSet['fields']));
* @throws CRM_Core_Exception
* @return int
*/
- static function getOnlyPriceFieldValueID(array $priceSet) {
+ public static function getOnlyPriceFieldValueID(array $priceSet) {
$priceFieldID = self::getOnlyPriceFieldID($priceSet);
- if(count($priceSet['fields'][$priceFieldID]['options']) > 1) {
+ if (count($priceSet['fields'][$priceFieldID]['options']) > 1) {
throw new CRM_Core_Exception(ts('expected only one price field to be in priceset but multiple are present'));
}
return (int) implode('_', array_keys($priceSet['fields'][$priceFieldID]['options']));
/**
* @param CRM_Core_Form $form
- * @param $id
+ * @param int $id
* @param string $entityTable
* @param bool $validOnly
- * @param null $priceSetId
+ * @param int $priceSetId
*
* @return bool|false|int|null
*/
- static function initSet(&$form, $id, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL) {
+ public static function initSet(&$form, $id, $entityTable = 'civicrm_event', $validOnly = FALSE, $priceSetId = NULL) {
if (!$priceSetId) {
$priceSetId = self::getFor($entityTable, $id);
}
/**
* @param $fields
- * @param $params
+ * @param array $params
* @param $lineItem
* @param string $component
*/
- static function processAmount(&$fields, &$params, &$lineItem, $component = '') {
+ public static function processAmount(&$fields, &$params, &$lineItem, $component = '') {
// using price set
$totalPrice = $totalTax = 0;
$radioLevel = $checkboxLevel = $selectLevel = $textLevel = array();
$params['amount_priceset_level_checkbox']["{$field['options'][$optionId]['id']}"] = $optionLabel;
if (isset($checkboxLevel)) {
$checkboxLevel = array_unique(array_merge(
- $checkboxLevel,
- array_keys($params['amount_priceset_level_checkbox'])
+ $checkboxLevel,
+ array_keys($params['amount_priceset_level_checkbox'])
)
);
}
unset($autoRenew[$dontCare]);
}
}
- if (count($autoRenew) > 1 ) {
+ if (count($autoRenew) > 1) {
$params['autoRenew'] = $autoRenew;
}
}
}
/**
- * Function to build the price set form.
+ * Build the price set form.
*
* @param CRM_Core_Form $form
*
* @return void
- * @access public
*/
- static function buildPriceSet(&$form) {
+ public static function buildPriceSet(&$form) {
$priceSetId = $form->get('priceSetId');
- $userid = $form->getVar('_userID');
if (!$priceSetId) {
return;
}
$validFieldsOnly = TRUE;
$className = CRM_Utils_System::getClassName($form);
if (in_array($className, array(
- 'CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
+ 'CRM_Contribute_Form_Contribution',
+ 'CRM_Member_Form_Membership',
+ ))) {
$validFieldsOnly = FALSE;
}
- $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
- $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
+ $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
+ $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
$validPriceFieldIds = array_keys($form->_priceSet['fields']);
$form->_quickConfig = $quickConfig = 0;
if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
// CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
- $adminFieldVisible = false;
+ $adminFieldVisible = FALSE;
if (CRM_Core_Permission::check('administer CiviCRM')) {
- $adminFieldVisible = true;
+ $adminFieldVisible = TRUE;
}
foreach ($feeBlock as $id => $field) {
if (CRM_Utils_Array::value('visibility', $field) == 'public' ||
- (CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == true) ||
+ (CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE) ||
!$validFieldsOnly
) {
$options = CRM_Utils_Array::value('options', $field);
if ($className == 'CRM_Contribute_Form_Contribution_Main' && $component = 'membership') {
+ $userid = $form->getVar('_membershipContactID');
$checklifetime = self::checkCurrentMembership($options, $userid);
if ($checklifetime) {
$form->assign('ispricelifetime', TRUE);
}
/**
- * Function to check the current Membership
+ * Check the current Membership
* having end date null.
*/
- static function checkCurrentMembership(&$options, $userid) {
+ public static function checkCurrentMembership(&$options, $userid) {
if (!$userid || empty($options)) {
return;
}
}
/**
- * Function to set daefult the price set fields.
+ * Set daefult the price set fields.
*
- * @param $form
+ * @param CRM_Core_Form $form
* @param $defaults
*
- * @return array $defaults
- * @access public
+ * @return array
*/
- static function setDefaultPriceSet(&$form, &$defaults) {
+ public static function setDefaultPriceSet(&$form, &$defaults) {
if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) {
return $defaults;
}
/**
* Supports event create function by setting up required price sets, not tested but expect
* it will work for contribution page
- * @param array $params as passed to api/bao create fn
- * @param CRM_Core_DAO $entity object for given entity
- * @param string $entityName name of entity - e.g event
+ * @param array $params
+ * As passed to api/bao create fn.
+ * @param CRM_Core_DAO $entity
+ * Object for given entity.
+ * @param string $entityName
+ * Name of entity - e.g event.
*/
- static function setPriceSets(&$params, $entity, $entityName) {
- if(empty($params['price_set_id']) || !is_array($params['price_set_id'])) {
+ public static function setPriceSets(&$params, $entity, $entityName) {
+ if (empty($params['price_set_id']) || !is_array($params['price_set_id'])) {
return;
}
// CRM-14069 note that we may as well start by assuming more than one.
$pse->entity_table = 'civicrm_' . $entityName;
$pse->entity_id = $entity->id;
while ($pse->fetch()) {
- if(!in_array($pse->price_set_id, $params['price_set_id'])) {
+ if (!in_array($pse->price_set_id, $params['price_set_id'])) {
// note an even more aggressive form of this deletion currently happens in event form
// past price sets discounts are made inaccessible by this as the discount_id is set to NULL
// on the participant record
if (CRM_Price_BAO_PriceSet::removeFrom('civicrm_' . $entityName, $entity->id)) {
- CRM_Core_BAO_Discount::del($entity->id,'civicrm_' . $entityName);
+ CRM_Core_BAO_Discount::del($entity->id, 'civicrm_' . $entityName);
}
}
}
//}
}
}
+
/**
* Get field ids of a price set
*
- * @param int $id Price Set id
+ * @param int $id
+ * Price Set id.
*
- * @return array of the field ids
+ * @return array
+ * Array of the field ids
*
- * @access public
- * @static
*/
public static function getFieldIds($id) {
$priceField = new CRM_Price_DAO_PriceField();
}
/**
- * This function is to make a copy of a price set, including
- * all the fields
+ * Copy a price set, including all the fields
*
- * @param int $id the price set id to copy
+ * @param int $id
+ * The price set id to copy.
*
- * @return the copy object
- * @access public
- * @static
+ * @return CRM_Price_DAO_PriceSet
*/
- static function copy($id) {
+ public static function copy($id) {
$maxId = CRM_Core_DAO::singleValueQuery("SELECT max(id) FROM civicrm_price_set");
$title = ts('[Copy id %1]', array(1 => $maxId + 1));
$fieldsFix = array(
- 'suffix' => array('title' => ' ' . $title,
- 'name' => '__Copy_id_' . ($maxId + 1) . '_',
+ 'suffix' => array(
+ 'title' => ' ' . $title,
+ 'name' => '__Copy_id_' . ($maxId + 1) . '_',
),
);
$copy = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceSet',
- array('id' => $id),
- NULL,
- $fieldsFix
+ array('id' => $id),
+ NULL,
+ $fieldsFix
);
//copying all the blocks pertaining to the price set
$copyPriceField = &CRM_Core_DAO::copyGeneric('CRM_Price_DAO_PriceField',
- array('price_set_id' => $id),
- array('price_set_id' => $copy->id)
+ array('price_set_id' => $id),
+ array('price_set_id' => $copy->id)
);
if (!empty($copyPriceField)) {
$price = array_combine(self::getFieldIds($id), self::getFieldIds($copy->id));
}
/**
- * This function is to check price set permission
+ * check price set permission
*
- * @param int $sid the price set id
+ * @param int $sid
+ * The price set id.
*
* @return bool
*/
- static function checkPermission($sid) {
+ public static function checkPermission($sid) {
if ($sid && self::eventPriceSetDomainID()) {
$domain_id = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $sid, 'domain_id', 'id');
if (CRM_Core_Config::domainID() != $domain_id) {
* Get the sum of participant count
* for all fields of given price set.
*
- * @param int $sid the price set id
+ * @param int $sid
+ * The price set id.
*
* @param bool $onlyActive
*
* @return int|null|string
- * @access public
- * @static
*/
public static function getPricesetCount($sid, $onlyActive = TRUE) {
$count = 0;
}
/**
- * Function to check if auto renew option should be shown
+ * Check if auto renew option should be shown
*
- * @param int $priceSetId price set id
+ * @param int $priceSetId
+ * Price set id.
*
- * @return int $autoRenewOption ( 0:hide, 1:optional 2:required )
+ * @return int
+ * $autoRenewOption ( 0:hide, 1:optional 2:required )
*/
public static function checkAutoRenewForPriceSet($priceSetId) {
// auto-renew option should be visible if membership types associated with all the fields has
$params = array(1 => array($priceSetId, 'Integer'));
- $dao = CRM_Core_DAO::executeQuery($query, $params);
+ $dao = CRM_Core_DAO::executeQuery($query, $params);
$autoRenewOption = 2;
- $interval = $unit = array();
+ $interval = $unit = array();
while ($dao->fetch()) {
if (!$dao->auto_renew) {
$autoRenewOption = 0;
}
/**
- * Function to retrieve auto renew frequency and interval
+ * Retrieve auto renew frequency and interval
*
- * @param int $priceSetId price set id
+ * @param int $priceSetId
+ * Price set id.
*
- * @return array associate array of frequency interval and unit
- * @static
- * @access public
+ * @return array
+ * associate array of frequency interval and unit
*/
public static function getRecurDetails($priceSetId) {
$query = 'SELECT mt.duration_interval, mt.duration_unit
/**
* @return object
*/
- static function eventPriceSetDomainID() {
+ public static function eventPriceSetDomainID() {
return CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME,
'event_price_set_domain_id',
NULL, FALSE
}
/**
- * update the is_quick_config flag in the db
+ * Update the is_quick_config flag in the db
*
- * @param int $id id of the database record
- * @param boolean $isQuickConfig value we want to set the is_quick_config field
+ * @param int $id
+ * Id of the database record.
+ * @param bool $isQuickConfig we want to set the is_quick_config field.
+ * Value we want to set the is_quick_config field.
*
- * @return Object DAO object on sucess, null otherwise
- * @static
- * @access public
+ * @return Object
+ * DAO object on sucess, null otherwise
*/
- static function setIsQuickConfig($id, $isQuickConfig) {
+ public static function setIsQuickConfig($id, $isQuickConfig) {
return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_quick_config', $isQuickConfig);
}
* Check if price set id provides option for
* user to select both auto-renew and non-auto-renew memberships
*
- * @access public
- * @static
- *
*/
public static function checkMembershipPriceSet($id) {
- $query =
-"
-SELECT pfv.id, pfv.price_field_id, pfv.name, pfv.membership_type_id, pf.html_type, mt.auto_renew
+ $query
+ = "SELECT pfv.id, pfv.price_field_id, pfv.name, pfv.membership_type_id, pf.html_type, mt.auto_renew
FROM civicrm_price_field_value pfv
LEFT JOIN civicrm_price_field pf ON pf.id = pfv.price_field_id
LEFT JOIN civicrm_price_set ps ON ps.id = pf.price_set_id
$daoAutoRenew = 0;
}
if (!empty($autoRenew) && !in_array($daoAutoRenew, $autoRenew)) {
- return true;
+ return TRUE;
}
$autoRenew[] = $daoAutoRenew;
}
- return false;
+ return FALSE;
}
/**
* Copy priceSet when event/contibution page is copied
*
- * @params string $baoName BAO name
- * @params int $id old event/contribution page id
- * @params int $newId newly created event/contribution page id
- *
* @param string $baoName
- * @param integer $id
- * @param integer $newId
+ * BAO name.
+ * @param int $id
+ * Old event/contribution page id.
+ * @param int $newId
+ * Newly created event/contribution page id.
*/
- static function copyPriceSet($baoName, $id, $newId) {
+ public static function copyPriceSet($baoName, $id, $newId) {
$priceSetId = CRM_Price_BAO_PriceSet::getFor($baoName, $id);
if ($priceSetId) {
$isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config');
- if($isQuickConfig) {
+ if ($isQuickConfig) {
$copyPriceSet = &CRM_Price_BAO_PriceSet::copy($priceSetId);
CRM_Price_BAO_PriceSet::addTo($baoName, $newId, $copyPriceSet->id);
}
}
}
- /*
+ /**
* Function to set tax_amount and tax_rate in LineItem
*
+ * @param array $field
+ * @param array $lineItem
+ * @param int $optionValueId
*
+ * @return array
*/
- static function setLineItem($field, $lineItem, $optionValueId) {
+ public static function setLineItem($field, $lineItem, $optionValueId) {
if ($field['html_type'] == 'Text') {
$taxAmount = $field['options'][$optionValueId]['tax_amount'] * $lineItem[$optionValueId]['qty'];
}
return $lineItem;
}
}
-