diff options
| author | Frederic Guillot <fred@kanboard.net> | 2016-05-17 22:25:18 -0400 | 
|---|---|---|
| committer | Frederic Guillot <fred@kanboard.net> | 2016-05-17 22:25:18 -0400 | 
| commit | 46ed06268dc3d591fb7bb90a5a9a75e77c17b86c (patch) | |
| tree | 4e4cc7d42bed1d5ca5e1c9d65415def3161cad2c /app/Controller/SubtaskController.php | |
| parent | 996997a12d1b435956a96640eb6cf39045f6ef46 (diff) | |
Rename subtask controller
Diffstat (limited to 'app/Controller/SubtaskController.php')
| -rw-r--r-- | app/Controller/SubtaskController.php | 177 | 
1 files changed, 177 insertions, 0 deletions
| diff --git a/app/Controller/SubtaskController.php b/app/Controller/SubtaskController.php new file mode 100644 index 00000000..830548da --- /dev/null +++ b/app/Controller/SubtaskController.php @@ -0,0 +1,177 @@ +<?php + +namespace Kanboard\Controller; + +use Kanboard\Core\Controller\AccessForbiddenException; +use Kanboard\Core\Controller\PageNotFoundException; + +/** + * Subtask controller + * + * @package  Kanboard\Controller + * @author   Frederic Guillot + */ +class SubtaskController extends BaseController +{ +    /** +     * Creation form +     * +     * @access public +     * @param array $values +     * @param array $errors +     * @throws AccessForbiddenException +     * @throws PageNotFoundException +     */ +    public function create(array $values = array(), array $errors = array()) +    { +        $task = $this->getTask(); + +        if (empty($values)) { +            $values = array( +                'task_id' => $task['id'], +                'another_subtask' => $this->request->getIntegerParam('another_subtask', 0) +            ); +        } + +        $this->response->html($this->template->render('subtask/create', array( +            'values' => $values, +            'errors' => $errors, +            'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), +            'task' => $task, +        ))); +    } + +    /** +     * Validation and creation +     * +     * @access public +     */ +    public function save() +    { +        $task = $this->getTask(); +        $values = $this->request->getValues(); + +        list($valid, $errors) = $this->subtaskValidator->validateCreation($values); + +        if ($valid) { +            if ($this->subtask->create($values)) { +                $this->flash->success(t('Sub-task added successfully.')); +            } else { +                $this->flash->failure(t('Unable to create your sub-task.')); +            } + +            if (isset($values['another_subtask']) && $values['another_subtask'] == 1) { +                return $this->create(array('project_id' => $task['project_id'], 'task_id' => $task['id'], 'another_subtask' => 1)); +            } + +            return $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true); +        } + +        return $this->create($values, $errors); +    } + +    /** +     * Edit form +     * +     * @access public +     * @param array $values +     * @param array $errors +     * @throws AccessForbiddenException +     * @throws PageNotFoundException +     */ +    public function edit(array $values = array(), array $errors = array()) +    { +        $task = $this->getTask(); +        $subtask = $this->getSubtask(); + +        $this->response->html($this->template->render('subtask/edit', array( +            'values' => empty($values) ? $subtask : $values, +            'errors' => $errors, +            'users_list' => $this->projectUserRole->getAssignableUsersList($task['project_id']), +            'status_list' => $this->subtask->getStatusList(), +            'subtask' => $subtask, +            'task' => $task, +        ))); +    } + +    /** +     * Update and validate a subtask +     * +     * @access public +     */ +    public function update() +    { +        $task = $this->getTask(); +        $this->getSubtask(); + +        $values = $this->request->getValues(); +        list($valid, $errors) = $this->subtaskValidator->validateModification($values); + +        if ($valid) { +            if ($this->subtask->update($values)) { +                $this->flash->success(t('Sub-task updated successfully.')); +            } else { +                $this->flash->failure(t('Unable to update your sub-task.')); +            } + +            return $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); +        } + +        return $this->edit($values, $errors); +    } + +    /** +     * Confirmation dialog before removing a subtask +     * +     * @access public +     */ +    public function confirm() +    { +        $task = $this->getTask(); +        $subtask = $this->getSubtask(); + +        $this->response->html($this->template->render('subtask/remove', array( +            'subtask' => $subtask, +            'task' => $task, +        ))); +    } + +    /** +     * Remove a subtask +     * +     * @access public +     */ +    public function remove() +    { +        $this->checkCSRFParam(); +        $task = $this->getTask(); +        $subtask = $this->getSubtask(); + +        if ($this->subtask->remove($subtask['id'])) { +            $this->flash->success(t('Sub-task removed successfully.')); +        } else { +            $this->flash->failure(t('Unable to remove this sub-task.')); +        } + +        $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id'])), true); +    } + +    /** +     * Move subtask position +     * +     * @access public +     */ +    public function movePosition() +    { +        $project_id = $this->request->getIntegerParam('project_id'); +        $task_id = $this->request->getIntegerParam('task_id'); +        $values = $this->request->getJson(); + +        if (! empty($values) && $this->helper->user->hasProjectAccess('SubtaskController', 'movePosition', $project_id)) { +            $result = $this->subtask->changePosition($task_id, $values['subtask_id'], $values['position']); +            $this->response->json(array('result' => $result)); +        } else { +            throw new AccessForbiddenException(); +        } +    } +} | 
