コード例 #1
0
 public function updateApiFromEvent(Google_Service_Calendar_Event $event, Member $member, $publicFlag)
 {
     $conn = $this->getConnection();
     $conn->beginTransaction();
     try {
         $schedule = $this->findOneByApiIdUnique($event->id);
         if ('cancelled' === $event->status) {
             if ($schedule) {
                 $schedule->delete();
             }
             $conn->commit();
             return true;
         }
         if (!$schedule) {
             $schedule = new Schedule();
             $schedule->setApiIdUnique($event->id);
         } elseif ($event->etag === $schedule->api_etag) {
             $conn->rollback();
             return $schedule->id;
         }
         $schedule->setTitle($event->summary);
         $schedule->setBody($event->description);
         $schedule->setMember($member);
         $schedule->setPublicFlag($this->getEventPublicFlag($event, $publicFlag));
         if ($event->start->dateTime) {
             $startDateTime = new DateTime($event->start->dateTime);
             $schedule->setStartDate($startDateTime->format('Y-m-d'));
             $schedule->setStartTime($startDateTime->format('H:i:s'));
         } elseif ($event->start->date) {
             $schedule->setStartDate($event->start->date);
         }
         if ($event->end->dateTime) {
             $endDateTime = new DateTime($event->end->dateTime);
             $schedule->setEndDate($endDateTime->format('Y-m-d'));
             $schedule->setEndTime($endDateTime->format('H:i:s'));
         } elseif ($event->end->date) {
             $schedule->setStartDate($event->end->date);
         }
         $schedule->setApiEtag($event->etag);
         $schedule->save();
         ScheduleMemberTable::getInstance()->updateScheduleMember(array('schedule_id' => $schedule->id, 'member_id' => $schedule->member_id));
         foreach ($event->attendees as $attendee) {
             $memberId = opCalendarPluginToolkit::seekEmailAndGetMemberId($attendee->email);
             if (!$memberId) {
                 continue;
             }
             ScheduleMemberTable::getInstance()->updateScheduleMember(array('schedule_id' => $schedule->id, 'member_id' => $memberId));
         }
         $conn->commit();
     } catch (Exception $e) {
         $conn->rollback();
         throw $e;
     }
     return $schedule->id;
 }
コード例 #2
0
 public function save($con = null)
 {
     $schedule = new Schedule();
     $schedule->setStartDate($this->getValue('start_date'));
     $schedule->setEndDate($this->getValue('start_date'));
     $schedule->setTitle($this->getValue('title'));
     $schedule->setBody('');
     $schedule->setMember(sfContext::getInstance()->getUser()->getMember());
     $scheduleMember = new ScheduleMember();
     $scheduleMember->setSchedule($schedule);
     $scheduleMember->setMember($schedule->Member);
     $scheduleMember->save($con);
     return $schedule->save($con);
 }