|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Api\Controllers; |
|
4
|
|
|
|
|
5
|
|
|
use Dingo\Api\Http; |
|
6
|
|
|
use Dingo\Api\Routing\Helpers; |
|
7
|
|
|
use App\User; |
|
8
|
|
|
use App\Notification; |
|
9
|
|
|
use App\NotificationAttrib; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
|
|
12
|
|
|
class NotificationController extends Controller |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
use Helpers; |
|
16
|
|
|
|
|
17
|
|
|
public function __construct() { |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Display a listing of all notifications |
|
22
|
|
|
* |
|
23
|
|
|
* @return \Illuminate\Http\Response |
|
24
|
|
|
*/ |
|
25
|
|
|
public function index(Request $request, $type = null) |
|
26
|
|
|
{ |
|
27
|
|
|
if ($type === 'archive') |
|
28
|
|
|
{ |
|
29
|
|
|
//$notifications = Notification::read([$request->user()->user_id])->limit()->get(); |
|
|
|
|
|
|
30
|
|
|
$notifications = Notification::select('notifications.*','key')->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->where('user_id', $user_id)->where(['key'=>'read', 'value'=> 1]); |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
else { |
|
33
|
|
|
//$notifications = Notification::unread()->limit()->get(); |
|
|
|
|
|
|
34
|
|
|
$notifications = Notification::select('notifications.*','key')->leftJoin('notifications_attribs', 'notifications.notifications_id', '=', 'notifications_attribs.notifications_id')->whereNull('user_id')->orWhere(['key'=>'sticky', 'value'=> 1])->get(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
if ($request->query('displayFormat') == 'human') { |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
return $notifications; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function update(Request $request, $id, $action) |
|
43
|
|
|
{ |
|
44
|
|
|
if ($action === 'read' || $action === 'sticky') |
|
45
|
|
|
{ |
|
46
|
|
|
if (NotificationAttrib::where('notifications_id', $id)->delete() >= 0) |
|
47
|
|
|
{ |
|
48
|
|
|
$read = new NotificationAttrib; |
|
49
|
|
|
$read->notifications_id = $id; |
|
|
|
|
|
|
50
|
|
|
$read->user_id = $request->user()->user_id; |
|
|
|
|
|
|
51
|
|
|
$read->key = $action; |
|
|
|
|
|
|
52
|
|
|
$read->value = 1; |
|
|
|
|
|
|
53
|
|
View Code Duplication |
if ($read->save()) |
|
|
|
|
|
|
54
|
|
|
{ |
|
55
|
|
|
return $this->response->array(array('statusText'=>'OK')); |
|
56
|
|
|
} |
|
57
|
|
|
else { |
|
58
|
|
|
return $this->response->errorInternal(); |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
} |
|
62
|
|
|
elseif ($action === 'unread' || $action === 'unsticky') |
|
63
|
|
|
{ |
|
64
|
|
View Code Duplication |
if (NotificationAttrib::where('notifications_id', $id)->delete() >= 0) |
|
|
|
|
|
|
65
|
|
|
{ |
|
66
|
|
|
return $this->response->array(array('statusText'=>'OK')); |
|
67
|
|
|
} |
|
68
|
|
|
else { |
|
69
|
|
|
return $this->response->errorInternal(); |
|
70
|
|
|
} |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
} |
|
75
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.