Skip to content

Commit

Permalink
add notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamadmurad committed Jul 17, 2022
1 parent a03d7f0 commit 4b919ad
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 74 deletions.
8 changes: 8 additions & 0 deletions app/Http/Controllers/AssignmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers;

use App\Helpers\MainHelper;
use App\Models\Assignment;
use App\Models\AssignmentSubmit;
use App\Models\assignmentSubmitObjectives;
Expand Down Expand Up @@ -189,6 +190,13 @@ public function submitMark(Request $request,Subject $subject, Assignment $assign
'status' => 1,
]);

(new MainHelper)->notify_user([
'user_id'=>$submit->student_id,
'message'=>"Your assignment $assignment->name has been marked " ,
'url'=>"http://example.com",
'methods'=>['database']
]);

return redirect()->back();
}
}
17 changes: 17 additions & 0 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Controllers\Auth;

use App\Helpers\MainHelper;
use App\Http\Controllers\Controller;
use App\Models\User;
use App\Providers\RouteServiceProvider;
Expand Down Expand Up @@ -60,13 +61,29 @@ public function store(Request $request)
if ($request->get('status') == 0) {
$user->update(['is_verified' => 1]);
$user->syncRoles(['student']);

(new MainHelper)->notify_user([
'user_id'=>1,
'message'=>"New Student Account $user->email" ,
'url'=>"http://example.com",
'methods'=>['database']
]);

} else {

$user->syncRoles(['teacher']);
if ($request->hasFile('cert_img')) {
//$user->hasMedia('certificate') ? $teacher->getFirstMedia('certificate')->delete(): null;
$user->addMediaFromRequest('cert_img')->toMediaCollection('certificate');
}

(new MainHelper)->notify_user([
'user_id'=>1,
'message'=>"New Teacher Account $user->email need to active" ,
'url'=>"http://example.com",
'methods'=>['database']
]);

}
event(new Registered($user));

Expand Down
17 changes: 16 additions & 1 deletion app/Http/Controllers/EnrollController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function enroll(Subject $subject){
'points' => 0,
]);
(new MainHelper)->notify_user([
'user_id'=>1,
'user_id'=>$subject->creator_id,
'message'=>"Student $user->name has enroll $subject->name Subject" ,
'url'=>"http://example.com",
'methods'=>['database']
Expand Down Expand Up @@ -88,6 +88,14 @@ public function markObjSeed(Subject $subject, Objective $objective)
// $user->seen()->attach($objective->id);
// event(new objective_complete($user, $objective, $subject));


(new MainHelper)->notify_user([
'user_id'=>$subject->creator_id,
'message'=>"Student $user->name has been complete $objective->name" ,
'url'=>"http://example.com",
'methods'=>['database']
]);

DB::commit();
} catch (\Exception $e) {
DB::rollBack();
Expand Down Expand Up @@ -135,6 +143,13 @@ public function assignmentStore(Request $request,Subject $subject, Assignment $a
if ($request->hasFile('file')) {
$submit->addMediaFromRequest('file')->toMediaCollection('submit_file');
}
$user = Auth::user();
(new MainHelper)->notify_user([
'user_id'=>$subject->creator_id,
'message'=>"Student $user->name has been submit assignment $assignment->name" ,
'url'=>"http://example.com",
'methods'=>['database']
]);

$this->successFlash('Submitted');
return redirect()->back();
Expand Down
24 changes: 19 additions & 5 deletions app/Http/Controllers/ExamFrontController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Events\exam_complete;
use App\Events\exam_fail;
use App\Events\placement_complete;
use App\Helpers\MainHelper;
use App\Models\Exam;
use App\Models\ExamSubmit;
use App\Models\Placement;
Expand Down Expand Up @@ -65,6 +66,13 @@ public function store(Request $request, Subject $subject, Exam $exam)
event(new exam_fail($subject, $exam, $final_mark));
}

$user = Auth::user();
(new MainHelper)->notify_user([
'user_id' => $subject->creator_id,
'message' => "Student $user->name has been submit Exam $exam->name",
'url' => "http://example.com",
'methods' => ['database']
]);

DB::commit();
} catch (\Exception $e) {
Expand Down Expand Up @@ -132,18 +140,24 @@ public function storePlacement(Request $request, Subject $subject, Placement $pl
'correct' => $isCorrect,
]);

if ($isCorrect){
$user =Auth::user();
if ($isCorrect) {
$user = Auth::user();
$objective = $question->objective;
$this->objectiveSeen($user,$objective,$subject);
$this->objectiveSeen($user, $objective, $subject);

}
}
}


event(new placement_complete($subject,$placement));

event(new placement_complete($subject, $placement));
$user = Auth::user();
(new MainHelper)->notify_user([
'user_id' => $subject->creator_id,
'message' => "Student $user->name has been submit placement $placement->name",
'url' => "http://example.com",
'methods' => ['database']
]);
// dd($request->all());

DB::commit();
Expand Down
10 changes: 6 additions & 4 deletions app/Http/Controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

use Illuminate\Http\Request;
use App\View\Components\Notifications as NotificationComponent;
use Illuminate\Support\Facades\Auth;

class NotificationsController extends Controller
{
public function index(Request $request){
auth()->user()->unreadNotifications->markAsRead();
$notifications = \Auth::user()->notifications()->simplePaginate();
$notifications = Auth::user()->notifications()->simplePaginate();
return view('admin.notifications.index',compact('notifications'));
}
public function notifications_see(Request $request){
Expand All @@ -18,7 +20,7 @@ public function notifications_see(Request $request){

public function notifications_ajax(Request $request){

$notifications = \Auth::user()->notifications()->limit(15)->get();
$notifications = Auth::user()->notifications()->limit(15)->get();
$not_response = array(
'response' => (new NotificationComponent($notifications))->render(1),
'count_unseen_notifications' => intval($notifications->whereNull('read_at')->count()),
Expand All @@ -32,8 +34,8 @@ public function notifications_ajax(Request $request){
];

if ($data['notifications']['counter_session'] < $not_response['count_unseen_notifications'])
$data['alert'] = true;
$data['alert'] = true;

session(['seen_notifications' => $not_response['count_unseen_notifications']]);
return $data;
}
Expand Down
8 changes: 8 additions & 0 deletions app/Http/Livewire/SubjectReviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire;

use App\Helpers\MainHelper;
use App\Models\Subject;
use Illuminate\Support\Facades\Auth;
use Livewire\Component;
Expand Down Expand Up @@ -49,6 +50,13 @@ public function submit()
$this->reviews = $this->subject->reviews()->get();
$this->reviewsCount = $this->subject->reviews()->count();

$user = Auth::user();
(new MainHelper)->notify_user([
'user_id' => $this->subject->creator_id,
'message' => "Student $user->name has been review subject $this->subject->name",
'url' => "http://example.com",
'methods' => ['database']
]);
$this->emitTo('subject-rate', 'refreshComponent');
}
}
33 changes: 33 additions & 0 deletions app/View/Components/Notifications.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace App\View\Components;

use Illuminate\View\Component;

class Notifications extends Component
{
/**
* Create a new component instance.
*
* @return void
*/
public $notifications;
public function __construct($notifications)
{
$this->notifications=$notifications;
}

/**
* Get the view / contents that represent the component.
*
* @return \Illuminate\Contracts\View\View|\Closure|string
*/
public function render($render=null)
{
$notifications=$this->notifications;
return (null!==$render)?view('components.notifications',compact('notifications'))->render():view('components.notifications');
}
}



Binary file added public/sounds/notification.wav
Binary file not shown.
52 changes: 52 additions & 0 deletions resources/views/components/notifications.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@if(isset($notifications))
@foreach($notifications as $notification)
@php
$bg = $notification['read_at']==null ?"#f1f1f1":"#ffffff";
@endphp
<li class="mb-2 dropdown-item border-radius-md">
{{-- <a class="dropdown-item border-radius-md" href="javascript:;" style="background:{{$bg}} ">--}}
<div class="d-flex py-1">
{{-- <div class="my-auto">--}}
{{-- <img--}}
{{-- --}}{{-- src="./assets/img/team-2.jpg"--}}
{{-- @if(isset($notification['image']) && $notification['image']!=null)--}}
{{-- src="{{$notification['image']}}"--}}
{{-- @else--}}
{{-- src="{{ env('DEFAULT_IMAGE_NOTIFICATION') }}"--}}
{{-- @endif--}}
{{-- class="avatar avatar-sm me-3 ">--}}
{{-- </div>--}}
<div class="d-flex flex-column justify-content-center">
<h6 class="text-sm font-weight-normal mb-1">
@if($notification['read_at']==null)
<span
class="font-weight-bold">New Notification</span>
@endif
{!!$notification->data['message']!!}
</h6>
<p class="text-xs text-secondary mb-0">
<i class="fa fa-clock me-1" aria-hidden="true"></i>
{{\Illuminate\Support\Carbon::parse($notification['created_at'])->diffForHumans()}}
</p>
</div>
</div>
{{-- </a>--}}
</li>
@endforeach
@if(count($notifications)==0)
<li class="mb-2">

<div class="d-flex py-1">

<div class="d-flex flex-column justify-content-center">
<h6 class="text-sm font-weight-normal mb-1">
No Notification
</h6>

</div>
</div>

</li>

@endif
@endif
4 changes: 2 additions & 2 deletions resources/views/layouts/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
{{-- <meta name="csrf-token" content="{{ csrf_token() }}">--}}
<meta name="csrf-token" content="{{ csrf_token() }}">

{{-- <title>{{ config('app.name', 'Laravel') }}</title>--}}
<title>{{ config('app.name', 'Laravel') }}</title>


<!-- Styles -->
Expand Down
8 changes: 4 additions & 4 deletions resources/views/layouts/nav.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@
@endif
left: -18px; top: 0px; border-radius: 50%; background: #c00; color: #fff; font-size: 14px; justify-content: center; align-items: center;" id="dropdown-notifications-icon">{{$unreadNotifications}}</span>
</a>
<ul class="dropdown-menu dropdown-menu-end px-2 py-3 me-sm-n4" aria-labelledby="notificationDropdown">
<ul class="dropdown-menu dropdown-menu-end px-2 py-3 me-sm-n4 notifications-container" aria-labelledby="notificationDropdown">
@foreach($notifications as $notification)
@php
$bg = $notification['read_at']==null ?"#f1f1f1":"#ffffff";
@endphp
<li class="mb-2">
<a class="dropdown-item border-radius-md" href="javascript:;" style="background:{{$bg}} ">
<li class="mb-2 dropdown-item border-radius-md">
{{-- <a class="dropdown-item border-radius-md" href="javascript:;" style="background:{{$bg}} ">--}}
<div class="d-flex py-1">
{{-- <div class="my-auto">--}}
{{-- <img--}}
Expand All @@ -61,7 +61,7 @@ class="font-weight-bold">New Notification</span>
</p>
</div>
</div>
</a>
{{-- </a>--}}
</li>
@endforeach
@if(count($notifications)==0)
Expand Down
Loading

0 comments on commit 4b919ad

Please sign in to comment.