Completed
Push — master ( cb49ac...f14b58 )
by claudio
13:10
created

Planner::verifyGroup()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4286
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace plunner;
4
5
6
/**
7
 * Class Planner
8
 *
9
 * @package plunner
10
 * @author Claudio Cardinale <[email protected]>
11
 * @copyright 2015 Claudio Cardinale
12
 * @version 1.0.0
13
 * @property integer $id
14
 * @property string $name
15
 * @property string $email
16
 * @property string $password
17
 * @property integer $company_id
18
 * @property string $remember_token
19
 * @property \Carbon\Carbon $created_at
20
 * @property \Carbon\Carbon $updated_at
21
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Group[] $groupsManaged
22
 * @property-read \plunner\Company $company
23
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Group[] $groups
24
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Meeting[] $meetings
25
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Calendar[] $calendars
26
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereId($value)
27
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereName($value)
28
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereEmail($value)
29
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner wherePassword($value)
30
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereCompanyId($value)
31
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereRememberToken($value)
32
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereCreatedAt($value)
33
 * @method static \Illuminate\Database\Query\Builder|\plunner\Planner whereUpdatedAt($value)
34
 * @property-read mixed $is_planner
35
 */
36
class Planner extends Employee
37
{
38
39
    /**
40
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
41
     */
42 40
    public function groupsManaged()
43
    {
44 40
        return $this->groupsManagedRelationship();
45
    }
46
47
    /*
48
    * for a planer employee the policyCheckable methods say if the planer can modify or not that part
49
    */
50
51
    /**
52
     * @param Group $group
53
     * @return bool
54
     */
55 38
    public function verifyGroup(Group $group)
56
    {
57 38
        $group = $this->groupsManaged()->where('id', $group->id)->first();
58
59 38
        return (is_object($group) && $group->exists);
60
    }
61
62
    /**
63
     * @param Employee $employee
64
     * @return bool
65
     */
66
    public function verifyEmployee(Employee $employee)
67
    {
68
        $group = $this->groupsManaged()->whereHas('employees',function ($query) use ($employee) {$query->where('employees.id', $employee->id);})->first();
69
70
        return (is_object($group) && $group->exists);
71
    }
72
73
    /**
74
     * @param Company $company
75
     * @return bool
76
     */
77
    public function verifyCompany(Company $company)
78
    {
79
        return false;
80
    }
81
82
    /**
83
     * the employee can see a calendar
84
     * @param Calendar $calendar
85
     * @return bool
86
     */
87
    public function verifyCalendar(Calendar $calendar)
88
    {
89
        //TODO implement and test
90
        return false;
91
    }
92
93
    /**
94
     * @param Timeslot $timeslot
95
     * @return bool
96
     */
97
    public function verifyTimeslot(Timeslot $timeslot)
98
    {
99
        //TODO implement and test this
100
        return false;
101
    }
102
103
    /**
104
     * @param Meeting $meeting
105
     * @return bool
106
     */
107 18
    public function verifyMeeting(Meeting $meeting)
108
    {
109
        //TODO test this
110 18
        return $meeting->group->planner_id == $this->id;
111
    }
112
113
114
    /**
115
     * @param MeetingTimeslot $meetingTimeslot
116
     * @return bool
117
     */
118 8
    public function verifyMeetingTimeslot(MeetingTimeslot $meetingTimeslot)
119
    {
120
        //TODO test this
121 8
        return $this->verifyMeeting($meetingTimeslot->meeting);
122
    }
123
}
124