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


PHP CRM_Member_BAO_Membership::save方法代码示例

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


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

示例1: add

 /**
  * Takes an associative array and creates a membership object.
  *
  * the function extracts all the params it needs to initialize the created
  * membership 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_Member_BAO_Membership
  */
 public static function add(&$params, $ids = array())
 {
     $oldStatus = $oldType = NULL;
     $params['id'] = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('membership', $ids));
     if ($params['id']) {
         CRM_Utils_Hook::pre('edit', 'Membership', $params['id'], $params);
     } else {
         CRM_Utils_Hook::pre('create', 'Membership', NULL, $params);
     }
     $id = $params['id'];
     // we do this after the hooks are called in case it has been altered
     if ($id) {
         $membershipObj = new CRM_Member_DAO_Membership();
         $membershipObj->id = $id;
         $membershipObj->find();
         while ($membershipObj->fetch()) {
             $oldStatus = $membershipObj->status_id;
             $oldType = $membershipObj->membership_type_id;
         }
     }
     if (array_key_exists('is_override', $params) && !$params['is_override']) {
         $params['is_override'] = 'null';
     }
     $membership = new CRM_Member_BAO_Membership();
     $membership->copyValues($params);
     $membership->id = $id;
     $membership->save();
     $membership->free();
     if (empty($membership->contact_id) || empty($membership->status_id)) {
         // this means we are in renewal mode and are just updating the membership
         // record or this is an API update call and all fields are not present in the update record
         // however the hooks don't care and want all data CRM-7784
         $tempMembership = new CRM_Member_DAO_Membership();
         $tempMembership->id = $membership->id;
         $tempMembership->find(TRUE);
         $membership = $tempMembership;
     }
     //get the log start date.
     //it is set during renewal of membership.
     $logStartDate = CRM_Utils_Array::value('log_start_date', $params);
     $logStartDate = $logStartDate ? CRM_Utils_Date::isoToMysql($logStartDate) : CRM_Utils_Date::isoToMysql($membership->start_date);
     $values = self::getStatusANDTypeValues($membership->id);
     $membershipLog = array('membership_id' => $membership->id, 'status_id' => $membership->status_id, 'start_date' => $logStartDate, 'end_date' => CRM_Utils_Date::isoToMysql($membership->end_date), 'modified_date' => date('Ymd'), 'membership_type_id' => $values[$membership->id]['membership_type_id'], 'max_related' => $membership->max_related);
     $session = CRM_Core_Session::singleton();
     // If we have an authenticated session, set modified_id to that user's contact_id, else set to membership.contact_id
     if ($session->get('userID')) {
         $membershipLog['modified_id'] = $session->get('userID');
     } elseif (!empty($ids['userId'])) {
         $membershipLog['modified_id'] = $ids['userId'];
     } else {
         $membershipLog['modified_id'] = $membership->contact_id;
     }
     CRM_Member_BAO_MembershipLog::add($membershipLog, CRM_Core_DAO::$_nullArray);
     // reset the group contact cache since smart groups might be affected due to this
     CRM_Contact_BAO_GroupContactCache::remove();
     if ($id) {
         if ($membership->status_id != $oldStatus) {
             $allStatus = CRM_Member_BAO_Membership::buildOptions('status_id', 'get');
             $activityParam = array('subject' => "Status changed from {$allStatus[$oldStatus]} to {$allStatus[$membership->status_id]}", 'source_contact_id' => $membershipLog['modified_id'], 'target_contact_id' => $membership->contact_id, 'source_record_id' => $membership->id, 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Membership Status'), 'status_id' => 2, 'priority_id' => 2, 'activity_date_time' => date('Y-m-d H:i:s'));
             civicrm_api3('activity', 'create', $activityParam);
         }
         if (isset($membership->membership_type_id) && $membership->membership_type_id != $oldType) {
             $membershipTypes = CRM_Member_BAO_Membership::buildOptions('membership_type_id', 'get');
             $activityParam = array('subject' => "Type changed from {$membershipTypes[$oldType]} to {$membershipTypes[$membership->membership_type_id]}", 'source_contact_id' => $membershipLog['modified_id'], 'target_contact_id' => $membership->contact_id, 'source_record_id' => $membership->id, 'activity_type_id' => CRM_Core_PseudoConstant::getKey('CRM_Activity_BAO_Activity', 'activity_type_id', 'Change Membership Type'), 'status_id' => 2, 'priority_id' => 2, 'activity_date_time' => date('Y-m-d H:i:s'));
             civicrm_api3('activity', 'create', $activityParam);
         }
         CRM_Utils_Hook::post('edit', 'Membership', $membership->id, $membership);
     } else {
         CRM_Utils_Hook::post('create', 'Membership', $membership->id, $membership);
     }
     return $membership;
 }
开发者ID:konadave,项目名称:civicrm-core,代码行数:86,代码来源:Membership.php

示例2: fixMembershipStatusBeforeRenew

 /**
  * Method to fix membership status of stale membership
  * 
  * This method first checks if the membership is stale. If it is,
  * then status will be updated based on existing start and end
  * dates and log will be added for the status change.
  * 
  * @param  array  $currentMembership   referance to the array
  *                                     containing all values of
  *                                     the current membership
  * @param  array  $changeToday         array of month, day, year
  *                                     values in case today needs
  *                                     to be customised, null otherwise
  * 
  * @return void
  * @static
  */
 static function fixMembershipStatusBeforeRenew(&$currentMembership, $changeToday)
 {
     $today = null;
     if ($changeToday) {
         $today = CRM_Utils_Date::processDate($changeToday, null, false, 'Y-m-d');
     }
     require_once 'CRM/Member/BAO/MembershipStatus.php';
     $status = CRM_Member_BAO_MembershipStatus::getMembershipStatusByDate($currentMembership['start_date'], $currentMembership['end_date'], $currentMembership['join_date'], $today);
     if (empty($status) || empty($status['id'])) {
         CRM_Core_Error::fatal(ts('Oops, it looks like there is no valid membership status corresponding to the membership start and end dates for this membership. Contact the site administrator for assistance.'));
     }
     $currentMembership['today_date'] = $today;
     if ($status['id'] !== $currentMembership['status_id']) {
         $memberDAO = new CRM_Member_BAO_Membership();
         $memberDAO->id = $currentMembership['id'];
         $memberDAO->find(true);
         $memberDAO->status_id = $status['id'];
         $memberDAO->join_date = CRM_Utils_Date::isoToMysql($memberDAO->join_date);
         $memberDAO->start_date = CRM_Utils_Date::isoToMysql($memberDAO->start_date);
         $memberDAO->end_date = CRM_Utils_Date::isoToMysql($memberDAO->end_date);
         $memberDAO->save();
         CRM_Core_DAO::storeValues($memberDAO, $currentMembership);
         $memberDAO->free();
         $currentMembership['is_current_member'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipStatus', $currentMembership['status_id'], 'is_current_member');
         $format = '%Y%m%d';
         $logParams = array('membership_id' => $currentMembership['id'], 'status_id' => $status['id'], 'start_date' => CRM_Utils_Date::customFormat($currentMembership['start_date'], $format), 'end_date' => CRM_Utils_Date::customFormat($currentMembership['end_date'], $format), 'modified_id' => $currentMembership['contact_id'], 'modified_date' => CRM_Utils_Date::customFormat($currentMembership['today_date'], $format), 'renewal_reminder_date' => CRM_Utils_Date::customFormat($currentMembership['reminder_date'], $format));
         $dontCare = null;
         require_once 'CRM/Member/BAO/MembershipLog.php';
         CRM_Member_BAO_MembershipLog::add($logParams, $dontCare);
     }
 }
开发者ID:hampelm,项目名称:Ginsberg-CiviDemo,代码行数:48,代码来源:Membership.php


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