/**
  * @param UserSession $userSession
  * @param string $timezone
  */
 public function PageLoad($userSession, $timezone)
 {
     $type = $this->page->GetCalendarType();
     $year = $this->page->GetYear();
     $month = $this->page->GetMonth();
     $day = $this->page->GetDay();
     $defaultDate = Date::Now()->ToTimezone($timezone);
     if (empty($year)) {
         $year = $defaultDate->Year();
     }
     if (empty($month)) {
         $month = $defaultDate->Month();
     }
     if (empty($day)) {
         $day = $defaultDate->Day();
     }
     $schedules = $this->scheduleRepository->GetAll();
     $showInaccessible = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter());
     $resources = $this->resourceService->GetAllResources($showInaccessible, $userSession);
     $selectedScheduleId = $this->page->GetScheduleId();
     $selectedSchedule = $this->GetDefaultSchedule($schedules);
     $selectedResourceId = $this->page->GetResourceId();
     $calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone, $selectedSchedule->GetWeekdayStart());
     $reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay()->AddDays(1), $userSession->UserId, ReservationUserLevel::ALL, $selectedScheduleId, $selectedResourceId);
     $calendar->AddReservations(CalendarReservation::FromViewList($reservations, $timezone));
     $this->page->BindCalendar($calendar);
     $this->page->SetDisplayDate($calendar->FirstDay());
     $this->page->BindFilters(new CalendarFilters($schedules, $resources, $selectedScheduleId, $selectedResourceId));
     $this->page->SetScheduleId($selectedScheduleId);
     $this->page->SetResourceId($selectedResourceId);
     $this->page->SetFirstDay($selectedSchedule->GetWeekdayStart());
     $details = $this->subscriptionService->ForUser($userSession->UserId);
     $this->page->BindSubscription($details);
 }
 /**
  * @param ResourceDto $resource
  * @param ReservationItemView[][] $reservations
  * @return ReservationItemView|null
  */
 private function GetOngoingReservation($resource, $reservations)
 {
     if (array_key_exists($resource->GetId(), $reservations) && $reservations[$resource->GetId()][0]->StartDate->LessThan(Date::Now())) {
         return $reservations[$resource->GetId()][0];
     }
     return null;
 }
 public function testScheduleResponseReturnsLayoutForEachDayOfWeek()
 {
     $schedule = new FakeSchedule();
     $layout = $this->getMock('IScheduleLayout');
     $timezone = $this->server->GetSession()->Timezone;
     $date1 = Date::Now()->ToTimezone($timezone);
     $date2 = $date1->AddDays(1);
     $date3 = $date1->AddDays(2);
     $date4 = $date1->AddDays(3);
     $date5 = $date1->AddDays(4);
     $date6 = $date1->AddDays(5);
     $date7 = $date1->AddDays(6);
     $periods1 = array(new SchedulePeriod($date1, $date1));
     $periods2 = array(new SchedulePeriod($date2, $date2));
     $periods3 = array(new SchedulePeriod($date3, $date3));
     $periods4 = array(new SchedulePeriod($date4, $date4));
     $periods5 = array(new SchedulePeriod($date5, $date5));
     $periods6 = array(new SchedulePeriod($date6, $date6));
     $periods7 = array(new SchedulePeriod($date7, $date7));
     $layout->expects($this->at(0))->method('GetLayout')->with($this->equalTo($date1))->will($this->returnValue($periods1));
     $layout->expects($this->at(1))->method('GetLayout')->with($this->equalTo($date2))->will($this->returnValue($periods2));
     $layout->expects($this->at(2))->method('GetLayout')->with($this->equalTo($date3))->will($this->returnValue($periods3));
     $layout->expects($this->at(3))->method('GetLayout')->with($this->equalTo($date4))->will($this->returnValue($periods4));
     $layout->expects($this->at(4))->method('GetLayout')->with($this->equalTo($date5))->will($this->returnValue($periods5));
     $layout->expects($this->at(5))->method('GetLayout')->with($this->equalTo($date6))->will($this->returnValue($periods6));
     $layout->expects($this->at(6))->method('GetLayout')->with($this->equalTo($date7))->will($this->returnValue($periods7));
     $response = new ScheduleResponse($this->server, $schedule, $layout);
     $this->assertEquals(array(new SchedulePeriodResponse($periods1[0])), $response->periods[$date1->Weekday()]);
     $this->assertEquals(array(new SchedulePeriodResponse($periods2[0])), $response->periods[$date2->Weekday()]);
     $this->assertEquals(array(new SchedulePeriodResponse($periods3[0])), $response->periods[$date3->Weekday()]);
     $this->assertEquals(array(new SchedulePeriodResponse($periods4[0])), $response->periods[$date4->Weekday()]);
     $this->assertEquals(array(new SchedulePeriodResponse($periods5[0])), $response->periods[$date5->Weekday()]);
     $this->assertEquals(array(new SchedulePeriodResponse($periods6[0])), $response->periods[$date6->Weekday()]);
     $this->assertEquals(array(new SchedulePeriodResponse($periods7[0])), $response->periods[$date7->Weekday()]);
 }
示例#4
0
 public function __construct()
 {
     $this->sessionToken = 'sessiontoken';
     $this->sessionExpires = Date::Now()->ToIso();
     $this->isAuthenticated = true;
     $this->userId = 123;
 }
 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));
 }
 public function PageLoad(UserSession $user)
 {
     $now = Date::Now();
     $resources = $this->resourceService->GetAllResources(false, $user);
     $reservations = $this->GetReservations($this->reservationViewRepository->GetReservationList($now, $now));
     $next = $this->reservationViewRepository->GetNextReservations($now);
     $available = array();
     $unavailable = array();
     $allday = array();
     foreach ($resources as $resource) {
         $reservation = $this->GetOngoingReservation($resource, $reservations);
         if ($reservation != null) {
             if (!$reservation->EndDate->DateEquals(Date::Now())) {
                 $allday[] = new UnavailableDashboardItem($resource, $reservation);
             } else {
                 $unavailable[] = new UnavailableDashboardItem($resource, $reservation);
             }
         } else {
             if (array_key_exists($resource->GetId(), $next)) {
                 $available[] = new AvailableDashboardItem($resource, $next[$resource->GetId()]);
             } else {
                 $available[] = new AvailableDashboardItem($resource);
             }
         }
     }
     $this->control->SetAvailable($available);
     $this->control->SetUnavailable($unavailable);
     $this->control->SetUnavailableAllDay($allday);
 }
 public function testGetsAllReservationsWithReminderDateOfThisMinute()
 {
     $seriesId = 123;
     $instanceId = 456;
     $referenceNumber = 'refnum1';
     $startDate = Date::Now()->AddDays(1)->ToDatabase();
     $endDate = Date::Now()->AddDays(2)->ToDatabase();
     $title = 'reservation title';
     $description = 'reservation description';
     $resourceName = 'resource name';
     $emailAddress = '*****@*****.**';
     $fname = 'first';
     $lname = 'last';
     $timezone = 'America/Chicago';
     $reminder_minutes = 100;
     $now = Date::Now();
     $language = 'en_us';
     $row1 = new ReminderNoticeRow($seriesId, $instanceId, $referenceNumber, $startDate, $endDate, $title, $description, $resourceName, $emailAddress, $fname, $lname, $timezone, $reminder_minutes, $language);
     $row2 = new ReminderNoticeRow();
     $rows = array_merge($row1->Rows(), $row2->Rows());
     $this->db->SetRows($rows);
     $reminderNotices = $this->repository->GetReminderNotices($now, ReservationReminderType::Start);
     $expectedCommand = new GetReminderNoticesCommand($now->ToTheMinute(), ReservationReminderType::Start);
     $this->assertEquals(2, count($reminderNotices));
     $this->assertEquals($expectedCommand, $this->db->_LastCommand);
     $expectedReminderNotice = ReminderNotice::FromRow($rows[0]);
     $this->assertEquals($expectedReminderNotice, $reminderNotices[0]);
 }
 public function testCreatesSerializableLayout()
 {
     $baseDate = Date::Now();
     $b1 = $baseDate->AddDays(1);
     $e1 = $baseDate->AddDays(2);
     $b2 = $baseDate->AddDays(3);
     $e2 = $baseDate->AddDays(4);
     $b3 = $baseDate->AddDays(5);
     $e3 = $baseDate->AddDays(6);
     $b4 = $baseDate->AddDays(7);
     $e4 = $baseDate->AddDays(8);
     $l1 = 'label 1';
     $l2 = 'label 2';
     $p1 = new SchedulePeriod($b1, $e1);
     $p2 = new NonSchedulePeriod($b2, $e2);
     $p3 = new SchedulePeriod($b3, $e3, $l1);
     $p4 = new NonSchedulePeriod($b4, $e4, $l2);
     $periods = array($p1, $p2, $p3, $p4);
     $actual = new ScheduleLayoutSerializable($periods);
     $actualPeriods = $actual->periods;
     $this->assertEquals(count($periods), count($actualPeriods));
     $this->assertEquals($p1->Begin()->__toString(), $actualPeriods[0]->begin);
     $this->assertEquals($p1->End()->__toString(), $actualPeriods[0]->end);
     $this->assertEquals($p1->BeginDate()->__toString(), $actualPeriods[0]->beginDate);
     $this->assertEquals($p1->EndDate()->__toString(), $actualPeriods[0]->endDate);
     $this->assertEquals($p1->Label(), $actualPeriods[0]->label);
     $this->assertEquals($p1->LabelEnd(), $actualPeriods[0]->labelEnd);
     $this->assertEquals($p1->IsReservable(), $actualPeriods[0]->isReservable);
     $this->assertEquals($p2->Begin()->__toString(), $actualPeriods[1]->begin);
     $this->assertEquals($p2->End()->__toString(), $actualPeriods[1]->end);
     $this->assertEquals($p2->Label(), $actualPeriods[1]->label);
     $this->assertEquals($p2->LabelEnd(), $actualPeriods[1]->labelEnd);
     $this->assertEquals($p2->IsReservable(), $actualPeriods[1]->isReservable);
 }
示例#9
0
 public function __construct(Date $date)
 {
     $this->date = $date->GetDate();
     if ($this->date->DateEquals(Date::Now())) {
         $this->Highlight();
     }
 }
 public function Bind(IReservationComponentInitializer $initializer)
 {
     $timezone = $initializer->GetTimezone();
     $reservationDate = $initializer->GetReservationDate();
     $requestedEndDate = $initializer->GetEndDate();
     $requestedStartDate = $initializer->GetStartDate();
     $requestedScheduleId = $initializer->GetScheduleId();
     $requestedDate = $reservationDate == null ? Date::Now()->ToTimezone($timezone) : $reservationDate->ToTimezone($timezone);
     $startDate = $requestedStartDate == null ? $requestedDate : $requestedStartDate->ToTimezone($timezone);
     $endDate = $requestedEndDate == null ? $requestedDate : $requestedEndDate->ToTimezone($timezone);
     if ($initializer->IsNew()) {
         $resource = $initializer->PrimaryResource();
         if ($resource->GetMinimumLength() != null && !$resource->GetMinimumLength()->Interval()->IsNull()) {
             $endDate = $startDate->ApplyDifference($resource->GetMinimumLength()->Interval());
         }
     }
     $layout = $this->scheduleRepository->GetLayout($requestedScheduleId, new ReservationLayoutFactory($timezone));
     $startPeriods = $layout->GetLayout($startDate);
     if (count($startPeriods) > 1 && $startPeriods[0]->Begin()->Compare($startPeriods[1]->Begin()) > 0) {
         $period = array_shift($startPeriods);
         $startPeriods[] = $period;
     }
     $endPeriods = $layout->GetLayout($endDate);
     $initializer->SetDates($startDate, $endDate, $startPeriods, $endPeriods);
     $hideRecurrence = !$initializer->CurrentUser()->IsAdmin && Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION, ConfigKeys::RESERVATION_PREVENT_RECURRENCE, new BooleanConverter());
     $initializer->HideRecurrence($hideRecurrence);
 }
示例#11
0
 public static function Now()
 {
     if (empty(self::$Now)) {
         return Date::Now()->ToDatabase();
     } else {
         return date(self::$_format, self::$Now);
     }
 }
 public function __construct()
 {
     $this->interval = 3;
     $this->monthlyType = RepeatMonthlyType::DayOfMonth . '|' . RepeatMonthlyType::DayOfWeek . '|null';
     $this->type = RepeatType::Daily . '|' . RepeatType::Monthly . '|' . RepeatType::None . '|' . RepeatType::Weekly . '|' . RepeatType::Yearly;
     $this->weekdays = array(0, 1, 2, 3, 4, 5, 6);
     $this->repeatTerminationDate = Date::Now()->ToIso();
 }
示例#13
0
 public function testCanGetNow()
 {
     $format = 'd m y H:i:s';
     Date::_ResetNow();
     $now = Date::Now();
     $datenow = new DateTime(date(Date::SHORT_FORMAT, time()));
     $this->assertEquals($datenow->format($format), $now->Format($format));
 }
 public function PageLoad()
 {
     if (!$this->validator->IsValid()) {
         return;
     }
     $userId = $this->page->GetUserId();
     $scheduleId = $this->page->GetScheduleId();
     $resourceId = $this->page->GetResourceId();
     $accessoryIds = $this->page->GetAccessoryIds();
     $resourceGroupId = $this->page->GetResourceGroupId();
     $weekAgo = Date::Now()->AddDays(-7);
     $nextYear = Date::Now()->AddDays(365);
     $sid = null;
     $rid = null;
     $uid = null;
     $aid = null;
     $resourceIds = array();
     $reservations = array();
     $res = array();
     $summaryFormat = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_ICS_SUMMARY);
     $reservationUserLevel = ReservationUserLevel::OWNER;
     if (!empty($scheduleId)) {
         $schedule = $this->subscriptionService->GetSchedule($scheduleId);
         $sid = $schedule->GetId();
     }
     if (!empty($resourceId)) {
         $resource = $this->subscriptionService->GetResource($resourceId);
         $rid = $resource->GetId();
     }
     if (!empty($accessoryIds)) {
         ## No transformation is implemented. It is assumed the accessoryIds is provided as AccessoryName
         ## filter is defined by LIKE "PATTERN%"
         $aid = $accessoryIds;
     }
     if (!empty($userId)) {
         $user = $this->subscriptionService->GetUser($userId);
         $uid = $user->Id();
         $reservationUserLevel = ReservationUserLevel::ALL;
         $summaryFormat = Configuration::Instance()->GetSectionKey(ConfigSection::RESERVATION_LABELS, ConfigKeys::RESERVATION_LABELS_MY_ICS_SUMMARY);
     }
     if (!empty($resourceGroupId)) {
         $resourceIds = $this->subscriptionService->GetResourcesInGroup($resourceGroupId);
     }
     if (!empty($uid) || !empty($sid) || !empty($rid) || !empty($resourceIds)) {
         $res = $this->reservationViewRepository->GetReservationList($weekAgo, $nextYear, $uid, $reservationUserLevel, $sid, $rid);
     } elseif (!empty($aid)) {
         throw new Exception('need to give an accessory a public id, allow subscriptions');
         $res = $this->reservationViewRepository->GetAccessoryReservationList($weekAgo, $nextYear, $accessoryIds);
     }
     Log::Debug('Loading calendar subscription for userId %s, scheduleId %s, resourceId %s. Found %s reservations.', $userId, $scheduleId, $resourceId, count($res));
     $session = ServiceLocator::GetServer()->GetUserSession();
     foreach ($res as $r) {
         if (empty($resourceIds) || in_array($r->ResourceId, $resourceIds)) {
             $reservations[] = new iCalendarReservationView($r, $session, $this->privacyFilter, $summaryFormat);
         }
     }
     $this->page->SetReservations($reservations);
 }
 public function __construct()
 {
     $now = Date::Now();
     $this->startDate = $now->AddDays(5)->Format('Y-m-d');
     $this->endDate = $now->AddDays(6)->Format('Y-m-d');
     $this->repeatTerminationDate = $now->AddDays(60)->Format('Y-m-d');
     $this->accessories = array(new FakeAccessoryFormElement(1, 2, 'accessoryname'));
     $this->attributes = array(new AttributeFormElement(1, "something"));
     $this->attachment = new FakeUploadedFile();
 }
示例#16
0
 public function __construct($seriesId = 1, $reservationId = 1, $referenceNumber = 'referencenumber', $startDate = null, $endDate = null, $title = 'title', $description = 'description', $resourceName = 'resourcename', $emailAddress = '*****@*****.**', $fname = 'fname', $lname = 'lname', $timezone = 'UTC', $reminder_minutes = 100, $language = 'en_us')
 {
     if (empty($startDate)) {
         $startDate = Date::Now()->ToDatabase();
     }
     if (empty($endDate)) {
         $endDate = Date::Now()->ToDatabase();
     }
     $this->row = array(ColumnNames::SERIES_ID => $seriesId, ColumnNames::RESERVATION_INSTANCE_ID => $reservationId, ColumnNames::REFERENCE_NUMBER => $referenceNumber, ColumnNames::RESERVATION_START => $startDate, ColumnNames::RESERVATION_END => $endDate, ColumnNames::RESERVATION_TITLE => $title, ColumnNames::RESERVATION_DESCRIPTION => $description, ColumnNames::RESOURCE_NAME_ALIAS => $resourceName, ColumnNames::EMAIL => $emailAddress, ColumnNames::FIRST_NAME => $fname, ColumnNames::LAST_NAME => $lname, ColumnNames::TIMEZONE_NAME => $timezone, ColumnNames::REMINDER_MINUTES_PRIOR => $reminder_minutes, ColumnNames::LANGUAGE_CODE => $language);
 }
示例#17
0
 public function ProcessPageLoad()
 {
     $user = ServiceLocator::GetServer()->GetUserSession();
     $this->presenter->PageLoad($user, $user->Timezone);
     $this->Set('HeaderLabels', Resources::GetInstance()->GetDays('full'));
     $this->Set('Today', Date::Now()->ToTimezone($user->Timezone));
     $this->Set('TimeFormat', Resources::GetInstance()->GetDateFormat('calendar_time'));
     $this->Set('DateFormat', Resources::GetInstance()->GetDateFormat('calendar_dates'));
     $this->Display('Calendar/' . $this->template);
 }
 public function testRuleIsInvalidIfStartIsInPast()
 {
     $start = Date::Now()->AddDays(-2);
     $end = Date::Now()->AddDays(-1);
     $reservation = new TestReservationSeries();
     $reservation->WithCurrentInstance(new TestReservation('1', new DateRange($start, $end)));
     $rule = new ReservationStartTimeRule($this->scheduleRepository);
     $result = $rule->Validate($reservation);
     $this->assertFalse($result->IsValid());
 }
示例#19
0
 public function GetFuture()
 {
     $announcements = array();
     $reader = ServiceLocator::GetDatabase()->Query(new GetDashboardAnnouncementsCommand(Date::Now()));
     while ($row = $reader->GetRow()) {
         $announcements[] = $row[ColumnNames::ANNOUNCEMENT_TEXT];
     }
     $reader->Free();
     return $announcements;
 }
示例#20
0
 /**
  * @param string $dateString
  * @param UserSession $session
  * @return Date
  */
 public static function GetDate($dateString, UserSession $session)
 {
     try {
         if (BookedStringHelper::Contains($dateString, 'T')) {
             return Date::ParseExact($dateString);
         }
         return Date::Parse($dateString, $session->Timezone);
     } catch (Exception $ex) {
         return Date::Now();
     }
 }
示例#21
0
 public function __construct($reportName, $userId, Report_Usage $usage, Report_ResultSelection $selection, Report_GroupBy $groupBy, Report_Range $range, Report_Filter $filter)
 {
     $this->reportName = $reportName;
     $this->userId = $userId;
     $this->usage = $usage;
     $this->selection = $selection;
     $this->groupBy = $groupBy;
     $this->range = $range;
     $this->filter = $filter;
     $this->dateCreated = Date::Now();
 }
 public function testLoadsExistingReservationAndUpdatesData()
 {
     $seriesId = 109809;
     $expectedSeries = new ExistingReservationSeries();
     $currentDuration = new DateRange(Date::Now()->AddDays(1), Date::Now()->AddDays(2), 'UTC');
     $removedResourceId = 190;
     $resource = new FakeBookableResource(1);
     $additionalId1 = $this->page->resourceIds[0];
     $additionalId2 = $this->page->resourceIds[1];
     $additional1 = new FakeBookableResource($additionalId1);
     $additional2 = new FakeBookableResource($additionalId2);
     $reservation = new Reservation($expectedSeries, $currentDuration);
     $expectedSeries->WithId($seriesId);
     $expectedSeries->WithCurrentInstance($reservation);
     $expectedSeries->WithPrimaryResource($resource);
     $expectedSeries->WithResource(new FakeBookableResource($removedResourceId));
     $expectedSeries->WithAttribute(new AttributeValue(100, 'to be removed'));
     $referenceNumber = $this->page->existingReferenceNumber;
     $timezone = $this->user->Timezone;
     $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries));
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($this->page->resourceId))->will($this->returnValue($resource));
     $this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalId1))->will($this->returnValue($additional1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalId2))->will($this->returnValue($additional2));
     $this->page->repeatType = RepeatType::Daily;
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->page, $this->user->Timezone);
     $expectedDuration = DateRange::Create($this->page->GetStartDate() . " " . $this->page->GetStartTime(), $this->page->GetEndDate() . " " . $this->page->GetEndTime(), $timezone);
     $attachment = new FakeUploadedFile();
     $this->page->attachment = $attachment;
     $this->page->hasEndReminder = false;
     $existingSeries = $this->presenter->BuildReservation();
     $expectedAccessories = array(new ReservationAccessory(1, 2, 'accessoryname'));
     $expectedAttributes = array(1 => new AttributeValue(1, 'something'));
     $this->assertEquals($seriesId, $existingSeries->SeriesId());
     $this->assertEquals($this->page->seriesUpdateScope, $existingSeries->SeriesUpdateScope());
     $this->assertEquals($this->page->title, $existingSeries->Title());
     $this->assertEquals($this->page->description, $existingSeries->Description());
     $this->assertEquals($this->page->userId, $existingSeries->UserId());
     $this->assertEquals($resource, $existingSeries->Resource());
     $this->assertEquals($repeatOptions, $existingSeries->RepeatOptions());
     $this->assertEquals(array($additional1, $additional2), $existingSeries->AdditionalResources());
     $this->assertEquals($this->page->participants, $existingSeries->CurrentInstance()->AddedParticipants());
     $this->assertEquals($this->page->invitees, $existingSeries->CurrentInstance()->AddedInvitees());
     $this->assertTrue($expectedDuration->Equals($existingSeries->CurrentInstance()->Duration()), "Expected: {$expectedDuration} Actual: {$existingSeries->CurrentInstance()->Duration()}");
     $this->assertEquals($this->user, $expectedSeries->BookedBy());
     $this->assertEquals($expectedAccessories, $existingSeries->Accessories());
     $this->assertEquals($expectedAttributes, $existingSeries->AttributeValues());
     $expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $seriesId);
     $this->assertEquals(array($expectedAttachment), $expectedSeries->AddedAttachments());
     $this->assertEquals($this->page->removedFileIds, $existingSeries->RemovedAttachmentIds());
     $this->assertEquals(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()), $existingSeries->GetStartReminder());
     $this->assertEquals(ReservationReminder::None(), $existingSeries->GetEndReminder());
 }
 public function testOkIfReservationIsShorterThanTheMaximumDuration()
 {
     $resource = new FakeBookableResource(1, "2");
     $resource->SetMaxLength("25h00m");
     $reservation = new TestReservationSeries();
     $reservation->WithResource($resource);
     $duration = new DateRange(Date::Now(), Date::Now()->AddDays(1));
     $reservation->WithDuration($duration);
     $rule = new ResourceMaximumDurationRule();
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
 public function testUpdatesSession()
 {
     $userId = 123;
     $token = 'my special token';
     $expectedSession = new WebServiceUserSession($userId);
     $expectedSession->SessionToken = $token;
     $expectedSession->UserId = $userId;
     $serializedSession = serialize($expectedSession);
     $this->repo->Update($expectedSession);
     $command = new UpdateUserSessionCommand($userId, $token, Date::Now(), $serializedSession);
     $this->assertEquals($command, $this->db->_LastCommand);
 }
 public function testOkIfLatestInstanceIsBeforeTheMaximumNoticeTime()
 {
     $resource = new FakeBookableResource(1, "2");
     $resource->SetMaxNotice("1h00m");
     $reservation = new TestReservationSeries();
     $reservation->WithResource($resource);
     $duration = new DateRange(Date::Now(), Date::Now());
     $reservation->WithDuration($duration);
     $rule = new ResourceMaximumNoticeRule();
     $result = $rule->Validate($reservation);
     $this->assertTrue($result->IsValid());
 }
示例#26
0
 public function PageLoad($userSession, $timezone)
 {
     $type = $this->page->GetCalendarType();
     $year = $this->page->GetYear();
     $month = $this->page->GetMonth();
     $day = $this->page->GetDay();
     $defaultDate = Date::Now()->ToTimezone($timezone);
     if (empty($year)) {
         $year = $defaultDate->Year();
     }
     if (empty($month)) {
         $month = $defaultDate->Month();
     }
     if (empty($day)) {
         $day = $defaultDate->Day();
     }
     $schedules = $this->scheduleRepository->GetAll();
     $showInaccessible = Configuration::Instance()->GetSectionKey(ConfigSection::SCHEDULE, ConfigKeys::SCHEDULE_SHOW_INACCESSIBLE_RESOURCES, new BooleanConverter());
     $resources = $this->resourceService->GetAllResources($showInaccessible, $userSession);
     $selectedScheduleId = $this->page->GetScheduleId();
     $selectedSchedule = $this->GetDefaultSchedule($schedules);
     $selectedResourceId = $this->page->GetResourceId();
     $selectedGroupId = $this->page->GetGroupId();
     $resourceGroups = $this->resourceService->GetResourceGroups($selectedScheduleId, $userSession);
     if (!empty($selectedGroupId)) {
         $tempResources = array();
         $resourceIds = $resourceGroups->GetResourceIds($selectedGroupId);
         $selectedGroup = $resourceGroups->GetGroup($selectedGroupId);
         $this->page->BindSelectedGroup($selectedGroup);
         foreach ($resources as $resource) {
             if (in_array($resource->GetId(), $resourceIds)) {
                 $tempResources[] = $resource;
             }
         }
         $resources = $tempResources;
     }
     if (!empty($selectedResourceId)) {
         $subscriptionDetails = $this->subscriptionService->ForResource($selectedResourceId);
     } else {
         $subscriptionDetails = $this->subscriptionService->ForSchedule($selectedSchedule->GetId());
     }
     $calendar = $this->calendarFactory->Create($type, $year, $month, $day, $timezone, $selectedSchedule->GetWeekdayStart());
     $reservations = $this->reservationRepository->GetReservationList($calendar->FirstDay(), $calendar->LastDay()->AddDays(1), null, null, $selectedScheduleId, $selectedResourceId);
     $calendar->AddReservations(CalendarReservation::FromScheduleReservationList($reservations, $resources, $userSession, true));
     $this->page->BindCalendar($calendar);
     $this->page->BindFilters(new CalendarFilters($schedules, $resources, $selectedScheduleId, $selectedResourceId, $resourceGroups));
     $this->page->SetDisplayDate($calendar->FirstDay());
     $this->page->SetScheduleId($selectedScheduleId);
     $this->page->SetResourceId($selectedResourceId);
     $this->page->SetFirstDay($selectedSchedule->GetWeekdayStart());
     $this->page->BindSubscription($subscriptionDetails);
 }
示例#27
0
 public function testSavesReportForUser()
 {
     $reportName = 'reportName';
     $userId = 12;
     $usage = new Report_Usage(Report_Usage::ACCESSORIES);
     $selection = new Report_ResultSelection(Report_ResultSelection::COUNT);
     $groupBy = new Report_GroupBy(Report_GroupBy::RESOURCE);
     $range = new Report_Range(Report_Range::ALL_TIME, Date::Now(), Date::Now());
     $filter = new Report_Filter(null, null, null, null, null, null);
     $savedReport = new SavedReport($reportName, $userId, $usage, $selection, $groupBy, $range, $filter);
     $this->reportingRepository->expects($this->once())->method('SaveCustomReport')->with($this->equalTo($savedReport));
     $this->rs->Save($reportName, $userId, $usage, $selection, $groupBy, $range, $filter);
 }
 public function testShowsAllAnnouncements()
 {
     $now = Date::Now();
     $announcements = $this->GetAnnouncementRows();
     $this->db->SetRow(0, $announcements);
     $expectedAnnouncements = array();
     foreach ($announcements as $item) {
         $expectedAnnouncements[] = $item[ColumnNames::ANNOUNCEMENT_TEXT];
     }
     $this->presenter->PageLoad();
     $this->assertEquals($this->announcements->_ExpectedAnnouncements, $this->page->_LastAnnouncements);
     $this->assertTrue($this->announcements->_GetFutureCalled);
 }
示例#29
0
 /**
  * @param Date|null $reservationStart
  * @param Date|null $reservationEnd
  * @return bool
  */
 public static function HideReservationDetails($reservationStart = null, $reservationEnd = null)
 {
     $hideReservationDetails = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_RESERVATION_DETAILS, new LowerCaseConverter());
     if ($hideReservationDetails == 'past' && $reservationEnd != null) {
         return $reservationEnd->LessThan(Date::Now());
     } elseif ($hideReservationDetails == 'future' && $reservationEnd != null) {
         return $reservationEnd->GreaterThan(Date::Now());
     } elseif ($hideReservationDetails == 'current' && $reservationStart != null) {
         return $reservationStart->LessThan(Date::Now());
     }
     $converter = new BooleanConverter();
     return $converter->Convert($hideReservationDetails);
 }
示例#30
0
 /**
  * @param $reservations iCalendarReservationView[]
  * @return string
  */
 public function Render($reservations)
 {
     $config = Configuration::Instance();
     $this->Set('bookedVersion', $config->GetKey(ConfigKeys::VERSION));
     $this->Set('DateStamp', Date::Now());
     /**
      * ScriptUrl is used to generate iCal UID's. As a workaround to this bug
      * https://bugzilla.mozilla.org/show_bug.cgi?id=465853
      * we need to avoid using any slashes "/"
      */
     $url = $config->GetScriptUrl();
     $this->Set('UID', parse_url($url, PHP_URL_HOST));
     $this->Set('Reservations', $reservations);
     return $this->smarty->fetch('Export/ical.tpl');
 }