public function Update($resourceId, $request, $session) { $errors = $this->validator->ValidateUpdateRequest($resourceId, $request); if (!empty($errors)) { return new ResourceControllerResult(null, $errors); } $resource = $this->BuildResource($request, $resourceId); $this->repository->Update($resource); return new ResourceControllerResult($resourceId); }
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); } }
/** * @param int $scheduleId * @param int $moveResourcesToThisScheduleId */ public function Delete($scheduleId, $moveResourcesToThisScheduleId) { $resources = $this->resourceRepository->GetScheduleResources($scheduleId); foreach ($resources as $resource) { $resource->SetScheduleId($moveResourcesToThisScheduleId); $this->resourceRepository->Update($resource); } $schedule = $this->scheduleRepository->LoadById($scheduleId); $this->scheduleRepository->Delete($schedule); }
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); } } }