SuivisController.php 3.45 KB
<?php
namespace App\Controller;

use App\Controller\AppController;

/**
 * Suivis Controller
 *
 * @property \App\Model\Table\SuivisTable $Suivis
 */
class SuivisController extends AppController
{

    /**
     * Index method
     *
     * @return \Cake\Network\Response|null
     */
    public function index()
    {
        $this->paginate = [
            'contain' => ['Materiels']
        ];
        $suivis = $this->paginate($this->Suivis);

        $this->set(compact('suivis'));
        $this->set('_serialize', ['suivis']);
    }

    /**
     * View method
     *
     * @param string|null $id Suivi id.
     * @return \Cake\Network\Response|null
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function view($id = null)
    {
        $suivi = $this->Suivis->get($id, [
            'contain' => ['Materiels', 'Documents']
        ]);

        $this->set('suivi', $suivi);
        $this->set('_serialize', ['suivi']);
    }

    /**
     * Add method
     *
     * @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise.
     */
    public function add()
    {
        $suivi = $this->Suivis->newEntity();
        if ($this->request->is('post')) {
            $suivi = $this->Suivis->patchEntity($suivi, $this->request->data);
            if ($this->Suivis->save($suivi)) {
                $this->Flash->success(__('The suivi has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The suivi could not be saved. Please, try again.'));
            }
        }
        $materiels = $this->Suivis->Materiels->find('list', ['limit' => 200]);
        $this->set(compact('suivi', 'materiels'));
        $this->set('_serialize', ['suivi']);
    }

    /**
     * Edit method
     *
     * @param string|null $id Suivi id.
     * @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise.
     * @throws \Cake\Network\Exception\NotFoundException When record not found.
     */
    public function edit($id = null)
    {
        $suivi = $this->Suivis->get($id, [
            'contain' => []
        ]);
        if ($this->request->is(['patch', 'post', 'put'])) {
            $suivi = $this->Suivis->patchEntity($suivi, $this->request->data);
            if ($this->Suivis->save($suivi)) {
                $this->Flash->success(__('The suivi has been saved.'));
                return $this->redirect(['action' => 'index']);
            } else {
                $this->Flash->error(__('The suivi could not be saved. Please, try again.'));
            }
        }
        $materiels = $this->Suivis->Materiels->find('list', ['limit' => 200]);
        $this->set(compact('suivi', 'materiels'));
        $this->set('_serialize', ['suivi']);
    }

    /**
     * Delete method
     *
     * @param string|null $id Suivi id.
     * @return \Cake\Network\Response|null Redirects to index.
     * @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found.
     */
    public function delete($id = null)
    {
        $this->request->allowMethod(['post', 'delete']);
        $suivi = $this->Suivis->get($id);
        if ($this->Suivis->delete($suivi)) {
            $this->Flash->success(__('The suivi has been deleted.'));
        } else {
            $this->Flash->error(__('The suivi could not be deleted. Please, try again.'));
        }
        return $this->redirect(['action' => 'index']);
    }
}