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) { |
|
|
|
|
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
|
|
|
|
This check looks for imports that have been defined, but are not used in the scope.