Completed
Pull Request — master (#14)
by claudio
10:12
created

Planner::verifyCalendar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4286
cc 1
eloc 2
nc 1
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
 */
35
class Planner extends Employee
36
{
37
38 6
    public function groupsManaged()
39
    {
40 6
        return $this->HasMany(Group::class);
41
    }
42
43
    /*
44
    * for a planer employee the policyCheckable methods say if the planer can modify or not that part
45
    */
46
47
    /**
48
     * @param Group $group
49
     * @return bool
50
     */
51 4
    public function verifyGroup(Group $group)
52
    {
53 4
        $group = $this->groupsManaged()->where('id', $group->id)->first();
54
55 4
        return (is_object($group) && $group->exists);
56
    }
57
58
    /**
59
     * @param Employee $employee
60
     * @return bool
61
     */
62
    public function verifyEmployee(Employee $employee)
63
    {
64
        $group = $this->groupsManaged()->whereHas('employees',function ($query) use ($employee) {$query->where('employees.id', $employee->id);})->first();
65
66
        return (is_object($group) && $group->exists);
67
    }
68
69
    /**
70
     * @param Company $company
71
     * @return bool
72
     */
73
    public function verifyCompany(Company $company)
74
    {
75
        return false;
76
    }
77
78
    /**
79
     * the employee can see a calendar
80
     * @param Calendar $calendar
81
     * @return bool
82
     */
83
    public function verifyCalendar(Calendar $calendar)
84
    {
85
        //TODO implement and test
86
        return false;
87
    }
88
}
89