summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/PredefinedTaskDescriptionController.php116
-rw-r--r--app/Controller/ProjectPredefinedContentController.php15
2 files changed, 118 insertions, 13 deletions
diff --git a/app/Controller/PredefinedTaskDescriptionController.php b/app/Controller/PredefinedTaskDescriptionController.php
new file mode 100644
index 00000000..1b7eca12
--- /dev/null
+++ b/app/Controller/PredefinedTaskDescriptionController.php
@@ -0,0 +1,116 @@
+<?php
+
+namespace Kanboard\Controller;
+
+use Kanboard\Core\Controller\PageNotFoundException;
+
+/**
+ * Predefined Task Description Controller
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class PredefinedTaskDescriptionController extends BaseController
+{
+ public function create(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->template->render('predefined_task_description/create', array(
+ 'values' => $values,
+ 'errors' => $errors,
+ 'project' => $project,
+ )));
+ }
+
+ public function save()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+
+ list($valid, $errors) = $this->predefinedTaskDescriptionValidator->validate($values);
+
+ if ($valid) {
+ if ($this->predefinedTaskDescriptionModel->create($project['id'], $values['title'], $values['description']) !== false) {
+ $this->flash->success(t('Template created successfully.'));
+ } else {
+ $this->flash->failure(t('Unable to create this template.'));
+ }
+
+ $this->response->redirect($this->helper->url->to('ProjectPredefinedContentController', 'show', array('project_id' => $project['id'])), true);
+ } else {
+ $this->create($values, $errors);
+ }
+ }
+
+ public function edit(array $values = array(), array $errors = array())
+ {
+ $project = $this->getProject();
+ $template = $this->predefinedTaskDescriptionModel->getById($project['id'], $this->request->getIntegerParam('id'));
+
+ $this->response->html($this->template->render('predefined_task_description/edit', array(
+ 'values' => empty($values) ? $template : $values,
+ 'template' => $template,
+ 'errors' => $errors,
+ 'project' => $project,
+ )));
+ }
+
+ public function update()
+ {
+ $project = $this->getProject();
+ $template = $this->getTemplate($project);
+ $values = $this->request->getValues();
+
+ list($valid, $errors) = $this->predefinedTaskDescriptionValidator->validate($values);
+
+ if ($valid) {
+ if ($this->predefinedTaskDescriptionModel->update($project['id'], $template['id'], $values['title'], $values['description']) !== false) {
+ $this->flash->success(t('Template updated successfully.'));
+ } else {
+ $this->flash->failure(t('Unable to update this template.'));
+ }
+
+ $this->response->redirect($this->helper->url->to('ProjectPredefinedContentController', 'show', array('project_id' => $project['id'])), true);
+ } else {
+ $this->edit($values, $errors);
+ }
+ }
+
+ public function confirm()
+ {
+ $project = $this->getProject();
+ $template = $this->getTemplate($project);
+
+ $this->response->html($this->template->render('predefined_task_description/remove', array(
+ 'template' => $template,
+ 'project' => $project,
+ )));
+ }
+
+ public function remove()
+ {
+ $this->checkCSRFParam();
+ $project = $this->getProject();
+ $template = $this->getTemplate($project);
+
+ if ($this->predefinedTaskDescriptionModel->remove($project['id'], $template['id'])) {
+ $this->flash->success(t('Template removed successfully.'));
+ } else {
+ $this->flash->failure(t('Unable to remove this template.'));
+ }
+
+ $this->response->redirect($this->helper->url->to('ProjectPredefinedContentController', 'show', array('project_id' => $project['id'])), true);
+ }
+
+ protected function getTemplate(array $project)
+ {
+ $template = $this->predefinedTaskDescriptionModel->getById($project['id'], $this->request->getIntegerParam('id'));
+
+ if (empty($template)) {
+ throw new PageNotFoundException();
+ }
+
+ return $template;
+ }
+} \ No newline at end of file
diff --git a/app/Controller/ProjectPredefinedContentController.php b/app/Controller/ProjectPredefinedContentController.php
index 1195dfa3..709d6b79 100644
--- a/app/Controller/ProjectPredefinedContentController.php
+++ b/app/Controller/ProjectPredefinedContentController.php
@@ -10,13 +10,6 @@ namespace Kanboard\Controller;
*/
class ProjectPredefinedContentController extends BaseController
{
- /**
- * Edit project
- *
- * @access public
- * @param array $values
- * @param array $errors
- */
public function show(array $values = array(), array $errors = array())
{
$project = $this->getProject();
@@ -25,15 +18,11 @@ class ProjectPredefinedContentController extends BaseController
'values' => empty($values) ? $project : $values,
'errors' => $errors,
'project' => $project,
- 'title' => t('Predefined Contents')
+ 'predefined_task_descriptions' => $this->predefinedTaskDescriptionModel->getAll($project['id']),
+ 'title' => t('Predefined Contents'),
)));
}
- /**
- * Validate and update a project
- *
- * @access public
- */
public function update()
{
$project = $this->getProject();