public $components = array('RequestHandler');
public function index() {
+
+ // GETTING COMMAND CONTROLLER
+ App::import('Controller', 'Commands');
+ $commandsController = new CommandsController;
+
+ // GETTING ALL TASKS
$tasks = $this->Task->find('all');
+
+ // GETTING TASKS FOR EACH PATCH
+ $commandsArray = array();
+ foreach($tasks as $task) {
+
+ // GETTING TASKS ID
+ if($task['Task']['commands']) {
+ $commands_id = explode("|", $task['Task']['commands']);
+ $commands = array();
+ foreach($commands_id as $command_id) {
+ $commands[] = $commandsController->Command->findById($command_id);
+ }
+
+ // ADDIND TASKS TO ARRAY
+ $commandsArray[$task['Task']['id']] = $commands;
+ }
+ }
+
+ // SENDING DATA TO VIEW
+ $this->set(array(
+ 'commandsArray' => $commandsArray,
+ '_serialize' => array('commandsArray')
+ ));
$this->set(array(
'tasks' => $tasks,
'_serialize' => array('tasks')
}
}
}
+
+ public function order_command($id = null, $order = null, $direction = null) {
+ if (!$id) {
+ throw new NotFoundException(__('Tâche introuvable'));
+ }
+ $task = $this->Task->findById($id);
+ if (!$task) {
+ throw new NotFoundException(__('Tâche introuvable'));
+ }
+ $this->Task->id = $id;
+
+ // GETTING COMMANDS ID
+ $commands_id = explode("|", $task['Task']['commands']);
+
+ // CHANGING PLACES
+ $newCommands_id = array();
+ $key = $order-1;
+ if($direction == "up") {
+ $newkey = $key-1;
+ } else if($direction == "down") {
+ $newkey = $order;
+ }
+ foreach($commands_id as $command_id) {
+ $newCommands_id[] = $command_id;
+ }
+ if(isset($newkey)) {
+ $newCommands_id[$newkey] = $commands_id[$key];
+ $newCommands_id[$key] = $commands_id[$newkey];
+ }
+
+ // SAVING CHANGES
+ $this->Task->value('commands', implode("|", $newCommands_id));
+ $this->Task->save();
+ $this->redirect(array('action' => 'index'));
+ }
}