+++ /dev/null
-<?php
- class CommandsController extends AppController {
- public $helpers = array('Html', 'Form');
- public $components = array('RequestHandler');
-
- public function index() {
- $commands = $this->Command->find('all');
- $this->set(array(
- 'commands' => $commands,
- '_serialize' => array('commands')
- ));
- }
-
- public function add($task_id = null) {
- App::import('Controller', 'Tasks');
- $tasksController = new TasksController;
-
- // FORM IS SENT
- if ($this->request->is('POST')) {
- $this->Command->create();
- $this->Command->value('value', $this->request->data['Command']['value']);
- if ($this->Command->save($this->request->data)) {
-
- // GETTING TASK
- $task_id = $this->request->data['Command']['task'];
- if(isset($task_id)) {
- $task = $tasksController->Task->findById($task_id);
- $this->set('task', $task);
-
- // ADDING COMMAND TO TASK
- $commands = array();
- if($task['Task']['commands']) {
- $commands = explode('|', $task['Task']['commands']);
- }
- $commands[] = $this->Command->id;
- $tasksController->Task->read(null, $task_id);
- $tasksController->Task->set('commands', implode("|", $commands));
- $tasksController->Task->save();
- }
- $this->Session->setFlash(__("La commande a été enregistrée."));
- if(isset($task_id)) {
- $this->redirect(array('controller' => 'tasks', 'action' => 'index'));
- } else {
- $this->redirect(array('action' => 'index'));
- }
- }
- $this->Session->setFlash(__("Enregistrement de la commande impossible."));
-
- // FORM IS NOT SENT OR ACCESS VIA WRONG METHOD
- } else {
-
- // GETTING TASK IF ITS ID IS SET IN REQUEST
- if(isset($task_id)) {
- $task = $tasksController->Task->findById($task_id);
- $this->set('task', $task);
- }
- }
- }
- }