public function __construct($booking)
 {
     $this->start = ilViteroUtils::parseSoapDate($booking->start);
     $this->end = ilViteroUtils::parseSoapDate($booking->end);
     if ($booking->cafe) {
         $this->fullday = true;
     } else {
         $this->fullday = false;
     }
 }
 /**
  * Vreate new vitero user
  * @param ilObjUser $iu
  * @return <type>
  */
 public function createUser(ilObjUser $iu)
 {
     try {
         $this->initClient();
         $user = new stdClass();
         $user->user = new stdClass();
         $user->user->password = ilViteroUtils::randPassword();
         $user->user->customeridlist = ilViteroSettings::getInstance()->getCustomer();
         $this->loadFromUser($user->user, $iu);
         $nuser = $this->getClient()->createUser($user);
         return $nuser->userid;
     } catch (SoapFault $e) {
         $code = $this->parseErrorCode($e);
         $GLOBALS['ilLog']->write(__METHOD__ . ': Create user failed with message code: ' . $code);
         $GLOBALS['ilLog']->write(__METHOD__ . ': Last request: ' . $this->getClient()->__getLastRequest());
         throw new ilViteroConnectorException($e->getMessage(), $code);
     }
 }
 /**
  * Constructor
  * @param object $booking
  */
 public function __construct($booking)
 {
     $this->booking_id = $booking->bookingid;
     switch ($booking->repetitionpattern) {
         case 1:
             $this->frequence_type = ilCalendarRecurrence::FREQ_DAILY;
             break;
         case 2:
             $this->frequence_type = ilCalendarRecurrence::FREQ_WEEKLY;
             break;
         case 3:
             $this->frequence_type = ilCalendarRecurrence::FREQ_WEEKLY;
             $this->byday = array('MO', 'TU', 'WE', 'TH', 'FR');
             break;
         case 4:
             $this->frequence_type = ilCalendarRecurrence::FREQ_WEEKLY;
             $this->byday = array('SA', 'SU');
             break;
         default:
     }
     if ($booking->repetitionenddate) {
         $this->frequence_until_date = ilViteroUtils::parseSoapDate($booking->repetitionenddate);
     }
 }
 /**
  * Lookup next booking
  * @param ilDate $start
  * @param ilDate $end
  * @param <type> $group_id
  * @return array
  */
 public static function lookupNextBooking(ilDateTime $start, ilDateTime $end, $group_id)
 {
     try {
         $con = new ilViteroBookingSoapConnector();
         $bookings = $con->getByGroupAndDate($group_id, $start, $end);
     } catch (Exception $e) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Vitero connection failed with message: ' . $e->getMessage());
         return NULL;
     }
     $bookings_arr = array();
     if (is_object($bookings->booking)) {
         $bookings_arr = array($bookings->booking);
     } elseif (is_array($bookings->booking)) {
         $bookings_arr = $bookings->booking;
     }
     include_once './Services/Calendar/classes/class.ilDateList.php';
     $next_booking['start'] = NULL;
     foreach ($bookings_arr as $booking) {
         // Calculate duration
         $fstart = ilViteroUtils::parseSoapDate($booking->start);
         $fend = ilViteroUtils::parseSoapDate($booking->end);
         $duration = $fend->get(IL_CAL_UNIX) - $fstart->get(IL_CAL_UNIX);
         $buffer_start = $booking->startbuffer;
         $buffer_end = $booking->endbuffer;
         $apps = self::calculateBookingAppointments($start, $end, $booking);
         foreach ($apps as $app) {
             if ($next_booking['start'] instanceof ilDateTime) {
                 if (ilDateTime::_before($app, $next_booking['start'])) {
                     $next_booking['start'] = $app;
                     $next_booking['open'] = clone $next_booking['start'];
                     $next_booking['open']->increment(ilDateTime::MINUTE, $buffer_start * -1);
                     $next_booking['end'] = clone $next_booking['start'];
                     $next_booking['end']->setDate($next_booking->get(IL_CAL_UNIX) + $duration, IL_CAL_UNIX);
                     $next_booking['closed'] = clone $next_booking['end'];
                     $next_booking['closed']->increment(ilDateTime::MINUTE, $buffer_end);
                     $next_booking['id'] = $booking->bookingid;
                 }
             } else {
                 $next_booking['start'] = $app;
                 $next_booking['open'] = clone $next_booking['start'];
                 $next_booking['open']->increment(ilDateTime::MINUTE, $buffer_start * -1);
                 $next_booking['end'] = clone $next_booking['start'];
                 $next_booking['end']->setDate($next_booking['end']->get(IL_CAL_UNIX) + $duration, IL_CAL_UNIX);
                 $next_booking['closed'] = clone $next_booking['end'];
                 $next_booking['closed']->increment(ilDateTime::MINUTE, $buffer_end);
                 $next_booking['id'] = $booking->bookingid;
             }
         }
     }
     return $next_booking;
 }
 protected function initUpdateBookingForm($booking)
 {
     global $lng;
     $lng->loadLanguageModule('dateplaner');
     $lng->loadLanguageModule('crs');
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $form = new ilPropertyFormGUI();
     $form->setFormAction($this->ctrl->getFormAction($this, 'showContent'));
     $form->setTitle(ilViteroPlugin::getInstance()->txt('tbl_update_appointment'));
     $form->addCommandButton('updateBooking', $GLOBALS['lng']->txt('save'));
     $form->addCommandButton('showContent', $GLOBALS['lng']->txt('cancel'));
     // Show only start if type is "cafe"
     if ($booking->booking->cafe) {
         $start = new ilDateTimeInputGUI($lng->txt('event_start_date'), 'cstart');
         $start->setShowTime(false);
         $start->setDate(ilViteroUtils::parseSoapDate($booking->booking->start));
         $form->addItem($start);
     } else {
         include_once './Services/Form/classes/class.ilDateDurationInputGUI.php';
         $dt = new ilDateDurationInputGUI($lng->txt('cal_fullday'), 'roomduration');
         $dt->setMinuteStepSize(15);
         $dt->setStartText($lng->txt('event_start_date'));
         $dt->setEndText($lng->txt('event_end_date'));
         $dt->setShowTime(true);
         $dt->setStart(ilViteroUtils::parseSoapDate($booking->booking->start));
         $dt->setEnd(ilViteroUtils::parseSoapDate($booking->booking->end));
         $form->addItem($dt);
         $this->initFormTimeBuffer($form);
         $form->getItemByPostVar('buffer_before')->setValue($booking->booking->startbuffer);
         $form->getItemByPostVar('buffer_after')->setValue($booking->booking->endbuffer);
     }
     return $form;
 }
 /**
  * Copy bookings from one group to another
  * @param <type> $a_old_group
  * @param <type> $a_new_group
  * @throws ilViteroConnectorException
  */
 public function copyBookings($a_old_group, $a_new_group)
 {
     // Read all bookings of old group
     $now = new ilDateTime(time(), IL_CAL_UNIX);
     $later = clone $now;
     $later->increment(IL_CAL_YEAR, 5);
     try {
         $bookings = $this->getByGroupAndDate($a_old_group, $now, $later);
     } catch (ilViteroConnectorException $e) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Copying vitero group failed with message ' . $e);
         return false;
     }
     foreach ((array) $bookings->booking as $booking) {
         $room = new ilViteroRoom();
         $room->setBufferBefore($booking->startbuffer);
         $room->setBufferAfter($booking->endbuffer);
         $room->setRoomSize($booking->roomsize);
         $room->enableCafe($booking->cafe ? true : false);
         $room->setStart(ilViteroUtils::parseSoapDate($booking->start));
         $room->setEnd(ilViteroUtils::parseSoapDate($booking->end));
         $room->setRepetition($booking->repetitionpattern);
         $rep_end = ilViteroUtils::parseSoapDate($booking->repetitionenddate);
         if ($rep_end instanceof ilDateTime) {
             $room->setRepetitionEndDate($rep_end);
         }
         try {
             $this->create($room, $a_new_group);
         } catch (ilViteroConnectorException $e) {
             $GLOBALS['ilLog']->write(__METHOD__ . ': Copying vitero group failed with message ' . $e);
         }
     }
 }
 /**
  * Parse bookings
  * @param int $a_groupid
  * @param ilDate $start
  * @param ilDate $end
  *
  * throws ilViteroConnectionException
  */
 public function parse($a_groupid, ilDateTime $start, ilDateTime $end)
 {
     $booking_list = array();
     try {
         $con = new ilViteroBookingSoapConnector();
         $bookings = $con->getByGroupAndDate($a_groupid, $start, $end);
     } catch (Exception $e) {
         throw $e;
     }
     $booking_arr = array();
     if (is_object($bookings->booking)) {
         $booking_arr = array($bookings->booking);
     } elseif (is_array($bookings->booking)) {
         $booking_arr = $bookings->booking;
     }
     $counter = 0;
     foreach ($booking_arr as $booking) {
         $fstart = ilViteroUtils::parseSoapDate($booking->start);
         $fend = ilViteroUtils::parseSoapDate($booking->end);
         $duration = $fend->get(IL_CAL_UNIX) - $fstart->get(IL_CAL_UNIX);
         foreach (ilViteroUtils::calculateBookingAppointments($start, $end, $booking) as $dl) {
             $booking_list[$counter]['rec'] = $booking->repetitionpattern;
             $booking_list[$counter]['id'] = $booking->bookingid;
             $booking_list[$counter]['start'] = $dl;
             $booking_list[$counter]['startt'] = $dl->get(IL_CAL_UNIX);
             $bend = clone $dl;
             $bend->setDate($dl->get(IL_CAL_UNIX) + $duration, IL_CAL_UNIX);
             $booking_list[$counter]['end'] = $bend;
             if ($booking->cafe) {
                 $booking_list[$counter]['start'] = new ilDate($booking_list[$counter]['startt'], IL_CAL_UNIX);
                 $booking_list[$counter]['time'] = ilDatePresentation::formatDate($booking_list[$counter]['start']);
             } else {
                 $booking_list[$counter]['time'] = ilDatePresentation::formatPeriod($booking_list[$counter]['start'], $booking_list[$counter]['end']);
             }
             $booking_list[$counter]['duration'] = ilFormat::_secondsToString($booking_list[$counter]['end']->get(IL_CAL_UNIX) - $booking_list[$counter]['start']->get(IL_CAL_UNIX), false);
             if ($booking->repetitionpattern) {
                 $repend = ilViteroUtils::parseSoapDate($booking->repetitionenddate);
                 $booking_list[$counter]['ends'] = ilDatePresentation::formatDate(new ilDate($repend->get(IL_CAL_UNIX), IL_CAL_UNIX));
             }
             $counter++;
         }
     }
     $this->setMaxCount(count($booking_list));
     $this->setData($booking_list);
 }
 /**
  * insert
  *
  * @access public
  * @param
  * @return
  */
 public function insert($a_tpl)
 {
     $tpl = ilViteroPlugin::getInstance()->getTemplate('tpl.recurrence_input.html', true, true);
     $options = array(ilViteroUtils::REC_ONCE => ilViteroUtils::recurrenceToString(ilViteroUtils::REC_ONCE), ilViteroUtils::REC_DAILY => ilViteroUtils::recurrenceToString(ilViteroUtils::REC_DAILY), ilViteroUtils::REC_WEEKLY => ilViteroUtils::recurrenceToString(ilViteroUtils::REC_WEEKLY), ilViteroUtils::REC_WEEKDAYS => ilViteroUtils::recurrenceToString(ilViteroUtils::REC_WEEKDAYS), ilViteroUtils::REC_WEEKENDS => ilViteroUtils::recurrenceToString(ilViteroUtils::REC_WEEKENDS));
     $tpl->setVariable('FREQUENCE', ilUtil::formSelect($this->getReccurrence(), 'frequence', $options, false, true, '', '', array('onchange' => 'ilHideFrequencies();', 'id' => 'il_recurrence_1')));
     $tpl->setVariable('TXT_EVERY', $this->lng->txt('cal_every'));
     // UNTIL
     $this->buildUntilSelection($tpl);
     $a_tpl->setCurrentBlock("prop_custom");
     $a_tpl->setVariable("CUSTOM_CONTENT", $tpl->get());
     $a_tpl->parseCurrentBlock();
 }