function &getFields()
 {
     if (!isset($this->_lineItemFields)) {
         $this->_lineItemFields = array();
         $LIFields = CRM_Price_DAO_LineItem::fields();
         unset($LIFields['entity_table']);
         unset($LIFields['entity_id']);
         unset($LIFields['participant_count']);
         unset($LIFields['deductible_amount']);
         unset($LIFields['price_field_id']);
         unset($LIFields['contribution_id']);
         unset($LIFields['id']);
         $fields = array();
         //FKClassName, export, import, headerPattern, dataPattern
         foreach ($LIFields as $name => $field) {
             //$field['where'] = "civicrm_line_item.".$field['name'];
             $field['export'] = true;
             $field['import'] = true;
             unset($field['required']);
             $fields['lineitems_' . $name] = $field;
         }
         /*
         $fields['lineitems_join_type'] = array(
             'name'  => 'join_type',
             'title' => 'Join Type',
             'type'  => CRM_Utils_Type::T_INT,
         );
         */
         //todo: Add field for join selector
         $this->_lineItemFields = $fields;
     }
     return $this->_lineItemFields;
 }
 /**
  * returns the list of fields that can be exported
  *
  * @access public
  * return array
  * @static
  */
 static function &export($prefix = false)
 {
     if (!self::$_export) {
         self::$_export = array();
         $fields = self::fields();
         foreach ($fields as $name => $field) {
             if (CRM_Utils_Array::value('export', $field)) {
                 if ($prefix) {
                     self::$_export['line_item'] =& $fields[$name];
                 } else {
                     self::$_export[$name] =& $fields[$name];
                 }
             }
         }
     }
     return self::$_export;
 }
 function upgrade_3_3_beta1($rev)
 {
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->processSQL($rev);
     // CRM-6902
     // Add column price_field_value_id in civicrm_line_item.
     // Do not drop option_group_id column now since we need it to
     // update line items.
     $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;";
     CRM_Core_DAO::executeQuery($updateLineItem1);
     $priceFieldDAO = new CRM_Price_DAO_Field();
     $priceFieldDAO->find();
     $ids = array();
     while ($priceFieldDAO->fetch()) {
         $opGroupDAO = new CRM_Core_DAO_OptionGroup();
         $opGroupDAO->name = 'civicrm_price_field.amount.' . $priceFieldDAO->id;
         if (!$opGroupDAO->find(TRUE)) {
             $opGroupDAO->free();
             continue;
         }
         $opValueDAO = new CRM_Core_DAO_OptionValue();
         $opValueDAO->option_group_id = $opGroupDAO->id;
         $opValueDAO->find();
         while ($opValueDAO->fetch()) {
             // FIX ME: not migrating description(?), there will
             // be a field description for each option.
             $fieldValue = array('price_field_id' => $priceFieldDAO->id, 'label' => $opValueDAO->label, 'name' => CRM_Utils_String::munge($opValueDAO->label, '_', 64), 'amount' => $opValueDAO->name, 'weight' => $opValueDAO->weight, 'is_default' => $opValueDAO->is_default, 'is_active' => $opValueDAO->is_active);
             if ($priceFieldDAO->count) {
                 // Migrate Participant Counts on option level.
                 // count of each option will be the same
                 // as earlier field count.
                 $fieldValue['count'] = $priceFieldDAO->count;
             }
             $fieldValueDAO = CRM_Price_BAO_FieldValue::add($fieldValue, $ids);
             $lineItemDAO = new CRM_Price_DAO_LineItem();
             $lineItemDAO->option_group_id = $opGroupDAO->id;
             $lineItemDAO->label = $opValueDAO->label;
             $lineItemDAO->unit_price = $opValueDAO->name;
             $labelFound = $priceFound = FALSE;
             // check with label and amount
             if (!$lineItemDAO->find(TRUE)) {
                 $lineItemDAO->free();
                 $lineItemDAO = new CRM_Price_DAO_LineItem();
                 $lineItemDAO->option_group_id = $opGroupDAO->id;
                 $lineItemDAO->label = $opValueDAO->label;
                 // check with label only
                 if ($lineItemDAO->find(TRUE)) {
                     $labelFound = TRUE;
                 }
             } else {
                 $labelFound = TRUE;
                 $priceFound = TRUE;
             }
             $lineItemDAO->free();
             // update civicrm_line_item for price_field_value_id.
             // Used query to avoid line by line update.
             if ($labelFound || $priceFound) {
                 $lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'), 2 => array($opValueDAO->label, 'String'));
                 $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2";
                 if ($priceFound) {
                     $lineItemParams[3] = array($opValueDAO->name, 'Float');
                     $updateLineItems .= " AND unit_price = %3";
                 }
                 CRM_Core_DAO::executeQuery($updateLineItems, $lineItemParams);
             }
         }
         $opGroupDAO->delete();
         $opValueDAO->free();
         $opGroupDAO->free();
     }
     $priceFieldDAO->free();
     // Now drop option_group_id column from civicrm_line_item
     $updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,\n                           ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;";
     CRM_Core_DAO::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE);
     $updatePriceField = "ALTER TABLE civicrm_price_field DROP count";
     CRM_Core_DAO::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE);
     // as the table 'civicrm_price_field' is localised and column 'count' is dropped
     // after the views are rebuild, we need to rebuild views to avoid invalid refrence of table.
     if ($upgrade->multilingual) {
         CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev);
     }
 }
Ejemplo n.º 4
0
 /**
  * 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()) {
         $lineItem->label = $newLabel;
         $lineItem->save();
         // update amount and fee level in civicrm_contribution and civicrm_participant
         $params = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'), 2 => array(CRM_Core_DAO::VALUE_SEPARATOR . $newLabel . ' -', 'String'));
         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);
             $participantIds = CRM_Event_BAO_Participant::getParticipantIds($lineItem->contribution_id);
             foreach ($participantIds as $key => $id) {
                 if (!empty($id)) {
                     CRM_Core_DAO::executeQuery("UPDATE `civicrm_participant` SET `fee_level` = REPLACE(fee_level, %1, %2) WHERE id = {$id}", $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 = array(1 => array(CRM_Core_DAO::VALUE_SEPARATOR . $prevLabel . ' -', 'String'), 2 => array(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);
         }
     }
 }
Ejemplo n.º 6
0
 /**
  * Delete line items for given entity.
  *
  * @param int $entityId
  * @param int $entityTable
  *
  * @access public
  * @static
  */
 public static function deleteLineItems($entityId, $entityTable)
 {
     $result = false;
     if (!$entityId || !$entityTable) {
         return $result;
     }
     require_once 'CRM/Core/Transaction.php';
     $transaction = new CRM_Core_Transaction();
     $lineItem = new CRM_Price_DAO_LineItem();
     $lineItem->entity_id = $entityId;
     $lineItem->entity_table = $entityTable;
     $result = $lineItem->delete();
     $transaction->commit();
     return $result;
 }