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 GetAccessory
  * @description Loads a specific accessory by id
  * @param int $accessoryId
  * @response AccessoryResponse
  * @return void
  */
 public function GetAccessory($accessoryId)
 {
     $accessory = $this->accessoryRepository->LoadById($accessoryId);
     if (empty($accessory)) {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     } else {
         $this->server->WriteResponse(new AccessoryResponse($this->server, $accessory));
     }
 }
Ejemplo n.º 3
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);
     }
 }
Ejemplo n.º 4
0
 /**
  * @name GetGroup
  * @description Loads a specific group by id
  * @response GroupResponse
  * @param int $groupId
  * @return void
  */
 public function GetGroup($groupId)
 {
     $group = $this->groupRepository->LoadById($groupId);
     if ($group != null) {
         $this->server->WriteResponse(new GroupResponse($this->server, $group));
     } else {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
Ejemplo n.º 5
0
 /**
  * @name GetSchedule
  * @description Loads a specific schedule by id
  * @response ScheduleResponse
  * @param $scheduleId
  * @return void
  */
 public function GetSchedule($scheduleId)
 {
     $schedule = $this->scheduleRepository->LoadById($scheduleId);
     if ($schedule != null) {
         $layout = $this->scheduleRepository->GetLayout($schedule->GetId(), new ScheduleLayoutFactory($this->server->GetSession()->Timezone));
         $this->server->WriteResponse(new ScheduleResponse($this->server, $schedule, $layout));
     } else {
         $this->server->WriteResponse(RestResponse::NotFound(), RestResponse::NOT_FOUND_CODE);
     }
 }
Ejemplo n.º 6
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);
     }
 }
Ejemplo n.º 7
0
 /**
  * @name GetSlots
  * @description Loads slots for a specific schedule
  * Optional query string parameters:  resourceId, startDateTime, endDateTime.
  * If no dates are provided the default schedule dates will be returned.
  * If dates do not include the timezone offset, the timezone of the authenticated user will be assumed.
  * @response ScheduleSlotsResponse
  * @param $scheduleId
  * @return void
  */
 public function GetSlots($scheduleId)
 {
     $startDate = $this->GetDate(WebServiceQueryStringKeys::START_DATE_TIME);
     $endDate = $this->GetDate(WebServiceQueryStringKeys::END_DATE_TIME);
     $resourceId = $this->server->GetQueryString(WebServiceQueryStringKeys::RESOURCE_ID);
     $scheduleWebServiceView = new ScheduleWebServiceView($scheduleId, $startDate);
     $permissionServiceFactory = new PermissionServiceFactory();
     $scheduleRepository = new ScheduleRepository();
     $userRepository = new UserRepository();
     $resourceService = new ResourceService(new ResourceRepository(), $permissionServiceFactory->GetPermissionService(), new AttributeService(new AttributeRepository()), $userRepository);
     $builder = new ScheduleWebServicePageBuilder($startDate, $endDate, $resourceId);
     $reservationService = new ReservationService(new ReservationViewRepository(), new ReservationListingFactory());
     $dailyLayoutFactory = new DailyLayoutFactory();
     $scheduleService = new ScheduleService($scheduleRepository, $resourceService);
     $presenter = new SchedulePresenter($scheduleWebServiceView, $scheduleService, $resourceService, $builder, $reservationService, $dailyLayoutFactory);
     $presenter->PageLoad($this->server->GetSession());
     $layout = $scheduleWebServiceView->GetDailyLayout();
     $isError = $scheduleWebServiceView->IsPermissionError();
     $dates = $scheduleWebServiceView->GetDates();
     $resources = $scheduleWebServiceView->GetResources();
     if ($isError) {
         $this->server->WriteResponse(RestResponse::Unauthorized(), RestResponse::UNAUTHORIZED_CODE);
     } else {
         $response = new ScheduleSlotsResponse($this->server, $scheduleId, $layout, $dates, $resources, $this->privacyFilter);
         $this->server->WriteResponse($response);
     }
 }
Ejemplo n.º 8
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));
 }
Ejemplo n.º 9
0
 /**
  * @name DeleteUser
  * @description Deletes an existing user
  * @response DeletedResponse
  * @param int $userId
  * @return void
  */
 public function Delete($userId)
 {
     Log::Debug('UsersWriteWebService.Delete() User=%s', $this->server->GetSession()->UserId);
     $result = $this->controller->Delete($userId, $this->server->GetSession());
     if ($result->WasSuccessful()) {
         Log::Debug('UsersWriteWebService.Delete() - User Deleted. UserId=%s', $result->UserId());
         $this->server->WriteResponse(new DeletedResponse(), RestResponse::OK_CODE);
     } else {
         Log::Debug('UsersWriteWebService.Delete() - User Delete Failed.');
         $this->server->WriteResponse(new FailedResponse($this->server, $result->Errors()), RestResponse::BAD_REQUEST_CODE);
     }
 }
Ejemplo n.º 10
0
 /**
  * @name DeleteCustomAttribute
  * @description Deletes an existing custom attribute
  * @response DeletedResponse
  * @param int $attributeId
  * @return void
  */
 public function Delete($attributeId)
 {
     Log::Debug('AttributesWriteWebService.Delete() AttributeId=%s, UserId=%s', $attributeId, $this->server->GetSession()->UserId);
     $result = $this->attributeController->Delete($attributeId, $this->server->GetSession());
     if ($result->WasSuccessful()) {
         Log::Debug('AttributesWriteWebService.Delete() - Attribute Deleted. AttributeId=%s', $result->AttributeId());
         $this->server->WriteResponse(new DeletedResponse(), RestResponse::OK_CODE);
     } else {
         Log::Debug('AttributesWriteWebService.Delete() - Attribute Delete Failed.');
         $this->server->WriteResponse(new FailedResponse($this->server, $result->Errors()), RestResponse::BAD_REQUEST_CODE);
     }
 }
Ejemplo n.º 11
0
 /**
  * @name DeleteReservation
  * @description Deletes an existing reservation.
  * Pass an optional updateScope query string parameter to restrict changes. Possible values for updateScope are this|full|future
  * @response DeletedResponse
  * @param string $referenceNumber
  * @return void
  */
 public function Delete($referenceNumber)
 {
     Log::Debug('ReservationWriteWebService.Delete() User=%s, ReferenceNumber=%s', $this->server->GetSession()->UserId, $referenceNumber);
     $updateScope = $this->server->GetQueryString(WebServiceQueryStringKeys::UPDATE_SCOPE);
     $result = $this->controller->Delete($this->server->GetSession(), $referenceNumber, $updateScope);
     if ($result->WasSuccessful()) {
         Log::Debug('ReservationWriteWebService.Delete() - Reservation Deleted. ReferenceNumber=%s', $result->CreatedReferenceNumber());
         $this->server->WriteResponse(new DeletedResponse(), RestResponse::OK_CODE);
     } else {
         Log::Debug('ReservationWriteWebService.Delete() - Reservation Failed.');
         $this->server->WriteResponse(new FailedResponse($this->server, $result->Errors()), RestResponse::BAD_REQUEST_CODE);
     }
 }
Ejemplo n.º 12
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));
 }