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


PHP CRM_Contribute_DAO_Contribution::fieldKeys方法代码示例

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


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

示例1: rebook

 /**
  * Will rebook all given contributions to the given target contact
  *
  * @param $contribution_ids  an array of contribution IDs
  * @param $contact_id        the target contact ID
  */
 static function rebook($contribution_ids, $contact_id, $redirect_url = NULL)
 {
     $contact_id = (int) $contact_id;
     $excludeList = array('id', 'contribution_id', 'trxn_id', 'invoice_id', 'cancel_date', 'cancel_reason', 'address_id', 'contribution_contact_id', 'contribution_status_id');
     $cancelledStatus = CRM_Core_OptionGroup::getValue('contribution_status', 'Cancelled', 'name');
     $completedStatus = CRM_Core_OptionGroup::getValue('contribution_status', 'Completed', 'name');
     $contribution_fieldKeys = CRM_Contribute_DAO_Contribution::fieldKeys();
     $sepa_ooff_payment_id = CRM_Core_OptionGroup::getValue('payment_instrument', 'OOFF', 'name');
     $contribution_count = count($contribution_ids);
     $session = CRM_Core_Session::singleton();
     $rebooked = 0;
     foreach ($contribution_ids as $contributionId) {
         $params = array('version' => 3, 'sequential' => 1, 'id' => $contributionId);
         $contribution = civicrm_api('Contribution', 'getsingle', $params);
         if (empty($contribution['is_error'])) {
             // contribution exists
             // cancel contribution
             $params = array('version' => 3, 'contribution_status_id' => $cancelledStatus, 'cancel_reason' => ts('Rebooked to CiviCRM ID %1', array(1 => $contact_id, 'domain' => 'de.systopia.donrec')), 'cancel_date' => date('YmdHis'), 'currency' => $contribution['currency'], 'id' => $contribution['id']);
             $cancelledContribution = civicrm_api('Contribution', 'create', $params);
             if (!empty($cancelledContribution['is_error']) && !empty($cancelledContribution['error_message'])) {
                 CRM_Core_Session::setStatus($cancelledContribution['error_message'], ts("Error", array('domain' => 'de.systopia.donrec')), "error");
             }
             // Now compile $attributes, taking the exclusionList into account
             $attributes = array('version' => 3, 'contribution_contact_id' => $contact_id, 'contribution_status_id' => $completedStatus, 'payment_instrument_id' => CRM_Core_OptionGroup::getValue('payment_instrument', $contribution['instrument_id'], 'id'));
             foreach ($contribution as $key => $value) {
                 if (!in_array($key, $excludeList) && in_array($key, $contribution_fieldKeys)) {
                     // to be sure that this keys really exists
                     $attributes[$key] = $value;
                 }
                 if (strstr($key, 'custom')) {
                     // get custom fields
                     // load custom field spec for exception handling
                     $custom_field_id = substr($key, 7);
                     $custom_field = civicrm_api('CustomField', 'getsingle', array('id' => $custom_field_id, 'version' => 3));
                     // Exception 1: dates are not properly formatted
                     if ($custom_field['data_type'] == 'Date') {
                         if (!empty($value)) {
                             $value = date('YmdHis', strtotime($value));
                         }
                     }
                     $attributes[$key] = $value;
                 }
             }
             // create new contribution
             $newContribution = civicrm_api('Contribution', 'create', $attributes);
             if (!empty($newContribution['is_error']) && !empty($newContribution['error_message'])) {
                 CRM_Core_Session::setStatus($newContribution['error_message'], ts("Error", array('domain' => 'de.systopia.donrec')), "error");
             }
             // Exception handling for SEPA OOFF payments (org.project60.sepa extension)
             if (!empty($sepa_ooff_payment_id) && $attributes['payment_instrument_id'] == $sepa_ooff_payment_id) {
                 CRM_Donrec_Form_Task_Rebook::fixOOFFMandate($contribution, $newContribution['id']);
             }
             // create rebook note
             $params = array('version' => 3, 'sequential' => 1, 'note' => ts('Rebooked from CiviCRM ID %1', array(1 => $contribution['contact_id'], 'domain' => 'de.systopia.donrec')), 'entity_table' => 'civicrm_contribution', 'entity_id' => $newContribution['id']);
             $result = civicrm_api('Note', 'create', $params);
             // move all notes from the old contribution
             $notes = civicrm_api('Note', 'get', array('entity_id' => $contributionId, 'entity_table' => 'civicrm_contribution', 'version' => 3));
             if (!empty($notes['is_error'])) {
                 CRM_Core_Error::debug_log_message("de.systopia.donrec: Error while reading notes: " . $notes['error_message']);
             } else {
                 foreach ($notes['values'] as $note) {
                     $dao = new CRM_Core_DAO_Note();
                     $dao->id = $note['id'];
                     $dao->entity_id = $newContribution['id'];
                     $dao->save();
                 }
             }
             $rebooked += 1;
         }
     }
     if ($rebooked == $contribution_count) {
         CRM_Core_Session::setStatus(ts('%1 contribution(s) successfully rebooked!', array(1 => $contribution_count, 'domain' => 'de.systopia.donrec')), ts('Successfully rebooked!'), 'success');
     } else {
         CRM_Core_Error::debug_log_message("de.systopia.donrec: Only {$rebooked} of {$contribution_count} contributions rebooked.", array('domain' => 'de.systopia.donrec'));
         CRM_Core_Session::setStatus(ts('Please check your data and try again', array(1 => $contribution_count)), ts('Nothing rebooked!'), 'warning');
         CRM_Utils_System::redirect($redirect_url);
     }
 }
开发者ID:systopia,项目名称:de.systopia.donrec,代码行数:84,代码来源:Rebook.php


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