cleanInput('projectID'); $archive = $this->cleanInput('archive'); $search = $this->cleanInput('search'); $order = $this->cleanInput('order'); $direction = $this->cleanInput('direction'); $offers = \Offer::getAllOffers($projectID, $archive, $search, $order, $direction); return $this->json($offers); } public function getOffersWithoutProject(): ResponseInterface { $offersWithoutProject = \Offer::getOffersWithoutProject(); return $this->json($offersWithoutProject); } public function saveOffer(): ResponseInterface { $offerValidation = new \OfferValidation(); if (!$offerValidation->getValidationResult()) { return $this->json([ 'success' => false, 'messages' => $offerValidation->getErrorMessages() ]); } $offer = $this->request->getPost(); $offerID = $offer['id']; unset($offer['id']); $offerID = \Offer::saveOffer($offerID, $offer); $createProject = $this->checkCreateproject($offerID); return $this->json(['success' => true, 'offerID' => $offerID, 'createProject' => $createProject]); } public function archiveOffer(int $offerID, string $status): ResponseInterface { \Offer::whereId($offerID)->update(['archive' => $status]); return $this->json(['success' => true]); } public function removeOffer(int $offerID): ResponseInterface { $removeOffer = new \RemoveOffer($offerID); if ($removeOffer->getRemoveAllowed() === false) { return $this->json(['result' => false]); } \Offer::removeOffer($offerID); return $this->json(['result' => true]); } private function checkCreateproject(int $offerID): bool { $offer = \Offer::find($offerID); if (is_int($offer->project_id)) { return false; } if (is_null($offer->accepteddate)) { return false; } return true; } }