summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-05-16 20:19:07 -0400
committerFrederic Guillot <fred@kanboard.net>2016-05-16 20:19:07 -0400
commitabdf6f97800e7e838b5841820815385b183bab67 (patch)
tree75576da4a975561d0b93c7bcc7be94a385a4cd75 /app/Controller
parentde8ce875f4295e0b3bef20fcca051401f96816ef (diff)
Improve group controllers and views
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/GroupAjaxController.php (renamed from app/Controller/GroupHelper.php)8
-rw-r--r--app/Controller/GroupCreationController.php49
-rw-r--r--app/Controller/GroupListController.php (renamed from app/Controller/Group.php)105
-rw-r--r--app/Controller/GroupModificationController.php53
4 files changed, 117 insertions, 98 deletions
diff --git a/app/Controller/GroupHelper.php b/app/Controller/GroupAjaxController.php
index 06e5ec71..496e9ef2 100644
--- a/app/Controller/GroupHelper.php
+++ b/app/Controller/GroupAjaxController.php
@@ -5,12 +5,12 @@ namespace Kanboard\Controller;
use Kanboard\Formatter\GroupAutoCompleteFormatter;
/**
- * Group Helper
+ * Group Ajax Controller
*
- * @package controller
- * @author Frederic Guillot
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
*/
-class GroupHelper extends BaseController
+class GroupAjaxController extends BaseController
{
/**
* Group auto-completion (Ajax)
diff --git a/app/Controller/GroupCreationController.php b/app/Controller/GroupCreationController.php
new file mode 100644
index 00000000..7d0bb93c
--- /dev/null
+++ b/app/Controller/GroupCreationController.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Class GroupCreationController
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class GroupCreationController extends BaseController
+{
+ /**
+ * Display a form to create a new group
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function show(array $values = array(), array $errors = array())
+ {
+ $this->response->html($this->template->render('group_creation/show', array(
+ 'errors' => $errors,
+ 'values' => $values,
+ )));
+ }
+
+ /**
+ * Validate and save a new group
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->groupValidator->validateCreation($values);
+
+ if ($valid) {
+ if ($this->group->create($values['name']) !== false) {
+ $this->flash->success(t('Group created successfully.'));
+ return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true);
+ } else {
+ $this->flash->failure(t('Unable to create your group.'));
+ }
+ }
+
+ return $this->show($values, $errors);
+ }
+}
diff --git a/app/Controller/Group.php b/app/Controller/GroupListController.php
index 2f91e72a..17f3b2a9 100644
--- a/app/Controller/Group.php
+++ b/app/Controller/GroupListController.php
@@ -5,10 +5,10 @@ namespace Kanboard\Controller;
/**
* Group Controller
*
- * @package controller
- * @author Frederic Guillot
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
*/
-class Group extends BaseController
+class GroupListController extends BaseController
{
/**
* List all groups
@@ -18,7 +18,7 @@ class Group extends BaseController
public function index()
{
$paginator = $this->paginator
- ->setUrl('group', 'index')
+ ->setUrl('GroupListController', 'index')
->setMax(30)
->setOrder('name')
->setQuery($this->group->getQuery())
@@ -41,7 +41,7 @@ class Group extends BaseController
$group = $this->group->getById($group_id);
$paginator = $this->paginator
- ->setUrl('group', 'users', array('group_id' => $group_id))
+ ->setUrl('GroupListController', 'users', array('group_id' => $group_id))
->setMax(30)
->setOrder('username')
->setQuery($this->groupMember->getQuery($group_id))
@@ -55,86 +55,6 @@ class Group extends BaseController
}
/**
- * Display a form to create a new group
- *
- * @access public
- * @param array $values
- * @param array $errors
- */
- public function create(array $values = array(), array $errors = array())
- {
- $this->response->html($this->helper->layout->app('group/create', array(
- 'errors' => $errors,
- 'values' => $values,
- 'title' => t('New group')
- )));
- }
-
- /**
- * Validate and save a new group
- *
- * @access public
- */
- public function save()
- {
- $values = $this->request->getValues();
- list($valid, $errors) = $this->groupValidator->validateCreation($values);
-
- if ($valid) {
- if ($this->group->create($values['name']) !== false) {
- $this->flash->success(t('Group created successfully.'));
- return $this->response->redirect($this->helper->url->to('group', 'index'));
- } else {
- $this->flash->failure(t('Unable to create your group.'));
- }
- }
-
- return $this->create($values, $errors);
- }
-
- /**
- * Display a form to update a group
- *
- * @access public
- * @param array $values
- * @param array $errors
- */
- public function edit(array $values = array(), array $errors = array())
- {
- if (empty($values)) {
- $values = $this->group->getById($this->request->getIntegerParam('group_id'));
- }
-
- $this->response->html($this->helper->layout->app('group/edit', array(
- 'errors' => $errors,
- 'values' => $values,
- 'title' => t('Edit group')
- )));
- }
-
- /**
- * Validate and save a group
- *
- * @access public
- */
- public function update()
- {
- $values = $this->request->getValues();
- list($valid, $errors) = $this->groupValidator->validateModification($values);
-
- if ($valid) {
- if ($this->group->update($values) !== false) {
- $this->flash->success(t('Group updated successfully.'));
- return $this->response->redirect($this->helper->url->to('group', 'index'));
- } else {
- $this->flash->failure(t('Unable to update your group.'));
- }
- }
-
- return $this->edit($values, $errors);
- }
-
- /**
* Form to associate a user to a group
*
* @access public
@@ -150,12 +70,11 @@ class Group extends BaseController
$values['group_id'] = $group_id;
}
- $this->response->html($this->helper->layout->app('group/associate', array(
+ $this->response->html($this->template->render('group/associate', array(
'users' => $this->user->prepareList($this->groupMember->getNotMembers($group_id)),
'group' => $group,
'errors' => $errors,
'values' => $values,
- 'title' => t('Add group member to "%s"', $group['name']),
)));
}
@@ -171,7 +90,7 @@ class Group extends BaseController
if (isset($values['group_id']) && isset($values['user_id'])) {
if ($this->groupMember->addUser($values['group_id'], $values['user_id'])) {
$this->flash->success(t('Group member added successfully.'));
- return $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $values['group_id'])));
+ return $this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $values['group_id'])), true);
} else {
$this->flash->failure(t('Unable to add group member.'));
}
@@ -192,10 +111,9 @@ class Group extends BaseController
$group = $this->group->getById($group_id);
$user = $this->user->getById($user_id);
- $this->response->html($this->helper->layout->app('group/dissociate', array(
+ $this->response->html($this->template->render('group/dissociate', array(
'group' => $group,
'user' => $user,
- 'title' => t('Remove user from group "%s"', $group['name']),
)));
}
@@ -216,7 +134,7 @@ class Group extends BaseController
$this->flash->failure(t('Unable to remove this user from the group.'));
}
- $this->response->redirect($this->helper->url->to('group', 'users', array('group_id' => $group_id)));
+ $this->response->redirect($this->helper->url->to('GroupListController', 'users', array('group_id' => $group_id)), true);
}
/**
@@ -229,9 +147,8 @@ class Group extends BaseController
$group_id = $this->request->getIntegerParam('group_id');
$group = $this->group->getById($group_id);
- $this->response->html($this->helper->layout->app('group/remove', array(
+ $this->response->html($this->template->render('group/remove', array(
'group' => $group,
- 'title' => t('Remove group'),
)));
}
@@ -251,6 +168,6 @@ class Group extends BaseController
$this->flash->failure(t('Unable to remove this group.'));
}
- $this->response->redirect($this->helper->url->to('group', 'index'));
+ $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true);
}
}
diff --git a/app/Controller/GroupModificationController.php b/app/Controller/GroupModificationController.php
new file mode 100644
index 00000000..1f225a14
--- /dev/null
+++ b/app/Controller/GroupModificationController.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace Kanboard\Controller;
+
+/**
+ * Class GroupModificationController
+ *
+ * @package Kanboard\Controller
+ * @author Frederic Guillot
+ */
+class GroupModificationController extends BaseController
+{
+ /**
+ * Display a form to update a group
+ *
+ * @access public
+ * @param array $values
+ * @param array $errors
+ */
+ public function show(array $values = array(), array $errors = array())
+ {
+ if (empty($values)) {
+ $values = $this->group->getById($this->request->getIntegerParam('group_id'));
+ }
+
+ $this->response->html($this->template->render('group_modification/show', array(
+ 'errors' => $errors,
+ 'values' => $values,
+ )));
+ }
+
+ /**
+ * Validate and save a group
+ *
+ * @access public
+ */
+ public function save()
+ {
+ $values = $this->request->getValues();
+ list($valid, $errors) = $this->groupValidator->validateModification($values);
+
+ if ($valid) {
+ if ($this->group->update($values) !== false) {
+ $this->flash->success(t('Group updated successfully.'));
+ return $this->response->redirect($this->helper->url->to('GroupListController', 'index'), true);
+ } else {
+ $this->flash->failure(t('Unable to update your group.'));
+ }
+ }
+
+ return $this->show($values, $errors);
+ }
+}