Skip to content

Commit

Permalink
add notification page
Browse files Browse the repository at this point in the history
  • Loading branch information
t0n1zz committed Dec 10, 2018
1 parent 21f1863 commit 19a60ee
Show file tree
Hide file tree
Showing 13 changed files with 2,644 additions and 1,939 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/LaporanCuDiskusiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function store(Request $request)

$kelas = LaporanCuDiskusi::create($request->all());

$this->store_notification($request,'Menulis');
$this->store_notification($request,'Menambah');

return response()
->json([
Expand Down
84 changes: 84 additions & 0 deletions app/Http/Controllers/NotificationController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Http\Controllers;

use Auth;
use Response;
use App\User;
use Illuminate\Http\Request;

class NotificationController extends Controller
{

public function get()
{
$id = auth('api')->user()->getId();
$kelas = User::findOrFail($id);
$notification = collect();
$unreadNotification = count($kelas->unreadNotifications);

$i = 0;
foreach ($kelas->notifications as $notif) {
$username = User::where('id',$notif->data['user'])->select('name')->first();

$n = collect($notif);
$n->put('user',$username);
$notification->push($n);
if (++$i == 15) break;
}

return response()
->json([
'notification' => $notification,
'unreadNotification' => $unreadNotification
]);
}

public function getAll()
{
$id = auth('api')->user()->getId();
$kelas = User::findOrFail($id);
$notification = collect();
$unreadNotification = count($kelas->unreadNotifications);

$i = 0;
foreach ($kelas->notifications as $notif) {
$username = User::where('id',$notif->data['user'])->select('name')->first();

$n = collect($notif);
$n->put('user',$username);
$notification->push($n);
if (++$i == 50) break;
}

return response()
->json([
'notification' => $notification,
'unreadNotification' => $unreadNotification
]);
}

public function markRead($id)
{
auth('api')->user()->unreadNotifications->where('id', $id)->markAsRead();

return response()
->json([
'marked' => true
]);
}

public function markAllRead()
{
$id = Auth::user('api')->getId();

$kelas = User::findOrFail($id);

$kelas->unreadNotifications->markAsRead();

return response()
->json([
'marked' => true
]);
}
}
74 changes: 0 additions & 74 deletions app/Http/Controllers/SystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

namespace App\Http\Controllers;

use Auth;
use Response;
use App\User;
use Illuminate\Http\Request;

class SystemController extends Controller
Expand All @@ -16,77 +14,5 @@ public function download_file($filename){

return Response::download($file);
}

public function getNotif()
{
$id = auth('api')->user()->getId();
$kelas = User::findOrFail($id);
$notification = collect();
$unreadNotification = count($kelas->unreadNotifications);

$i = 0;
foreach ($kelas->notifications as $notif) {
$username = User::where('id',$notif->data['user'])->select('name')->first();

$n = collect($notif);
$n->put('user',$username);
$notification->push($n);
if (++$i == 15) break;
}

return response()
->json([
'notification' => $notification,
'unreadNotification' => $unreadNotification
]);
}

public function getNotifAll()
{
$id = auth('api')->user()->getId();
$kelas = User::findOrFail($id);
$notification = collect();
$unreadNotification = count($kelas->unreadNotifications);

$i = 0;
foreach ($kelas->notifications as $notif) {
$username = User::where('id',$notif->data['user'])->select('name')->first();

$n = collect($notif);
$n->put('user',$username);
$notification->push($n);
}

return response()
->json([
'notification' => $notification,
'unreadNotification' => $unreadNotification
]);
}


public function markAllNotifRead()
{
$id = Auth::user('api')->getId();

$kelas = User::findOrFail($id);

$kelas->unreadNotifications->markAsRead();

return response()
->json([
'marked' => true
]);
}

public function markNotifRead($id)
{
auth('api')->user()->unreadNotifications->where('id', $id)->markAsRead();

return response()
->json([
'marked' => true
]);
}

}
Loading

0 comments on commit 19a60ee

Please sign in to comment.