public function PageLoad()
 {
     $this->page->BindResources($this->resourceRepo->GetResourceList());
     $this->page->BindAccessories($this->resourceRepo->GetAccessoryList());
     $this->page->BindSchedules($this->scheduleRepo->GetAll());
     $this->page->BindGroups($this->groupRepo->GetList()->Results());
 }
 public function testWhenInitializing()
 {
     $accessories = array();
     $this->resourceRepository->expects($this->once())->method('GetAccessoryList')->will($this->returnValue($accessories));
     $this->page->expects($this->once())->method('BindAccessories')->with($this->equalTo($accessories));
     $this->presenter->PageLoad();
 }
 public function testGetsAllAccessories()
 {
     $accessories = array(new AccessoryDto(1, 'name', 23));
     $this->resourceRepository->expects($this->once())->method('GetAccessoryList')->will($this->returnValue($accessories));
     $this->service->GetAll();
     $this->assertEquals(new AccessoriesResponse($this->server, $accessories), $this->server->_LastResponse);
     $this->assertEquals(RestResponse::OK_CODE, $this->server->_LastResponseCode);
 }
 public function testGetsResourceByPublicId()
 {
     $expected = new FakeBookableResource(123);
     $publicId = uniqid();
     $this->resourceRepo->expects($this->once())->method('LoadByPublicId')->with($this->equalTo($publicId))->will($this->returnValue($expected));
     $actual = $this->service->GetResource($publicId);
     $this->assertEquals($expected, $actual);
 }
 /**
  * @return ExistingReservationSeries
  */
 public function BuildReservation()
 {
     $referenceNumber = $this->page->GetReferenceNumber();
     $existingSeries = $this->persistenceService->LoadByReferenceNumber($referenceNumber);
     $existingSeries->ApplyChangesTo($this->page->GetSeriesUpdateScope());
     $resourceId = $this->page->GetResourceId();
     $additionalResourceIds = $this->page->GetResources();
     if (empty($resourceId)) {
         // the first additional resource will become the primary if the primary is removed
         $resourceId = array_shift($additionalResourceIds);
     }
     $resource = $this->resourceRepository->LoadById($resourceId);
     $existingSeries->Update($this->page->GetUserId(), $resource, $this->page->GetTitle(), $this->page->GetDescription(), $this->userSession);
     $existingSeries->UpdateDuration($this->GetReservationDuration());
     $roFactory = new RepeatOptionsFactory();
     $existingSeries->Repeats($roFactory->CreateFromComposite($this->page, $this->userSession->Timezone));
     $additionalResources = array();
     foreach ($additionalResourceIds as $additionalResourceId) {
         if ($additionalResourceId != $resourceId) {
             $additionalResources[] = $this->resourceRepository->LoadById($additionalResourceId);
         }
     }
     $existingSeries->ChangeResources($additionalResources);
     $existingSeries->ChangeParticipants($this->page->GetParticipants());
     $existingSeries->ChangeInvitees($this->page->GetInvitees());
     $existingSeries->ChangeAccessories($this->GetAccessories());
     $existingSeries->ChangeAttributes($this->GetAttributes());
     $existingSeries->AllowParticipation($this->page->GetAllowParticipation());
     $attachments = $this->page->GetAttachments();
     foreach ($attachments as $attachment) {
         if ($attachment != null) {
             if ($attachment->IsError()) {
                 Log::Error('Error attaching file %s. %s', $attachment->OriginalName(), $attachment->Error());
             } else {
                 Log::Debug('Attaching file %s to series %s', $attachment->OriginalName(), $existingSeries->SeriesId());
                 $att = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), $existingSeries->SeriesId());
                 $existingSeries->AddAttachment($att);
             }
         }
     }
     foreach ($this->page->GetRemovedAttachmentIds() as $fileId) {
         $existingSeries->RemoveAttachment($fileId);
     }
     if ($this->page->HasStartReminder()) {
         $existingSeries->AddStartReminder(new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval()));
     } else {
         $existingSeries->RemoveStartReminder();
     }
     if ($this->page->HasEndReminder()) {
         $existingSeries->AddEndReminder(new ReservationReminder($this->page->GetEndReminderValue(), $this->page->GetEndReminderInterval()));
     } else {
         $existingSeries->RemoveEndReminder();
     }
     return $existingSeries;
 }
Example #6
0
 public function PageLoad()
 {
     $resources = $this->resourceRepository->GetResourceList();
     $groups = $this->groupRepository->GetList()->Results();
     $schedules = $this->scheduleRepository->GetAll();
     $this->page->BindResources($resources);
     $this->page->BindGroups($groups);
     $this->page->BindSchedules($schedules);
     $quotas = $this->quotaRepository->GetAll();
     $this->page->BindQuotas($quotas);
 }
 public function BuildReservation()
 {
     $userId = $this->_page->GetUserId();
     $primaryResourceId = $this->_page->GetResourceId();
     $resource = $this->_resourceRepository->LoadById($primaryResourceId);
     $title = $this->_page->GetTitle();
     $description = $this->_page->GetDescription();
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->_page, $this->userSession->Timezone);
     $duration = $this->GetReservationDuration();
     /*EXPERIMENT*/
     $experiment = $this->_page->getExperiment();
     $reservationSeries = ReservationSeries::Create($userId, $resource, $title, $description, $duration, $repeatOptions, $this->userSession, $experiment);
     $resourceIds = $this->_page->GetResources();
     foreach ($resourceIds as $resourceId) {
         if ($primaryResourceId != $resourceId) {
             $reservationSeries->AddResource($this->_resourceRepository->LoadById($resourceId));
         }
     }
     $accessories = $this->_page->GetAccessories();
     foreach ($accessories as $accessory) {
         $reservationSeries->AddAccessory(new ReservationAccessory($accessory->Id, $accessory->Quantity, $accessory->Name));
     }
     $attributes = $this->_page->GetAttributes();
     foreach ($attributes as $attribute) {
         $reservationSeries->AddAttributeValue(new AttributeValue($attribute->Id, $attribute->Value));
     }
     $participantIds = $this->_page->GetParticipants();
     $reservationSeries->ChangeParticipants($participantIds);
     $inviteeIds = $this->_page->GetInvitees();
     $reservationSeries->ChangeInvitees($inviteeIds);
     $reservationSeries->AllowParticipation($this->_page->GetAllowParticipation());
     $attachments = $this->_page->GetAttachments();
     foreach ($attachments as $attachment) {
         if ($attachment != null) {
             if ($attachment->IsError()) {
                 Log::Error('Error attaching file %s. %s', $attachment->OriginalName(), $attachment->Error());
             } else {
                 $att = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), 0);
                 $reservationSeries->AddAttachment($att);
             }
         }
     }
     if ($this->_page->HasStartReminder()) {
         $reservationSeries->AddStartReminder(new ReservationReminder($this->_page->GetStartReminderValue(), $this->_page->GetStartReminderInterval()));
     }
     if ($this->_page->HasEndReminder()) {
         $reservationSeries->AddEndReminder(new ReservationReminder($this->_page->GetEndReminderValue(), $this->_page->GetEndReminderInterval()));
     }
     return $reservationSeries;
 }
 public function LoadBlackout()
 {
     $id = $this->page->GetBlackoutId();
     $session = ServiceLocator::GetServer()->GetUserSession();
     Log::Debug('Loading blackout for editing. Id=%s', $id);
     $series = $this->manageBlackoutsService->LoadBlackout($id, $session->UserId);
     if ($series != null) {
         $this->page->BindResources($this->resourceRepository->GetResourceList());
         $this->page->SetBlackoutResources($series->ResourceIds());
         $this->page->SetBlackoutId($id);
         $this->page->SetBlackoutStartDate($series->CurrentBlackout()->StartDate()->ToTimezone($session->Timezone));
         $this->page->SetBlackoutEndDate($series->CurrentBlackout()->EndDate()->ToTimezone($session->Timezone));
         $this->page->SetTitle($series->Title());
         $this->page->SetIsRecurring($series->RepeatType() != RepeatType::None);
         $repeatConfiguration = $series->RepeatConfiguration();
         $this->page->SetRepeatInterval($repeatConfiguration->Interval);
         $this->page->SetRepeatMonthlyType($repeatConfiguration->MonthlyType);
         if ($repeatConfiguration->TerminationDate != null) {
             $this->page->SetRepeatTerminationDate($repeatConfiguration->TerminationDate->ToTimezone($session->Timezone));
         }
         $this->page->SetRepeatType($repeatConfiguration->Type);
         $this->page->SetRepeatWeekdays($repeatConfiguration->Weekdays);
         $this->page->SetWasBlackoutFound(true);
     } else {
         $this->page->SetWasBlackoutFound(false);
     }
     $this->page->ShowBlackout();
 }
 public function testWhenInitializing()
 {
     $groups = array();
     $bookableResources = array();
     $schedules = array();
     $groupResult = new PageableData($groups);
     $quotaList = array();
     $this->resourceRepository->expects($this->once())->method('GetResourceList')->will($this->returnValue($bookableResources));
     $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($bookableResources));
     $this->groupRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupResult));
     $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups));
     $this->scheduleRepository->expects($this->once())->method('GetAll')->will($this->returnValue($schedules));
     $this->page->expects($this->once())->method('BindSchedules')->with($this->equalTo($schedules));
     $this->quotaRepository->expects($this->once())->method('GetAll')->will($this->returnValue($quotaList));
     $this->presenter->PageLoad();
 }
 public function testGetsSelectedResourcesFromPageAndAssignsPermission()
 {
     $resourcesThatShouldRemainUnchanged = array(5, 10);
     $allowedResourceIds = array(1, 2, 4, 20, 30);
     $submittedResourceIds = array(1, 4);
     $currentResourceIds = array(1, 20, 30);
     $expectedResourceIds = array(1, 4, 5, 10);
     $allResourceIds = array_unique(array_merge($resourcesThatShouldRemainUnchanged, $allowedResourceIds, $submittedResourceIds, $currentResourceIds));
     $resources = array();
     foreach ($allResourceIds as $rid) {
         $resources[] = new FakeBookableResource($rid);
     }
     $userId = 9928;
     $adminUserId = $this->fakeUser->UserId;
     $user = new FakeUser();
     $user->WithPermissions(array_merge($resourcesThatShouldRemainUnchanged, $currentResourceIds));
     $adminUser = new FakeUser();
     $adminUser->_ResourceAdminResourceIds = $allowedResourceIds;
     $adminUser->_IsResourceAdmin = false;
     $this->page->expects($this->atLeastOnce())->method('GetUserId')->will($this->returnValue($userId));
     $this->page->expects($this->atLeastOnce())->method('GetAllowedResourceIds')->will($this->returnValue($submittedResourceIds));
     $this->resourceRepo->expects($this->once())->method('GetResourceList')->will($this->returnValue($resources));
     $this->userRepo->expects($this->at(0))->method('LoadById')->with($this->equalTo($adminUserId))->will($this->returnValue($adminUser));
     $this->userRepo->expects($this->at(1))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user));
     $this->userRepo->expects($this->once())->method('Update')->with($this->equalTo($user));
     $this->presenter->ChangePermissions();
     $actual = $user->AllowedResourceIds();
     $this->assertEquals(sort($expectedResourceIds), sort($actual));
 }
 public function testMovesGroupNode()
 {
     $nodeId = 1;
     $targetId = 2;
     $nodeType = ResourceGroup::GROUP_TYPE;
     $previousNodeId = 3;
     $group = new ResourceGroup($nodeId, 'name', $previousNodeId);
     $group->MoveTo($targetId);
     $this->page->expects($this->atLeastOnce())->method('GetNodeId')->will($this->returnValue($nodeId));
     $this->page->expects($this->atLeastOnce())->method('GetTargetNodeId')->will($this->returnValue($targetId));
     $this->page->expects($this->atLeastOnce())->method('GetNodeType')->will($this->returnValue($nodeType));
     $this->page->expects($this->atLeastOnce())->method('GetPreviousNodeId')->will($this->returnValue($previousNodeId));
     $this->resourceRepository->expects($this->once())->method('LoadResourceGroup')->with($this->equalTo($nodeId))->will($this->returnValue($group));
     $this->resourceRepository->expects($this->once())->method('UpdateResourceGroup')->with($group);
     $this->presenter->MoveNode();
 }
 public function testAddsNewBlackoutTimeForSchedule()
 {
     $startDate = '1/1/2011';
     $endDate = '1/2/2011';
     $startTime = '01:30 PM';
     $endTime = '12:15 AM';
     $timezone = $this->fakeUser->Timezone;
     $dr = DateRange::Create($startDate . ' ' . $startTime, $endDate . ' ' . $endTime, $timezone);
     $title = 'out of service';
     $conflictAction = ReservationConflictResolution::Delete;
     $conflictResolution = ReservationConflictResolution::Create($conflictAction);
     $endDateString = '2012-01-01';
     $repeatType = RepeatType::Daily;
     $repeatInterval = 1;
     $repeatDays = array(1, 2);
     $repeatMonthlyType = RepeatMonthlyType::DayOfMonth;
     $roFactory = new RepeatOptionsFactory();
     $repeatEndDate = Date::Parse($endDateString, $timezone);
     $repeatOptions = $roFactory->Create($repeatType, $repeatInterval, $repeatEndDate, $repeatDays, $repeatMonthlyType);
     $this->ExpectPageToReturnCommonBlackoutInfo($startDate, $startTime, $endDate, $endTime, $title, $conflictAction);
     $this->ExpectPageToReturnRepeatInfo($repeatType, $repeatInterval, $endDateString, $repeatDays, $repeatMonthlyType);
     $scheduleId = 123;
     $this->page->expects($this->once())->method('GetBlackoutScheduleId')->will($this->returnValue($scheduleId));
     $this->page->expects($this->once())->method('GetApplyBlackoutToAllResources')->will($this->returnValue(true));
     $resources = array(new FakeBookableResource(1), new FakeBookableResource(2), new FakeBookableResource(3));
     $this->resourceRepository->expects($this->once())->method('GetScheduleResources')->with($this->equalTo($scheduleId))->will($this->returnValue($resources));
     $result = $this->getMock('IBlackoutValidationResult');
     $this->blackoutsService->expects($this->once())->method('Add')->with($this->equalTo($dr), $this->equalTo(array(1, 2, 3)), $this->equalTo($title), $this->equalTo($conflictResolution), $this->equalTo($repeatOptions))->will($this->returnValue($result));
     $this->presenter->AddBlackout();
 }
 public function testDeletesResourceType()
 {
     $id = 9919;
     $this->page->expects($this->once())->method('GetId')->will($this->returnValue($id));
     $this->resourceRepository->expects($this->once())->method('RemoveResourceType')->with($this->equalTo($id));
     $this->presenter->Delete();
 }
 public function testUpdatesReservationResourceStatuses()
 {
     $resourceStatusId = ResourceStatus::HIDDEN;
     $resourceStatusReasonId = 111;
     $referenceNumber = 'abc123';
     $reservations = array(new TestReservationItemView(1, Date::Now(), Date::Now(), 1), new TestReservationItemView(1, Date::Now(), Date::Now(), 2));
     $pageableReservations = new PageableData($reservations);
     $resource1 = new FakeBookableResource(1);
     $resource1->ChangeStatus(ResourceStatus::AVAILABLE, null);
     $resource2 = new FakeBookableResource(2);
     $resource2->ChangeStatus(ResourceStatus::AVAILABLE, null);
     $this->page->expects($this->once())->method('CanUpdateResourceStatuses')->will($this->returnValue(true));
     $this->page->expects($this->once())->method('GetResourceStatus')->will($this->returnValue($resourceStatusId));
     $this->page->expects($this->once())->method('GetUpdateScope')->will($this->returnValue('all'));
     $this->page->expects($this->once())->method('GetResourceStatusReason')->will($this->returnValue($resourceStatusReasonId));
     $this->page->expects($this->once())->method('GetResourceStatusReferenceNumber')->will($this->returnValue($referenceNumber));
     $this->reservationsService->expects($this->once())->method('LoadFiltered')->with($this->isNull(), $this->isNull(), $this->equalTo(new ReservationFilter(null, null, $referenceNumber, null, null, null, null, null)), $this->equalTo($this->fakeUser))->will($this->returnValue($pageableReservations));
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with(1)->will($this->returnValue($resource1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with(2)->will($this->returnValue($resource2));
     $this->resourceRepository->expects($this->at(1))->method('Update')->with($this->anything());
     $this->resourceRepository->expects($this->at(3))->method('Update')->with($this->anything());
     $this->presenter->UpdateResourceStatus();
     $this->assertEquals($resourceStatusId, $resource1->GetStatusId());
     $this->assertEquals($resourceStatusReasonId, $resource1->GetStatusReasonId());
 }
Example #15
0
 /**
  * @name GetAvailability
  * @description Returns resource availability for the requested time. "availableAt" and "availableUntil" will include availability through the next 7 days
  * Optional query string parameter: dateTime. If no dateTime is requested the current datetime will be used.
  * @response ResourcesAvailabilityResponse
  * @return void
  */
 public function GetAvailability($resourceId = null)
 {
     $dateQueryString = $this->server->GetQueryString(WebServiceQueryStringKeys::DATE_TIME);
     if (!empty($dateQueryString)) {
         $requestedTime = WebServiceDate::GetDate($dateQueryString, $this->server->GetSession());
     } else {
         $requestedTime = Date::Now();
     }
     if (empty($resourceId)) {
         $resources = $this->resourceRepository->GetResourceList();
     } else {
         $resources[] = $this->resourceRepository->LoadById($resourceId);
     }
     $lastDateSearched = $requestedTime->AddDays(30);
     $reservations = $this->GetReservations($this->reservationRepository->GetReservationList($requestedTime, $lastDateSearched, null, null, null, $resourceId));
     $resourceAvailability = array();
     foreach ($resources as $resource) {
         $reservation = $this->GetOngoingReservation($resource, $reservations);
         if ($reservation != null) {
             $lastReservationBeforeOpening = $this->GetLastReservationBeforeAnOpening($resource, $reservations);
             if ($lastReservationBeforeOpening == null) {
                 $lastReservationBeforeOpening = $reservation;
             }
             $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, $lastReservationBeforeOpening, null, $lastReservationBeforeOpening->EndDate, $lastDateSearched);
         } else {
             $resourceId = $resource->GetId();
             if (array_key_exists($resourceId, $reservations)) {
                 $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, null, $reservations[$resourceId][0], null, $lastDateSearched);
             } else {
                 $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, null, null, null, $lastDateSearched);
             }
         }
     }
     $this->server->WriteResponse(new ResourcesAvailabilityResponse($this->server, $resourceAvailability));
 }
 public function UpdateResourceStatus()
 {
     if (!$this->page->CanUpdateResourceStatuses()) {
         Log::Debug('User does not have rights to update resource statuses');
         return;
     }
     $session = ServiceLocator::GetServer()->GetUserSession();
     $statusId = $this->page->GetResourceStatus();
     $reasonId = $this->page->GetResourceStatusReason();
     $referenceNumber = $this->page->GetResourceStatusReferenceNumber();
     $resourceId = $this->page->GetUpdateResourceId();
     $updateScope = $this->page->GetUpdateScope();
     Log::Debug('Updating resource status. ResourceId=%s, ReferenceNumber=%s, StatusId=%s, ReasonId=%s, UserId=%s', $resourceId, $referenceNumber, $statusId, $reasonId, $session->UserId);
     $resourceIds = array();
     if (empty($updateScope)) {
         $resourceIds[] = $resourceId;
     } else {
         $reservations = $this->manageReservationsService->LoadFiltered(null, null, new ReservationFilter(null, null, $referenceNumber, null, null, null, null), $session);
         /** @var $reservation ReservationItemView */
         foreach ($reservations->Results() as $reservation) {
             $resourceIds[] = $reservation->ResourceId;
         }
     }
     foreach ($resourceIds as $id) {
         $resource = $this->resourceRepository->LoadById($id);
         $resource->ChangeStatus($statusId, $reasonId);
         $this->resourceRepository->Update($resource);
     }
 }
 public function testFiltersResourcesWhenGettingResourceGroups()
 {
     $scheduleId = 18;
     $expectedGroups = new FakeResourceGroupTree();
     $expectedGroups->AddGroup(new ResourceGroup(1, 'g'));
     $this->resourceRepository->expects($this->once())->method('GetResourceGroups')->with($this->equalTo($scheduleId), $this->anything())->will($this->returnValue($expectedGroups));
     $groups = $this->resourceService->GetResourceGroups($scheduleId, $this->fakeUser);
     $this->assertEquals($expectedGroups, $groups);
 }
 public function testFiltersByGroupId()
 {
     $scheduleId = 122;
     $groupId = 10;
     $resourceId = 4;
     $groups = $this->getMock('ResourceGroupTree');
     $resource1 = new FakeBookableResource(1, 'resource1');
     $resource2 = new FakeBookableResource(2, 'resource2');
     $resource3 = new FakeBookableResource(3, 'resource3');
     $resource4 = new FakeBookableResource($resourceId, 'resource4');
     $resources = array($resource1, $resource2, $resource3, $resource4);
     $this->resourceRepository->expects($this->once())->method('GetResourceGroups')->with($this->equalTo($scheduleId))->will($this->returnValue($groups));
     $groups->expects($this->once())->method('GetResourceIds')->with($this->equalTo($groupId))->will($this->returnValue(array($resourceId)));
     $filter = new ScheduleResourceFilter($scheduleId);
     $filter->GroupId = $groupId;
     $resourceIds = $filter->FilterResources($resources, $this->resourceRepository, $this->attributeService);
     $this->assertEquals(1, count($resourceIds));
     $this->assertEquals($resourceId, $resourceIds[0]);
 }
Example #19
0
 /**
  * @param int $resourceId
  * @param WebServiceUserSession $session
  * @return ResourceControllerResult
  */
 public function Delete($resourceId, $session)
 {
     $errors = $this->validator->ValidateDeleteRequest($resourceId);
     if (!empty($errors)) {
         return new ResourceControllerResult(null, $errors);
     }
     $resource = $this->repository->LoadById($resourceId);
     $this->repository->Delete($resource);
     return new ResourceControllerResult($resourceId);
 }
 /**
  * @param int $scheduleId
  * @param int $moveResourcesToThisScheduleId
  */
 public function Delete($scheduleId, $moveResourcesToThisScheduleId)
 {
     $resources = $this->resourceRepository->GetScheduleResources($scheduleId);
     foreach ($resources as $resource) {
         $resource->SetScheduleId($moveResourcesToThisScheduleId);
         $this->resourceRepository->Update($resource);
     }
     $schedule = $this->scheduleRepository->LoadById($scheduleId);
     $this->scheduleRepository->Delete($schedule);
 }
 public function testCreationBuildsReservationFromPageData()
 {
     $timezone = $this->user->Timezone;
     $userId = $this->page->GetUserId();
     $resourceId = $this->page->GetResourceId();
     $title = $this->page->GetTitle();
     $description = $this->page->GetDescription();
     $startDate = $this->page->GetStartDate();
     $endDate = $this->page->GetEndDate();
     $startTime = $this->page->GetStartTime();
     $endTime = $this->page->GetEndTime();
     $additionalResources = $this->page->GetResources();
     $pageAccessories = $this->page->GetAccessories();
     $pageAttributes = $this->page->GetAttributes();
     $roFactory = new RepeatOptionsFactory();
     $repeatOptions = $roFactory->CreateFromComposite($this->page, $timezone);
     $participants = $this->page->GetParticipants();
     $invitees = $this->page->GetInvitees();
     $attachment = new FakeUploadedFile();
     $this->page->attachment = $attachment;
     $resource = new FakeBookableResource($resourceId, 'r1');
     $additionalResource1 = new FakeBookableResource($additionalResources[0], 'r2');
     $additionalResource2 = new FakeBookableResource($additionalResources[1], 'r3');
     $accessories = array();
     foreach ($pageAccessories as $pa) {
         $accessories[] = new ReservationAccessory($pa->Id, $pa->Quantity, $pa->Name);
     }
     $expectedAttributes = array();
     foreach ($pageAttributes as $attr) {
         $expectedAttributes[] = new AttributeValue($attr->Id, $attr->Value);
     }
     $startReminder = new ReservationReminder($this->page->GetStartReminderValue(), $this->page->GetStartReminderInterval());
     $endReminder = new ReservationReminder($this->page->GetEndReminderValue(), $this->page->GetEndReminderInterval());
     $this->resourceRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue($resource));
     $this->resourceRepository->expects($this->at(1))->method('LoadById')->with($this->equalTo($additionalResources[0]))->will($this->returnValue($additionalResource1));
     $this->resourceRepository->expects($this->at(2))->method('LoadById')->with($this->equalTo($additionalResources[1]))->will($this->returnValue($additionalResource2));
     $duration = DateRange::Create($startDate . ' ' . $startTime, $endDate . ' ' . $endTime, $timezone);
     $actualReservation = $this->presenter->BuildReservation();
     $this->assertEquals($userId, $actualReservation->UserId());
     $this->assertEquals($resourceId, $actualReservation->ResourceId());
     $this->assertEquals($title, $actualReservation->Title());
     $this->assertEquals($description, $actualReservation->Description());
     $this->assertEquals($duration, $actualReservation->CurrentInstance()->Duration());
     $this->assertEquals($repeatOptions, $actualReservation->RepeatOptions());
     $this->assertEquals($participants, $actualReservation->CurrentInstance()->AddedParticipants());
     $this->assertEquals($invitees, $actualReservation->CurrentInstance()->AddedInvitees());
     $this->assertEquals($accessories, $actualReservation->Accessories());
     $this->assertTrue(in_array($expectedAttributes[0], $actualReservation->AttributeValues()));
     $expectedAttachment = ReservationAttachment::Create($attachment->OriginalName(), $attachment->MimeType(), $attachment->Size(), $attachment->Contents(), $attachment->Extension(), 0);
     $this->assertEquals(array($expectedAttachment), $actualReservation->AddedAttachments());
     $this->assertEquals($startReminder, $actualReservation->GetStartReminder());
     $this->assertEquals($endReminder, $actualReservation->GetEndReminder());
 }
 public function testDeletesResource()
 {
     $resourceId = 998;
     $resource = new FakeBookableResource($resourceId);
     $this->validator->expects($this->once())->method('ValidateDeleteRequest')->with($this->equalTo($resourceId))->will($this->returnValue(array()));
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId))->will($this->returnValue($resource));
     $this->repository->expects($this->once())->method('Delete')->with($this->equalTo($resource));
     $response = $this->controller->Delete($resourceId, $this->session);
     $this->assertTrue($response->WasSuccessful());
     $this->assertEquals($resourceId, $response->ResourceId());
     $this->assertEmpty($response->Errors());
 }
 public function GetScheduleId()
 {
     if (!empty($this->scheduleId)) {
         return $this->scheduleId;
     }
     $this->scheduleId = $this->page->GetRequestedScheduleId();
     if (empty($this->scheduleId)) {
         $requestedResourceId = $this->page->GetRequestedResourceId();
         if (!empty($requestedResourceId)) {
             $resource = $this->resourceRepository->LoadById($requestedResourceId);
             $this->scheduleId = $resource->GetScheduleId();
         } else {
             $schedules = $this->scheduleRepository->GetAll();
             foreach ($schedules as $s) {
                 if ($s->GetIsDefault()) {
                     $this->scheduleId = $s->GetId();
                     break;
                 }
             }
         }
     }
     return $this->scheduleId;
 }
Example #24
0
 /**
  * @name GetAvailability
  * @description Returns resource availability for the requested time. "availableAt" and "availableUntil" will include availability through the next 7 days
  * Optional query string parameter: dateTime. If no dateTime is requested the current datetime will be used.
  * @response ResourcesAvailabilityResponse
  * @return void
  */
 public function GetAvailability($resourceId = null)
 {
     $dateQueryString = $this->server->GetQueryString(WebServiceQueryStringKeys::DATE_TIME);
     if (!empty($dateQueryString)) {
         $requestedTime = WebServiceDate::GetDate($dateQueryString, $this->server->GetSession());
     } else {
         $requestedTime = Date::Now();
     }
     if (empty($resourceId)) {
         $resources = $this->resourceRepository->GetResourceList();
     } else {
         $resources[] = $this->resourceRepository->LoadById($resourceId);
     }
     $startDate = $requestedTime->AddDays(-1);
     $endDate = $requestedTime->AddDays(7);
     $reservations = $this->reservationRepository->GetReservationList($startDate, $endDate, null, null, null, $resourceId);
     $indexedReservations = array();
     foreach ($reservations as $reservation) {
         $key = $reservation->GetResourceId();
         if (!array_key_exists($key, $indexedReservations)) {
             $indexedReservations[$key] = array();
         }
         $indexedReservations[$key][] = $reservation;
     }
     $resourceAvailability = array();
     foreach ($resources as $resource) {
         $resourceId = $resource->GetResourceId();
         $conflict = null;
         $nextReservation = null;
         $opening = null;
         if (array_key_exists($resourceId, $indexedReservations)) {
             $resourceReservations = $indexedReservations[$resourceId];
             /** @var $reservation ReservationItemView */
             foreach ($resourceReservations as $i => $reservation) {
                 if ($conflict == null && $reservation->BufferedTimes()->Contains($requestedTime, false)) {
                     $conflict = $reservation;
                 }
                 if ($nextReservation == null && $reservation->StartDate->GreaterThan($requestedTime)) {
                     $nextReservation = $reservation;
                 }
             }
             $opening = $this->GetOpeningAfter($resourceReservations, $requestedTime);
             if ($opening == null && $conflict != null) {
                 $opening = $conflict->BufferedTimes()->GetEnd();
             }
         }
         $resourceAvailability[] = new ResourceAvailabilityResponse($this->server, $resource, $conflict, $nextReservation, $opening, $endDate);
     }
     $this->server->WriteResponse(new ResourcesAvailabilityResponse($this->server, $resourceAvailability));
 }
 public function testUsesFirstAdditionalResourceIfPrimaryIsRemoved()
 {
     $referenceNumber = $this->page->existingReferenceNumber;
     $builder = new ExistingReservationSeriesBuilder();
     $builder->WithPrimaryResource(new FakeBookableResource(100));
     $expectedSeries = $builder->Build();
     $additionalId = 5;
     $this->page->resourceId = null;
     $this->page->resourceIds = array($additionalId);
     $resource = new FakeBookableResource($additionalId);
     $this->persistenceService->expects($this->once())->method('LoadByReferenceNumber')->with($this->equalTo($referenceNumber))->will($this->returnValue($expectedSeries));
     $this->resourceRepository->expects($this->once())->method('LoadById')->with($this->equalTo($additionalId))->will($this->returnValue($resource));
     $existingSeries = $this->presenter->BuildReservation();
     $this->assertEquals($resource, $existingSeries->Resource());
 }
 public function ProcessDataRequest($dataRequest)
 {
     if ($dataRequest == 'all') {
         $this->page->SetResourcesJson(array_map(array('AdminResourceJson', 'FromBookable'), $this->resourceRepository->GetResourceList()));
     } else {
         if ($dataRequest == 'users') {
             $groups = $this->resourceRepository->GetUsersWithPermission($this->page->GetResourceId());
             $response = new UserResults($groups->Results(), $groups->PageInfo()->Total);
             $this->page->SetJsonResponse($response);
         } else {
             if ($dataRequest == 'groups') {
                 $groups = $this->resourceRepository->GetGroupsWithPermission($this->page->GetResourceId());
                 $response = new GroupResults($groups->Results(), $groups->PageInfo()->Total);
                 $this->page->SetJsonResponse($response);
             }
         }
     }
 }
 public function testGetsSingleResourceAvailabilityForARequestTime()
 {
     $date = Date::Parse('2014-01-01 04:30:00', 'America/Chicago');
     $this->server->SetQueryString(WebServiceQueryStringKeys::DATE_TIME, $date->ToIso());
     $resourceId1 = 1;
     $startTime = $date->AddHours(-1);
     $endTime = $date->AddHours(1);
     $resource = new FakeBookableResource($resourceId1);
     $this->repository->expects($this->once())->method('LoadById')->with($this->equalTo($resourceId1))->will($this->returnValue($resource));
     $conflicting = new TestReservationItemView(1, $startTime, $endTime, $resourceId1);
     $upcoming = new TestReservationItemView(2, $endTime, $endTime->AddHours(3), $resourceId1);
     $upcoming2 = new TestReservationItemView(3, $endTime->AddHours(3), $endTime->AddHours(4), $resourceId1);
     $upcoming3 = new TestReservationItemView(4, $endTime->AddHours(5), $endTime->AddHours(6), $resourceId1);
     $reservations = array($conflicting, $upcoming, $upcoming2, $upcoming3);
     $endDate = $date->AddDays(7);
     $this->reservationRepository->expects($this->once())->method('GetReservationList')->with($this->equalTo($date->AddDays(-1)->ToUtc()), $this->equalTo($endDate->ToUtc()), $this->isEmpty(), $this->isEmpty(), $this->isEmpty(), $this->equalTo($resourceId1))->will($this->returnValue($reservations));
     $this->service->GetAvailability($resourceId1);
     $resources = array(new ResourceAvailabilityResponse($this->server, $resource, $conflicting, $upcoming, $endTime->AddHours(4), $endDate));
     $this->assertEquals(new ResourcesAvailabilityResponse($this->server, $resources), $this->server->_LastResponse);
 }
Example #28
0
 public function FilterResources($resources, IResourceRepository $resourceRepository, IAttributeService $attributeService)
 {
     $resourceIds = array();
     if (!$this->HasFilter()) {
         foreach ($resources as $resource) {
             $resourceIds[] = $resource->GetId();
         }
         return $resourceIds;
     }
     $groupResourceIds = array();
     if (!empty($this->GroupId) && empty($this->ResourceId)) {
         $groups = $resourceRepository->GetResourceGroups($this->ScheduleId);
         $groupResourceIds = $groups->GetResourceIds($this->GroupId);
     }
     $resourceAttributeValues = null;
     if (!empty($this->ResourceAttributes)) {
         $resourceAttributeValues = $attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, null);
     }
     $resourceTypeAttributeValues = null;
     if (!empty($this->ResourceTypeAttributes)) {
         $resourceTypeAttributeValues = $attributeService->GetAttributes(CustomAttributeCategory::RESOURCE_TYPE, null);
     }
     $resourceIds = array();
     foreach ($resources as $resource) {
         $resourceIds[] = $resource->GetId();
         if (!empty($this->ResourceId) && $resource->GetId() != $this->ResourceId) {
             array_pop($resourceIds);
             continue;
         }
         if (!empty($this->GroupId) && !in_array($resource->GetId(), $groupResourceIds)) {
             array_pop($resourceIds);
             continue;
         }
         if (!empty($this->MinCapacity) && $resource->GetMaxParticipants() < $this->MinCapacity) {
             array_pop($resourceIds);
             continue;
         }
         if (!empty($this->ResourceTypeId) && $resource->GetResourceTypeId() != $this->ResourceTypeId) {
             array_pop($resourceIds);
             continue;
         }
         $resourceAttributesPass = true;
         if (!empty($this->ResourceAttributes)) {
             $values = $resourceAttributeValues->GetAttributes($resource->GetId());
             /** var @attribute AttributeValue */
             foreach ($this->ResourceAttributes as $attribute) {
                 $value = $this->GetAttribute($values, $attribute->AttributeId);
                 if (!$this->AttributeValueMatches($attribute, $value)) {
                     $resourceAttributesPass = false;
                     break;
                 }
             }
         }
         if (!$resourceAttributesPass) {
             array_pop($resourceIds);
             continue;
         }
         $resourceTypeAttributesPass = true;
         if (!empty($this->ResourceTypeAttributes)) {
             if (!$resource->HasResourceType()) {
                 array_pop($resourceIds);
                 // there's a filter but this resource doesn't have a resource type
                 continue;
             }
             $values = $resourceTypeAttributeValues->GetAttributes($resource->GetResourceTypeId());
             /** var @attribute AttributeValue */
             foreach ($this->ResourceTypeAttributes as $attribute) {
                 $value = $this->GetAttribute($values, $attribute->AttributeId);
                 if (!$this->AttributeValueMatches($attribute, $value)) {
                     $resourceTypeAttributesPass = false;
                     break;
                 }
             }
         }
         if (!$resourceTypeAttributesPass) {
             array_pop($resourceIds);
             continue;
         }
     }
     return $resourceIds;
 }
Example #29
0
 public function GetResourceTypes()
 {
     return $this->_resourceRepository->GetResourceTypes();
 }
 public function Delete()
 {
     $reasonId = $this->page->GetReasonId();
     $this->resourceRepository->RemoveStatusReason($reasonId);
 }