Company::verifyMeeting()   A
last analyzed

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 0
Metric Value
dl 0
loc 5
ccs 0
cts 2
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace plunner;
4
5
use Illuminate\Auth\Authenticatable;
6
use Illuminate\Auth\Passwords\CanResetPassword;
7
use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
8
use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
9
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
10
use Illuminate\Database\Eloquent\Model;
11
use Illuminate\Foundation\Auth\Access\Authorizable;
12
13
/**
14
 * Class Company
15
 *
16
 * @author Claudio Cardinale <[email protected]>
17
 * @copyright 2015 Claudio Cardinale
18
 * @version 1.0.0
19
 * @package plunner
20
 * @property integer $id
21
 * @property string $name
22
 * @property string $email
23
 * @property string $password
24
 * @property boolean $verified
25
 * @property string $remember_token
26
 * @property \Carbon\Carbon $created_at
27
 * @property \Carbon\Carbon $updated_at
28
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Employee[] $employees
29
 * @property-read \Illuminate\Database\Eloquent\Collection|\plunner\Group[] $groups
30
 */
31
class Company extends Model implements AuthenticatableContract,
32
    AuthorizableContract,
33
    CanResetPasswordContract,
34
    PolicyCheckable
35
{
36
    use Authenticatable, Authorizable, CanResetPassword;
37
38
    /**
39
     * The attributes that are mass assignable.
40
     *
41
     * @var array
42
     */
43
    protected $fillable = ['name', 'email', 'password'];
44
45
    /**
46
     * The attributes excluded from the model's JSON form.
47
     *
48
     * @var array
49
     */
50
    protected $hidden = ['password', 'remember_token'];
51
52
    /**
53
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
54
     */
55 195
    public function employees()
56
    {
57 195
        return $this->hasMany(Employee::class);
58
    }
59
60 84
    public function groups()
61
    {
62 84
        return $this->hasMany(Group::class);
63
    }
64
65
    /**
66
     * @param Group $group
67
     * @return bool
68
     */
69 24
    public function verifyGroup(Group $group)
70
    {
71 24
        return $group->company_id === $this->id;
72
    }
73
74
    /**
75
     * @param Employee $employee
76
     * @return bool
77
     */
78 24
    public function verifyEmployee(Employee $employee)
79
    {
80 24
        return $employee->company_id === $this->id;
81
    }
82
83
    /**
84
     * @param Company $company
85
     * @return bool
86
     */
87
    public function verifyCompany(Company $company)
88
    {
89
        return $company->id === $this->id;
90
    }
91
92
    /**
93
     * @param Calendar $calendar
94
     * @return bool
95
     */
96
    public function verifyCalendar(Calendar $calendar)
97
    {
98
        //TODO test this
99
        return $calendar->employee->company->id == $this->id;
100
    }
101
102
    /**
103
     * @param Timeslot $timeslot
104
     * @return bool
105
     */
106
    public function verifyTimeslot(Timeslot $timeslot)
107
    {
108
        //TODO implement and test this
109
        return false;
110
    }
111
112
    /**
113
     * @param Meeting $meeting
114
     * @return bool
115
     */
116
    public function verifyMeeting(Meeting $meeting)
117
    {
118
        //TODO implement and test this
119
        return false;
120
    }
121
122
    /**
123
     * @param MeetingTimeslot $meetingTimeslot
124
     * @return bool
125
     */
126
    public function verifyMeetingTimeslot(MeetingTimeslot $meetingTimeslot)
127
    {
128
        //TODO implement and test this
129
        return false;
130
    }
131
132
    /**
133
     * @param \DateTime $from
134
     * @param \DateTime $to
135
     * @return \Illuminate\Support\Collection
136
     */
137 6
    public function getEmployeesTimeSlots($from, $to)
138
    {
139 6
        return \DB::table('employees')
140 6
            ->join('calendars', 'employees.id', '=', 'calendars.employee_id')
141 6
            ->join('timeslots', 'calendars.id', '=', 'timeslots.calendar_id')
142 6
            ->where('calendars.enabled', '=', '1')
143 6
            ->where('timeslots.time_start', '>=', $from)
144 6
            ->where('timeslots.time_end', '<=', $to)
145 6
            ->where('employees.company_id', '=', $this->id)
146 6
            ->select('employees.id', 'timeslots.time_start', 'timeslots.time_end')
147 6
            ->get();
148
    }
149
150
    /**
151
     * @param \DateTime $from
152
     * @param \DateTime $to
153
     * @return \Illuminate\Support\Collection
154
     */
155 9
    public function getMeetingsTimeSlots($from, $to)
156
    {
157 9
        return \DB::table('meetings')
158 9
            ->join('groups', 'meetings.group_id', '=', 'groups.id')
159 9
            ->join('meeting_timeslots', 'meetings.id', '=', 'meeting_timeslots.meeting_id')
160 9
            ->where('meeting_timeslots.time_start', '>=', $from)
161 9
            ->where('meeting_timeslots.time_end', '<=', $to)
162 9
            ->where('groups.company_id', '=', $this->id)
163 9
            ->where('meetings.start_time', '=', NULL)
164 9
            ->select('meetings.id', 'meetings.duration', 'meeting_timeslots.time_start', 'meeting_timeslots.time_end')
165 9
            ->get();
166
    }
167
168
    /**
169
     * @param array $users
170
     * @param array $meetings
171
     * @return \Illuminate\Support\Collection
172
     */
173 6
    public function getUsersMeetings(array $users, array $meetings)
174
    {
175 6
        return \DB::table('meetings')
176 6
            ->join('groups', 'meetings.group_id', '=', 'groups.id')
177 6
            ->join('employee_group', 'employee_group.group_id', '=', 'groups.id')
178 6
            ->join('employees', 'employee_group.employee_id', '=', 'employees.id')
179 6
            ->whereIn('employees.id', $users)
180 6
            ->whereIn('meetings.id', $meetings)
181 6
            ->where('groups.company_id', '=', $this->id)//this is not needed
182 6
            ->where('employees.company_id', '=', $this->id)//this is not needed
183 6
            ->select('employees.id as employee_id', 'meetings.id as meeting_id')
184 6
            ->get();
185
    }
186
}
187