public function __construct(ReservationItemView $reservationItemView, IRestServer $server, $showUser, $showDetails)
 {
     $this->referenceNumber = $reservationItemView->ReferenceNumber;
     $this->startDate = $reservationItemView->StartDate->ToIso();
     $this->endDate = $reservationItemView->EndDate->ToIso();
     $this->duration = $reservationItemView->GetDuration()->__toString();
     $this->resourceName = $reservationItemView->ResourceName;
     if ($showUser) {
         $this->firstName = $reservationItemView->FirstName;
         $this->lastName = $reservationItemView->LastName;
     }
     if ($showDetails) {
         $this->title = $reservationItemView->Title;
         $this->description = $reservationItemView->Description;
     }
     $this->requiresApproval = (bool) $reservationItemView->RequiresApproval;
     $this->isRecurring = (bool) $reservationItemView->IsRecurring;
     $this->scheduleId = $reservationItemView->ScheduleId;
     $this->userId = $reservationItemView->UserId;
     $this->resourceId = $reservationItemView->ResourceId;
     $this->bufferTime = $reservationItemView->GetBufferTime()->__toString();
     $bufferedDuration = $reservationItemView->BufferedTimes();
     $this->bufferedStartDate = $bufferedDuration->GetBegin()->ToIso();
     $this->bufferedEndDate = $bufferedDuration->GetEnd()->ToIso();
     $this->AddService($server, WebServices::GetResource, array(WebServiceParams::ResourceId => $reservationItemView->ResourceId));
     $this->AddService($server, WebServices::GetReservation, array(WebServiceParams::ReferenceNumber => $reservationItemView->ReferenceNumber));
     $this->AddService($server, WebServices::GetUser, array(WebServiceParams::UserId => $reservationItemView->UserId));
     $this->AddService($server, WebServices::GetSchedule, array(WebServiceParams::ScheduleId => $reservationItemView->ScheduleId));
 }
 /**
  * @param ReservationItemView $existingReservation
  * @return bool
  */
 public function Handle(ReservationItemView $existingReservation)
 {
     $reservation = $this->repository->LoadById($existingReservation->GetId());
     $reservation->ApplyChangesTo(SeriesUpdateScope::ThisInstance);
     $reservation->Delete(ServiceLocator::GetServer()->GetUserSession());
     $this->repository->Delete($reservation);
     return true;
 }
Example #3
0
 protected function GetFullName(ReservationItemView $reservation)
 {
     $shouldHide = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter());
     if ($shouldHide && (is_null($this->user) || $this->user->UserId != $reservation->UserId && !$this->user->IsAdminForGroup($reservation->OwnerGroupIds()))) {
         return Resources::GetInstance()->GetString('Private');
     }
     $name = new FullName($reservation->FirstName, $reservation->LastName);
     return $name->__toString();
 }
 /**
  * @param IRestServer $server
  * @param BookableResource $resource
  * @param ReservationItemView|null $conflictingReservation
  * @param ReservationItemView|null $nextReservation
  * @param Date|null $nextAvailableTime
  */
 public function __construct(IRestServer $server, $resource, $conflictingReservation, $nextReservation, $nextAvailableTime)
 {
     $this->resource = new ResourceReference($server, $resource);
     $this->available = $conflictingReservation == null;
     $this->AddService($server, WebServices::GetResource, array(WebServiceParams::ResourceId => $resource->GetId()));
     if (!$this->available) {
         $this->availableAt = $nextAvailableTime != null ? $nextAvailableTime->ToTimezone($server->GetSession()->Timezone)->ToIso() : null;
         $this->AddService($server, WebServices::GetUser, array(WebServiceParams::UserId => $conflictingReservation->UserId));
         $this->AddService($server, WebServices::GetReservation, array(WebServiceParams::ReferenceNumber => $conflictingReservation->ReferenceNumber));
     }
     if ($this->available && $nextReservation != null) {
         $this->availableUntil = $nextReservation->BufferedTimes()->GetBegin()->ToTimezone($server->GetSession()->Timezone)->ToIso();
     }
 }
 public function testGetReservationsPullsReservationFromTheRepositoryAndAddsThemToTheCoordinator()
 {
     $timezone = 'UTC';
     $startDate = Date::Now();
     $endDate = Date::Now();
     $scheduleId = 100;
     $range = new DateRange($startDate, $endDate);
     $repository = $this->getMock('IReservationViewRepository');
     $reservationListing = new TestReservationListing();
     $listingFactory = $this->getMock('IReservationListingFactory');
     $rows = FakeReservationRepository::GetReservationRows();
     $res1 = ReservationItemView::Populate($rows[0]);
     $res2 = ReservationItemView::Populate($rows[1]);
     $res3 = ReservationItemView::Populate($rows[2]);
     $date = Date::Now();
     $blackout1 = new TestBlackoutItemView(1, $date, $date, 1);
     $blackout2 = new TestBlackoutItemView(2, $date, $date, 2);
     $blackout3 = new TestBlackoutItemView(3, $date, $date, 3);
     $repository->expects($this->once())->method('GetReservationList')->with($this->equalTo($startDate), $this->equalTo($endDate), $this->isNull(), $this->isNull(), $this->equalTo($scheduleId), $this->isNull())->will($this->returnValue(array($res1, $res2, $res3)));
     $repository->expects($this->once())->method('GetBlackoutsWithin')->with($this->equalTo(new DateRange($startDate, $endDate)), $this->equalTo($scheduleId))->will($this->returnValue(array($blackout1, $blackout2, $blackout3)));
     $listingFactory->expects($this->once())->method('CreateReservationListing')->with($this->equalTo($timezone))->will($this->returnValue($reservationListing));
     $service = new ReservationService($repository, $listingFactory);
     $listing = $service->GetReservations($range, $scheduleId, $timezone);
     $this->assertEquals($reservationListing, $listing);
     $this->assertTrue(in_array($res1, $reservationListing->reservations));
     $this->assertTrue(in_array($res2, $reservationListing->reservations));
     $this->assertTrue(in_array($res3, $reservationListing->reservations));
     $this->assertTrue(in_array($blackout1, $reservationListing->blackouts));
     $this->assertTrue(in_array($blackout2, $reservationListing->blackouts));
     $this->assertTrue(in_array($blackout3, $reservationListing->blackouts));
 }
Example #6
0
 public function IsSameTrainingLevel(UserSession $session)
 {
     $reservationType = $this->_reservation->GetAttributeValue(5);
     $userId = $session->UserId;
     $userRepository = new UserRepository();
     $user = $userRepository->LoadById($userId);
     $userTrainingType = $user->GetAttributeValue(17);
     return $reservationType == $userTrainingType;
 }
 /**
  * @param null|string $id
  * @param Date $startDate
  * @param Date $endDate
  * @param int $resourceId
  */
 public function __construct($id, Date $startDate, Date $endDate, $resourceId = 1)
 {
     parent::__construct();
     $this->ReservationId = $id;
     $this->StartDate = $startDate;
     $this->EndDate = $endDate;
     $this->ResourceId = $resourceId;
     $this->Date = new DateRange($startDate, $endDate);
     $this->RepeatType = RepeatType::None;
 }
Example #8
0
 /**
  * @param SchedulePeriod $begin
  * @param SchedulePeriod $end
  * @param Date $displayDate
  * @param int $periodSpan
  * @param ReservationItemView $reservation
  */
 public function __construct(SchedulePeriod $begin, SchedulePeriod $end, Date $displayDate, $periodSpan, ReservationItemView $reservation)
 {
     $this->_reservation = $reservation;
     $this->_begin = $begin->BeginDate();
     $this->_displayDate = $displayDate;
     $this->_end = $end->EndDate();
     $this->_periodSpan = $periodSpan;
     $this->_participantNumber = count($reservation->ParticipantIds);
     $this->_participantNames = $reservation->ParticipantNames;
     $this->_inviteeNames = $reservation->InviteeNames;
     $this->_beginSlotId = $begin->Id();
     $this->_endSlotId = $end->Id();
     $resourceId = $this->_reservation->GetResourceId();
     $resourceRepo = new ResourceRepository();
     $resource = $resourceRepo->LoadById($resourceId);
     $this->_maxparticipantsnumber = $resource->GetMaxParticipants();
     $this->_beginPeriod = $begin;
     $this->_endPeriod = $end;
 }
 public function PageLoad(UserSession $currentUser)
 {
     if (!$this->validator->IsValid()) {
         return;
     }
     $referenceNumber = $this->page->GetReferenceNumber();
     $reservations = array();
     if (!empty($referenceNumber)) {
         $res = $this->reservationViewRepository->GetReservationForEditing($referenceNumber);
         $item = ReservationItemView::FromReservationView($res);
         $reservations = array(new iCalendarReservationView($item, $currentUser, $this->privacyFilter));
     }
     $this->page->SetReservations($reservations);
 }
 /**
  * @static
  * @param $row array
  * @return ReservationItemView
  */
 public static function Populate($row)
 {
     $view = new ReservationItemView($row[ColumnNames::REFERENCE_NUMBER], Date::FromDatabase($row[ColumnNames::RESERVATION_START]), Date::FromDatabase($row[ColumnNames::RESERVATION_END]), $row[ColumnNames::RESOURCE_NAME], $row[ColumnNames::RESOURCE_ID], $row[ColumnNames::RESERVATION_INSTANCE_ID], $row[ColumnNames::RESERVATION_USER_LEVEL], $row[ColumnNames::RESERVATION_TITLE], $row[ColumnNames::RESERVATION_DESCRIPTION], $row[ColumnNames::SCHEDULE_ID], $row[ColumnNames::OWNER_FIRST_NAME], $row[ColumnNames::OWNER_LAST_NAME], $row[ColumnNames::OWNER_USER_ID], $row[ColumnNames::OWNER_PHONE], $row[ColumnNames::OWNER_ORGANIZATION], $row[ColumnNames::OWNER_POSITION], $row[ColumnNames::PARTICIPANT_LIST], $row[ColumnNames::INVITEE_LIST], $row[ColumnNames::ATTRIBUTE_LIST], $row[ColumnNames::USER_PREFERENCES], $row[ColumnNames::RESERVATION_STATUS]);
     if (isset($row[ColumnNames::RESERVATION_CREATED])) {
         $view->CreatedDate = Date::FromDatabase($row[ColumnNames::RESERVATION_CREATED]);
         $view->DateCreated = Date::FromDatabase($row[ColumnNames::RESERVATION_CREATED]);
     }
     if (isset($row[ColumnNames::RESERVATION_MODIFIED])) {
         $view->ModifiedDate = Date::FromDatabase($row[ColumnNames::RESERVATION_MODIFIED]);
     }
     if (isset($row[ColumnNames::REPEAT_TYPE])) {
         $repeatConfig = RepeatConfiguration::Create($row[ColumnNames::REPEAT_TYPE], $row[ColumnNames::REPEAT_OPTIONS]);
         $view->RepeatType = $repeatConfig->Type;
         $view->RepeatInterval = $repeatConfig->Interval;
         $view->RepeatWeekdays = $repeatConfig->Weekdays;
         $view->RepeatMonthlyType = $repeatConfig->MonthlyType;
         $view->RepeatTerminationDate = $repeatConfig->TerminationDate;
         $view->IsRecurring = $row[ColumnNames::REPEAT_TYPE] != RepeatType::None;
     }
     if (isset($row[ColumnNames::RESERVATION_STATUS])) {
         $view->RequiresApproval = $row[ColumnNames::RESERVATION_STATUS] == ReservationStatus::Pending;
     }
     if (isset($row[ColumnNames::EMAIL])) {
         $view->OwnerEmailAddress = $row[ColumnNames::EMAIL];
     }
     if (isset($row[ColumnNames::SERIES_ID])) {
         $view->SeriesId = $row[ColumnNames::SERIES_ID];
     }
     if (isset($row[ColumnNames::RESOURCE_STATUS_REASON_ID])) {
         $view->ResourceStatusReasonId = $row[ColumnNames::RESOURCE_STATUS_REASON_ID];
     }
     if (isset($row[ColumnNames::RESOURCE_STATUS_ID_ALIAS])) {
         $view->ResourceStatusId = $row[ColumnNames::RESOURCE_STATUS_ID_ALIAS];
     }
     if (isset($row[ColumnNames::RESOURCE_BUFFER_TIME])) {
         $view->WithBufferTime($row[ColumnNames::RESOURCE_BUFFER_TIME]);
     }
     if (isset($row[ColumnNames::GROUP_LIST])) {
         $view->WithOwnerGroupIds(explode(',', $row[ColumnNames::GROUP_LIST]));
     }
     if (isset($row[ColumnNames::START_REMINDER_MINUTES_PRIOR])) {
         $view->StartReminder = new ReservationReminderView($row[ColumnNames::START_REMINDER_MINUTES_PRIOR]);
     }
     if (isset($row[ColumnNames::END_REMINDER_MINUTES_PRIOR])) {
         $view->EndReminder = new ReservationReminderView($row[ColumnNames::END_REMINDER_MINUTES_PRIOR]);
     }
     return $view;
 }
Example #11
0
 private static function GetClass(ReservationItemView $reservation)
 {
     if ($reservation->RequiresApproval) {
         return 'reserved pending';
     }
     $user = ServiceLocator::GetServer()->GetUserSession();
     if ($reservation->IsUserOwner($user->UserId)) {
         return 'reserved mine';
     }
     if ($reservation->IsUserParticipating($user->UserId)) {
         return 'reserved participating';
     }
     return 'reserved';
 }
 public function testKnowsIfParticipatingOrInvited()
 {
     $participant_list = '2=name name!sep!3=name name';
     $invitee_list = '4=name name!sep!5=name name';
     $reservationView = new ReservationItemView('ref', Date::Now(), Date::Now(), 'resource', 1, 1, ReservationUserLevel::OWNER, 'title', 'desc', 1, 'f', 'l', 1, null, null, null, $participant_list, $invitee_list);
     $this->assertTrue($reservationView->IsUserParticipating(2));
     $this->assertTrue($reservationView->IsUserParticipating(3));
     $this->assertFalse($reservationView->IsUserParticipating(4));
     $this->assertFalse($reservationView->IsUserParticipating(5));
     $this->assertFalse($reservationView->IsUserInvited(2));
     $this->assertFalse($reservationView->IsUserInvited(3));
     $this->assertTrue($reservationView->IsUserInvited(4));
     $this->assertTrue($reservationView->IsUserInvited(5));
 }
Example #13
0
 public function IsParticipating(UserSession $session)
 {
     return $this->_reservation->IsUserParticipating($session->UserId) || $this->_reservation->IsUserInvited($session->UserId);
 }
 public function testReservationDoesNotOccurOnDateIfNoneOfTheReservationOccursAtAnyTimeOnThatDate()
 {
     $d1 = new Date('2009-10-09 22:00:00', 'UTC');
     // 2009-10-09 17:00:00 CST
     $d2 = new Date('2009-10-09 23:00:00', 'UTC');
     // 2009-10-09 18:00:00 CST
     $res1 = new ReservationItemView(1, $d1, $d2);
     $this->assertFalse($res1->OccursOn(Date::Parse('2009-10-10', 'CST')));
 }