Files
dbois/application/controllers/projects/OffersController.php
T
2018-07-30 10:45:53 +02:00

90 lines
2.1 KiB
PHP

<?php
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
/**
* Created by Pensare Software.
* User: Theo Weijmer
* Date: 05/01/2018
* Time: 15:03
*/
class OffersController extends MY_Controller {
public function __construct()
{
parent::__construct();
if ( AUTHENTICATED == FALSE ) die( 'NO ACCESS' );
$models = [];
$libraries = [];
$this->load->model( $models );
$this->load->library( $libraries );
}
public function index()
{
}
public function getAllOffers( $projectID, $archive = 'F' )
{
$offers = Offer::getAllOffers( $projectID, $archive );
$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;
}
}