return;
case 'participant_fee_id':
- $val_regexp = [];
- foreach ($value as $k => &$val) {
- $val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
- $val_regexp[$k] = CRM_Core_DAO::escapeString(preg_quote(trim($val)));
- $val = CRM_Core_DAO::escapeString(trim($val));
+ $labels = [];
+ foreach ($value as $val) {
+ $labels[] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
}
- $feeLabel = implode('|', $val_regexp);
- $query->_where[$grouping][] = "civicrm_participant.fee_level REGEXP '{$feeLabel}'";
- $query->_qill[$grouping][] = ts("Fee level") . " IN " . implode(', ', $value);
- $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
+ $query->_where[$grouping][] = "civicrm_line_item.price_field_value_id IN (" . implode(', ', $value) . ")";
+ $query->_qill[$grouping][] = ts("Fee level") . " IN " . implode(', ', $labels);
+ $query->_tables['civicrm_participant'] = $query->_tables['civicrm_line_item'] = $query->_whereTables['civicrm_line_item'] = 1;
return;
case 'participant_fee_amount_high':
$from = " $side JOIN civicrm_discount discount ON ( civicrm_participant.discount_id = discount.id )";
$from .= " $side JOIN civicrm_option_group discount_name ON ( discount_name.id = discount.price_set_id ) ";
break;
+
+ case 'civicrm_line_item':
+ $from .= " $side JOIN civicrm_line_item ON civicrm_line_item.entity_id = civicrm_participant.id AND civicrm_line_item.entity_table = 'civicrm_participant'";
+ break;
}
return $from;
}
$fieldValueBAO = new CRM_Price_BAO_PriceFieldValue();
$fieldValueBAO->copyValues($params);
- if ($id = CRM_Utils_Array::value('id', $ids)) {
- $fieldValueBAO->id = $id;
- $prevLabel = self::getOptionLabel($id);
- if (!empty($params['label']) && $prevLabel != $params['label']) {
- self::updateAmountAndFeeLevel($id, $prevLabel, $params['label']);
- }
- }
// CRM-16189
$priceFieldID = CRM_Utils_Array::value('price_field_id', $params);
if (!$priceFieldID) {
CRM_Core_DAO::executeQuery($sql, $params);
}
- /**
- * Update price option label in line_item, civicrm_contribution and civicrm_participant.
- *
- * @param int $id - id of the price_field_value
- * @param string $prevLabel
- * @param string $newLabel
- *
- */
- public static function updateAmountAndFeeLevel($id, $prevLabel, $newLabel) {
- // update price field label in line item.
- $lineItem = new CRM_Price_DAO_LineItem();
- $lineItem->price_field_value_id = $id;
- $lineItem->label = $prevLabel;
- $lineItem->find();
- while ($lineItem->fetch()) {
- $lineItemParams['id'] = $lineItem->id;
- $lineItemParams['label'] = $newLabel;
- CRM_Price_BAO_LineItem::create($lineItemParams);
-
- // update amount and fee level in civicrm_contribution and civicrm_participant
- $params = [
- 1 => [CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'],
- 2 => [CRM_Core_DAO::VALUE_SEPARATOR . $newLabel . ' -', 'String'],
- ];
- // Update contribution
- if (!empty($lineItem->contribution_id)) {
- CRM_Core_DAO::executeQuery("UPDATE `civicrm_contribution` SET `amount_level` = REPLACE(amount_level, %1, %2) WHERE id = {$lineItem->contribution_id}", $params);
- }
- // Update participant
- if ($lineItem->entity_table == 'civicrm_participant') {
- CRM_Core_DAO::executeQuery("UPDATE `civicrm_participant` SET `fee_level` = REPLACE(fee_level, %1, %2) WHERE id = {$lineItem->entity_id}", $params);
- }
- }
- }
-
}
$params['visibility_id'] = CRM_Utils_Array::value('visibility_id', $params, FALSE);
$ids = [];
if ($this->_oid) {
- $ids['id'] = $this->_oid;
+ $params['id'] = $this->_oid;
}
$optionValue = CRM_Price_BAO_PriceFieldValue::create($params, $ids);
$this->callAPISuccess('PriceFieldValue', 'create', ['id' => $pfv2['id'], 'label' => 'Price FIeld Value 2 Label']);
$participantGet = $this->callAPISuccess('Participant', 'get', ['id' => $participant['id']]);
$this->assertEquals(["pricefieldvalue1 - 2", "pricefieldvalue2 - 2"], $participantGet['values'][$participant['id']]['participant_fee_level']);
+ $conatactID4 = $this->individualCreate();
+ $myParams['contact_id'] = $conatactID4;
+ $myParams['participant_fee_level'] = CRM_Core_DAO::VALUE_SEPARATOR . "pricefieldvalue1 - 2" . CRM_Core_DAO::VALUE_SEPARATOR . "Price FIeld Value 2 Label - 2" . CRM_Core_DAO::VALUE_SEPARATOR;
+ $AdditionalParticipant = $this->callAPISuccess('Participant', 'create', $myParams);
+ $this->assertEquals(["pricefieldvalue1 - 2", "Price FIeld Value 2 Label - 2"], $AdditionalParticipant['values'][$AdditionalParticipant['id']]['fee_level']);
+ $lineItems = $this->callAPISuccess('LineItem', 'get', [
+ 'entity_id' => $AdditionalParticipant['id'],
+ 'entity_table' => 'civicrm_participant',
+ ]);
+ $this->assertEquals(2, $lineItems['count']);
+
+ // Check quantity, label and unit price of lines.
+ // TODO: These assertions depend on the order of the line items, which is
+ // technically incorrect.
+
+ $lineItem = array_pop($lineItems['values']);
+ $this->assertEquals(2, $lineItem['qty']);
+ $this->assertEquals(5, $lineItem['unit_price']);
+ $this->assertEquals('Price FIeld Value 2 Label', $lineItem['label']);
+
+ $lineItem = array_pop($lineItems['values']);
+ $this->assertEquals(2, $lineItem['qty']);
+ $this->assertEquals(20, $lineItem['unit_price']);
+ $this->assertEquals('pricefieldvalue1', $lineItem['label']);
// Cleanup
$this->callAPISuccess('participant', 'delete', ['id' => $participant['id']]);