UserController   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 94
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 8
c 3
b 1
f 0
lcom 1
cbo 6
dl 0
loc 94
ccs 30
cts 30
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getSettings() 0 7 1
A postSettings() 0 6 1
A getMessagesSettings() 0 10 1
A postMessagesSettings() 0 6 1
B getIssues() 0 22 4
1
<?php
2
3
/*
4
 * This file is part of the Tinyissue package.
5
 *
6
 * (c) Mohamed Alsharaf <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tinyissue\Http\Controllers;
13
14
use Tinyissue\Form\UserMessagesSettings as MessagesForm;
15
use Tinyissue\Form\UserSetting as Form;
16
use Tinyissue\Http\Requests\FormRequest;
17
use Tinyissue\Model\Project;
18
19
/**
20
 * UserController is the controller class for managing request related to logged in user account.
21
 *
22
 * @author Mohamed Alsharaf <[email protected]>
23
 */
24
class UserController extends Controller
25
{
26
    /**
27
     * Edit the user's settings.
28
     *
29
     * @param Form $form
30
     *
31
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
32
     */
33 4
    public function getSettings(Form $form)
34
    {
35 4
        return view('user.settings', [
36 4
            'form'     => $form,
37 4
            'projects' => $this->getLoggedUser()->projects()->get(),
38
        ]);
39
    }
40
41
    /**
42
     * To update user settings.
43
     *
44
     * @param FormRequest\UserSetting $request
45
     *
46
     * @return \Illuminate\Http\RedirectResponse
47
     */
48 3
    public function postSettings(FormRequest\UserSetting $request)
49
    {
50 3
        $this->getLoggedUser()->updateSetting($request->all());
51
52 3
        return redirect('user/settings')->with('notice', trans('tinyissue.settings_updated'));
53
    }
54
55
    /**
56
     * Shows the user's assigned issues.
57
     *
58
     * @param string  $display
59
     * @param Project $project
60
     *
61
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
62
     */
63 2
    public function getIssues($display = 'list', Project $project = null)
64
    {
65 2
        $view = $display === 'kanban' ? 'kanban' : 'list';
66 2
        $data = [];
67
68 2
        if ($display === 'kanban') {
69 1
            $data['columns'] = [];
70 1
            $data['issues']  = [];
71 1
            if ($project->id) {
72 1
                $data['columns'] = $project->getKanbanTagsForUser($this->getLoggedUser());
73 1
                $ids             = $data['columns']->lists('id')->all();
74 1
                $data['issues']  = $this->getLoggedUser()->issuesGroupByTags($ids, $project->id);
75
            }
76
77 1
            $data['project']  = $project;
78 1
            $data['projects'] = $this->getLoggedUser()->projects()->get();
79
        } else {
80 1
            $data['projects'] = $this->getLoggedUser()->projectsWidthIssues(Project::STATUS_OPEN)->get();
81
        }
82
83 2
        return view('user.issues-' . $view, $data);
84
    }
85
86
    /**
87
     * Edit the user's message settings.
88
     *
89
     * @param MessagesForm $form
90
     *
91
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
92
     */
93 1
    public function getMessagesSettings(MessagesForm $form)
94
    {
95 1
        $projects = $this->getLoggedUser()->projects()->with('projectUsers')->get();
96 1
        $form->setProjects($projects);
97
98 1
        return view('user.messages-settings', [
99 1
            'form'     => $form,
100 1
            'projects' => $projects,
101
        ]);
102
    }
103
104
    /**
105
     * To update user settings.
106
     *
107
     * @param FormRequest\UserMessagesSettings $request
108
     *
109
     * @return \Illuminate\Http\RedirectResponse
110
     */
111 1
    public function postMessagesSettings(FormRequest\UserMessagesSettings $request)
112
    {
113 1
        $this->getLoggedUser()->updateMessagesSettings((array) $request->input('projects', []));
114
115 1
        return redirect('user/settings/messages')->with('notice', trans('tinyissue.messages_settings_updated'));
116
    }
117
}
118