/**
  * @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;
 }
 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 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;
 }
Example #4
0
 private function BuildRepeatOptions($repeatType, $configurationString)
 {
     $configuration = RepeatConfiguration::Create($repeatType, $configurationString);
     $factory = new RepeatOptionsFactory();
     return $factory->Create($repeatType, $configuration->Interval, $configuration->TerminationDate, $configuration->Weekdays, $configuration->MonthlyType);
 }
 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());
 }
Example #6
0
 /**
  * @param string[] $row
  * @return BlackoutSeries
  */
 public static function FromRow($row)
 {
     $series = new BlackoutSeries($row[ColumnNames::OWNER_USER_ID], $row[ColumnNames::BLACKOUT_TITLE]);
     $series->WithId($row[ColumnNames::BLACKOUT_SERIES_ID]);
     $series->SetCurrentBlackout(new DateRange(Date::FromDatabase($row[ColumnNames::BLACKOUT_START]), Date::FromDatabase($row[ColumnNames::BLACKOUT_END])));
     $series->WithCurrentBlackoutId($row[ColumnNames::BLACKOUT_INSTANCE_ID]);
     $configuration = RepeatConfiguration::Create($row[ColumnNames::REPEAT_TYPE], $row[ColumnNames::REPEAT_OPTIONS]);
     $factory = new RepeatOptionsFactory();
     $options = $factory->Create($row[ColumnNames::REPEAT_TYPE], $configuration->Interval, $configuration->TerminationDate, $configuration->Weekdays, $configuration->MonthlyType);
     $series->WithRepeatOptions($options);
     return $series;
 }
Example #7
0
 public function testFactoryCreatesNoRepeatOptions()
 {
     $factory = new RepeatOptionsFactory();
     $options = $factory->Create('none', 1, null, null, null);
     $this->assertInstanceOf('RepeatNone', $options);
 }
 public function UpdateBlackout()
 {
     $session = ServiceLocator::GetServer()->GetUserSession();
     $id = $this->page->GetUpdateBlackoutId();
     $scope = $this->page->GetSeriesUpdateScope();
     Log::Debug('Updating blackout. BlackoutId=%s, UpdateScope=%s', $id, $scope);
     $resourceIds = $this->page->GetBlackoutResourceIds();
     $startDate = $this->page->GetBlackoutStartDate();
     $startTime = $this->page->GetBlackoutStartTime();
     $endDate = $this->page->GetBlackoutEndDate();
     $endTime = $this->page->GetBlackoutEndTime();
     $blackoutDate = DateRange::Create($startDate . ' ' . $startTime, $endDate . ' ' . $endTime, $session->Timezone);
     $title = $this->page->GetBlackoutTitle();
     $conflictAction = $this->page->GetBlackoutConflictAction();
     $repeatOptionsFactory = new RepeatOptionsFactory();
     $repeatOptions = $repeatOptionsFactory->CreateFromComposite($this->page, $session->Timezone);
     $result = $this->manageBlackoutsService->Update($id, $blackoutDate, $resourceIds, $title, ReservationConflictResolution::Create($conflictAction), $repeatOptions, $scope);
     $this->page->ShowUpdateResult($result->WasSuccessful(), $result->Message(), $result->ConflictingReservations(), $result->ConflictingBlackouts(), $session->Timezone);
 }
 public function testUpdatesBlackout()
 {
     $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;
     $blackoutInstanceId = 1111;
     $scope = SeriesUpdateScope::ThisInstance;
     $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);
     $resourceIds = array(123, 456);
     $this->page->expects($this->once())->method('GetBlackoutResourceIds')->will($this->returnValue($resourceIds));
     $this->page->expects($this->once())->method('GetUpdateBlackoutId')->will($this->returnValue($blackoutInstanceId));
     $this->page->expects($this->once())->method('GetSeriesUpdateScope')->will($this->returnValue($scope));
     $result = $this->getMock('IBlackoutValidationResult');
     $this->blackoutsService->expects($this->once())->method('Update')->with($this->equalTo($blackoutInstanceId), $this->equalTo($dr), $this->equalTo($resourceIds), $this->equalTo($title), $this->equalTo($conflictResolution), $this->equalTo($repeatOptions), $this->equalTo($scope))->will($this->returnValue($result));
     $this->presenter->UpdateBlackout();
 }