summaryrefslogtreecommitdiff
path: root/app/Controller/ProjectEditController.php
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-25 22:46:21 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-25 22:46:21 -0400
commitf2cce5ade869420bb73d5af2ad17907b1c3bb3da (patch)
tree3fda5e4beec87ff5781ad8e3e980abc75dd7518d /app/Controller/ProjectEditController.php
parent24ce1b42f8c23293f504ae312dc5e6b903ab869c (diff)
Rename ProjectEdit controller
Diffstat (limited to 'app/Controller/ProjectEditController.php')
-rw-r--r--app/Controller/ProjectEditController.php133
1 files changed, 133 insertions, 0 deletions
diff --git a/app/Controller/ProjectEditController.php b/app/Controller/ProjectEditController.php
new file mode 100644
index 00000000..774c6909
--- /dev/null
+++ b/app/Controller/ProjectEditController.php
@@ -0,0 +1,133 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Project Edit Controller
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class ProjectEditController extends BaseController
+{
+ /**
+ * General edition (most common operations)
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function edit(array $values = array(), array $errors = array())
+ {
+ $this->renderView('project_edit/general', $values, $errors);
+ }
+
+ /**
+ * Change start and end dates
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function dates(array $values = array(), array $errors = array())
+ {
+ $this->renderView('project_edit/dates', $values, $errors);
+ }
+
+ /**
+ * Change project description
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function description(array $values = array(), array $errors = array())
+ {
+ $this->renderView('project_edit/description', $values, $errors);
+ }
+
+ /**
+ * Change task priority
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function priority(array $values = array(), array $errors = array())
+ {
+ $this->renderView('project_edit/task_priority', $values, $errors);
+ }
+
+ /**
+ * Validate and update a project
+ *
+ * @access public
+ */
+ public function update()
+ {
+ $project = $this->getProject();
+ $values = $this->request->getValues();
+ $redirect = $this->request->getStringParam('redirect', 'edit');
+
+ $values = $this->prepareValues($redirect, $project, $values);
+ list($valid, $errors) = $this->projectValidator->validateModification($values);
+
+ if ($valid) {
+ if ($this->project->update($values)) {
+ $this->flash->success(t('Project updated successfully.'));
+ return $this->response->redirect($this->helper->url->to('ProjectEditController', $redirect, array('project_id' => $project['id'])), true);
+ } else {
+ $this->flash->failure(t('Unable to update this project.'));
+ }
+ }
+
+ return $this->$redirect($values, $errors);
+ }
+
+ /**
+ * Prepare form values
+ *
+ * @access private
+ * @param string $redirect
+ * @param array $project
+ * @param array $values
+ * @return array
+ */
+ private function prepareValues($redirect, array $project, array $values)
+ {
+ if ($redirect === 'edit') {
+ if (isset($values['is_private'])) {
+ if (! $this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) {
+ unset($values['is_private']);
+ }
+ } elseif ($project['is_private'] == 1 && ! isset($values['is_private'])) {
+ if ($this->helper->user->hasProjectAccess('ProjectCreation', 'create', $project['id'])) {
+ $values += array('is_private' => 0);
+ }
+ }
+ }
+
+ return $values;
+ }
+
+ /**
+ * Common method to render different views
+ *
+ * @access private
+ * @param string $template
+ * @param array $values
+ * @param array $errors
+ */
+ private function renderView($template, array $values, array $errors)
+ {
+ $project = $this->getProject();
+
+ $this->response->html($this->helper->layout->project($template, array(
+ 'owners' => $this->projectUserRole->getAssignableUsersList($project['id'], true),
+ 'values' => empty($values) ? $project : $values,
+ 'errors' => $errors,
+ 'project' => $project,
+ 'title' => t('Edit project')
+ )));
+ }
+}