1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Edofre\Fullcalendar; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Class Fullcalendar |
7
|
|
|
* @package Edofre\Fullcalendar |
8
|
|
|
*/ |
9
|
|
|
class Fullcalendar |
10
|
|
|
{ |
11
|
|
|
/** @var string */ |
12
|
|
|
protected $id = 'fullcalendar'; |
13
|
|
|
/** @var array */ |
14
|
|
|
protected $events = []; |
15
|
|
|
/** @var array */ |
16
|
|
|
protected $defaultOptions = [ |
17
|
|
|
'header' => [ |
18
|
|
|
'left' => 'prev,next today', |
19
|
|
|
'center' => 'title', |
20
|
|
|
'right' => 'month,agendaWeek,agendaDay', |
21
|
|
|
], |
22
|
|
|
'firstDay' => 1, |
23
|
|
|
]; |
24
|
|
|
/** @var array */ |
25
|
|
|
protected $clientOptions = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Renders the view that includes the script files |
29
|
|
|
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View |
30
|
|
|
*/ |
31
|
|
|
public static function renderScriptFiles() |
32
|
|
|
{ |
33
|
|
|
return view('fullcalendar::files', [ |
34
|
|
|
'include_gcal' => config('fullcalendar.enable_gcal'), |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @return string |
40
|
|
|
*/ |
41
|
|
|
public function generate() |
42
|
|
|
{ |
43
|
|
|
return $this->calendar() . $this->script(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create the <div> the calendar will be rendered into |
48
|
|
|
* @return string |
49
|
|
|
*/ |
50
|
|
|
private function calendar() |
51
|
|
|
{ |
52
|
|
|
return "<div id='" . $this->getId() . "'></div>"; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
|
|
public function getId() |
59
|
|
|
{ |
60
|
|
|
return $this->id; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param $id |
65
|
|
|
*/ |
66
|
|
|
public function setId($id) |
67
|
|
|
{ |
68
|
|
|
$this->id = $id; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the <script> block to render the calendar |
73
|
|
|
* @return \Illuminate\View\View |
74
|
|
|
*/ |
75
|
|
|
private function script() |
76
|
|
|
{ |
77
|
|
|
return view('fullcalendar::script', [ |
|
|
|
|
78
|
|
|
'id' => $this->getId(), |
79
|
|
|
'options' => $this->getOptionsJson(), |
80
|
|
|
'include_scripts' => config('fullcalendar.include_scripts', true), |
81
|
|
|
'include_gcal' => config('fullcalendar.enable_gcal', false), |
82
|
|
|
])->render(); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return string |
87
|
|
|
*/ |
88
|
|
|
public function getOptionsJson() |
89
|
|
|
{ |
90
|
|
|
$options = $this->getOptions(); |
91
|
|
|
|
92
|
|
|
if (!isset($options['events'])) { |
93
|
|
|
$options['events'] = $this->events; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
// Encode the JSON properly to format the callbacks |
97
|
|
|
return JsonEncoder::encode($options); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Get the fullcalendar options (not including the events list) |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public function getOptions() |
106
|
|
|
{ |
107
|
|
|
return array_merge($this->defaultOptions, $this->clientOptions); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param array $options |
113
|
|
|
*/ |
114
|
|
|
public function setOptions(array $options) |
115
|
|
|
{ |
116
|
|
|
$this->clientOptions = $options; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @return array |
121
|
|
|
*/ |
122
|
|
|
public function getEvents() |
123
|
|
|
{ |
124
|
|
|
return $this->events; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @param mixed $events |
129
|
|
|
*/ |
130
|
|
|
public function setEvents($events) |
131
|
|
|
{ |
132
|
|
|
$this->events = $events; |
|
|
|
|
133
|
|
|
} |
134
|
|
|
} |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: