AdministrationController::getSettings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
crap 1
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\Settings as FormSettings;
15
use Tinyissue\Http\Requests\FormRequest;
16
use Tinyissue\Model\Project;
17
use Tinyissue\Model\Tag;
18
use Tinyissue\Model\User;
19
use Tinyissue\Services\SettingsManager;
20
21
/**
22
 * AdministrationController is the controller class for managing request related the application system admin.
23
 *
24
 * @author Mohamed Alsharaf <[email protected]>
25
 */
26
class AdministrationController extends Controller
27
{
28
    /**
29
     * Show general application stats.
30
     *
31
     * @param Tag     $tag
32
     * @param Project $project
33
     * @param User    $user
34
     *
35
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
36
     */
37 2
    public function getIndex(Tag $tag, Project $project, User $user)
38
    {
39 2
        return view('administration.index', [
40 2
            'users'             => $user->countUsers(),
41 2
            'active_projects'   => $project->countOpenProjects(),
42 2
            'archived_projects' => $project->countArchivedProjects(),
43 2
            'open_issues'       => $project->countOpenIssues(),
44 2
            'closed_issues'     => $project->countClosedIssues(),
45 2
            'projects'          => $this->getLoggedUser()->projects()->get(),
46 2
            'tags'              => $tag->count(),
47
        ]);
48
    }
49
50
    /**
51
     * Add new tag page.
52
     *
53
     * @param FormSettings $form
54
     *
55
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
56
     */
57 1
    public function getSettings(FormSettings $form)
58
    {
59 1
        return view('administration.settings', [
60 1
            'form'     => $form,
61 1
            'projects' => $this->getLoggedUser()->projects()->get(),
62
        ]);
63
    }
64
65
    /**
66
     * To create new tag.
67
     *
68
     * @param FormRequest\Settings $request
69
     *
70
     * @return \Illuminate\Http\RedirectResponse
71
     */
72 1
    public function postSettings(FormRequest\Settings $request)
73
    {
74 1
        app('tinyissue.settings')->save($request->except('_token'));
75
76 1
        return redirect('administration/settings')->with('notice', trans('tinyissue.settings_saved'));
77
    }
78
79
    /**
80
     * Toggle site maintenance mode.
81
     *
82
     * @return \Illuminate\Http\RedirectResponse
83
     */
84
    public function getChangeMaintenanceMode()
85
    {
86
        $action = 'down';
87
        if (app()->isDownForMaintenance()) {
88
            $action = 'up';
89
            app('session')->remove('notice-error');
90
        }
91
92
        \Artisan::call($action);
93
94
        return redirect('administration');
95
    }
96
}
97