public function CheckAll(IExistingReservationPage $page, UserSession $user, ReservationView $reservationView)
 {
     if (!$reservationView->IsDisplayable()) {
         $page->RedirectToError(ErrorMessages::RESERVATION_NOT_FOUND);
         return;
     }
 }
 public function CanApprove(ReservationView $reservationView, UserSession $currentUser)
 {
     if (!$reservationView->RequiresApproval()) {
         return false;
     }
     if ($currentUser->IsAdmin) {
         return true;
     }
     $canReserveForUser = $this->authorizationService->CanApproveFor($currentUser, $reservationView->OwnerId);
     if ($canReserveForUser) {
         return true;
     }
     foreach ($reservationView->Resources as $resource) {
         if ($this->authorizationService->CanApproveForResource($currentUser, $resource)) {
             return true;
         }
     }
     return false;
 }
 private function SetAttachments(ReservationView $reservationView)
 {
     $getAttachments = new GetReservationAttachmentsCommand($reservationView->SeriesId);
     $result = ServiceLocator::GetDatabase()->Query($getAttachments);
     while ($row = $result->GetRow()) {
         $reservationView->AddAttachment(new ReservationAttachmentView($row[ColumnNames::FILE_ID], $row[ColumnNames::SERIES_ID], $row[ColumnNames::FILE_NAME]));
     }
 }
Example #4
0
 public function GetReservationAttributes(UserSession $userSession, ReservationView $reservationView, $requestedUserId = 0)
 {
     if ($requestedUserId == 0) {
         $requestedUserId = $reservationView->OwnerId;
     }
     $attributes = array();
     $customAttributes = $this->GetByCategory(CustomAttributeCategory::RESERVATION);
     foreach ($customAttributes as $attribute) {
         //			$secondaryCategory = $attribute->SecondaryCategory();
         if ($this->CanReserveFor($userSession, $requestedUserId)) {
             $attributes[] = new Attribute($attribute, $reservationView->GetAttributeValue($attribute->Id()));
         }
     }
     return $attributes;
 }
 public function Bind(IReservationComponentInitializer $initializer)
 {
     $this->page->SetAdditionalResources($this->reservationView->AdditionalResourceIds);
     $this->page->SetTitle($this->reservationView->Title);
     $this->page->SetDescription($this->reservationView->Description);
     $this->page->SetReferenceNumber($this->reservationView->ReferenceNumber);
     $this->page->SetReservationId($this->reservationView->ReservationId);
     $this->page->SetIsRecurring($this->reservationView->IsRecurring());
     $this->page->SetRepeatType($this->reservationView->RepeatType);
     $this->page->SetRepeatInterval($this->reservationView->RepeatInterval);
     $this->page->SetRepeatMonthlyType($this->reservationView->RepeatMonthlyType);
     if ($this->reservationView->RepeatTerminationDate != null) {
         $this->page->SetRepeatTerminationDate($this->reservationView->RepeatTerminationDate->ToTimezone($initializer->GetTimezone()));
     }
     $this->page->SetRepeatWeekdays($this->reservationView->RepeatWeekdays);
     $participants = $this->reservationView->Participants;
     $invitees = $this->reservationView->Invitees;
     $this->page->SetParticipants($participants);
     $this->page->SetInvitees($invitees);
     $this->page->SetAllowParticipantsToJoin($this->reservationView->AllowParticipation);
     $this->page->SetAccessories($this->reservationView->Accessories);
     $currentUser = $initializer->CurrentUser();
     $this->page->SetCurrentUserParticipating($this->IsCurrentUserParticipating($currentUser->UserId));
     $this->page->SetCurrentUserInvited($this->IsCurrentUserInvited($currentUser->UserId));
     $canBeEdited = $this->reservationAuthorization->CanEdit($this->reservationView, $currentUser);
     $this->page->SetIsEditable($canBeEdited);
     $this->page->SetIsApprovable($this->reservationAuthorization->CanApprove($this->reservationView, $currentUser));
     $this->page->SetAttachments($this->reservationView->Attachments);
     $showUser = $this->privacyFilter->CanViewUser($initializer->CurrentUser(), $this->reservationView);
     $showDetails = $this->privacyFilter->CanViewDetails($initializer->CurrentUser(), $this->reservationView);
     $initializer->ShowUserDetails($showUser);
     $initializer->ShowReservationDetails($showDetails);
     if (!empty($this->reservationView->StartReminder)) {
         $this->page->SetStartReminder($this->reservationView->StartReminder->GetValue(), $this->reservationView->StartReminder->GetInterval());
     }
     if (!empty($this->reservationView->EndReminder)) {
         $this->page->SetEndReminder($this->reservationView->EndReminder->GetValue(), $this->reservationView->EndReminder->GetInterval());
     }
 }
 public function testBindsCustomAttributesWithValues()
 {
     $val1 = 'v1';
     $val2 = 'v2';
     $reservationView = new ReservationView();
     $reservationView->AddAttribute(new AttributeValue(10, $val1));
     $reservationView->AddAttribute(new AttributeValue(20, $val2));
     $binder = new ReservationCustomAttributeValueBinder($this->attributeRepository, $reservationView);
     $attributes = array(new CustomAttribute(10, '1', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 1), new CustomAttribute(20, '2', CustomAttributeTypes::SINGLE_LINE_TEXTBOX, CustomAttributeCategory::RESERVATION, '', false, '', 2));
     $this->attributeRepository->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($attributes));
     $this->initializer->expects($this->at(0))->method('AddAttribute')->with($this->equalTo($attributes[0]), $this->equalTo($val1));
     $this->initializer->expects($this->at(1))->method('AddAttribute')->with($this->equalTo($attributes[1]), $this->equalTo($val2));
     $binder->Bind($this->initializer);
 }
 public function testBuildsViewObjectFromDatabase()
 {
     $referenceNumber = "12345";
     $reservationId = 187;
     $resourceId = 12;
     $scheduleId = 73;
     $startDate = new Date('2010-01-01 05:00', 'UTC');
     $endDate = new Date('2010-01-01 12:00', 'UTC');
     $dateCreated = new Date('2010-01-01', 'UTC');
     $ownerId = 92;
     $title = 'ti';
     $description = 'de';
     $repeatType = RepeatType::Yearly;
     $repeatOptions = 'interval=5';
     $seriesId = 1000;
     $ownerFirst = 'f';
     $ownerLast = 'l';
     $statusId = ReservationStatus::Pending;
     $resourceName = 'resource';
     $resourceId1 = 88;
     $resourceName1 = 'r1';
     $adminGroupId1 = 1239;
     $scheduleAdminGroupId = 992323;
     $resourceId2 = 99;
     $resourceName2 = 'r2';
     $userId1 = 87;
     $fname1 = 'f1';
     $lname1 = 'l1';
     $email1 = 'e1';
     $userId2 = 97;
     $fname2 = 'f2';
     $lname2 = 'l2';
     $email2 = 'e2';
     $userId3 = 98;
     $fname3 = 'f3';
     $lname3 = 'l3';
     $email3 = 'e3';
     $email = '*****@*****.**';
     $allowParticipation = 1;
     $ownerLevel = ReservationUserLevel::OWNER;
     $participantLevel = ReservationUserLevel::PARTICIPANT;
     $inviteeLevel = ReservationUserLevel::INVITEE;
     $getReservationForEditingCommand = new GetReservationForEditingCommand($referenceNumber);
     $getReservationResources = new GetReservationResourcesCommand($seriesId);
     $getParticipants = new GetReservationParticipantsCommand($reservationId);
     $getAccessories = new GetReservationAccessoriesCommand($seriesId);
     $getAttributes = new GetAttributeValuesCommand($seriesId, CustomAttributeCategory::RESERVATION);
     $getAttachments = new GetReservationAttachmentsCommand($seriesId);
     $getReminders = new GetReservationReminders($seriesId);
     $reservationRow = array(ColumnNames::RESERVATION_INSTANCE_ID => $reservationId, ColumnNames::REFERENCE_NUMBER => $referenceNumber, ColumnNames::RESOURCE_ID => $resourceId, ColumnNames::SCHEDULE_ID => $scheduleId, ColumnNames::RESERVATION_START => $startDate->ToDatabase(), ColumnNames::RESERVATION_END => $endDate->ToDatabase(), ColumnNames::USER_ID => $ownerId, ColumnNames::RESERVATION_TITLE => $title, ColumnNames::RESERVATION_DESCRIPTION => $description, ColumnNames::REPEAT_TYPE => $repeatType, ColumnNames::REPEAT_OPTIONS => $repeatOptions, ColumnNames::SERIES_ID => $seriesId, ColumnNames::FIRST_NAME => $ownerFirst, ColumnNames::LAST_NAME => $ownerLast, ColumnNames::RESERVATION_STATUS => $statusId, ColumnNames::RESERVATION_CREATED => $dateCreated->ToDatabase(), ColumnNames::RESOURCE_NAME => $resourceName, ColumnNames::EMAIL => $email, ColumnNames::RESERVATION_MODIFIED => Date::Now()->ToDatabase(), ColumnNames::RESERVATION_ALLOW_PARTICIPATION => $allowParticipation);
     $resourceRows = array($this->GetResourceRow($reservationId, $resourceId1, $resourceName1, $adminGroupId1, $scheduleId, $scheduleAdminGroupId), $this->GetResourceRow($reservationId, $resourceId2, $resourceName2, null, $scheduleId, $scheduleAdminGroupId));
     $participantRows = array($this->GetParticipantRow($reservationId, $userId1, $fname1, $lname1, $email1, $ownerLevel), $this->GetParticipantRow($reservationId, $userId2, $fname2, $lname2, $email2, $participantLevel), $this->GetParticipantRow($reservationId, $userId3, $fname3, $lname3, $email3, $inviteeLevel));
     $accessory1 = 123;
     $accessory2 = 1232;
     $quantity1 = 123;
     $quantity2 = 1232;
     $accessoryName1 = 'a1';
     $accessoryName2 = 'a2';
     $accessoryQuantity1 = 111;
     $accessoryQuantity2 = 222;
     $attributeId1 = 9292;
     $attributeId2 = 884;
     $attributeValue1 = 'v1';
     $attributeValue2 = 'v1';
     $attributeLabel1 = 'al1';
     $attributeLabel2 = 'al2';
     $startReminderMinutes = 25;
     $endReminderMinutes = 120;
     $accessoryRows = new ReservationAccessoryRow();
     $accessoryRows->WithAccessory($accessory1, $quantity1, $accessoryName1, $accessoryQuantity1)->WithAccessory($accessory2, $quantity2, $accessoryName2, $accessoryQuantity2);
     $attributeRows = new CustomAttributeValueRow();
     $attributeRows->With($attributeId1, $attributeValue1, $attributeLabel1)->With($attributeId2, $attributeValue2, $attributeLabel2);
     $reminderRows = new ReservationReminderRow();
     $reminderRows->With(1, $seriesId, $startReminderMinutes, ReservationReminderType::Start)->With(2, $seriesId, $endReminderMinutes, ReservationReminderType::End);
     $fileId1 = 1;
     $fileName1 = 'fn1';
     $fileId2 = 2;
     $fileName2 = 'fn2';
     $attachmentRows = new ReservationAttachmentItemRow();
     $attachmentRows->With($fileId1, $seriesId, $fileName1)->With($fileId2, $seriesId, $fileName2);
     $this->db->SetRow(0, array($reservationRow));
     $this->db->SetRow(1, $resourceRows);
     $this->db->SetRow(2, $participantRows);
     $this->db->SetRow(3, $accessoryRows->Rows());
     $this->db->SetRow(4, $attributeRows->Rows());
     $this->db->SetRow(5, $attachmentRows->Rows());
     $this->db->SetRow(6, $reminderRows->Rows());
     $reservationView = $this->repository->GetReservationForEditing($referenceNumber);
     $commands = $this->db->_Commands;
     $this->assertEquals(7, count($commands));
     $this->assertEquals($getReservationForEditingCommand, $commands[0]);
     $this->assertEquals($getReservationResources, $commands[1]);
     $this->assertEquals($getParticipants, $commands[2]);
     $this->assertEquals($getAccessories, $commands[3]);
     $this->assertEquals($getAttributes, $commands[4]);
     $this->assertEquals($getAttachments, $commands[5]);
     $this->assertEquals($getReminders, $commands[6]);
     $expectedView = new ReservationView();
     $expectedView->AdditionalResourceIds = array($resourceId1, $resourceId2);
     $expectedView->Description = $description;
     $expectedView->EndDate = $endDate;
     $expectedView->OwnerId = $ownerId;
     $expectedView->ReferenceNumber = $referenceNumber;
     $expectedView->ReservationId = $reservationId;
     $expectedView->ResourceId = $resourceId;
     $expectedView->ResourceName = $resourceName;
     $expectedView->DateCreated = $dateCreated;
     $expectedView->ScheduleId = $scheduleId;
     $expectedView->StartDate = $startDate;
     $expectedView->Title = $title;
     $expectedView->RepeatType = $repeatType;
     $expectedView->RepeatInterval = '5';
     $expectedView->SeriesId = $seriesId;
     $expectedView->OwnerFirstName = $ownerFirst;
     $expectedView->OwnerLastName = $ownerLast;
     $expectedView->StatusId = $statusId;
     $expectedView->OwnerEmailAddress = $email;
     $expectedView->DateModified = Date::Now()->ToUtc();
     $expectedView->Participants = array(new ReservationUserView($userId2, $fname2, $lname2, $email2, $participantLevel));
     $expectedView->Invitees = array(new ReservationUserView($userId3, $fname3, $lname3, $email3, $inviteeLevel));
     $expectedView->Resources = array(new ReservationResourceView($resourceId1, $resourceName1, $adminGroupId1, $scheduleId, $scheduleAdminGroupId, ResourceStatus::AVAILABLE), new ReservationResourceView($resourceId2, $resourceName2, null, $scheduleId, $scheduleAdminGroupId, ResourceStatus::AVAILABLE));
     $expectedView->Accessories = array(new ReservationAccessoryView($accessory1, $quantity1, $accessoryName1, $accessoryQuantity1), new ReservationAccessoryView($accessory2, $quantity2, $accessoryName2, $accessoryQuantity2));
     $expectedView->AddAttribute(new AttributeValue($attributeId1, $attributeValue1, $attributeLabel1));
     $expectedView->AddAttribute(new AttributeValue($attributeId2, $attributeValue2, $attributeLabel2));
     $expectedView->AddAttachment(new ReservationAttachmentView($fileId1, $seriesId, $fileName1));
     $expectedView->AddAttachment(new ReservationAttachmentView($fileId2, $seriesId, $fileName2));
     $expectedView->StartReminder = new ReservationReminderView($startReminderMinutes);
     $expectedView->EndReminder = new ReservationReminderView($endReminderMinutes);
     $expectedView->AllowParticipation = true;
     $this->assertEquals($expectedView, $reservationView);
 }