summaryrefslogtreecommitdiff
path: root/app/Controller/GroupCreationController.php
blob: b297b19fa089deaad7fce1de1a4b21cfc351f063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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->groupModel->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);
    }
}