X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FPrice%2FBAO%2FPriceSet.php;h=d03b8b2c7b5ad60dffb2d1afe149ab06a9d4fd32;hb=acb1052ec2199198d0ca02bda45e61cc95ec6d35;hp=d3d2d1b19946522973620be22bab0cee12d34e03;hpb=1861d923dd4e29ac945caa98e1efbeda0bb71483;p=civicrm-core.git diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index d3d2d1b199..d03b8b2c7b 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -1,7 +1,7 @@ copyValues($params); if (self::eventPriceSetDomainID()) { @@ -78,30 +79,30 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { /** * 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 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 * - * @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); } @@ -111,10 +112,8 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * * @param string $entity * - * @return array $defaultPriceSet default price set - * - * @access public - * @static + * @return array + * default price set * */ public static function getDefaultPriceSet($entity = 'contribution') { @@ -138,14 +137,14 @@ WHERE ps.name = '{$entityName}' 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, ); } @@ -155,12 +154,11 @@ WHERE ps.name = '{$entityName}' /** * Get the price set title. * - * @param int $id id of price set - * - * @return string title + * @param int $id + * Id of price set. * - * @access public - * @static + * @return string + * title * */ public static function getTitle($id) { @@ -170,7 +168,8 @@ WHERE ps.name = '{$entityName}' /** * 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 @@ -277,13 +276,13 @@ WHERE ct.id = cp.financial_type_id AND /** * 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 @@ -317,8 +316,8 @@ WHERE ct.id = cp.financial_type_id AND * 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 */ @@ -346,14 +345,14 @@ WHERE ct.id = cp.financial_type_id AND * 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(); } @@ -363,12 +362,14 @@ WHERE ct.id = cp.financial_type_id AND * * @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) { @@ -382,8 +383,9 @@ WHERE ct.id = cp.financial_type_id AND 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%' "; @@ -399,13 +401,13 @@ WHERE ct.id = cp.financial_type_id AND /** * 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; @@ -431,10 +433,12 @@ WHERE ct.id = cp.financial_type_id AND /** * 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 = ' @@ -482,7 +486,8 @@ WHERE ct.id = cp.financial_type_id AND * * @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 @@ -514,9 +519,9 @@ WHERE ct.id = cp.financial_type_id AND $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 '; @@ -579,8 +584,8 @@ WHERE id = %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'])); @@ -594,9 +599,9 @@ WHERE id = %1"; * @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'])); @@ -612,7 +617,7 @@ WHERE id = %1"; * * @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); } @@ -710,7 +715,7 @@ WHERE id = %1"; * @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(); @@ -821,8 +826,8 @@ WHERE id = %1"; $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']) ) ); } @@ -875,7 +880,7 @@ WHERE id = %1"; unset($autoRenew[$dontCare]); } } - if (count($autoRenew) > 1 ) { + if (count($autoRenew) > 1) { $params['autoRenew'] = $autoRenew; } } @@ -887,9 +892,8 @@ WHERE id = %1"; * @param CRM_Core_Form $form * * @return void - * @access public */ - static function buildPriceSet(&$form) { + public static function buildPriceSet(&$form) { $priceSetId = $form->get('priceSetId'); if (!$priceSetId) { return; @@ -898,12 +902,14 @@ WHERE id = %1"; $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')) { @@ -935,14 +941,14 @@ WHERE id = %1"; 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); @@ -972,7 +978,7 @@ WHERE id = %1"; * Check the current Membership * having end date null. */ - static function checkCurrentMembership(&$options, $userid) { + public static function checkCurrentMembership(&$options, $userid) { if (!$userid || empty($options)) { return; } @@ -1004,10 +1010,9 @@ WHERE id = %1"; * @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; } @@ -1030,12 +1035,15 @@ WHERE id = %1"; /** * 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. @@ -1050,12 +1058,12 @@ WHERE id = %1"; $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); } } } @@ -1068,15 +1076,16 @@ WHERE id = %1"; //} } } + /** * 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(); @@ -1089,35 +1098,34 @@ WHERE id = %1"; } /** - * 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)); @@ -1137,13 +1145,14 @@ WHERE id = %1"; } /** - * 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) { @@ -1157,13 +1166,12 @@ WHERE id = %1"; * 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; @@ -1219,9 +1227,11 @@ GROUP BY mt.member_of_contact_id"; /** * 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 @@ -1239,9 +1249,9 @@ GROUP BY mt.member_of_contact_id"; $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; @@ -1266,11 +1276,11 @@ GROUP BY mt.member_of_contact_id"; /** * 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 @@ -1288,7 +1298,7 @@ GROUP BY mt.member_of_contact_id"; /** * @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 @@ -1298,14 +1308,15 @@ GROUP BY mt.member_of_contact_id"; /** * 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); } @@ -1313,14 +1324,10 @@ GROUP BY mt.member_of_contact_id"; * 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 @@ -1343,25 +1350,28 @@ WHERE ps.id = %1 $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 * - * @param string $baoName BAO name - * @param int $id old event/contribution page id - * @param int $newId newly created event/contribution page id + * @param string $baoName + * 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); } @@ -1396,12 +1406,16 @@ WHERE ps.id = %1 } } - /* + /** * 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']; } @@ -1415,4 +1429,3 @@ WHERE ps.id = %1 return $lineItem; } } -