<?php

class Agreements extends Controller {
    private $_agreementModel;
    private $data;
    
    public function __construct() {
        $this->_agreementModel = $this->model('AgreementModel');
    }

    public function index() {
        $this->data['agreements'] = $this->_agreementModel->getAllAgreements();
        $this->view('Manage/agreement/index', $this->data);
    }

    public function create() {
        $this->view('Manage/agreement/new');
    }

    public function edit($id) {
        $this->data['agreements'] = $this->_agreementModel->getAgreementById($id);
        $this->view('Manage/agreement/edit', $this->data);
    }

    public function update() {
        $POST = $_POST;
        $this->data['agreements'] = $this->_agreementModel->getAllAgreements();
        $this->_agreementModel->updateAgreement($POST['codigoactual'], $POST);
        redirect('/agreement/index');
    }

    public function persist() {
        $POST = $_POST;
        $this->_agreementModel->createAgreement($POST);
        redirect('/agreement/index');
    }
}