Exemplo n.º 1
0
 /**
  * @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 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 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);
     }
 }
Exemplo n.º 4
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));
 }
Exemplo n.º 5
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);
 }
 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;
 }
Exemplo n.º 7
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));
 }
Exemplo n.º 8
0
 public function BulkUpdate()
 {
     $scheduleId = $this->page->GetScheduleId();
     $resourceTypeId = $this->page->GetResourceTypeId();
     $location = $this->page->GetLocation();
     $contact = $this->page->GetContact();
     $description = $this->page->GetDescription();
     $notes = $this->page->GetNotes();
     $adminGroupId = $this->page->GetAdminGroupId();
     $statusId = $this->page->GetStatusId();
     $reasonId = $this->page->GetStatusReasonId();
     // need to figure out difference between empty and unchanged
     $minDuration = $this->page->GetMinimumDuration();
     $minDurationNone = $this->page->GetMinimumDurationNone();
     $maxDuration = $this->page->GetMaximumDuration();
     $maxDurationNone = $this->page->GetMaximumDurationNone();
     $bufferTime = $this->page->GetBufferTime();
     $bufferTimeNone = $this->page->GetBufferTimeNone();
     $minNotice = $this->page->GetStartNoticeMinutes();
     $minNoticeNone = $this->page->GetStartNoticeNone();
     $maxNotice = $this->page->GetEndNoticeMinutes();
     $maxNoticeNone = $this->page->GetEndNoticeNone();
     $allowMultiDay = $this->page->GetAllowMultiday();
     $requiresApproval = $this->page->GetRequiresApproval();
     $autoAssign = $this->page->GetAutoAssign();
     $allowSubscription = $this->page->GetAllowSubscriptions();
     $attributes = $this->page->GetAttributes();
     $resourceIds = $this->page->GetBulkUpdateResourceIds();
     foreach ($resourceIds as $resourceId) {
         try {
             $resource = $this->resourceRepository->LoadById($resourceId);
             if ($this->ChangingDropDown($scheduleId)) {
                 $resource->SetScheduleId($scheduleId);
             }
             if ($this->ChangingDropDown($resourceTypeId)) {
                 $resource->SetResourceTypeId($resourceTypeId);
             }
             if ($this->ChangingValue($location)) {
                 $resource->SetLocation($location);
             }
             if ($this->ChangingValue($contact)) {
                 $resource->SetContact($contact);
             }
             if ($this->ChangingValue($description)) {
                 $resource->SetDescription($description);
             }
             if ($this->ChangingValue($notes)) {
                 $resource->SetNotes($notes);
             }
             if ($this->ChangingDropDown($adminGroupId)) {
                 $resource->SetAdminGroupId($adminGroupId);
             }
             if ($this->ChangingDropDown($statusId)) {
                 $resource->ChangeStatus($statusId, $reasonId);
             }
             if (!$minDurationNone) {
                 $resource->SetMinLength($minDuration);
             }
             if (!$maxDurationNone) {
                 $resource->SetMaxLength($maxDuration);
             }
             if (!$bufferTimeNone) {
                 $resource->SetBufferTime($bufferTime);
             }
             if (!$minNoticeNone) {
                 $resource->SetMinNotice($minNotice);
             }
             if (!$maxNoticeNone) {
                 $resource->SetMaxNotice($maxNotice);
             }
             if ($this->ChangingDropDown($allowMultiDay)) {
                 $resource->SetAllowMultiday($allowMultiDay);
             }
             if ($this->ChangingDropDown($requiresApproval)) {
                 $resource->SetRequiresApproval($requiresApproval);
             }
             if ($this->ChangingDropDown($autoAssign)) {
                 $resource->SetAutoAssign($autoAssign);
             }
             if ($this->ChangingDropDown($allowSubscription)) {
                 if ($allowSubscription) {
                     $resource->EnableSubscription();
                 } else {
                     $resource->DisableSubscription();
                 }
             }
             /** @var AttributeValue $attribute */
             foreach ($this->GetAttributeValues() as $attribute) {
                 if (!empty($attribute->Value)) {
                     $resource->ChangeAttribute($attribute);
                 }
             }
             $this->resourceRepository->Update($resource);
         } catch (Exception $ex) {
             Log::Error('Error bulk updating resource. Id=%s. Error=%s', $resourceId, $ex);
         }
     }
 }
 /**
  * @param int $resourceId
  * @return CalendarSubscriptionDetails
  */
 public function ForResource($resourceId)
 {
     $resource = $this->resourceRepository->LoadById($resourceId);
     return new CalendarSubscriptionDetails($resource->GetIsCalendarSubscriptionAllowed(), new CalendarSubscriptionUrl(null, null, $resource->GetPublicId()));
 }