From 3e1ed6757a6629a385ae46a580a1346fb0aa128d Mon Sep 17 00:00:00 2001 From: David <davidkwan95@gmail.com> Date: Tue, 17 May 2016 08:13:06 +0700 Subject: [PATCH] add notification (not completed) --- .../Http/Controllers/VendorUserController.php | 4 ++ IES-Bandung/app/Model/Notification.php | 39 +++++++++++++++++++ IES-Bandung/app/Model/Recommendation.php | 2 +- .../2016_05_17_001045_notification.php | 30 ++++++++++++++ .../views/layouts/dropdownLoggedIn.blade.php | 12 +++++- 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100644 IES-Bandung/app/Model/Notification.php create mode 100644 IES-Bandung/database/migrations/2016_05_17_001045_notification.php diff --git a/IES-Bandung/app/Http/Controllers/VendorUserController.php b/IES-Bandung/app/Http/Controllers/VendorUserController.php index 45b9a42..a95d394 100644 --- a/IES-Bandung/app/Http/Controllers/VendorUserController.php +++ b/IES-Bandung/app/Http/Controllers/VendorUserController.php @@ -10,6 +10,7 @@ use App\Model\VendorUser; use App\Model\VendorRateAndReview; use App\Model\ObjectSell; use App\Model\Recommendation; +use App\Model\Notification; use Auth; class VendorUserController extends Controller @@ -33,6 +34,8 @@ class VendorUserController extends Controller $loggedInUserId = Auth::user()['id']; $isRecommended = count(Recommendation::getRecommendation($loggedInUserId, $vendorId))>0; + $recommendationReceivedSinceLastRead = $loggedInUserId === $vendorId?Notification::countRecommendationReceivedSinceLastRead($vendorId):0; + return view('vendorUser', [ 'editable' => $editable, 'user' => $user, @@ -42,6 +45,7 @@ class VendorUserController extends Controller 'userId' => $loggedInUserId, 'vendorId' => $vendorId, 'recommendation' => $recommendation, + 'recommendationReceivedSinceLastRead' => $recommendationReceivedSinceLastRead, 'isRecommended' => $isRecommended]); } diff --git a/IES-Bandung/app/Model/Notification.php b/IES-Bandung/app/Model/Notification.php new file mode 100644 index 0000000..72b3ac8 --- /dev/null +++ b/IES-Bandung/app/Model/Notification.php @@ -0,0 +1,39 @@ +<?php + +namespace App\Model; + +use Illuminate\Database\Eloquent\Model; +use App\Model\Recommendation; +use App\User; + +class Notification extends Model +{ + protected $table = 'notification'; + + public static function getLastNotificationReadTime($vendorId){ + $time = Notification:: + where('vendor_id', '=', $vendorId) + ->first(); + + if(count($time) == 0){ + $model = new Notification; + $model->vendor_id = $vendorId; + $model->save(); + echo $model; + return $model['updated_at']; + } else { + return $time['updated_at']; + } + } + + public static function countRecommendationReceivedSinceLastRead($vendorId) { + $lastRead = Notification::getLastNotificationReadTime($vendorId); + + return Recommendation:: + where('vendor_id', '=', $vendorId) + ->where('updated_at', '>', $lastRead) + ->get() + ->count('vendor_id'); + } + +} diff --git a/IES-Bandung/app/Model/Recommendation.php b/IES-Bandung/app/Model/Recommendation.php index 4fc7906..bceb853 100644 --- a/IES-Bandung/app/Model/Recommendation.php +++ b/IES-Bandung/app/Model/Recommendation.php @@ -31,7 +31,7 @@ class Recommendation extends Model return Recommendation:: where('vendor_id', '=', $vendorId) ->get() - ->sum('vendor_id'); + ->count('vendor_id'); } } diff --git a/IES-Bandung/database/migrations/2016_05_17_001045_notification.php b/IES-Bandung/database/migrations/2016_05_17_001045_notification.php new file mode 100644 index 0000000..5a0001c --- /dev/null +++ b/IES-Bandung/database/migrations/2016_05_17_001045_notification.php @@ -0,0 +1,30 @@ +<?php + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; + +class Notification extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('notification', function (Blueprint $table) { + $table->integer('vendor_id'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +} diff --git a/IES-Bandung/resources/views/layouts/dropdownLoggedIn.blade.php b/IES-Bandung/resources/views/layouts/dropdownLoggedIn.blade.php index 526f816..e3d183d 100644 --- a/IES-Bandung/resources/views/layouts/dropdownLoggedIn.blade.php +++ b/IES-Bandung/resources/views/layouts/dropdownLoggedIn.blade.php @@ -1,14 +1,22 @@ +{{ $notif = isset($recommendationReceivedSinceLastRead)? $recommendationReceivedSinceLastRead:0}} <li class="dropdown"> <a href="#" data-toggle="dropdown" class="dropdown-toggle"> <i class="icon-bdg_alert text14"></i> <span class="visible-xs-inline">Notifikasi</span> - <span class="badge badge-sm up bg-dark pull-right-xs">1</span> + <span class="badge badge-sm up bg-dark pull-right-xs">{{ $notif }}</span> </a> <!-- dropdown --> <div class="dropdown-menu w-xl animated fadeIn"> <div class="panel bg-white"> <div class="panel-heading b-light bg-light"> - <strong>Kamu Punya <span>1</span> Notifikasi</strong> + <strong>Kamu Punya <span>{{ $notif?1:0 }}</span> Notifikasi baru</strong> + </div> + <div class="list-group" {{ $notif?"":"hidden" }} > + <a href class="list-group-item"> + <span class="clear block m-b-none"> + {{ $notif }} user merekomendasikanmu<br> + </span> + </a> </div> <div class="list-group"> <a href class="list-group-item"> -- GitLab