Beispiel #1
0
 /**
  * @param $fields
  * @param array $params
  * @param $lineItem
  */
 public static function processAmount(&$fields, &$params, &$lineItem)
 {
     // using price set
     $totalPrice = 0;
     $radioLevel = $checkboxLevel = $selectLevel = $textLevel = array();
     foreach ($fields as $id => $field) {
         if (empty($params["price_{$id}"]) || empty($params["price_{$id}"]) && $params["price_{$id}"] == NULL) {
             // skip if nothing was submitted for this field
             continue;
         }
         switch ($field['html_type']) {
             case 'Text':
                 $params["price_{$id}"] = array(key($field['options']) => $params["price_{$id}"]);
                 CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 $totalPrice += $lineItem[key($field['options'])]['line_total'];
                 break;
             case 'Radio':
                 //special case if user select -none-
                 if ($params["price_{$id}"] <= 0) {
                     continue;
                 }
                 $params["price_{$id}"] = array($params["price_{$id}"] => 1);
                 $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
                 $optionLabel = CRM_Utils_Array::value('label', $field['options'][$optionValueId]);
                 $params['amount_priceset_level_radio'] = array();
                 $params['amount_priceset_level_radio'][$optionValueId] = $optionLabel;
                 if (isset($radioLevel)) {
                     $radioLevel = array_merge($radioLevel, array_keys($params['amount_priceset_level_radio']));
                 } else {
                     $radioLevel = array_keys($params['amount_priceset_level_radio']);
                 }
                 CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 $totalPrice += $lineItem[$optionValueId]['line_total'];
                 break;
             case 'Select':
                 $params["price_{$id}"] = array($params["price_{$id}"] => 1);
                 $optionValueId = CRM_Utils_Array::key(1, $params["price_{$id}"]);
                 $optionLabel = $field['options'][$optionValueId]['label'];
                 $params['amount_priceset_level_select'] = array();
                 $params['amount_priceset_level_select'][CRM_Utils_Array::key(1, $params["price_{$id}"])] = $optionLabel;
                 if (isset($selectLevel)) {
                     $selectLevel = array_merge($selectLevel, array_keys($params['amount_priceset_level_select']));
                 } else {
                     $selectLevel = array_keys($params['amount_priceset_level_select']);
                 }
                 CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 $totalPrice += $lineItem[$optionValueId]['line_total'];
                 break;
             case 'CheckBox':
                 $params['amount_priceset_level_checkbox'] = $optionIds = array();
                 foreach ($params["price_{$id}"] as $optionId => $option) {
                     $optionIds[] = $optionId;
                     $optionLabel = $field['options'][$optionId]['label'];
                     $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'])));
                     } else {
                         $checkboxLevel = array_keys($params['amount_priceset_level_checkbox']);
                     }
                 }
                 CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::format($id, $params, $field, $lineItem);
                 foreach ($optionIds as $optionId) {
                     $totalPrice += $lineItem[$optionId]['line_total'];
                 }
                 break;
         }
     }
     $amount_level = array();
     $totalParticipant = 0;
     if (is_array($lineItem)) {
         foreach ($lineItem as $values) {
             $totalParticipant += $values['participant_count'];
             if ($values['html_type'] == 'Text') {
                 $amount_level[] = $values['label'] . ' - ' . $values['qty'];
                 continue;
             }
             $amount_level[] = $values['label'];
         }
     }
     $displayParticipantCount = '';
     if ($totalParticipant > 0) {
         $displayParticipantCount = ' Participant Count -' . $totalParticipant;
     }
     $params['amount_level'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $amount_level) . $displayParticipantCount . CRM_Core_DAO::VALUE_SEPARATOR;
     $params['amount'] = $totalPrice;
 }