Example #1
0
 public static function factory($item)
 {
     $event = new self();
     if ($item->SUMMARY) {
         $event->setName($item->SUMMARY->getValue());
     }
     if ($item->DTSTART) {
         $event->setStartDAte($item->DTSTART->getDateTime());
     }
     if ($item->DTEND) {
         $event->setEndDate($item->DTEND->getDateTime());
     }
     if ($item->DESCRIPTION) {
         $event->setDescription($item->DESCRIPTION->getValue());
     }
     //->setUrl($item->URL->getValue())
     return $event;
 }
Example #2
0
 /**
  * @return Duration|null
  */
 public static function createFromRequest()
 {
     $dt = Loader::helper('form/date_time');
     $dateStart = $dt->translate('pdStartDate');
     $dateEnd = $dt->translate('pdEndDate');
     if ($dateStart || $dateEnd) {
         // create a Duration object
         $pd = new self();
         if ($_REQUEST['pdStartDateAllDayActivate']) {
             $pd->setStartDateAllDay(1);
             $dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
         } else {
             $pd->setStartDateAllDay(0);
         }
         if ($_REQUEST['pdEndDateAllDayActivate']) {
             $pd->setEndDateAllDay(1);
             $dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
         } else {
             $pd->setEndDateAllDay(0);
         }
         $pd->setStartDate($dateStart);
         $pd->setEndDate($dateEnd);
         if ($_POST['pdRepeatPeriod'] && $_POST['pdRepeat']) {
             if ($_POST['pdRepeatPeriod'] == 'daily') {
                 $pd->setRepeatPeriod(self::REPEAT_DAILY);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodDaysEvery']);
             } elseif ($_POST['pdRepeatPeriod'] == 'weekly') {
                 $pd->setRepeatPeriod(self::REPEAT_WEEKLY);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodWeeksEvery']);
                 $pd->setRepeatPeriodWeekDays($_POST['pdRepeatPeriodWeeksDays']);
             } elseif ($_POST['pdRepeatPeriod'] == 'monthly') {
                 $pd->setRepeatPeriod(self::REPEAT_MONTHLY);
                 $repeat_by = $_POST['pdRepeatPeriodMonthsRepeatBy'];
                 $repeat = self::MONTHLY_REPEAT_WEEKLY;
                 switch ($repeat_by) {
                     case 'week':
                         $repeat = self::MONTHLY_REPEAT_WEEKLY;
                         break;
                     case 'month':
                         $repeat = self::MONTHLY_REPEAT_MONTHLY;
                         break;
                     case 'lastweekday':
                         $repeat = self::MONTHLY_REPEAT_LAST_WEEKDAY;
                         $dotw = $_POST['pdRepeatPeriodMonthsRepeatLastDay'] ?: 0;
                         $pd->setRepeatMonthLastWeekday($dotw);
                         break;
                 }
                 $pd->setRepeatMonthBy($repeat);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodMonthsEvery']);
             }
             $pd->setRepeatPeriodEnd($dt->translate('pdEndRepeatDateSpecific'));
         } else {
             $pd->setRepeatPeriod(self::REPEAT_NONE);
         }
         $pd->save();
         return $pd;
     } else {
         unset($pd);
     }
     return null;
 }
Example #3
0
 /**
  * Build a subscription entity based on a json-decoded subscription stdClass
  *
  * @param  stdClass $response The subscription data
  * @return Syspay_Merchant_Entity_Subscription The subscription object
  */
 public static function buildFromResponse(stdClass $response)
 {
     $subscription = new self();
     $subscription->setId(isset($response->id) ? $response->id : null);
     $subscription->setPlanId(isset($response->plan_id) ? $response->plan_id : null);
     $subscription->setPlanType(isset($response->plan_type) ? $response->plan_type : null);
     $subscription->setReference(isset($response->reference) ? $response->reference : null);
     $subscription->setStatus(isset($response->status) ? $response->status : null);
     $subscription->setPhase(isset($response->phase) ? $response->phase : null);
     $subscription->setExtra(isset($response->extra) ? $response->extra : null);
     $subscription->setEmsUrl(isset($response->ems_url) ? $response->ems_url : null);
     $subscription->setWebsiteId(isset($response->website_id) ? $response->website_id : null);
     $subscription->setCreated(isset($response->created) ? Syspay_Merchant_Utils::tsToDateTime($response->created) : null);
     $subscription->setStartDate(isset($response->start_date) ? Syspay_Merchant_Utils::tsToDateTime($response->start_date) : null);
     $subscription->setEndDate(isset($response->end_date) ? Syspay_Merchant_Utils::tsToDateTime($response->end_date) : null);
     $subscription->setEndReason(isset($response->end_reason) ? $response->end_reason : null);
     if (isset($response->payment_method) && $response->payment_method instanceof stdClass) {
         $paymentMethod = Syspay_Merchant_Entity_PaymentMethod::buildFromResponse($response->payment_method);
         $subscription->setPaymentMethod($paymentMethod);
     }
     if (isset($response->customer) && $response->customer instanceof stdClass) {
         $customer = Syspay_Merchant_Entity_Customer::buildFromResponse($response->customer);
         $subscription->setCustomer($customer);
     }
     if (isset($response->plan) && $response->plan instanceof stdClass) {
         $plan = Syspay_Merchant_Entity_Plan::buildFromResponse($response->plan);
         $subscription->setPlan($plan);
     }
     if (isset($response->next_event) && $response->next_event instanceof stdClass) {
         $nextEvent = Syspay_Merchant_Entity_SubscriptionEvent::buildFromResponse($response->next_event);
         $subscription->setNextEvent($nextEvent);
     }
     $subscription->raw = $response;
     return $subscription;
 }