示例#1
0
 /**
  * Insert/update a new entry in the database.
  *
  * @param array $params
  *   (reference), array $ids.
  *
  * @param $ids
  *
  * @return CRM_Upgrade_Snapshot_V4p2_Price_DAO_FieldValue
  */
 public static function &add(&$params, $ids)
 {
     $fieldValueBAO = new CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue();
     $fieldValueBAO->copyValues($params);
     if ($id = CRM_Utils_Array::value('id', $ids)) {
         $fieldValueBAO->id = $id;
     }
     if (!empty($params['is_default'])) {
         $query = 'UPDATE civicrm_price_field_value SET is_default = 0 WHERE  price_field_id = %1';
         $p = array(1 => array($params['price_field_id'], 'Integer'));
         CRM_Core_DAO::executeQuery($query, $p);
     }
     $fieldValueBAO->save();
     return $fieldValueBAO;
 }
示例#2
0
 /**
 * This method will create the lineItem array required for
 * processAmount method
 *
 * @param  int   $fid       price set field id
 * @param  array $params    reference to form values
 * @param  array $fields    reference to array of fields belonging
 *                          to the price set used for particular event
 * @param  array $values    reference to the values array(
   this is
 *                          lineItem array)
 *
 * @return void
 * @access static
 */
 static function format($fid, &$params, &$fields, &$values)
 {
     if (empty($params["price_{$fid}"])) {
         return;
     }
     $optionIDs = implode(',', array_keys($params["price_{$fid}"]));
     //lets first check in fun parameter,
     //since user might modified w/ hooks.
     $options = array();
     if (array_key_exists('options', $fields)) {
         $options = $fields['options'];
     } else {
         CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue::getValues($fid, $options, 'weight', TRUE);
     }
     $fieldTitle = CRM_Utils_Array::value('label', $fields);
     if (!$fieldTitle) {
         $fieldTitle = CRM_Core_DAO::getFieldValue('CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field', $fid, 'label');
     }
     foreach ($params["price_{$fid}"] as $oid => $qty) {
         $price = $options[$oid]['amount'];
         // lets clean the price in case it is not yet cleaned
         // CRM-10974
         $price = CRM_Utils_Rule::cleanMoney($price);
         $participantsPerField = CRM_Utils_Array::value('count', $options[$oid], 0);
         $values[$oid] = array('price_field_id' => $fid, 'price_field_value_id' => $oid, 'label' => CRM_Utils_Array::value('label', $options[$oid]), 'field_title' => $fieldTitle, 'description' => CRM_Utils_Array::value('description', $options[$oid]), 'qty' => $qty, 'unit_price' => $price, 'line_total' => $qty * $price, 'participant_count' => $qty * $participantsPerField, 'max_value' => CRM_Utils_Array::value('max_value', $options[$oid]), 'membership_type_id' => CRM_Utils_Array::value('membership_type_id', $options[$oid]), 'auto_renew' => CRM_Utils_Array::value('auto_renew', $options[$oid]), 'html_type' => $fields['html_type']);
     }
 }
示例#3
0
 /**
  * Validate the priceset.
  *
  * @param int $priceSetId
  * @param array $fields
  * @param array $error
  */
 public static function priceSetValidation($priceSetId, $fields, &$error)
 {
     // check for at least one positive
     // amount price field should be selected.
     $priceField = new CRM_Upgrade_Snapshot_V4p2_Price_DAO_Field();
     $priceField->price_set_id = $priceSetId;
     $priceField->find();
     $priceFields = array();
     while ($priceField->fetch()) {
         $key = "price_{$priceField->id}";
         if (!empty($fields[$key])) {
             $priceFields[$priceField->id] = $fields[$key];
         }
     }
     if (!empty($priceFields)) {
         // we should has to have positive amount.
         $sql = "\nSELECT  id, html_type\nFROM  civicrm_price_field\nWHERE  id IN (" . implode(',', array_keys($priceFields)) . ')';
         $fieldDAO = CRM_Core_DAO::executeQuery($sql);
         $htmlTypes = array();
         while ($fieldDAO->fetch()) {
             $htmlTypes[$fieldDAO->id] = $fieldDAO->html_type;
         }
         $selectedAmounts = array();
         foreach ($htmlTypes as $fieldId => $type) {
             $options = array();
             CRM_Upgrade_Snapshot_V4p2_Price_BAO_FieldValue::getValues($fieldId, $options);
             if (empty($options)) {
                 continue;
             }
             if ($type == 'Text') {
                 foreach ($options as $opId => $option) {
                     $selectedAmounts[$opId] = $priceFields[$fieldId] * $option['amount'];
                     break;
                 }
             } elseif (is_array($fields["price_{$fieldId}"])) {
                 foreach (array_keys($fields["price_{$fieldId}"]) as $opId) {
                     $selectedAmounts[$opId] = $options[$opId]['amount'];
                 }
             } elseif (in_array($fields["price_{$fieldId}"], array_keys($options))) {
                 $selectedAmounts[$fields["price_{$fieldId}"]] = $options[$fields["price_{$fieldId}"]]['amount'];
             }
         }
         list($componentName) = explode(':', $fields['_qf_default']);
         // now we have all selected amount in hand.
         $totalAmount = array_sum($selectedAmounts);
         if ($totalAmount < 0) {
             $error['_qf_default'] = ts('%1 amount can not be less than zero. Please select the options accordingly.', array(1 => $componentName));
         }
     } else {
         $error['_qf_default'] = ts("Please select at least one option from price set.");
     }
 }