| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace App\Http\Controllers\Dev\Notification;
- use App\Http\Controllers\Controller;
- use Illuminate\Http\Request;
- use App\Model\Notification\Notification;
- use App\Model\MetadataProgramNotification;
- use App\Model\TahunProgramDetail;
- use App\Model\MetadataProgramNotificationRead;
- use App\Model\Menu\Module;
- use App\Model\Privillage\Role;
- use App\Model\Region\Provinsi;
- use App\Model\Setting\UPT;
- use Auth;
- class NotificationController extends Controller
- {
- public function __construct()
- {
- $this->middleware('auth');
- }
-
- public function getNotification($id_tahun_program_detail)
- {
- $tahunProgramDetail = TahunProgramDetail::find($id_tahun_program_detail);
- $user = Auth::user();
- if (Role::where('id',Auth::user()->role_id)->value('akses') == 'administrator') {
- $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program)
- ->where('id_template_program_detail',$tahunProgramDetail->id_template_program_detail)
- ->orderBy('id','desc')
- ->get();
- }else{
- $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program)
- ->where('id_template_program_detail',$tahunProgramDetail->id_template_program_detail)
- ->where('id_upt',$user->upt)
- ->orderBy('id','desc')
- ->get();
- }
- $html = '';
- $id = '';
- foreach ($getNotification as $notification) {
- $program = !empty($tahunProgramDetail->templateProgram)?$tahunProgramDetail->templateProgram->nama:'-';
- $sub_program = !empty($tahunProgramDetail->templateProgramDetail)?$tahunProgramDetail->templateProgramDetail->nama:'-';
- if ($notification != '') {
- $html .= '<tr><td>'.$program.'</td><td>'.$notification->message.'</td><td>'.$notification->created_at.'</td></tr>';
- $id .= $notification->id.',';
- }
- else{
- $html = '<tr><td>Tidak Ada Pemberitahuan</td></tr>';
- }
- }
- return response()->json(['html' => $html,'id' => $id]);
- }
- public function updateToRead($id_tahun_program_detail)
- {
- $ok = 'false';
- $tahunProgramDetail = TahunProgramDetail::find($id_tahun_program_detail);
- $user = Auth::user();
-
- if (Role::where('id',Auth::user()->role_id)->value('akses') == 'administrator') {
- $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program)
- ->where('id_template_program',$tahunProgramDetail->id_template_program)
- ->pluck('id');
- }else{
- $getNotification = MetadataProgramNotification::where('id_tahun_program', $tahunProgramDetail->id_tahun_program)
- ->where('id_template_program',$tahunProgramDetail->id_template_program)
- ->where('id_upt',$user->upt)
- ->pluck('id');
- }
- foreach($getNotification as $notif_id){
- $attribute = [
- 'id_user'=> $user->id,
- 'id_metadata_program_notification'=> $notif_id,
- ];
- MetadataProgramNotificationRead::updateOrCreate($attribute,$attribute);
- $ok = 'true';
- }
- return $ok;
- }
- }
|