Passed
Push — master ( c430e0...09e8fc )
by Davide
02:42 queued 11s
created

Teacher   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 12
dl 0
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A events() 0 3 1
A eventsByTeacher() 0 11 1
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class Teacher extends Model
8
{
9
    /***************************************************************************/
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'teachers';
16
17
    /***************************************************************************/
18
19
    protected $fillable = [
20
        'name', 'bio', 'country_id', 'year_starting_practice', 'year_starting_teach', 'significant_teachers', 'profile_picture', 'website', 'facebook', 'created_by', 'slug',
21
    ];
22
23
    /**
24
     * Get the events for the teacher.
25
     */
26
    public function events()
27
    {
28
        return $this->belongsToMany('App\Event', 'event_has_teachers', 'teacher_id', 'event_id');
29
    }
30
31
    /***************************************************************************/
32
33
    /**
34
     * Get the events where this teacher is going to teach to.
35
     *
36
     * @param  \DavideCasiraghi\LaravelEventsCalendar\Models\Teacher  $teacher
37
     * @return \Illuminate\Http\Response
38
     */
39
    public static function eventsByTeacher($teacher, $lastestEventsRepetitionsQuery, $searchStartDate)
40
    {
41
        $ret = $teacher->events()
42
                         ->select('events.title', 'events.category_id', 'events.slug', 'events.venue_id', 'events.sc_venue_name', 'events.sc_country_name', 'events.sc_city_name', 'events.sc_teachers_names', 'event_repetitions.start_repeat', 'event_repetitions.end_repeat')
43
                         ->joinSub($lastestEventsRepetitionsQuery, 'event_repetitions', function ($join) use ($searchStartDate) {
0 ignored issues
show
Unused Code introduced by
The import $searchStartDate is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
44
                             $join->on('events.id', '=', 'event_repetitions.event_id');
45
                         })
46
                         ->orderBy('event_repetitions.start_repeat', 'asc')
47
                         ->get();
48
49
        return $ret;
50
    }
51
}
52