--- /dev/null
+<?php
+ class VersionsController extends AppController {
+ public $helpers = array('Html', 'Form');
+ public $components = array('RequestHandler');
+
+ public function index() {
+ // RÉCUPÉRATION DES VERSIONS
+ $versions = $this->Version->find('all');
+
+ // ENVOI DES DONNÉES À LA VUE
+ $this->set(array(
+ 'versions' => $versions,
+ '_serialize' => array('versions')
+ ));
+ }
+
+ public function view($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Mauvaise version'));
+ }
+
+ $version = $this->Version->findById($id);
+ if (!$version) {
+ throw new NotFoundException(__('Mauvaise version'));
+ }
+ $this->set('version', $version);
+ }
+
+ public function add() {
+ if ($this->request->is('version')) {
+ $this->Version->create();
+ if ($this->Version->save($this->request->data)) {
+ $this->Session->setFlash(__("La version a été enregistrée."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Enregistrement de la version impossible."));
+ }
+ }
+
+ public function edit($id = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Version introuvable'));
+ }
+
+ $version = $this->Version->findById($id);
+ if (!$version) {
+ throw new NotFoundException(__('Version introuvable'));
+ }
+
+ if ($this->request->is(array('version', 'put'))) {
+ $this->Version->id = $id;
+ if ($this->Version->save($this->request->data)) {
+ $this->Session->setFlash(__("La version a été mise à jour."));
+ return $this->redirect(array('action' => 'index'));
+ }
+ $this->Session->setFlash(__("Mise à jour de la version impossible."));
+ }
+
+ if (!$this->request->data) {
+ $this->request->data = $version;
+ }
+ }
+
+ public function delete($id) {
+ if ($this->request->is('get')) {
+ throw new MethodNotAllowedException();
+ }
+
+ if ($this->Version->delete($id)) {
+ $this->Session->setFlash(
+ __("La version d'id: %s a été supprimée.", h($id))
+ );
+ return $this->redirect(array('action' => 'index'));
+ }
+ }
+ }
+?>