コード例 #1
0
 /**
  * Calculate expire date.
  *
  * Based in the membership definition
  *
  * @since  1.0.0
  * @internal
  *
  * @param string $start_date Optional. The start date to calculate date from.
  * @param  bool $paid If the user made a payment to extend the expire date.
  * @return string The calculated expire date.
  */
 public function calc_expire_date($start_date = null, $paid = false)
 {
     $membership = $this->get_membership();
     $gateway = $this->get_gateway();
     $start_date = $this->calc_trial_expire_date($start_date);
     $expire_date = null;
     /*
      * When in trial period and gateway does not send automatic recurring
      * payment notifications, the expire date is equal to trial expire date.
      */
     if ($this->is_trial_eligible()) {
         $expire_date = $start_date;
     } else {
         if ($paid) {
             /*
              * Always extend the membership from current date or later, even if
              * the specified start-date is in the past.
              *
              * Example: User does not pay for 3 days (subscription set "pending")
              *          Then he pays: The 3 days without access are for free;
              *          his subscriptions is extended from current date!
              */
             $today = MS_Helper_Period::current_date();
             if (MS_Helper_Period::is_after($today, $start_date)) {
                 $start_date = $today;
             }
         }
         /*
          * The gatway calls the payment handler URL automatically:
          * This means that the user does not need to re-authorize each
          * payment.
          */
         switch ($membership->payment_type) {
             case MS_Model_Membership::PAYMENT_TYPE_PERMANENT:
                 $expire_date = false;
                 break;
             case MS_Model_Membership::PAYMENT_TYPE_FINITE:
                 $period_unit = MS_Helper_Period::get_period_value($membership->period, 'period_unit');
                 $period_type = MS_Helper_Period::get_period_value($membership->period, 'period_type');
                 $expire_date = MS_Helper_Period::add_interval($period_unit, $period_type, $start_date);
                 break;
             case MS_Model_Membership::PAYMENT_TYPE_DATE_RANGE:
                 $expire_date = $membership->period_date_end;
                 break;
             case MS_Model_Membership::PAYMENT_TYPE_RECURRING:
                 $period_unit = MS_Helper_Period::get_period_value($membership->pay_cycle_period, 'period_unit');
                 $period_type = MS_Helper_Period::get_period_value($membership->pay_cycle_period, 'period_type');
                 $expire_date = MS_Helper_Period::add_interval($period_unit, $period_type, $start_date);
                 break;
         }
     }
     return apply_filters('ms_model_relationship_calc_expire_date', $expire_date, $this);
 }