示例#1
0
 /**
  * Takes a bunch of params that are needed to match certain criteria and
  * retrieves the relevant objects.  Typically, the valid params are only
  * price_field_id.  This is the inverse function of create.  It also
  * stores all of the retrieved values in the default array.
  *
  * @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_Upgrade_Snapshot_V4p2_Price_BAO_LineItem object
  * @access public
  * @static
  */
 static function retrieve(&$params, &$defaults)
 {
     $lineItem = new CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem();
     $lineItem->copyValues($params);
     if ($lineItem->find(TRUE)) {
         CRM_Core_DAO::storeValues($lineItem, $defaults);
         return $lineItem;
     }
     return NULL;
 }
 /**
  * (Queue Task Callback)
  *
  * Find any participant records and create corresponding line-item
  * records.
  *
  * @param CRM_Queue_TaskContext $ctx
  * @param int $startId
  *   the first/lowest participant ID to convert.
  * @param int $endId
  *   the last/highest participant ID to convert.
  *
  * @return bool
  */
 public static function task_4_2_alpha1_convertParticipants(CRM_Queue_TaskContext $ctx, $startId, $endId)
 {
     $upgrade = new CRM_Upgrade_Form();
     //create lineitems for participant in edge cases using default price set for contribution.
     $query = "\nSELECT    cp.id as participant_id, cp.fee_amount, cp.fee_level,ce.is_monetary,\n          cpse.price_set_id, cpf.id as price_field_id, cpfv.id as price_field_value_id\nFROM      civicrm_participant cp\nLEFT JOIN civicrm_line_item cli ON cli.entity_id=cp.id and cli.entity_table = 'civicrm_participant'\nLEFT JOIN civicrm_event ce ON ce.id=cp.event_id\nLEFT JOIN civicrm_price_set_entity cpse ON cp.event_id = cpse.entity_id and cpse.entity_table = 'civicrm_event'\nLEFT JOIN civicrm_price_field cpf ON cpf.price_set_id = cpse.price_set_id\nLEFT JOIN civicrm_price_field_value cpfv ON cpfv.price_field_id = cpf.id AND cpfv.label = cp.fee_level\nWHERE     (cp.id BETWEEN %1 AND %2)\nAND       cli.entity_id IS NULL AND cp.fee_amount IS NOT NULL";
     $sqlParams = array(1 => array($startId, 'Integer'), 2 => array($endId, 'Integer'));
     $dao = CRM_Core_DAO::executeQuery($query, $sqlParams);
     if ($dao->N) {
         $defaultPriceSetId = CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Set', 'default_contribution_amount', 'id', 'name');
         $priceSets = current(CRM_Upgrade_Snapshot_V4p2_Price_BAO_Set::getSetDetail($defaultPriceSetId));
         $fieldID = key($priceSets['fields']);
     }
     while ($dao->fetch()) {
         $lineParams = array('entity_table' => 'civicrm_participant', 'entity_id' => $dao->participant_id, 'label' => $dao->fee_level ? $dao->fee_level : ts('Default'), 'qty' => 1, 'unit_price' => $dao->fee_amount, 'line_total' => $dao->fee_amount, 'participant_count' => 1);
         if ($dao->is_monetary && $dao->price_field_id) {
             $lineParams += array('price_field_id' => $dao->price_field_id, 'price_field_value_id' => $dao->price_field_value_id);
             $priceSetId = $dao->price_set_id;
         } else {
             $lineParams['price_field_id'] = $fieldID;
             $priceSetId = $defaultPriceSetId;
         }
         CRM_Upgrade_Snapshot_V4p2_Price_BAO_LineItem::create($lineParams);
     }
     return TRUE;
 }
示例#3
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;
 }