diff --git a/app/Http/Controllers/AssignmentController.php b/app/Http/Controllers/AssignmentController.php index e48ebfd..764052d 100644 --- a/app/Http/Controllers/AssignmentController.php +++ b/app/Http/Controllers/AssignmentController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Helpers\MainHelper; use App\Models\Assignment; use App\Models\AssignmentSubmit; use App\Models\assignmentSubmitObjectives; @@ -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(); } } diff --git a/app/Http/Controllers/Auth/RegisteredUserController.php b/app/Http/Controllers/Auth/RegisteredUserController.php index 8a1716f..6867b83 100644 --- a/app/Http/Controllers/Auth/RegisteredUserController.php +++ b/app/Http/Controllers/Auth/RegisteredUserController.php @@ -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; @@ -60,6 +61,14 @@ 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']); @@ -67,6 +76,14 @@ public function store(Request $request) //$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)); diff --git a/app/Http/Controllers/EnrollController.php b/app/Http/Controllers/EnrollController.php index cc7b44c..621eee6 100644 --- a/app/Http/Controllers/EnrollController.php +++ b/app/Http/Controllers/EnrollController.php @@ -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'] @@ -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(); @@ -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(); diff --git a/app/Http/Controllers/ExamFrontController.php b/app/Http/Controllers/ExamFrontController.php index e779722..7cc444d 100644 --- a/app/Http/Controllers/ExamFrontController.php +++ b/app/Http/Controllers/ExamFrontController.php @@ -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; @@ -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) { @@ -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(); diff --git a/app/Http/Controllers/NotificationsController.php b/app/Http/Controllers/NotificationsController.php index c0edc76..62accfe 100644 --- a/app/Http/Controllers/NotificationsController.php +++ b/app/Http/Controllers/NotificationsController.php @@ -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){ @@ -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()), @@ -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; } diff --git a/app/Http/Livewire/SubjectReviews.php b/app/Http/Livewire/SubjectReviews.php index e544791..ccb41fb 100644 --- a/app/Http/Livewire/SubjectReviews.php +++ b/app/Http/Livewire/SubjectReviews.php @@ -2,6 +2,7 @@ namespace App\Http\Livewire; +use App\Helpers\MainHelper; use App\Models\Subject; use Illuminate\Support\Facades\Auth; use Livewire\Component; @@ -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'); } } diff --git a/app/View/Components/Notifications.php b/app/View/Components/Notifications.php new file mode 100644 index 0000000..1c5af0d --- /dev/null +++ b/app/View/Components/Notifications.php @@ -0,0 +1,33 @@ +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'); + } +} + + + \ No newline at end of file diff --git a/public/sounds/notification.wav b/public/sounds/notification.wav new file mode 100644 index 0000000..d2d34f1 Binary files /dev/null and b/public/sounds/notification.wav differ diff --git a/resources/views/components/notifications.blade.php b/resources/views/components/notifications.blade.php new file mode 100644 index 0000000..3cc65a4 --- /dev/null +++ b/resources/views/components/notifications.blade.php @@ -0,0 +1,52 @@ +@if(isset($notifications)) + @foreach($notifications as $notification) + @php + $bg = $notification['read_at']==null ?"#f1f1f1":"#ffffff"; + @endphp + + @endforeach +@if(count($notifications)==0) +
  • + +
    + +
    +
    + No Notification +
    + +
    +
    + +
  • + +@endif +@endif diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index 280d561..e5d3d02 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -3,9 +3,9 @@ -{{-- --}} + -{{-- {{ config('app.name', 'Laravel') }}--}} + {{ config('app.name', 'Laravel') }} diff --git a/resources/views/layouts/nav.blade.php b/resources/views/layouts/nav.blade.php index 1b2be9d..3de8424 100644 --- a/resources/views/layouts/nav.blade.php +++ b/resources/views/layouts/nav.blade.php @@ -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}} -