X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FPrice%2FBAO%2FPriceSet.php;h=d03b8b2c7b5ad60dffb2d1afe149ab06a9d4fd32;hb=acb1052ec2199198d0ca02bda45e61cc95ec6d35;hp=177451c7d4945a46383a0c345c173aedf04e0697;hpb=fa92b4af1c4abf280689cea6445c7a9b99858831;p=civicrm-core.git diff --git a/CRM/Price/BAO/PriceSet.php b/CRM/Price/BAO/PriceSet.php index 177451c7d4..d03b8b2c7b 100644 --- a/CRM/Price/BAO/PriceSet.php +++ b/CRM/Price/BAO/PriceSet.php @@ -43,7 +43,6 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * Static field for default price set details * * @var array - * @static */ static $_defaultPriceSet = NULL; @@ -57,15 +56,18 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { /** * 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 CRM_Price_DAO_PriceSet object - * @static + * @return CRM_Price_DAO_PriceSet */ public static function create(&$params) { - if(empty($params['id']) && empty($params['name'])) { + 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()) { @@ -77,11 +79,12 @@ 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 - * @static + * @return CRM_Price_DAO_PriceSet */ public static function retrieve(&$params, &$defaults) { return CRM_Core_DAO::commonRetrieve('CRM_Price_DAO_PriceSet', $params, $defaults); @@ -90,13 +93,14 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { /** * 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 + * @return Object + * DAO object on sucess, null otherwise */ public static function setIsActive($id, $isActive) { return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_active', $isActive); @@ -108,9 +112,8 @@ class CRM_Price_BAO_PriceSet extends CRM_Price_DAO_PriceSet { * * @param string $entity * - * @return array $defaultPriceSet default price set - * - * @static + * @return array + * default price set * */ public static function getDefaultPriceSet($entity = 'contribution') { @@ -134,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, ); } @@ -151,11 +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. * - * @static + * @return string + * title * */ public static function getTitle($id) { @@ -165,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 @@ -272,12 +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 * - * @static */ public static function deleteSet($id) { // remove from all inactive forms @@ -311,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 */ @@ -340,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(); } @@ -357,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) { @@ -376,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%' "; @@ -393,12 +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 + * @return int|NULL + * price set id on success, null otherwise */ public static function getSetId(&$params) { $fid = NULL; @@ -424,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 = ' @@ -475,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 @@ -507,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 '; @@ -573,7 +585,7 @@ WHERE id = %1"; * @return int */ public static function getOnlyPriceFieldID(array $priceSet) { - if(count($priceSet['fields']) > 1) { + 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'])); @@ -589,7 +601,7 @@ WHERE id = %1"; */ 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'])); @@ -814,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']) ) ); } @@ -868,7 +880,7 @@ WHERE id = %1"; unset($autoRenew[$dontCare]); } } - if (count($autoRenew) > 1 ) { + if (count($autoRenew) > 1) { $params['autoRenew'] = $autoRenew; } } @@ -890,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')) { @@ -927,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); @@ -996,7 +1010,7 @@ WHERE id = %1"; * @param CRM_Core_Form $form * @param $defaults * - * @return array $defaults + * @return array */ public static function setDefaultPriceSet(&$form, &$defaults) { if (!isset($form->_priceSet) || empty($form->_priceSet['fields'])) { @@ -1021,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. */ public static function setPriceSets(&$params, $entity, $entityName) { - if(empty($params['price_set_id']) || !is_array($params['price_set_id'])) { + 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. @@ -1041,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); } } } @@ -1059,14 +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 * - * @static */ public static function getFieldIds($id) { $priceField = new CRM_Price_DAO_PriceField(); @@ -1079,34 +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 - * @static + * @return CRM_Price_DAO_PriceSet */ 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)); @@ -1126,9 +1145,10 @@ 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 */ @@ -1146,12 +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 - * @static */ public static function getPricesetCount($sid, $onlyActive = TRUE) { $count = 0; @@ -1207,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 @@ -1227,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; @@ -1254,10 +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 + * @return array + * associate array of frequency interval and unit */ public static function getRecurDetails($priceSetId) { $query = 'SELECT mt.duration_interval, mt.duration_unit @@ -1285,11 +1308,13 @@ 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 + * @return Object + * DAO object on sucess, null otherwise */ public static function setIsQuickConfig($id, $isQuickConfig) { return CRM_Core_DAO::setFieldValue('CRM_Price_DAO_PriceSet', $id, 'is_quick_config', $isQuickConfig); @@ -1299,13 +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 * - * @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 @@ -1328,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. */ 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); } @@ -1381,10 +1406,14 @@ 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 */ public static function setLineItem($field, $lineItem, $optionValueId) { if ($field['html_type'] == 'Text') {