HomeController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 10

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 10
dl 0
loc 48
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
B showHomepage() 0 28 2
1
<?php
2
3
/**
4
 * Storgman - Student Organizations Management
5
 * Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
6
 *
7
 * This file is part of Storgman.
8
 *
9
 * Storgman is free software: you can redistribute it and/or modify
10
 * it under the terms of the GNU General Public License as published by
11
 * the Free Software Foundation, either version 3 of the License, or
12
 * (at your option) any later version.
13
 *
14
 * Storgman is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with Storgman.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 * @package Storgman
23
 * @copyright Copyright (C) 2014-2016, Dejan Angelov <[email protected]>
24
 * @license https://github.com/angelov/storgman/blob/master/LICENSE
25
 * @author Dejan Angelov <[email protected]>
26
 */
27
28
namespace Angelov\Storgman\Members\Http\Controllers;
29
30
use Angelov\Storgman\Core\Http\Controllers\BaseController;
31
use Angelov\Storgman\Core\DateTime;
32
use Angelov\Storgman\Faculties\Repositories\FacultiesRepositoryInterface;
33
use Angelov\Storgman\Members\Member;
34
use Angelov\Storgman\Meetings\Repositories\MeetingsRepositoryInterface;
35
use Angelov\Storgman\Members\Repositories\MembersRepositoryInterface;
36
use Angelov\Storgman\Members\MembersStatisticsService;
37
use Illuminate\Contracts\Auth\Guard;
38
39
class HomeController extends BaseController
40
{
41
    protected $members;
42
    protected $meetings;
43
    protected $faculties;
44
    protected $membersStats;
45
46
    public function __construct(
47
        MembersRepositoryInterface $members,
48
        MeetingsRepositoryInterface $meetings,
49
        FacultiesRepositoryInterface $faculties,
50
        MembersStatisticsService $membersStats
51
    ) {
52
        $this->members = $members;
53
        $this->meetings = $meetings;
54
        $this->membersStats = $membersStats;
55
        $this->faculties = $faculties;
56
    }
57
58
    public function showHomepage(Guard $auth)
59
    {
60
        $today = new DateTime();
61
62
        /** @var Member $logged */
63
        $logged = $auth->user();
64
        $boardMember = $logged->isBoardMember();
65
66
        if (!$boardMember) {
67
            return redirect()->route('members.show', $logged->getId());
68
        }
69
70
        $withBirthday = $this->members->getByBirthdayDate($today);
71
        $attendance = $this->meetings->calculateAttendanceDetails();
72
        $byMembershipStatus = $this->members->countByMembershipStatus();
73
        $perFaculty = json_encode($this->faculties->countPerFaculty());
74
75
        $perMonthAll = $this->membersStats->newMembersMonthlyLastYear();
76
77
        $perMonth = [
78
            'months' => json_encode($perMonthAll->getMonthsTitles()),
79
            'values' => json_encode($perMonthAll->getMonthsValues())
80
        ];
81
82
        $vars = compact('withBirthday', 'attendance', 'byMembershipStatus', 'perFaculty', 'perMonth', 'boardMember');
83
84
        return view('homepage.index', $vars);
85
    }
86
}
87