1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
|
7
|
|
|
class EventRepetition extends Model |
8
|
|
|
{ |
9
|
|
|
/***************************************************************************/ |
10
|
|
|
/** |
11
|
|
|
* The table associated with the model. |
12
|
|
|
* |
13
|
|
|
* @var string |
14
|
|
|
*/ |
15
|
|
|
protected $table = 'event_repetitions'; |
16
|
|
|
|
17
|
|
|
/***************************************************************************/ |
18
|
|
|
|
19
|
|
|
protected $fillable = [ |
20
|
|
|
'event_id', 'start_repeat', 'end_repeat', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
public function user() |
24
|
|
|
{ |
25
|
|
|
return $this->belongsTo('App\Event', 'event_id', 'id'); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/***************************************************************************/ |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get for each event the first event repetition in the near future (JUST THE QUERY to use as SUBQUERY). |
32
|
|
|
* Parameters are Start date and End date of the interval |
33
|
|
|
* Return the query string,. |
34
|
|
|
* @param string $searchStartDate |
35
|
|
|
* @param string $searchEndDate |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
public static function getLastestEventsRepetitionsQuery($searchStartDate, $searchEndDate) |
39
|
|
|
{ |
40
|
|
|
$ret = self:: |
41
|
|
|
selectRaw('event_id, MIN(id) AS rp_id, start_repeat, end_repeat') |
42
|
|
|
->when($searchStartDate, function ($query, $searchStartDate) { |
43
|
|
|
return $query->where('event_repetitions.start_repeat', '>=', $searchStartDate); |
44
|
|
|
}) |
45
|
|
|
->when($searchEndDate, function ($query, $searchEndDate) { |
46
|
|
|
return $query->where('event_repetitions.end_repeat', '<=', $searchEndDate); |
47
|
|
|
}) |
48
|
|
|
->groupBy('event_id'); |
49
|
|
|
|
50
|
|
|
return $ret; |
51
|
|
|
} |
52
|
|
|
} |
53
|
|
|
|