|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace plunner\Http\Controllers\Employees\Meetings; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Http\Request; |
|
6
|
|
|
use plunner\Http\Controllers\Controller; |
|
7
|
|
|
use plunner\Http\Requests; |
|
8
|
|
|
use plunner\Meeting; |
|
9
|
|
|
|
|
10
|
|
|
class MeetingsController extends Controller |
|
11
|
|
|
{ |
|
12
|
15 |
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
15 |
|
config(['auth.model' => \plunner\Employee::class]); |
|
15
|
15 |
|
config(['jwt.user' => \plunner\Employee::class]); |
|
16
|
15 |
|
$this->middleware('jwt.authandrefresh:mode-en'); |
|
17
|
15 |
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Display a listing of the resource. |
|
21
|
|
|
* |
|
22
|
|
|
* @param Request $request needed for get query to get only current planed meetings |
|
23
|
|
|
* @return \Illuminate\Http\Response |
|
24
|
|
|
*/ |
|
25
|
6 |
|
public function index(Request $request) |
|
26
|
|
|
{ |
|
27
|
6 |
|
$employee = \Auth::user(); |
|
28
|
6 |
|
$meetings = $employee->meetings(); |
|
29
|
6 |
|
if ($request->query('current')) |
|
30
|
3 |
|
$meetings->where(function ($query) { //parenthesis for conditions ...(C1 OR C2)... |
|
31
|
3 |
|
$query->where('start_time', '=', NULL);//to be planned |
|
32
|
|
|
//datetime to consider timezone, don't use mysql NOW() |
|
33
|
3 |
|
$query->orWhere('start_time', '>=', new \DateTime());//planned |
|
34
|
3 |
|
}); |
|
35
|
6 |
|
return $meetings->get(); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Display the specified resource. |
|
40
|
|
|
* |
|
41
|
|
|
* @param int $id |
|
42
|
|
|
* @return \Illuminate\Http\Response |
|
43
|
|
|
*/ |
|
44
|
6 |
|
public function show($id) |
|
45
|
|
|
{ |
|
46
|
6 |
|
$meeting = Meeting::findOrFail($id); |
|
47
|
6 |
|
$this->authorize($meeting); |
|
48
|
3 |
|
return $meeting; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Store a newly created resource in storage. |
|
53
|
|
|
* |
|
54
|
|
|
* @param int $groupId |
|
55
|
|
|
* @param int $meetingId |
|
56
|
|
|
* @return static |
|
57
|
|
|
*/ |
|
58
|
|
|
public function showImage($groupId, $meetingId) |
|
59
|
|
|
{ |
|
60
|
|
|
$group = Group::findOrFail($groupId); |
|
61
|
|
|
$this->authorize($group); |
|
62
|
|
|
$meeting = Group::findOrFail($meetingId); |
|
63
|
|
|
$this->authorize($meeting); |
|
64
|
|
|
$ret = self::getImg($meeting); |
|
65
|
|
|
if ($ret === false) |
|
66
|
|
|
return \Response::json(['error' => 'The file is not uploaded'], 404); |
|
|
|
|
|
|
67
|
|
|
return (new Response($ret, 200)) |
|
68
|
|
|
->header('Content-Type', 'image/jpeg'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
private static function getImg(Meeting $meeting) |
|
72
|
|
|
{ |
|
73
|
|
|
$name = 'meetings/' . $meeting->id; |
|
74
|
|
|
if (!\Storage::exists($name)) |
|
|
|
|
|
|
75
|
|
|
return false; |
|
76
|
|
|
return \Storage::get($name); |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_functionexpects aPostobject, and outputs the author of the post. The base classPostreturns a simple string and outputting a simple string will work just fine. However, the child classBlogPostwhich is a sub-type ofPostinstead decided to return anobject, and is therefore violating the SOLID principles. If aBlogPostwere passed tomy_function, PHP would not complain, but ultimately fail when executing thestrtouppercall in its body.