1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace FaithGen\News\Policies; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use FaithGen\News\Helpers\NewsHelper; |
7
|
|
|
use FaithGen\News\Models\News; |
8
|
|
|
use FaithGen\SDK\Models\Ministry; |
9
|
|
|
use Illuminate\Auth\Access\HandlesAuthorization; |
10
|
|
|
|
11
|
|
|
class NewsPolicy |
12
|
|
|
{ |
13
|
|
|
use HandlesAuthorization; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Determine whether the user can view any news. |
17
|
|
|
* |
18
|
|
|
* @param \App\Models\Ministry $user |
19
|
|
|
* @return mixed |
20
|
|
|
*/ |
21
|
|
|
public function viewAny(Ministry $user) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
// |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Determine whether the user can view the news. |
28
|
|
|
* |
29
|
|
|
* @param Ministry $user |
30
|
|
|
* @param News $news |
31
|
|
|
* @return mixed |
32
|
|
|
*/ |
33
|
|
|
public function view(Ministry $user, News $news) |
34
|
|
|
{ |
35
|
|
|
return $user->id === $news->ministry_id; |
|
|
|
|
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Determine whether the user can create news. |
40
|
|
|
* |
41
|
|
|
* @param Ministry $user |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function create(Ministry $user) |
45
|
|
|
{ |
46
|
|
|
if ($user->account->level !== 'Free') { |
47
|
|
|
return true; |
48
|
|
|
} else { |
49
|
|
|
$newsCount = News::where('ministry_id', $user->id)->whereBetween('created_at', [Carbon::now()->firstOfMonth(), Carbon::now()->lastOfMonth()])->count(); |
50
|
|
|
if ($newsCount >= NewsHelper::$freeNewsCount) { |
51
|
|
|
return false; |
52
|
|
|
} else { |
53
|
|
|
return true; |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Determine whether the user can update the news. |
60
|
|
|
* |
61
|
|
|
* @param \App\Models\Ministry $user |
62
|
|
|
* @param News $news |
63
|
|
|
* @return mixed |
64
|
|
|
*/ |
65
|
|
|
public function update(Ministry $user, News $news) |
66
|
|
|
{ |
67
|
|
|
return $user->id === $news->ministry_id; |
|
|
|
|
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Determine whether the user can delete the news. |
72
|
|
|
* |
73
|
|
|
* @param \App\Models\Ministry $user |
74
|
|
|
* @param News $news |
75
|
|
|
* @return mixed |
76
|
|
|
*/ |
77
|
|
|
public static function delete(Ministry $user, News $news) |
78
|
|
|
{ |
79
|
|
|
return $user->id === $news->ministry_id; |
|
|
|
|
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.