Ejemplo n.º 1
0
 /**
  * @name GetUser
  * @description Loads the requested user by Id
  * @response UserResponse
  * @param int $userId
  * @return void
  */
 public function GetUser($userId)
 {
     $responseCode = RestResponse::OK_CODE;
     $hideUsers = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter());
     $userSession = $this->server->GetSession();
     $repository = $this->repositoryFactory->Create($userSession);
     $user = $repository->LoadById($userId);
     $loadedUserId = $user->Id();
     if (empty($loadedUserId)) {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
         return;
     }
     $attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::USER, array($userId));
     if ($userId == $userSession->UserId || !$hideUsers || $userSession->IsAdmin) {
         $response = new UserResponse($this->server, $user, $attributes);
     } else {
         $me = $repository->LoadById($userSession->UserId);
         if ($me->IsAdminFor($user)) {
             $response = new UserResponse($this->server, $user, $attributes);
         } else {
             $response = RestResponse::Unauthorized();
             $responseCode = RestResponse::UNAUTHORIZED_CODE;
         }
     }
     $this->server->WriteResponse($response, $responseCode);
 }
Ejemplo n.º 2
0
 /**
  * @name GetAttribute
  * @description Gets all custom attribute definitions for the requested attribute
  * @response CustomAttributeDefinitionResponse
  * @return void
  * @param int $attributeId
  */
 public function GetAttribute($attributeId)
 {
     $attribute = $this->attributeService->GetById($attributeId);
     if ($attribute != null) {
         $this->server->WriteResponse(new CustomAttributeDefinitionResponse($this->server, $attribute));
     } else {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
 public function testGetsAttributesByCategory()
 {
     $attributes = array(new TestCustomAttribute(1, 'label'));
     $categoryId = CustomAttributeCategory::RESERVATION;
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo($categoryId))->will($this->returnValue($attributes));
     $expectedResponse = new CustomAttributesResponse($this->server, $attributes);
     $this->service->GetAttributes($categoryId);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
Ejemplo n.º 4
0
 /**
  * @return void
  */
 public function Validate()
 {
     if (empty($this->attributes)) {
         $this->isValid = true;
         return;
     }
     $result = $this->service->Validate($this->category, $this->attributes, $this->entityId, $this->ignoreEmpty);
     $this->isValid = $result->IsValid();
     $this->messages = $result->Errors();
 }
Ejemplo n.º 5
0
 public function testGetsResourceList()
 {
     $resourceId = 123;
     $resources[] = new FakeBookableResource($resourceId);
     $attributes = new AttributeList();
     $this->repository->expects($this->once())->method('GetResourceList')->will($this->returnValue($resources));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo(array($resourceId)))->will($this->returnValue($attributes));
     $this->service->GetAll();
     $this->assertEquals(new ResourcesResponse($this->server, $resources, $attributes), $this->server->_LastResponse);
 }
 public function testCustomAttributesAreValidated()
 {
     $request = ResourceRequest::Example();
     $result = new AttributeServiceValidationResult(false, array('error'));
     $this->attributeService->expects($this->atLeastOnce())->method('Validate')->with($this->equalTo(CustomAttributeCategory::RESOURCE), $this->equalTo(array(new AttributeValue($request->customAttributes[0]->attributeId, $request->customAttributes[0]->attributeValue))))->will($this->returnValue($result));
     $createErrors = $this->validator->ValidateCreateRequest($request);
     $updateErrors = $this->validator->ValidateUpdateRequest(1, $request);
     $this->assertEquals(1, count($createErrors));
     $this->assertEquals(1, count($updateErrors));
 }
 public function testBindsResourceTypes()
 {
     $types = array(new ResourceType(1, 'name', 'desc'));
     $ids = array(1);
     $attributes = $this->getMock('IEntityAttributeList');
     $this->resourceRepository->expects($this->once())->method('GetResourceTypes')->will($this->returnValue($types));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE), $this->equalTo($ids))->will($this->returnValue($attributes));
     $this->page->expects($this->once())->method('BindResourceTypes')->with($this->equalTo($types));
     $this->page->expects($this->once())->method('BindAttributeList')->with($this->equalTo($attributes));
     $this->presenter->PageLoad();
 }
 public function PageLoad()
 {
     $types = $this->resourceRepository->GetResourceTypes();
     $ids = array();
     foreach ($types as $type) {
         $ids[] = $type->Id();
     }
     $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE_TYPE, $ids);
     $this->page->BindAttributeList($attributeList);
     $this->page->BindResourceTypes($types);
 }
Ejemplo n.º 9
0
 /**
  * @name GetResource
  * @description Loads a specific resource by id
  * @param int $resourceId
  * @response ResourceResponse
  * @return void
  */
 public function GetResource($resourceId)
 {
     $resource = $this->resourceRepository->LoadById($resourceId);
     $resourceId = $resource->GetResourceId();
     if (empty($resourceId)) {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     } else {
         $attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, array($resourceId));
         $this->server->WriteResponse(new ResourceResponse($this->server, $resource, $attributes));
     }
 }
Ejemplo n.º 10
0
 /**
  * @name GetReservation
  * @param string $referenceNumber
  * @description Loads a specific reservation by reference number
  * @response ReservationResponse
  * @return void
  */
 public function GetReservation($referenceNumber)
 {
     Log::Debug('GetReservation called. $referenceNumber=%s', $referenceNumber);
     $reservation = $this->reservationViewRepository->GetReservationForEditing($referenceNumber);
     if (!empty($reservation->ReferenceNumber)) {
         $attributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESERVATION);
         $response = new ReservationResponse($this->server, $reservation, $this->privacyFilter, $attributes);
         $this->server->WriteResponse($response);
     } else {
         $this->server->WriteResponse($response = RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
 /**
  * @param ReservationSeries $reservationSeries
  * @return ReservationRuleResult
  */
 public function Validate($reservationSeries)
 {
     $resources = Resources::GetInstance();
     $errorMessage = new StringBuilder();
     $result = $this->attributeService->Validate(CustomAttributeCategory::RESERVATION, $reservationSeries->AttributeValues());
     $isValid = $result->IsValid();
     foreach ($result->Errors() as $error) {
         $errorMessage->AppendLine($error);
     }
     if (!$isValid) {
         $errorMessage->PrependLine($resources->GetString('CustomAttributeErrors'));
     }
     return new ReservationRuleResult($isValid, $errorMessage->ToString());
 }
 public function testFiltersResourceTypeCustomAttributes()
 {
     $attributeId1 = 1;
     $attributeValue1 = 1;
     $attributeId2 = 2;
     $attributeValue2 = 'something';
     $resourceId = 3;
     $resourceTypeId = 4;
     $attributeList = new FakeAttributeList();
     $attributeList->Add($resourceTypeId, new Attribute(new CustomAttribute($attributeId1, '', CustomAttributeTypes::CHECKBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, $resourceTypeId), $attributeValue1));
     $attributeList->Add($resourceTypeId, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, $resourceTypeId), $attributeValue2));
     $attributeList->Add(1, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, 1), $attributeValue2));
     $attributeList->Add(3, new Attribute(new CustomAttribute($attributeId2, '', CustomAttributeTypes::MULTI_LINE_TEXTBOX, CustomAttributeCategory::RESOURCE, '', false, '', 0, 3), $attributeValue2));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE), $this->isNull())->will($this->returnValue($attributeList));
     $filter = new ScheduleResourceFilter();
     $filter->ResourceTypeAttributes = array(new AttributeValue($attributeId1, $attributeValue1), new AttributeValue($attributeId2, $attributeValue2));
     $resource1 = new FakeBookableResource(1, 'resource1');
     $resource1->SetResourceTypeId(100);
     $resource2 = new FakeBookableResource(2, 'resource2');
     $resource2->SetResourceTypeId(200);
     $resource3 = new FakeBookableResource($resourceId, 'resource3');
     $resource3->SetResourceTypeId($resourceTypeId);
     $resource4 = new FakeBookableResource(4, 'resource4');
     $resources = array($resource1, $resource2, $resource3, $resource4);
     $resourceIds = $filter->FilterResources($resources, $this->resourceRepository, $this->attributeService);
     $this->assertEquals(1, count($resourceIds));
     $this->assertEquals($resourceId, $resourceIds[0]);
 }
Ejemplo n.º 13
0
 public function testBindsUsersAndAttributesAndGroups()
 {
     $userId = 123;
     $pageNumber = 1;
     $pageSize = 10;
     $result = new UserItemView();
     $result->Id = $userId;
     $results = array($result);
     $userList = new PageableData($results);
     $resourceList = array(new FakeBookableResource(1));
     $attributeList = array(new FakeCustomAttribute(1, '1'));
     $this->page->expects($this->once())->method('GetPageNumber')->will($this->returnValue($pageNumber));
     $this->page->expects($this->once())->method('GetPageSize')->will($this->returnValue($pageSize));
     $this->page->expects($this->once())->method('GetFilterStatusId')->will($this->returnValue(AccountStatus::ALL));
     $this->userRepo->expects($this->once())->method('GetList')->with($this->equalTo($pageNumber), $this->equalTo($pageSize), $this->isNull(), $this->isNull(), $this->isNull(), $this->equalTo(AccountStatus::ALL))->will($this->returnValue($userList));
     $user = new FakeUser();
     $this->userRepo->expects($this->once())->method('LoadById')->with($this->fakeUser->UserId)->will($this->returnValue($user));
     $this->page->expects($this->once())->method('BindUsers')->with($this->equalTo($userList->Results()));
     $this->page->expects($this->once())->method('BindPageInfo')->with($this->equalTo($userList->PageInfo()));
     $this->resourceRepo->expects($this->once())->method('GetResourceList')->will($this->returnValue($resourceList));
     $this->page->expects($this->once())->method('BindResources')->with($this->equalTo($resourceList));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::USER))->will($this->returnValue($attributeList));
     $this->page->expects($this->once())->method('BindAttributeList')->with($this->equalTo($attributeList));
     $groups = array(new GroupItemView(1, 'gn'));
     $groupList = new PageableData($groups);
     $this->groupViewRepository->expects($this->once())->method('GetList')->will($this->returnValue($groupList));
     $this->page->expects($this->once())->method('BindGroups')->with($this->equalTo($groups));
     $this->presenter->PageLoad();
 }
Ejemplo n.º 14
0
 public function PageLoad()
 {
     if ($this->page->GetUserId() != null) {
         $userList = $this->userRepository->GetList(1, 1, null, null, new SqlFilterEquals(ColumnNames::USER_ID, $this->page->GetUserId()));
     } else {
         $userList = $this->userRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, null, $this->page->GetFilterStatusId());
     }
     $this->page->BindUsers($userList->Results());
     $this->page->BindPageInfo($userList->PageInfo());
     $groups = $this->groupViewRepository->GetList();
     $this->page->BindGroups($groups->Results());
     $resources = array();
     $user = $this->userRepository->LoadById(ServiceLocator::GetServer()->GetUserSession()->UserId);
     $allResources = $this->resourceRepository->GetResourceList();
     foreach ($allResources as $resource) {
         if ($user->IsResourceAdminFor($resource)) {
             $resources[] = $resource;
         }
     }
     $this->page->BindResources($resources);
     $userIds = array();
     /** @var $user UserItemView */
     foreach ($userList->Results() as $user) {
         $userIds[] = $user->Id;
     }
     $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::USER, $userIds);
     $this->page->BindAttributeList($attributeList);
 }
Ejemplo n.º 15
0
 public function testGetsResourceTypeCustomAttributes()
 {
     $customAttributes = array(new FakeCustomAttribute(1));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESOURCE_TYPE))->will($this->returnValue($customAttributes));
     $attributes = $this->resourceService->GetResourceTypeAttributes();
     $this->assertEquals(1, count($attributes));
     $this->assertEquals($customAttributes[0]->Id(), $attributes[0]->Id());
 }
Ejemplo n.º 16
0
 /**
  * @return Attribute[]
  */
 public function GetResourceTypeAttributes()
 {
     $attributes = array();
     $customAttributes = $this->_attributeService->GetByCategory(CustomAttributeCategory::RESOURCE_TYPE);
     foreach ($customAttributes as $ca) {
         $attributes[] = new Attribute($ca);
     }
     return $attributes;
 }
Ejemplo n.º 17
0
 public function PageLoad()
 {
     $this->BounceIfNotAllowingRegistration();
     $attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::USER);
     $this->page->SetAttributes($attributes->GetAttributes());
     $this->page->SetCaptchaImageUrl($this->captchaService->GetImageUrl());
     $this->PopulateTimezones();
     $this->PopulateHomepages();
 }
Ejemplo n.º 18
0
 public function PageLoad()
 {
     $userSession = ServiceLocator::GetServer()->GetUserSession();
     Log::Debug('ProfilePresenter loading user %s', $userSession->UserId);
     $user = $this->userRepository->LoadById($userSession->UserId);
     $this->page->SetUsername($user->Username());
     $this->page->SetFirstName($user->FirstName());
     $this->page->SetLastName($user->LastName());
     $this->page->SetEmail($user->EmailAddress());
     $this->page->SetTimezone($user->Timezone());
     $this->page->SetHomepage($user->Homepage());
     $this->page->SetPhone($user->GetAttribute(UserAttribute::Phone));
     $this->page->SetOrganization($user->GetAttribute(UserAttribute::Organization));
     $this->page->SetPosition($user->GetAttribute(UserAttribute::Position));
     $userId = $userSession->UserId;
     $attributes = $this->attributeService->GetAttributes(CustomAttributeCategory::USER, $userId);
     $this->page->SetAttributes($attributes->GetAttributes($userId));
     $this->PopulateTimezones();
     $this->PopulateHomepages();
 }
Ejemplo n.º 19
0
 public function testWhenNotHidingUserDetails()
 {
     $this->HideUsers(false);
     $userId = 999;
     $user = new FakeUser($userId);
     $attributes = $this->getMock('IEntityAttributeList');
     $this->userRepositoryFactory->expects($this->once())->method('Create')->with($this->equalTo($this->server->GetSession()))->will($this->returnValue($this->userRepository));
     $this->userRepository->expects($this->at(0))->method('LoadById')->with($this->equalTo($userId))->will($this->returnValue($user));
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER), $this->equalTo(array($userId)))->will($this->returnValue($attributes));
     $expectedResponse = new UserResponse($this->server, $user, $attributes);
     $this->service->GetUser($userId);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
 public function testLoadsASingleReservation()
 {
     $referenceNumber = '12323';
     $reservation = new ReservationView();
     $reservation->StartDate = Date::Now();
     $reservation->EndDate = Date::Now();
     $reservation->ReferenceNumber = $referenceNumber;
     $attributes = array(new FakeCustomAttribute());
     $this->reservationViewRepository->expects($this->once())->method('GetReservationForEditing')->with($this->equalTo($referenceNumber))->will($this->returnValue($reservation));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($attributes));
     $this->service->GetReservation($referenceNumber);
     $expectedResponse = new ReservationResponse($this->server, $reservation, $this->privacyFilter, $attributes);
     $this->assertEquals($expectedResponse, $this->server->_LastResponse);
 }
 public function ProcessDataRequest($dataRequest)
 {
     if ($dataRequest == 'load') {
         $referenceNumber = $this->page->GetReferenceNumber();
         $rv = $this->manageReservationsService->LoadByReferenceNumber($referenceNumber, ServiceLocator::GetServer()->GetUserSession());
         $this->page->SetReservationJson($rv);
     }
     if ($dataRequest == 'attribute') {
         $referenceNumber = $this->page->GetReferenceNumber();
         $rv = $this->manageReservationsService->LoadByReferenceNumber($referenceNumber, ServiceLocator::GetServer()->GetUserSession());
         $attributeId = $this->page->GetAttributeId();
         $attribute = $this->attributeService->GetById($attributeId);
         $this->page->ShowAttribute($attribute, $rv->GetAttributeValue($attributeId));
     }
 }
 public function testUsesTwoWeekSpanWhenNoDateFilterProvided()
 {
     $userTimezone = 'America/Chicago';
     $defaultStart = Date::Now()->AddDays(-7)->ToTimezone($userTimezone)->GetDate();
     $defaultEnd = Date::Now()->AddDays(7)->ToTimezone($userTimezone)->GetDate();
     $searchedScheduleId = 15;
     $searchedResourceId = 105;
     $searchedStatusId = ReservationStatus::Pending;
     $searchedUserId = 111;
     $searchedReferenceNumber = 'abc123';
     $searchedUserName = '******';
     $searchedResourceStatusId = 292;
     $searchedResourceStatusReasonId = 4292;
     /** @var TestCustomAttribute[] $customAttributes */
     $customAttributes = array(new TestCustomAttribute(1, 'something'));
     /** @var Attribute[] $attributes */
     $attributes = array(new Attribute($customAttributes[0], 'value'));
     $this->resourceRepository->expects($this->once())->method('GetStatusReasons')->will($this->returnValue(array()));
     $this->page->expects($this->any())->method('FilterButtonPressed')->will($this->returnValue(true));
     $this->page->expects($this->atLeastOnce())->method('GetStartDate')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetEndDate')->will($this->returnValue(null));
     $this->page->expects($this->atLeastOnce())->method('GetScheduleId')->will($this->returnValue($searchedScheduleId));
     $this->page->expects($this->atLeastOnce())->method('GetResourceId')->will($this->returnValue($searchedResourceId));
     $this->page->expects($this->atLeastOnce())->method('GetReservationStatusId')->will($this->returnValue($searchedStatusId));
     $this->page->expects($this->atLeastOnce())->method('GetUserId')->will($this->returnValue($searchedUserId));
     $this->page->expects($this->atLeastOnce())->method('GetUserName')->will($this->returnValue($searchedUserName));
     $this->page->expects($this->atLeastOnce())->method('GetReferenceNumber')->will($this->returnValue($searchedReferenceNumber));
     $this->page->expects($this->atLeastOnce())->method('GetResourceStatusFilterId')->will($this->returnValue($searchedResourceStatusId));
     $this->page->expects($this->atLeastOnce())->method('GetResourceStatusReasonFilterId')->will($this->returnValue($searchedResourceStatusReasonId));
     $this->page->expects($this->atLeastOnce())->method('GetAttributeFilters')->will($this->returnValue(array(new AttributeFormElement($customAttributes[0]->Id(), 'value'))));
     $filter = $this->GetExpectedFilter($defaultStart, $defaultEnd, $searchedReferenceNumber, $searchedScheduleId, $searchedResourceId, $searchedUserId, $searchedStatusId, $searchedResourceStatusId, $searchedResourceStatusReasonId, $attributes);
     $data = new PageableData($this->getReservations());
     $this->reservationsService->expects($this->once())->method('LoadFiltered')->with($this->anything(), $this->anything(), $this->equalTo($filter), $this->equalTo($this->fakeUser))->will($this->returnValue($data));
     $this->attributeService->expects($this->once())->method('GetByCategory')->with($this->equalTo(CustomAttributeCategory::RESERVATION))->will($this->returnValue($customAttributes));
     $this->page->expects($this->once())->method('SetAttributeFilters')->with($attributes);
     $this->page->expects($this->once())->method('SetStartDate')->with($this->equalTo($defaultStart));
     $this->page->expects($this->once())->method('SetEndDate')->with($this->equalTo($defaultEnd));
     $this->page->expects($this->once())->method('SetReferenceNumber')->with($this->equalTo($searchedReferenceNumber));
     $this->page->expects($this->once())->method('SetScheduleId')->with($this->equalTo($searchedScheduleId));
     $this->page->expects($this->once())->method('SetResourceId')->with($this->equalTo($searchedResourceId));
     $this->page->expects($this->once())->method('SetReservationStatusId')->with($this->equalTo($searchedStatusId));
     $this->page->expects($this->once())->method('SetUserId')->with($this->equalTo($searchedUserId));
     $this->page->expects($this->once())->method('SetUserName')->with($this->equalTo($searchedUserName));
     $this->page->expects($this->once())->method('SetUserName')->with($this->equalTo($searchedUserName));
     $this->page->expects($this->once())->method('SetResourceStatusFilterId')->with($this->equalTo($searchedResourceStatusId));
     $this->page->expects($this->once())->method('SetResourceStatusReasonFilterId')->with($this->equalTo($searchedResourceStatusReasonId));
     $this->presenter->PageLoad($userTimezone);
 }
Ejemplo n.º 23
0
 public function PageLoad()
 {
     if ($this->page->GetUserId() != null) {
         $userList = $this->userRepository->GetList(1, 1, null, null, new SqlFilterEquals(ColumnNames::USER_ID, $this->page->GetUserId()));
     } else {
         $userList = $this->userRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, null, $this->page->GetFilterStatusId());
     }
     $this->page->BindUsers($userList->Results());
     $this->page->BindPageInfo($userList->PageInfo());
     $groups = $this->groupViewRepository->GetList();
     $this->page->BindGroups($groups->Results());
     $user = $this->userRepository->LoadById(ServiceLocator::GetServer()->GetUserSession()->UserId);
     $resources = $this->GetResourcesThatCurrentUserCanAdminister($user);
     $this->page->BindResources($resources);
     $attributeList = $this->attributeService->GetByCategory(CustomAttributeCategory::USER);
     $this->page->BindAttributeList($attributeList);
 }
Ejemplo n.º 24
0
 public function PageLoad()
 {
     $resourceAttributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESOURCE);
     $filterValues = $this->page->GetFilterValues();
     $results = $this->resourceRepository->GetList($this->page->GetPageNumber(), $this->page->GetPageSize(), null, null, $filterValues->AsFilter($resourceAttributes));
     $resources = $results->Results();
     $this->page->BindResources($resources);
     $this->page->BindPageInfo($results->PageInfo());
     $schedules = $this->scheduleRepository->GetAll();
     $scheduleList = array();
     /* @var $schedule Schedule */
     foreach ($schedules as $schedule) {
         $scheduleList[$schedule->GetId()] = $schedule->GetName();
     }
     $this->page->BindSchedules($scheduleList);
     $this->page->AllSchedules($schedules);
     $resourceTypes = $this->resourceRepository->GetResourceTypes();
     $resourceTypeList = array();
     /* @var $resourceType ResourceType */
     foreach ($resourceTypes as $resourceType) {
         $resourceTypeList[$resourceType->Id()] = $resourceType;
     }
     $this->page->BindResourceTypes($resourceTypeList);
     $statusReasons = $this->resourceRepository->GetStatusReasons();
     $statusReasonList = array();
     foreach ($statusReasons as $reason) {
         $statusReasonList[$reason->Id()] = $reason;
     }
     $this->page->BindResourceStatusReasons($statusReasonList);
     $groups = $this->groupRepository->GetGroupsByRole(RoleLevel::RESOURCE_ADMIN);
     $this->page->BindAdminGroups($groups);
     $resourceIds = array();
     foreach ($resources as $resource) {
         $resourceIds[] = $resource->GetId();
     }
     $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, $resourceIds);
     $this->page->BindAttributeList($attributeList);
     $this->InitializeFilter($filterValues, $resourceAttributes);
 }
Ejemplo n.º 25
0
 public function PageLoad()
 {
     $resourceId = $this->page->GetResourceId();
     $resource = $this->resourceRepository->LoadById($resourceId);
     $this->page->BindResource($resource);
     $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE, $resourceId);
     $this->page->BindAttributes($attributeList->GetAttributes($resourceId));
     if ($resource->HasResourceType()) {
         $resourceType = $this->resourceRepository->LoadResourceType($resource->GetResourceTypeId());
         $attributeList = $this->attributeService->GetAttributes(CustomAttributeCategory::RESOURCE_TYPE, $resource->GetResourceTypeId());
         $this->page->BindResourceType($resourceType, $attributeList->GetAttributes($resource->GetResourceTypeId()));
     }
 }
Ejemplo n.º 26
0
 /**
  * @param $currentUser UserSession
  */
 public function PageLoad($currentUser)
 {
     $user = $this->userRepository->LoadById($this->page->GetUserId());
     if ($this->privacyFilter->CanViewUser($currentUser, null, $user->Id())) {
         $this->page->SetCanViewUser(true);
         $attributes = $this->attributeService->GetByCategory(CustomAttributeCategory::USER);
         $this->page->BindAttributes($attributes);
         $this->page->BindUser($user);
     } else {
         $this->page->SetCanViewUser(false);
     }
 }
 public function PageLoad($userTimezone)
 {
     $session = ServiceLocator::GetServer()->GetUserSession();
     $this->page->BindSchedules($this->scheduleRepository->GetAll());
     $this->page->BindResources($this->resourceRepository->GetResourceList());
     $statusReasonList = array();
     foreach ($this->resourceRepository->GetStatusReasons() as $reason) {
         $statusReasonList[$reason->Id()] = $reason;
     }
     $this->page->BindResourceStatuses($statusReasonList);
     $startDateString = $this->page->GetStartDate();
     $endDateString = $this->page->GetEndDate();
     $filterPreferences = new ReservationFilterPreferences();
     $filterPreferences->Load($this->userPreferenceRepository, $session->UserId);
     $startDate = $this->GetDate($startDateString, $userTimezone, $filterPreferences->GetFilterStartDateDelta());
     $endDate = $this->GetDate($endDateString, $userTimezone, $filterPreferences->GetFilterEndDateDelta());
     $scheduleId = $this->page->GetScheduleId();
     $resourceId = $this->page->GetResourceId();
     $userId = $this->page->GetUserId();
     $userName = $this->page->GetUserName();
     $reservationStatusId = $this->page->GetReservationStatusId();
     $referenceNumber = $this->page->GetReferenceNumber();
     $resourceStatusId = $this->page->GetResourceStatusFilterId();
     $resourceReasonId = $this->page->GetResourceStatusReasonFilterId();
     if (!$this->page->FilterButtonPressed()) {
         // Get filter settings from db
         $referenceNumber = $filterPreferences->GetFilterReferenceNumber();
         $scheduleId = $filterPreferences->GetFilterScheduleId();
         $resourceId = $filterPreferences->GetFilterResourceId();
         $userId = $filterPreferences->GetFilterUserId();
         $userName = $filterPreferences->GetFilterUserName();
         $reservationStatusId = $filterPreferences->GetFilterReservationStatusId();
         $resourceStatusId = $filterPreferences->GetFilterResourceStatusId();
         $resourceReasonId = $filterPreferences->GetFilterResourceReasonId();
         $filters = $filterPreferences->GetFilterCustomAttributes();
     } else {
         $startOffset = $this->GetDateOffsetFromToday($startDate, $userTimezone);
         $endOffset = $this->GetDateOffsetFromToday($endDate, $userTimezone);
         $formFilters = $this->page->GetAttributeFilters();
         $filters = array();
         foreach ($formFilters as $filter) {
             $filters[$filter->Id] = $filter->Value;
         }
         $filterPreferences->SetFilterStartDateDelta($startOffset == null ? -14 : $startOffset);
         $filterPreferences->SetFilterEndDateDelta($endOffset == null ? 14 : $endOffset);
         $filterPreferences->SetFilterReferenceNumber($referenceNumber);
         $filterPreferences->SetFilterScheduleId($scheduleId);
         $filterPreferences->SetFilterResourceId($resourceId);
         $filterPreferences->SetFilterUserId($userId);
         $filterPreferences->SetFilterUserName($userName);
         $filterPreferences->SetFilterReservationStatusId($reservationStatusId);
         $filterPreferences->SetFilterResourceStatusId($resourceStatusId);
         $filterPreferences->SetFilterResourceReasonId($resourceReasonId);
         $filterPreferences->SetFilterCustomAttributes($filters);
         $filterPreferences->Update($this->userPreferenceRepository, $session->UserId);
     }
     $reservationAttributes = $this->attributeService->GetByCategory(CustomAttributeCategory::RESERVATION);
     $attributeFilters = array();
     foreach ($reservationAttributes as $attribute) {
         $attributeValue = null;
         if (array_key_exists($attribute->Id(), $filters)) {
             $attributeValue = $filters[$attribute->Id()];
         }
         $attributeFilters[] = new Attribute($attribute, $attributeValue);
     }
     $this->page->SetStartDate($startDate);
     $this->page->SetEndDate($endDate);
     $this->page->SetReferenceNumber($referenceNumber);
     $this->page->SetScheduleId($scheduleId);
     $this->page->SetResourceId($resourceId);
     $this->page->SetUserId($userId);
     $this->page->SetUserName($userName);
     $this->page->SetReservationStatusId($reservationStatusId);
     $this->page->SetResourceStatusFilterId($resourceStatusId);
     $this->page->SetResourceStatusReasonFilterId($resourceReasonId);
     $this->page->SetAttributeFilters($attributeFilters);
     $this->page->SetReservationAttributes($reservationAttributes);
     $filter = new ReservationFilter($startDate, $endDate, $referenceNumber, $scheduleId, $resourceId, $userId, $reservationStatusId, $resourceStatusId, $resourceReasonId, $attributeFilters);
     $reservations = $this->manageReservationsService->LoadFiltered($this->page->GetPageNumber(), $this->page->GetPageSize(), $filter, $session);
     /** @var ReservationItemView[] $reservationList */
     $reservationList = $reservations->Results();
     $this->page->BindReservations($reservationList);
     $this->page->BindPageInfo($reservations->PageInfo());
     $seriesIds = array();
     /** @var $reservationItemView ReservationItemView */
     foreach ($reservationList as $reservationItemView) {
         $seriesIds[] = $reservationItemView->SeriesId;
     }
     if ($this->page->GetFormat() == 'csv') {
         $this->page->ShowCsv();
     } else {
         $this->page->ShowPage();
     }
 }
Ejemplo n.º 28
0
 public function PageLoad()
 {
     $hideUserInfo = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_USER_DETAILS, new BooleanConverter());
     $hideReservationDetails = Configuration::Instance()->GetSectionKey(ConfigSection::PRIVACY, ConfigKeys::PRIVACY_HIDE_RESERVATION_DETAILS, new BooleanConverter());
     $userSession = ServiceLocator::GetServer()->GetUserSession();
     $tz = $userSession->Timezone;
     $reservation = $this->_reservationRepository->GetReservationForEditing($this->_page->GetReservationId());
     if (!$reservation->IsDisplayable()) {
         return;
     }
     if ($hideReservationDetails || $hideUserInfo) {
         $canViewDetails = $this->_reservationAuthorization->CanViewDetails($reservation, ServiceLocator::GetServer()->GetUserSession());
         $hideReservationDetails = !$canViewDetails && $hideReservationDetails;
         $hideUserInfo = !$canViewDetails && $hideUserInfo;
     }
     $this->_page->SetHideDetails($hideReservationDetails);
     $this->_page->SetHideUser($hideUserInfo);
     $startDate = $reservation->StartDate->ToTimezone($tz);
     $endDate = $reservation->EndDate->ToTimezone($tz);
     $this->_page->SetName($reservation->OwnerFirstName, $reservation->OwnerLastName);
     $this->_page->SetResources($reservation->Resources);
     $this->_page->SetParticipants($reservation->Participants);
     $this->_page->SetSummary($reservation->Description);
     $this->_page->SetTitle($reservation->Title);
     $this->_page->SetAccessories($reservation->Accessories);
     $this->_page->SetDates($startDate, $endDate);
     $attributeValues = $this->attributeService->GetReservationAttributes($userSession, $reservation);
     $this->_page->BindAttributes($attributeValues);
 }
Ejemplo n.º 29
0
 private function ExpectAttributeServiceCalled($attributes = array())
 {
     $list = new FakeAttributeList($attributes);
     $this->attributeService->expects($this->once())->method('GetAttributes')->with($this->equalTo(CustomAttributeCategory::USER))->will($this->returnValue($list));
 }
Ejemplo n.º 30
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;
 }