当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_DAO::setCreateDefaults方法代码示例

本文整理汇总了PHP中CRM_Core_DAO::setCreateDefaults方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::setCreateDefaults方法的具体用法?PHP CRM_Core_DAO::setCreateDefaults怎么用?PHP CRM_Core_DAO::setCreateDefaults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CRM_Core_DAO的用法示例。


在下文中一共展示了CRM_Core_DAO::setCreateDefaults方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: add

 /**
  * Takes an associative array and creates a contribution object.
  *
  * the function extract all the params it needs to initialize the create a
  * contribution object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param array $ids
  *   The array that holds all the db ids.
  *
  * @return CRM_Contribute_BAO_Contribution|void
  */
 public static function add(&$params, $ids = array())
 {
     if (empty($params)) {
         return NULL;
     }
     //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array
     $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params));
     $duplicates = array();
     if (self::checkDuplicate($params, $duplicates, $contributionID)) {
         $error = CRM_Core_Error::singleton();
         $d = implode(', ', $duplicates);
         $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}");
         return $error;
     }
     // first clean up all the money fields
     $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount');
     //if priceset is used, no need to cleanup money
     if (!empty($params['skipCleanMoney'])) {
         unset($moneyFields[0]);
     }
     foreach ($moneyFields as $field) {
         if (isset($params[$field])) {
             $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
         }
     }
     //set defaults in create mode
     if (!$contributionID) {
         CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
     }
     self::calculateMissingAmountParams($params, $contributionID);
     if (!empty($params['payment_instrument_id'])) {
         $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name');
         if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) {
             $params['check_number'] = 'null';
         }
     }
     $setPrevContribution = TRUE;
     // CRM-13964 partial payment
     if (!empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) {
         $partialAmtTotal = $params['partial_payment_total'];
         $partialAmtPay = $params['partial_amount_pay'];
         $params['total_amount'] = $partialAmtTotal;
         if ($partialAmtPay < $partialAmtTotal) {
             $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name');
             $params['is_pay_later'] = 0;
             $setPrevContribution = FALSE;
         }
     }
     if ($contributionID) {
         CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Contribution', NULL, $params);
     }
     $contribution = new CRM_Contribute_BAO_Contribution();
     $contribution->copyValues($params);
     $contribution->id = $contributionID;
     if (empty($contribution->id)) {
         // (only) on 'create', make sure that a valid currency is set (CRM-16845)
         if (!CRM_Utils_Rule::currencyCode($contribution->currency)) {
             $config = CRM_Core_Config::singleton();
             $contribution->currency = $config->defaultCurrency;
         }
     }
     if ($contributionID && $setPrevContribution) {
         $params['prevContribution'] = self::getValues(array('id' => $contributionID), CRM_Core_DAO::$_nullArray, CRM_Core_DAO::$_nullArray);
     }
     $result = $contribution->save();
     // Add financial_trxn details as part of fix for CRM-4724
     $contribution->trxn_result_code = CRM_Utils_Array::value('trxn_result_code', $params);
     $contribution->payment_processor = CRM_Utils_Array::value('payment_processor', $params);
     //add Account details
     $params['contribution'] = $contribution;
     self::recordFinancialAccounts($params);
     // reset the group contact cache for this group
     CRM_Contact_BAO_GroupContactCache::remove();
     if ($contributionID) {
         CRM_Utils_Hook::post('edit', 'Contribution', $contribution->id, $contribution);
     } else {
         CRM_Utils_Hook::post('create', 'Contribution', $contribution->id, $contribution);
     }
     return $result;
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:96,代码来源:Contribution.php

示例2: create

 /**
  * Creates a new entry in the database.
  *
  * @param array $params
  *   (reference), array $ids.
  *
  * @param $ids
  *
  * @return CRM_Price_DAO_PriceFieldValue
  */
 public static function create(&$params, $ids = array())
 {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('id', $ids));
     if (!is_array($params) || empty($params)) {
         return NULL;
     }
     if (!$id && empty($params['name'])) {
         $params['name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 242));
     }
     if ($id && !empty($params['weight'])) {
         if (isset($params['name'])) {
             unset($params['name']);
         }
         $oldWeight = NULL;
         if ($id) {
             $oldWeight = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $id, 'weight', 'id');
         }
         $fieldValues = array('price_field_id' => CRM_Utils_Array::value('price_field_id', $params, 0));
         $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Price_DAO_PriceFieldValue', $oldWeight, $params['weight'], $fieldValues);
     } else {
         if (!$id) {
             CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
             if (empty($params['name'])) {
                 $params['name'] = CRM_Utils_String::munge(CRM_Utils_Array::value('label', $params), '_', 64);
             }
         }
     }
     return self::add($params, $ids);
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:39,代码来源:PriceFieldValue.php

示例3: add

 /**
  * Add the membership types.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  * @param array $ids
  *   Array contains the id - this param is deprecated.
  *
  *
  * @return object
  */
 public static function add(&$params, $ids = array())
 {
     $id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membershipStatus', $ids));
     if (!$id) {
         CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
         //copy name to label when not passed.
         if (empty($params['label']) && !empty($params['name'])) {
             $params['label'] = $params['name'];
         }
         if (empty($params['name']) && !empty($params['label'])) {
             $params['name'] = $params['label'];
         }
     }
     // set all other defaults to false.
     if (!empty($params['is_default'])) {
         $query = "UPDATE civicrm_membership_status SET is_default = 0";
         CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
     }
     // action is taken depending upon the mode
     $membershipStatus = new CRM_Member_DAO_MembershipStatus();
     $membershipStatus->copyValues($params);
     $membershipStatus->id = $id;
     $membershipStatus->save();
     return $membershipStatus;
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:36,代码来源:MembershipStatus.php

示例4: add

 /**
  * Takes an associative array and creates a contribution object.
  *
  * the function extract all the params it needs to initialize the create a
  * contribution object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  * @param array $ids
  *   The array that holds all the db ids.
  *
  * @return CRM_Contribute_BAO_Contribution|void
  */
 public static function add(&$params, $ids = array())
 {
     if (empty($params)) {
         return NULL;
     }
     //per http://wiki.civicrm.org/confluence/display/CRM/Database+layer we are moving away from $ids array
     $contributionID = CRM_Utils_Array::value('contribution', $ids, CRM_Utils_Array::value('id', $params));
     $duplicates = array();
     if (self::checkDuplicate($params, $duplicates, $contributionID)) {
         $error = CRM_Core_Error::singleton();
         $d = implode(', ', $duplicates);
         $error->push(CRM_Core_Error::DUPLICATE_CONTRIBUTION, 'Fatal', array($d), "Duplicate error - existing contribution record(s) have a matching Transaction ID or Invoice ID. Contribution record ID(s) are: {$d}");
         return $error;
     }
     // first clean up all the money fields
     $moneyFields = array('total_amount', 'net_amount', 'fee_amount', 'non_deductible_amount');
     //if priceset is used, no need to cleanup money
     if (!empty($params['skipCleanMoney'])) {
         unset($moneyFields[0]);
     }
     foreach ($moneyFields as $field) {
         if (isset($params[$field])) {
             $params[$field] = CRM_Utils_Rule::cleanMoney($params[$field]);
         }
     }
     //set defaults in create mode
     if (!$contributionID) {
         CRM_Core_DAO::setCreateDefaults($params, self::getDefaults());
     }
     $contributionStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     //if contribution is created with cancelled or refunded status, add credit note id
     if (!empty($params['contribution_status_id'])) {
         // @todo - should we include Chargeback? If so use self::isContributionStatusNegative($params['contribution_status_id'])
         if ($params['contribution_status_id'] == array_search('Refunded', $contributionStatus) || $params['contribution_status_id'] == array_search('Cancelled', $contributionStatus)) {
             if (empty($params['creditnote_id']) || $params['creditnote_id'] == "null") {
                 $params['creditnote_id'] = self::createCreditNoteId();
             }
         }
     } else {
         // Since the fee amount is expecting this (later on) ensure it is always set.
         // It would only not be set for an update where it is unchanged.
         $params['contribution_status_id'] = civicrm_api3('Contribution', 'getvalue', array('id' => $contributionID, 'return' => 'contribution_status_id'));
     }
     if (!$contributionID && CRM_Utils_Array::value('membership_id', $params) && self::checkContributeSettings('deferred_revenue_enabled')) {
         $memberStartDate = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $params['membership_id'], 'start_date');
         if ($memberStartDate) {
             $params['revenue_recognition_date'] = date('Ymd', strtotime($memberStartDate));
         }
     }
     self::calculateMissingAmountParams($params, $contributionID);
     if (!empty($params['payment_instrument_id'])) {
         $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument('name');
         if ($params['payment_instrument_id'] != array_search('Check', $paymentInstruments)) {
             $params['check_number'] = 'null';
         }
     }
     $setPrevContribution = TRUE;
     // CRM-13964 partial payment
     if (!empty($params['partial_payment_total']) && !empty($params['partial_amount_pay'])) {
         $partialAmtTotal = $params['partial_payment_total'];
         $partialAmtPay = $params['partial_amount_pay'];
         $params['total_amount'] = $partialAmtTotal;
         if ($partialAmtPay < $partialAmtTotal) {
             $params['contribution_status_id'] = CRM_Core_OptionGroup::getValue('contribution_status', 'Partially paid', 'name');
             $params['is_pay_later'] = 0;
             $setPrevContribution = FALSE;
         }
     }
     if ($contributionID && $setPrevContribution) {
         $params['prevContribution'] = self::getOriginalContribution($contributionID);
     }
     // CRM-16189
     CRM_Financial_BAO_FinancialAccount::checkFinancialTypeHasDeferred($params, $contributionID);
     if ($contributionID && !empty($params['revenue_recognition_date']) && !empty($params['prevContribution']) && !($contributionStatus[$params['prevContribution']->contribution_status_id] == 'Pending') && !self::allowUpdateRevenueRecognitionDate($contributionID)) {
         unset($params['revenue_recognition_date']);
     }
     if (!isset($params['tax_amount']) && $setPrevContribution && (isset($params['total_amount']) || isset($params['financial_type_id']))) {
         $params = CRM_Contribute_BAO_Contribution::checkTaxAmount($params);
     }
     if ($contributionID) {
         CRM_Utils_Hook::pre('edit', 'Contribution', $contributionID, $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Contribution', NULL, $params);
     }
     $contribution = new CRM_Contribute_BAO_Contribution();
     $contribution->copyValues($params);
//.........这里部分代码省略.........
开发者ID:nielosz,项目名称:civicrm-core,代码行数:101,代码来源:Contribution.php


注:本文中的CRM_Core_DAO::setCreateDefaults方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。