load->model( $models ); $this->load->library( $libraries ); } public function index() { } public function getAllOffers() { $projectID = $this->clean_input( 'projectID' ); $archive = $this->clean_input( 'archive' ); $search = $this->clean_input( 'search' ); $order = $this->clean_input( 'order' ); $direction = $this->clean_input( 'direction' ); $offers = Offer::getAllOffers( $projectID, $archive, $search, $order, $direction ); $this->json( $offers ); } public function getOffersWithoutProject() { $offersWithoutProject = Offer::getOffersWithoutProject(); $this->json( $offersWithoutProject); } public function saveOffer() { $offerValidation = new OfferValidation(); if ( ! $offerValidation->getValidationResult() ) return $this->json( [ 'success' => FALSE, 'messages' => $offerValidation->getErrorMessages()] ); $offer = $this->input->post(); $offerID = $offer['id']; unset( $offer['id'] ); $offerID = Offer::saveOffer( $offerID, $offer ); $createProject = $this->checkCreateproject( $offerID ); $this->json( ['success' => TRUE, 'offerID' => $offerID, 'createProject' => $createProject] ); } public function archiveOffer( $offerID, $status ) { Offer::whereId( $offerID )->update( ['archive' => $status] ); } public function removeOffer( $offerID ) { $removeOffer = new RemoveOffer( $offerID ); if ( $removeOffer->getRemoveAllowed() === FALSE ) return $this->json( ['result' => FALSE] ); Offer::removeOffer( $offerID ); $this->json( ['result' => TRUE] ); } private function checkCreateproject( $offerID ) { $offer = Offer::find( $offerID ); if ( is_int( $offer->project_id ) ) return FALSE; if ( is_null( $offer->accepteddate ) ) return FALSE; return TRUE; } }