diff --git a/IES-Bandung/app/Http/Controllers/VendorUserController.php b/IES-Bandung/app/Http/Controllers/VendorUserController.php index 45b9a42ac341846005cf3a01929f9e5d88d379e5..a95d394e8fbccc7f446beb57763f5c583e92769e 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 0000000000000000000000000000000000000000..72b3ac88c1139a1b1dd6c771444c4512d799145f --- /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 4fc79064fd8cadba9cd1ae1a84fbf1fcd3713d93..bceb85331389ba016948fa73318b914ab76acc7a 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 0000000000000000000000000000000000000000..5a0001cfd12c8711bd4a0bc6b62aa6bd9fd9a074 --- /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 526f816638d2d42ae60baa15d18a550d4d9291c6..e3d183d24cb8ca41535de2d114005d6648bdbeb7 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">