|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Crocodicstudio\Crudbooster\Modules\NotificationsModule; |
|
4
|
|
|
|
|
5
|
|
|
use Crocodicstudio\Crudbooster\controllers\CBController; |
|
6
|
|
|
|
|
7
|
|
|
class AdminNotificationsController extends CBController |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* AdminNotificationsController constructor. |
|
11
|
|
|
*/ |
|
12
|
|
|
public function __construct() |
|
13
|
|
|
{ |
|
14
|
|
|
$this->table = "cms_notifications"; |
|
15
|
|
|
$this->primaryKey = "id"; |
|
16
|
|
|
$this->titleField = "content"; |
|
17
|
|
|
$this->limit = 20; |
|
18
|
|
|
$this->orderby = ["id" => "desc"]; |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
public function cbInit() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setButtons(); |
|
24
|
|
|
$this->makeColumns(); |
|
25
|
|
|
|
|
26
|
|
|
$this->form = NotificationForm::makeForm(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
private function setButtons() |
|
30
|
|
|
{ |
|
31
|
|
|
$this->buttonAdd = false; |
|
32
|
|
|
$this->buttonExport = false; |
|
33
|
|
|
$this->buttonImport = false; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
private function makeColumns() |
|
37
|
|
|
{ |
|
38
|
|
|
$read_notification_url = url(cbAdminPath()).'/notifications/read'; |
|
39
|
|
|
|
|
40
|
|
|
$this->col = [ |
|
41
|
|
|
[ |
|
42
|
|
|
"label" => "Content", |
|
43
|
|
|
"name" => "content", |
|
44
|
|
|
"callback_php" => '"<a href=\"'.$read_notification_url.'/$row->id\">$row->content</a>"' |
|
45
|
|
|
], |
|
46
|
|
|
[ |
|
47
|
|
|
'label' => 'Read', |
|
48
|
|
|
'name' => 'is_read', |
|
49
|
|
|
'callback_php' => '($row->is_read)?"<span class=\"label label-default\">Already Read</span>":"<span class=\"label label-danger\">NEW</span>"', |
|
50
|
|
|
], |
|
51
|
|
|
]; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function hookQueryIndex($query) |
|
55
|
|
|
{ |
|
56
|
|
|
$query->where('cms_users_id', auth('cbAdmin')->id()); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function getLatestJson() |
|
60
|
|
|
{ |
|
61
|
|
|
$rows = $this->table() |
|
62
|
|
|
->where('cms_users_id', 0) |
|
63
|
|
|
->orWhere('cms_users_id', auth('cbAdmin')->id()) |
|
64
|
|
|
->orderby('id', 'desc') |
|
65
|
|
|
->where('is_read', 0) |
|
66
|
|
|
->whereNull('deleted_at') |
|
67
|
|
|
->take(25) |
|
68
|
|
|
->get(); |
|
69
|
|
|
|
|
70
|
|
|
return response()->json(['items' => $rows, 'total' => count($rows)]); |
|
|
|
|
|
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function getRead($id) |
|
74
|
|
|
{ |
|
75
|
|
|
$this->findRow($id)->update(['is_read' => 1]); |
|
76
|
|
|
$row = $this->findRow($id)->first(); |
|
77
|
|
|
|
|
78
|
|
|
return redirect($row->url); |
|
79
|
|
|
} |
|
80
|
|
|
} |