1339 lines
		
	
	
		
			49 KiB
		
	
	
	
		
			PHP
		
	
	
			
		
		
	
	
			1339 lines
		
	
	
		
			49 KiB
		
	
	
	
		
			PHP
		
	
	
| <?php
 | |
| 
 | |
| use App\Models\Master\MasterMenu;
 | |
| use App\Models\Master\MasterAccessMenu;
 | |
| use App\Models\Kuesioner;
 | |
| use App\Models\KuesionerLog;
 | |
| use App\Models\Master\FormKriteria;
 | |
| use App\Models\Penilaian;
 | |
| use App\Models\User;
 | |
| use App\Models\Master\Sekolah;
 | |
| use App\Models\SK;
 | |
| use App\Models\Master\MasterGroup;
 | |
| 
 | |
| 
 | |
| if (!function_exists('sekolah')) {
 | |
|     function sekolah($id){
 | |
|         $sekolah = Sekolah::find($id);
 | |
|         return $sekolah;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('listSekolah')) {
 | |
|     function listSekolah($sekolah){
 | |
| 
 | |
| 
 | |
|         $res = "Belum ada data";
 | |
|             $res = [];
 | |
|             $d = '';
 | |
|             foreach (json_decode($sekolah) as $key => $value) {
 | |
|                 $d .= '<span class="badge bg-success-light text-success">'.sekolah($value)->nama_sekolah.'</span><br>';
 | |
|                 
 | |
|             }
 | |
|             array_push($res, $d);
 | |
| 
 | |
|             $res = implode("", $res);
 | |
| 
 | |
|         return $res;
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| if (!function_exists('getPenghargaanTerakhir')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function getPenghargaanTerakhir($sekolah_id)
 | |
|     {
 | |
| 
 | |
|         $usulan = Kuesioner::where('ms_sekolah_id',$sekolah_id)->where('tahun',date('Y'))->first();
 | |
| 
 | |
|         if($usulan->level == 0){
 | |
|             $usulanAwal = 'Belum Pernah';
 | |
|         }elseif($usulan->level == 1){
 | |
|             $usulanAwal = 'Adiwiyata Kab/Kota';
 | |
|         }elseif($usulan->level == 2){
 | |
|             $usulanAwal = 'Adiwiyata Provinsi';
 | |
|         }elseif($usulan->level == 3){
 | |
|             $usulanAwal = 'Adiwiyata Nasional';
 | |
|         }elseif($usulan->level == 4){
 | |
|             $usulanAwal = 'Adiwiyata Mandiri';
 | |
|         }
 | |
| 
 | |
|         return $usulanAwal;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('getUsulan')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function getUsulan($sekolah_id)
 | |
|     {
 | |
| 
 | |
|         $usulan = Kuesioner::where('ms_sekolah_id',$sekolah_id)->where('tahun',date('Y'))->first();
 | |
| 
 | |
|         if(($usulan->level+1) == 1){
 | |
|             $jenis_usulan = 'Adiwiyata Kab/Kota';
 | |
|         }elseif(($usulan->level+1) == 2){
 | |
|             $jenis_usulan = 'Adiwiyata Provinsi';
 | |
|         }elseif(($usulan->level+1) == 3){
 | |
|             $jenis_usulan = 'Adiwiyata Nasional';
 | |
|         }elseif(($usulan->level+1) == 4){
 | |
|             $jenis_usulan = 'Adiwiyata Mandiri';
 | |
|         }
 | |
| 
 | |
|         return $jenis_usulan;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('getNilaiAll')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function getNilaiAll($type,$sekolah_id)
 | |
|     {
 | |
|         // $countSoal = FormKriteria::select('page_number')->groupBy('page_number')->orderBy('page_number','ASC')->pluck('page_number')->count();
 | |
|         if($type == 'sekolah'){
 | |
|             // III  = ((SUM(D246:D252)/11)*20)
 | |
|             // II   = ((SUM(D35:D243)/89)*60)
 | |
|             // I    = ((SUM(D9:D30)/19)*20)
 | |
| 
 | |
|             $kriteria1 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','I.Perencanaan Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai1  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria1)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',0) //inputan sekolah
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $kriteria2 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','II.Pelaksanaan Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai2  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria2)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',0) //inputan sekolah
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $kriteria3 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','III.Pemantauan dan Evaluasi Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai3  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria3)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',0) //inputan sekolah
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $nilai = (($nilai3/11)*20)+(($nilai2/89)*60)+(($nilai1/19)*20);
 | |
| 
 | |
|         }elseif($type == 'kota'){
 | |
|             $kriteria1 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','I.Perencanaan Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai1  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria1)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',1) //inputan Kota
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $kriteria2 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','II.Pelaksanaan Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai2  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria2)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',1) //inputan Kota
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $kriteria3 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','III.Pemantauan dan Evaluasi Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai3  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria3)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',1) //inputan Kota
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $nilai = (($nilai3/11)*20)+(($nilai2/89)*60)+(($nilai1/19)*20);
 | |
|         }elseif($type == 'provinsi'){
 | |
|             $kriteria1 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','I.Perencanaan Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai1  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria1)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',2) //inputan provinsi
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $kriteria2 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','II.Pelaksanaan Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai2  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria2)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',2) //inputan provinsi
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $kriteria3 = FormKriteria::select('page_number')->groupBy('page_number')->where('kategori','III.Pemantauan dan Evaluasi Gerakan PBLHS')->pluck('page_number')->toArray();
 | |
|             $nilai3  = Penilaian::where('ms_sekolah_id',$sekolah_id)->whereIn('page_number',$kriteria3)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',2) //inputan provinsi
 | |
|             ->sum('skor');
 | |
| 
 | |
|             $nilai = (($nilai3/11)*20)+(($nilai2/89)*60)+(($nilai1/19)*20);
 | |
|         }
 | |
| 
 | |
|         return @$nilai ? round(@$nilai) : 0;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('getNilai')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function getNilai($type,$page_number,$sekolah_id)
 | |
|     {
 | |
|         if($type == 'sekolah'){
 | |
|             $nilai  = Penilaian::where('ms_sekolah_id',$sekolah_id)
 | |
|             ->where('page_number',$page_number)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',0) //inputan sekolah
 | |
|             ->first();
 | |
|         }elseif($type == 'kota'){
 | |
|             $nilai  = Penilaian::where('ms_sekolah_id',$sekolah_id)
 | |
|             ->where('page_number',$page_number)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',1) //inputan sekolah
 | |
|             ->first();
 | |
|         }elseif($type == 'provinsi'){
 | |
|             $nilai  = Penilaian::where('ms_sekolah_id',$sekolah_id)
 | |
|             ->where('page_number',$page_number)
 | |
|             ->where('skor','!=',0)
 | |
|             ->where('tahun',date('Y'))
 | |
|             ->where('status',2) //inputan sekolah
 | |
|             ->first();
 | |
|         }
 | |
| 
 | |
|         return @$nilai ? @$nilai->skor : 0;
 | |
|     }
 | |
| }
 | |
| if (!function_exists('kuesionerLogStatus')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function kuesionerLogStatus($KuesionerId,$plain = null)
 | |
|     {
 | |
|         $log  = KuesionerLog::where('kuesioner_id',$KuesionerId)->orderBy('KuesionerLogId','DESC')->first();
 | |
|         if($plain == 'plain'){
 | |
|             $progress = str_replace('_',' ',\Str::title($log->step));
 | |
|         }else{
 | |
|             $progress = '<span class="badge bg-warning-light text-warning">'.str_replace('_',' ',\Str::title($log->step)).'</span>';
 | |
|         }
 | |
|         return $progress;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('status_kuesioner')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function status_kuesioner()
 | |
|     {
 | |
|         //0 = Belum di Verifikasi Dinas
 | |
|         //1 = Sudah Diusulkan Oleh Dinas atau Sudin
 | |
|         //2 = Approve Dokumen
 | |
|         //3 = Kirim Ke Penilai Kota ( Proses Penilaian )
 | |
|         //4 = Selesai Penilaian Kota
 | |
|         //5 = Dikembalikan Penilaian Kota ke Sekolah
 | |
|         //6 = Selesai Penilaian Provinsi
 | |
|         //7 = Dikembalikan Penilaian Provinsi ke Kota
 | |
|         //8 = Selesai Penilaian Nasional
 | |
|         //9 = Selesai Penilaian Mandiri
 | |
|         //10 = Selesai Final
 | |
|         //11 = Terbit SK
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('group')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function group($id)
 | |
|     {
 | |
|         $user = User::find($id);
 | |
|         $group = MasterGroup::where('MsGroupId',$user->ms_group_id)->first();
 | |
|         return @$group;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('user')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function user($id)
 | |
|     {
 | |
|         $user = User::find($id);
 | |
|         return @$user;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('checkPenilaian')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function checkPenilaian($page_number,$sekolah_id = null,$type = null)
 | |
|     {
 | |
|         if(@$sekolah_id){
 | |
|             $idSekolah = @$sekolah_id;
 | |
|         }else{
 | |
|             $idSekolah = session('sekolah_id');
 | |
|         }
 | |
| 
 | |
|         if(@$type == 'kota'){
 | |
|             $penilaian = Penilaian::where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',1)->first();
 | |
|         }elseif(@$type == 'provinsi'){
 | |
|             $penilaian = Penilaian::where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',2)->first();
 | |
|         }else{
 | |
|             $penilaian = Penilaian::where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',0)->first();
 | |
|         }
 | |
| 
 | |
|         // if(session('group_alias') == 'sekolah'){
 | |
|             
 | |
|         // }elseif(session('group_alias') == 'penilai_kota'){
 | |
|             
 | |
|         // }elseif(session('group_alias') == 'penilai_provinsi'){
 | |
|             
 | |
|         // }else{
 | |
|         //     $penilaian = Penilaian::where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->first();
 | |
|         // }
 | |
| 
 | |
|         // $penilaian = Penilaian::where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->first();   
 | |
|         return @$penilaian ? true : false;
 | |
|     }
 | |
| }
 | |
| if (!function_exists('hitungSkor')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function hitungSkor($key,$val,$lainnya = [])
 | |
|     {
 | |
| 
 | |
|         $skor = 0;
 | |
|         $countLainnya = 0;
 | |
|         if(@$lainnya){
 | |
|             $countLainnya = count(array_filter($lainnya, function ($value) {
 | |
|                 return !is_null($value);
 | |
|             }));
 | |
|         }
 | |
| 
 | |
|         if($key == 'rencana_gerakan_pblhs'){
 | |
|             if($val == "Sesuai dengan Laporan EDS dan hasil IPMLH."){
 | |
|                 $skor = 3;
 | |
|             }elseif($val == "Sesuai dengan Laporan EDS atau hasil IPMLH."){
 | |
|                 $skor = 2;
 | |
|             }elseif($val == "Tidak sesuai dengan Laporan EDS dan hasil IPMLH."){
 | |
|                 $skor = 1;
 | |
|             }else{
 | |
|                 $skor = 0;
 | |
|             }
 | |
|         }elseif($key == 'pihak_terlibat_pblhs'){
 | |
|             $array3 = ["Kepala Sekolah", "Dewan pendidik", "Komite sekolah", "Peserta Didik", "Masyarakat"];
 | |
|             $array2 = ["Kepala Sekolah", "Dewan pendidik", "Komite sekolah", "Peserta Didik"];
 | |
|             $array1 = ["Kepala Sekolah", "Dewan pendidik", "Komite sekolah"];
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
| 
 | |
|             if (!array_diff($array3, $val) && !array_diff($val, $array3)) {
 | |
|                 $skor = 3;
 | |
|             } elseif (!array_diff($array2, $val) && !array_diff($val, $array2)) {
 | |
|                 $skor = 2;
 | |
|             } elseif (!array_diff($array1, $val) && !array_diff($val, $array1)) {
 | |
|                 $skor = 1;
 | |
|             } else {
 | |
|                 $skor = 0;
 | |
|             }
 | |
| 
 | |
|         }elseif($key == 'dokumen_ktsp'){
 | |
| 
 | |
|             $array3 = ["Visi", "Misi", "Tujuan", "Program pengembangan diri"];
 | |
|             $array2 = ["Visi", "Misi", "Tujuan"];
 | |
|             $array22 = ["Visi", "Misi", "Program pengembangan diri"];
 | |
|             $array1 = ["Visi", "Misi","Tujuan", "Program pengembangan diri tidak memuat"];
 | |
| 
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
| 
 | |
|             if (!array_diff($array3, $val) && !array_diff($val, $array3)) {
 | |
|                 $skor = 3;
 | |
|             } elseif ((!array_diff($array2, $val) && !array_diff($val, $array2)) || (!array_diff($array22, $val) && !array_diff($val, $array22))) {
 | |
|                 $skor = 2;
 | |
|             } elseif (!array_diff($array1, $val) && !array_diff($val, $array1)) {
 | |
|                 $skor = 1;
 | |
|             } else {
 | |
|                 $skor = 0;
 | |
|             }
 | |
|         }elseif($key == 'aspek_prlh'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 5){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 3){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) == 1){
 | |
|                     $skor = 1;
 | |
|                 }else{
 | |
|                     $skor = 0;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|             
 | |
|         }elseif($key == 'unsur_warga_partisipasi'){
 | |
| 
 | |
|             // Unsur utama
 | |
|             $unsur_utama = ["Kepala sekolah", "Tenaga Pendidik", "Tenaga Kependidikan", "Peserta Didik (termasuk kader adiwiyata)"];
 | |
|             // Unsur tambahan
 | |
|             $unsur_tambahan = ["Orang tua / wali murid", "Petugas kebersihan", "Petugas keamanan", "Petugas kantin"];
 | |
| 
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
| 
 | |
|             // Cek apakah semua unsur utama dipilih
 | |
|             if (!array_diff($unsur_utama, $val)) {
 | |
|                 // Hitung unsur tambahan yang juga dipilih
 | |
|                 $tambahan_terpilih = array_intersect($unsur_tambahan, $val);
 | |
|                 $skor = 1 + count($tambahan_terpilih);
 | |
|             } else {
 | |
|                 $skor = 0; // Jika unsur utama tidak lengkap, nilai = 0
 | |
|             }
 | |
|         }elseif($key == 'upaya_pemeliharaan'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 7){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 6){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 5){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) <= 3){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|             
 | |
|         }elseif($key == 'pelihara_kebersihan'){
 | |
| 
 | |
|             $array3 = ["Sekolah bersih", "Sanitasi berfungsi", "Drainase berfungsi"];
 | |
|             $array2 = ["Sekolah bersih", "Sanitasi berfungsi"];
 | |
|             $array22 = ["Sekolah bersih", "Drainase berfungsi"];
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
|             if (!array_diff($array3, $val) && !array_diff($val, $array3)) {
 | |
|                 $skor = 3;
 | |
|             } elseif ((!array_diff($array2, $val) && !array_diff($val, $array2)) || (!array_diff($array22, $val) && !array_diff($val, $array22))) {
 | |
|                 $skor = 2;
 | |
|             } else {
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'upaya_pengurangan_timbulan'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 7){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 6){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 5){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) <= 3){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|             
 | |
|         }elseif($key == 'upaya_daur_ulang_sampah'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 3){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) == 1){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|             
 | |
|         }elseif($key == 'pihak_terlibat_pemindahan_sampah'){
 | |
|             $array3 = ["Peserta didik", "Kader Adiwiyata", "Petugas kebersihan"];
 | |
|             $array2 = ["Peserta didik", "Kader Adiwiyata"];
 | |
|             $array1 = ["Petugas kebersihan"];
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
|             if (!array_diff($array3, $val) && !array_diff($val, $array3)) {
 | |
|                 $skor = 3;
 | |
|             } elseif ((!array_diff($array2, $val) && !array_diff($val, $array2))) {
 | |
|                 $skor = 2;
 | |
|             }elseif ((!array_diff($array1, $val) && !array_diff($val, $array1))) {
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'kegiatan_penghijauan'){
 | |
|             $array3 = ["Penanaman", "Pemeliharaan", "Pembibitan"];
 | |
|             $array2 = ["Penanaman", "Pemeliharaan"];
 | |
|             $array1 = ["Penanaman"];
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
|             if (!array_diff($array3, $val) && !array_diff($val, $array3)) {
 | |
|                 $skor = 3;
 | |
|             } elseif ((!array_diff($array2, $val) && !array_diff($val, $array2))) {
 | |
|                 $skor = 2;
 | |
|             }elseif ((!array_diff($array1, $val) && !array_diff($val, $array1))) {
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'warga_sekolah'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 5){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 3){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) <= 1){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|             
 | |
|         }elseif($key == 'upaya_konservasi_air'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 7){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 6){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 5){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) <= 3){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'upaya_konservasi_energi'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 7){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 6){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 5){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) <= 3){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'jumlah_karya_inovatif'){
 | |
|             if(is_array($val)){
 | |
|                 if($val >= 5){
 | |
|                     $skor = 3;
 | |
|                 }elseif(($val >= 3) || ($val <= 4)){
 | |
|                     $skor = 2;
 | |
|                 }elseif(($val >= 1) || ($val <= 2)){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'aksi_penerapan_prlh'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 4){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 3){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 1){
 | |
|                     $skor = 2;
 | |
|                 }else{
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'pemilahan_sampah'){
 | |
|             if($val == 'Sampah terpilah dan terkelola dengan baik'){
 | |
|                 $skor = 3;
 | |
|             }elseif($val == 'Sampah terpilah namun tidak terkelola dengan baik'){
 | |
|                 $skor = 2;
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'jejaring_kerja'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 5){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 3){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 2;
 | |
|                 }else{
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'kegiatan_kampanye'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 5){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 3){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 2;
 | |
|                 }elseif(count($val) == 1){
 | |
|                     $skor = 1;
 | |
|                 }else{
 | |
|                     $skor = 0;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|             
 | |
|         }elseif($key == 'media'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 5){
 | |
|                     $skor = 3;
 | |
|                 }elseif((count($val) >= 3) || (count($val) <= 4)){
 | |
|                     $skor = 2;
 | |
|                 }elseif((count($val) >= 1) || (count($val) <= 2)){
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'kegiatan_kader_adiwiyata'){
 | |
|             if(is_array($val)){
 | |
|                 if(count($val) >= 5){
 | |
|                     $skor = 5;
 | |
|                 }elseif(count($val) == 4){
 | |
|                     $skor = 4;
 | |
|                 }elseif(count($val) == 3){
 | |
|                     $skor = 3;
 | |
|                 }elseif(count($val) == 2){
 | |
|                     $skor = 2;
 | |
|                 }else{
 | |
|                     $skor = 1;
 | |
|                 }
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'frekuensi_pelaksanaan'){
 | |
|             if($val == '3 kali dalam 1 tahun'){
 | |
|                 $skor = 3;
 | |
|             }elseif($val == '2 kali dalam 1 tahun'){
 | |
|                 $skor = 2;
 | |
|             }else{
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }elseif($key == 'unsur_pemantauan_evaluasi'){
 | |
|             $array3 = ["Kepala sekolah", "Dewan Pendidik", "Komite sekolah","Peserta Didik","Masyarakat"];
 | |
|             $array2 = ["Kepala sekolah", "Dewan Pendidik", "Komite sekolah","Peserta Didik"];
 | |
|             $array1 = ["Kepala sekolah", "Dewan Pendidik", "Komite sekolah"];
 | |
|             if(!empty($val) && !is_array($val)){
 | |
|                 $val = array($val);
 | |
|             }
 | |
|             if (!array_diff($array3, $val) && !array_diff($val, $array3)) {
 | |
|                 $skor = 3;
 | |
|             } elseif ((!array_diff($array2, $val) && !array_diff($val, $array2))) {
 | |
|                 $skor = 2;
 | |
|             }elseif ((!array_diff($array1, $val) && !array_diff($val, $array1))) {
 | |
|                 $skor = 1;
 | |
|             }
 | |
|         }
 | |
|         // 
 | |
| 
 | |
| 
 | |
|         return $skor;
 | |
| 
 | |
| 
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('formKriteria')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function formKriteria($page_number,$sekolah_id = null,$type = null)
 | |
|     {
 | |
|         $kriteria = FormKriteria::where('page_number',$page_number)->get();
 | |
| 
 | |
|         $html = '';
 | |
|         if(@$sekolah_id){
 | |
|             $idSekolah = @$sekolah_id;
 | |
|         }else{
 | |
|             $idSekolah = session('sekolah_id');
 | |
|         }
 | |
| 
 | |
|         $kuesioner = Kuesioner::where('ms_sekolah_id',$idSekolah)->where('tahun',date('Y'))->first();
 | |
| 
 | |
|         foreach($kriteria as $keyKriteria => $data){
 | |
| 
 | |
|             if(@$type == 'kota'){
 | |
|                 $penilaian = Penilaian::where('key',$data->key)->where('ms_sekolah_id',$idSekolah)->where('status',1)->first();
 | |
|                 $penilaianOld = Penilaian::where('key',$data->key)->where('ms_sekolah_id',$idSekolah)->where('status',0)->first();
 | |
|             }elseif(@$type == 'provinsi'){
 | |
|                 $penilaian = Penilaian::where('key',$data->key)->where('ms_sekolah_id',$idSekolah)->where('status',2)->first();
 | |
|                 $penilaianOld = Penilaian::where('key',$data->key)->where('ms_sekolah_id',$idSekolah)->where('status',1)->first();
 | |
|             }else{
 | |
|                 $penilaian = Penilaian::where('key',$data->key)->where('ms_sekolah_id',$idSekolah)->where('status',0)->first();
 | |
|             }
 | |
| 
 | |
|             // if(session('group_alias') == 'sekolah'){
 | |
| 
 | |
|                 
 | |
| 
 | |
|             // }elseif(session('group_alias') == 'penilai_kota'){
 | |
| 
 | |
|                 
 | |
| 
 | |
|             // }elseif(session('group_alias') == 'penilai_provinsi'){
 | |
| 
 | |
|                 
 | |
| 
 | |
|             // }else{
 | |
|             //     $penilaian = Penilaian::where('key',$data->key)->where('ms_sekolah_id',$idSekolah)->first();
 | |
|             // }
 | |
| 
 | |
|             
 | |
|             // dd();
 | |
| 
 | |
|             $html .= '<div class="card mb-2 removeFormKriteria">';
 | |
|                 $html .= '<div class="card-body">';
 | |
|                     $html .= '<h6><b>'.$data->judul.'</b></h6>';
 | |
|                     // $html .= '<input type="hidden" name="input_upload_files[]">';
 | |
| 
 | |
|                     //QUESTION
 | |
|                     if($data->type == 'textarea'){
 | |
|                         $value = json_decode(@$penilaian->value);
 | |
|                         $valueOld = json_decode(@$penilaianOld->value);
 | |
| 
 | |
|                         if(@$value){
 | |
|                             $nilai = @$value;
 | |
|                         }else{
 | |
|                             $nilai = @$valueOld;
 | |
|                         }
 | |
| 
 | |
|                         $html .= '<div class="form-group m-2">';
 | |
|                         $html .= '<textarea class="form-control is-required" name="input_'.$data->key.'">'.@$nilai.'</textarea>';
 | |
|                         $html .= '</div>';
 | |
| 
 | |
|                     }elseif($data->type == 'freetext'){
 | |
|                         $value = json_decode(@$penilaian->value);
 | |
|                         $valueOld = json_decode(@$penilaianOld->value);
 | |
| 
 | |
|                         if(@$value){
 | |
|                             $nilai = @$value;
 | |
|                         }else{
 | |
|                             $nilai = @$valueOld;
 | |
|                         }
 | |
| 
 | |
|                         $html .= '<div class="form-group m-2">';
 | |
|                             $html .= '<input type="text" class="form-control is-required" name="input_'.$data->key.'" value="'.@$nilai.'">';
 | |
|                         $html .= '</div>';
 | |
|                         
 | |
|                     }elseif($data->type == 'checkbox'){
 | |
|                         $option = json_decode($data->option);
 | |
|                         $value = json_decode(@$penilaian->value);
 | |
|                         $valueOld = json_decode(@$penilaianOld->value);
 | |
|                         
 | |
|                         foreach($option as $keyOption => $dataOption){
 | |
|                             if(@$value){
 | |
|                                 if(in_array($dataOption, (is_array(@$value) ? @$value : array(@$value)))){
 | |
|                                     $checked = 'checked';
 | |
|                                 }
 | |
|                             }else{
 | |
|                                 if(in_array($dataOption, (is_array(@$valueOld) ? @$valueOld : array(@$valueOld)))){
 | |
|                                     $checked = 'checked';
 | |
|                                 }
 | |
|                             }
 | |
| 
 | |
|                             $key = 'number_'.$keyKriteria.'_'.$keyOption;
 | |
| 
 | |
|                             $html .= '<div class="custom-control custom-checkbox m-2">';
 | |
|                                 $html .= '<input type="checkbox" '.@$checked.' class="custom-control-input is-required" id="'.$key.'" value="'.$dataOption.'" name="input_'.$data->key.'[]">';
 | |
|                                 $html .= '<label class="custom-control-label" for="'.$key.'">'.$dataOption.'</label>';
 | |
|                             $html .= '</div>';
 | |
|                         }
 | |
|                         
 | |
|                     }elseif($data->type == 'radio_button'){
 | |
|                         $option = json_decode($data->option);
 | |
|                         $value = json_decode(@$penilaian->value);
 | |
|                         $valueOld = json_decode(@$penilaianOld->value);
 | |
| 
 | |
|                         foreach($option as $keyOption => $dataOption){
 | |
| 
 | |
|                             $key = 'number_'.$keyKriteria.'_'.$keyOption;
 | |
| 
 | |
|                             $html .= '<div class="custom-control custom-radio m-2">';
 | |
|                                 $html .= '<input '.(@$value == $dataOption ? 'checked' : (@$valueOld == $dataOption ? 'checked' : '') ).' type="radio" class="custom-control-input is-required" id="'.$key.'" value="'.$dataOption.'" name="input_'.$data->key.'">';
 | |
|                                 $html .= '<label class="custom-control-label" for="'.$key.'">'.$dataOption.'</label>';
 | |
|                             $html .= '</div>';
 | |
|                         }
 | |
|                         
 | |
|                     }elseif($data->type == 'number'){
 | |
|                         $value = json_decode(@$penilaian->value);
 | |
| 
 | |
|                         $valueOld = json_decode(@$penilaianOld->value);
 | |
| 
 | |
|                         if(@$value){
 | |
|                             $nilai = @$value;
 | |
|                         }else{
 | |
|                             $nilai = @$valueOld;
 | |
|                         }
 | |
| 
 | |
|                         $html .= '<div class="form-group m-2">';
 | |
|                             $html .= '<input type="text" class="form-control is-required numberInput" name="input_'.$data->key.'" value="'.@$nilai.'">';
 | |
|                         $html .= '</div>';
 | |
|                     }
 | |
| 
 | |
|                 $html .= '</div>';
 | |
|             $html .= '</div>';
 | |
| 
 | |
|             if($data->active_lainnya == 1){
 | |
|                 if(session('group_alias') == 'sekolah'){
 | |
|                     $lainnya = Penilaian::where('key','lainnya')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',0)->first();
 | |
|                 }elseif(session('group_alias') == 'penilai_kota'){
 | |
| 
 | |
|                     $lainnya = Penilaian::where('key','lainnya')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',1)->first();
 | |
|                     $lainnyaOld = Penilaian::where('key','lainnya')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',0)->first();
 | |
| 
 | |
|                 }elseif(session('group_alias') == 'penilai_provinsi'){ 
 | |
|                     $lainnya = Penilaian::where('key','lainnya')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',2)->first();
 | |
|                     $lainnyaOld = Penilaian::where('key','lainnya')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',1)->first();
 | |
| 
 | |
|                 }else{
 | |
|                     $lainnya = Penilaian::where('key','lainnya')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->first();
 | |
|                 }
 | |
|                 if(@$lainnya){
 | |
|                     $valueLainnya = json_decode(@$lainnya->value);
 | |
|                 }else{
 | |
|                     $valueLainnya = json_decode(@$lainnyaOld->value);
 | |
|                 }
 | |
|                 // dd($valueLainnya);
 | |
| 
 | |
|                 $html .= '<div class="card mb-2 removeFormKriteria">';
 | |
|                     $html .= '<div class="card-body">';
 | |
|                         $html .= '<h6><b>'.$data->judul_lainnya.'</b></h6>';
 | |
| 
 | |
|                         for($i = 1; $i <= $data->number_answer_lainnya; $i++){
 | |
|                             $html .= '<div class="form-group m-2">';
 | |
|                                 $html .= '<input type="text" value="'.@$valueLainnya[$i-1].'" class="form-control" placeholder="Jawaban" name="input_lainnya[]">';
 | |
|                             $html .= '</div>';
 | |
|                         }
 | |
|                     $html .= '</div>';
 | |
|                 $html .= '</div>';
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         $link = Penilaian::where('key','upload_files')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->first();
 | |
|         $valueLink = json_decode(@$link->value);
 | |
| 
 | |
|         $catatan = Penilaian::where('key','catatan')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->first();
 | |
|         $valueCatatan = json_decode(@$catatan->value);
 | |
| 
 | |
|         if(session('group_alias') == 'sekolah'){
 | |
|             $html .= '<div class="card mb-2 removeFormKriteria">';
 | |
|                 $html .= '<input type="hidden" name="key" value="'.encode_id($page_number).'">';
 | |
|                 $html .= '<div class="card-body">';
 | |
|                     $html .= '<h6><b>Upload File Bukti</b></h6>';
 | |
|                     $html .= '<div class="form-group">';
 | |
|                     $html .= '<div style="border: 2px dashed #0087F7; padding: 20px;" class="dropzone" id="my-dropzone">
 | |
|                                 <div class="dz-message">
 | |
|                                     Drop PDF files here or click to upload
 | |
|                                 </div>
 | |
|                             </div>
 | |
|                             <div id="uploaded-files" style="margin-top: 20px;">
 | |
|                                 <ul id="file-list">';
 | |
|                                 if(@$valueLink){
 | |
|                                     if(is_array(@$valueLink)){
 | |
|                                         foreach(@$valueLink as $kuy => $file){
 | |
|                                             $html .=    '<li class="">
 | |
|                                                 <a class="" target="_blank" href="'.asset($file).'">File '.($kuy+1).'</a>
 | |
|                                             </li>';
 | |
|                                         }
 | |
|                                     }else{
 | |
|                                         $html .=    '<li><a target="_blank" href="'.asset(@$valueLink).'">File 1</a></li>';
 | |
|                                     }
 | |
|                                 }
 | |
|                     $html .=    '</ul>
 | |
|                             </div>
 | |
|                             ';
 | |
|                         // $html .= '<input type="file" class="form-control" name="input_link_grdive" placeholder="Link Google Drive (folder penyimpanan bukti)" value="'.@$valueLink.'">';
 | |
|                         // $html .= '<small><i>Contoh link : https://example.com</i></small>';
 | |
|                     $html .= '</div>';
 | |
|                 $html .= '</div>';
 | |
|             $html .= '</div>';
 | |
| 
 | |
|             if($kuesioner->status == 5){
 | |
|                 $catatan = Penilaian::where('key','catatan')->where('page_number',$page_number)->where('ms_sekolah_id',$idSekolah)->where('status',1)->first();
 | |
|                 $html .= '<div class="card mb-2 removeFormKriteria">';
 | |
|                     // $html .= '<input type="hidden" name="key" value="'.encode_id($page_number).'">';
 | |
|                     $html .= '<div class="card-body">';
 | |
|                         $html .= '<h6><b>Catatan</b></h6>';
 | |
|                         $html .= '<p>'.json_decode($catatan->value).'</p>';
 | |
|                     $html .= '</div>';
 | |
|                 $html .= '</div>';
 | |
|             }
 | |
|         }else{
 | |
| 
 | |
|             $html .= '<div class="card mb-2 removeFormKriteria">';
 | |
|                 $html .= '<div class="card-body">';
 | |
|                     $html .= '<h6><b>Bukti File</b></h6>';
 | |
|                     $html .= '<div class="form-group">';
 | |
|                         $html .= '<div id="uploaded-files" style="margin-top: 20px;">
 | |
|                                     <ul id="file-list">';
 | |
|                                         if(@$valueLink){
 | |
|                                             if(is_array(@$valueLink)){
 | |
|                                                 foreach(@$valueLink as $kuy => $file){
 | |
|                                                     $html .=    '<li class="">
 | |
|                                                         <a class="" target="_blank" href="'.asset($file).'">File '.($kuy+1).'</a>
 | |
|                                                     </li>';
 | |
|                                                 }
 | |
|                                             }else{
 | |
|                                                 $html .=    '<li><a target="_blank" href="'.asset(@$valueLink).'">File 1</a></li>';
 | |
|                                             }
 | |
|                                         }
 | |
|                             $html .=    '</ul>
 | |
|                                     </div>';
 | |
|                     $html .= '</div>';
 | |
|                 $html .= '</div>';
 | |
|             $html .= '</div>';
 | |
| 
 | |
|             $html .= '<div class="card mb-2 removeFormKriteria">';
 | |
|                 $html .= '<input type="hidden" name="key" value="'.encode_id($page_number).'">';
 | |
|                 $html .= '<div class="card-body">';
 | |
|                     $html .= '<h6><b>Catatan</b></h6>';
 | |
|                     $html .= '<div class="form-group">';
 | |
|                         $html .= '<textarea class="form-control" name="input_catatan" placeholder="Catatan">'.@$valueCatatan.'</textarea>';
 | |
|                     $html .= '</div>';
 | |
|                 $html .= '</div>';
 | |
|             $html .= '</div>';
 | |
|         }
 | |
| 
 | |
|         return $html;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('levelAdiwiyata')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function levelAdiwiyata($npsn)
 | |
|     {
 | |
|         $kuesioner     = Kuesioner::where('npsn',$npsn)->where('tahun',date('Y'))->first();
 | |
|         $sekolah       = Sekolah::where('npsn',$npsn)->first();
 | |
|         $sk            = SK::where('tahun',date('Y'))->where('sekolah','like','%'.$sekolah->MsSekolahId.'%')->first();
 | |
|         $data = null;
 | |
|         if(@$kuesioner){
 | |
|             $data = $kuesioner;
 | |
|         }else{
 | |
|             $kuesioner = Kuesioner::where('npsn',$npsn)->where('tahun',(date('Y')-1))->first();
 | |
|             $data = $kuesioner;
 | |
|         }
 | |
|         $level = '';
 | |
|         
 | |
|         if(@$data->level == 0){
 | |
|             if((@$data->level == 0) && (@$data->tim_adiwiyata == 2) && (@$data->info_pblhs == 2) ){
 | |
|                 if(@$sk->jenis_usulan == 1){
 | |
|                     $level = '3';
 | |
|                 }else{
 | |
|                     $level = '2';
 | |
|                 }
 | |
|             }elseif((@$data->level == 0) && (@$data->tim_adiwiyata == 2)){
 | |
|                 if(@$sk->jenis_usulan == 1){
 | |
|                     $level = '3';
 | |
|                 }else{
 | |
|                     $level = '1';
 | |
|                 }
 | |
|             }else{
 | |
|                 if(@$sk->jenis_usulan == 1){
 | |
|                     $level = '3';
 | |
|                 }else{
 | |
|                     $level = '0';
 | |
|                 }
 | |
|             }
 | |
|         }elseif(@$data->level == 1){
 | |
| 
 | |
|             if(@$sk->jenis_usulan == 2){
 | |
|                 $level = '4';
 | |
|             }else{
 | |
|                 $level = '3';
 | |
|             }
 | |
|         }elseif(@$data->level == 2){
 | |
|             if(@$sk->jenis_usulan == 3){
 | |
|                 $level = '5';
 | |
|             }else{
 | |
|                 $level = '4';
 | |
|             }
 | |
|         }else{
 | |
|             if(@$sk->jenis_usulan == 1){
 | |
|                 $level = '3';
 | |
|             }else{
 | |
|                 $level = '0';
 | |
|             }
 | |
|         }
 | |
| 
 | |
|         return $level;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('taskLabel')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function taskLabel($val)
 | |
|     {
 | |
|         if ($val == 'store') {
 | |
|             $task = 'save';
 | |
|         } elseif ($val == 'save_permission') {
 | |
|             $task = 'save group access';
 | |
|         } elseif ($val == 'destroy') {
 | |
|             $task = 'delete';
 | |
|         } elseif ($val == 'batch') {
 | |
|             $task = 'delete';
 | |
|         } else {
 | |
|             $task = $val;
 | |
|         }
 | |
| 
 | |
|         return $task;
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| if (!function_exists('logActivity')) {
 | |
|     /**
 | |
|      * @param $request
 | |
|      * @param $note
 | |
|      */
 | |
|     function logActivity($request, $note)
 | |
|     {
 | |
|         $repository = app(\App\Models\Log::class);
 | |
|         $data = [
 | |
|             'module' => $request->route()->getAction('prefix'),
 | |
|             'task' => taskLabel($request->route()->getActionMethod()),
 | |
|             'user_id' => session('uid'),
 | |
|             'ipaddress' => $request->getClientIp(),
 | |
|             'useragent' => $request->header('User-Agent'),
 | |
|             'note' => $note,
 | |
|             'created_at' => \Carbon\Carbon::now()
 | |
|         ];
 | |
| 
 | |
|         if (session('superuser') == false)
 | |
|             $repository->create($data);
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| if (!function_exists('trimId')) {
 | |
|     /**
 | |
|      * @param $val
 | |
|      * @return array
 | |
|      */
 | |
|     function trimId($val)
 | |
|     {
 | |
|         $string = explode('+', $val);
 | |
|         return $string;
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| if (!function_exists('dateTime')) {
 | |
|     /**
 | |
|      * make secure id
 | |
|      *
 | |
|      * @param string|null $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function dateTime($date)
 | |
|     {
 | |
|         return date('d-m-Y H:i:s',strtotime(@$date));
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('encode_id')) {
 | |
|     /**
 | |
|      * make secure id
 | |
|      *
 | |
|      * @param string|null $val
 | |
|      *
 | |
|      * @return string
 | |
|      */
 | |
|     function encode_id(?string $val = ''): string
 | |
|     {
 | |
|         $params = ['val' => $val];
 | |
|         return rtrim(base64_encode(serialize($params)), "=");
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('decode_id')) {
 | |
|     /**
 | |
|      * @param string|null $val
 | |
|      * ${STATIC}
 | |
|      *
 | |
|      * @return      mixed|null
 | |
|      * @author      alex.gz <amqit.consultant@gmail.com>
 | |
|      * @created     02/12/2023 4:28
 | |
|      *
 | |
|      */
 | |
|     function decode_id(?string $val = ''): mixed
 | |
|     {
 | |
|         $secure = unserialize(base64_decode($val));
 | |
|         return $secure ? $secure['val'] : null;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('permission')) {
 | |
|     /**
 | |
|      * @param        $access
 | |
|      * @param        $key
 | |
|      * @param string $method
 | |
|      * @param bool   $view
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     function permission($access, $key, string $method = 'menu', bool $view = false): mixed
 | |
|     {   
 | |
|         if (@session('group_id') != 1) {
 | |
|             if ($method == 'module') {
 | |
|                 if (is_array($access)) {
 | |
|                     $model = MasterAccessMenu::where('module', 'LIKE', "{$key}%")->where('ms_group_id', session('group_id'))->first();
 | |
|                     $query = count(array_intersect((array)$access, (array)$model->access));
 | |
|                 } else {
 | |
|                     $query = MasterAccessMenu::where($access, true)->where('module', 'LIKE', $key.'%')->where('ms_group_id', session('group_id'))->count();
 | |
|                     if ($query > 0) {
 | |
|                         return true;
 | |
|                     } else {
 | |
|                         return abort('401');
 | |
|                     }
 | |
|                 }
 | |
|             } else {
 | |
|                 $query = MasterAccessMenu::where($access, true)->where('ms_menu_id', $key)->where('ms_group_id', session('group_id'))->count();
 | |
|             }
 | |
| 
 | |
|             if ($query > 0) {
 | |
|                 return true;
 | |
|             } else {
 | |
|                 return false;
 | |
|             }
 | |
|         } else {
 | |
|             return true;
 | |
|         }
 | |
| 
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('access')) {
 | |
|     /**
 | |
|      * @param $access
 | |
|      * @param $key
 | |
|      *
 | |
|      * @return bool
 | |
|      */
 | |
|     function access($access, $key)
 | |
|     {
 | |
|         if (session('group_alias') != 'administrator') {
 | |
|             $query = MasterAccessMenu::where($access, 1)->where('module', $key)->where('ms_group_id', session('group_id'))->count();
 | |
|             if ($query > 0) {
 | |
|                 return true;
 | |
|             } else if (session('group_alias') == 'administrator') {
 | |
|                 return true;
 | |
|             } else {
 | |
|                 return false;
 | |
|             }
 | |
|         } else {
 | |
|             return true;
 | |
|         }
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('activeMenuClass')) {
 | |
|     /**
 | |
|      * Helper to grab the application version.
 | |
|      *
 | |
|      * @return mixed
 | |
|      */
 | |
|     function activeMenuClass($route){
 | |
|         // dd(request()->route()->getName());
 | |
|         // if(request()->route()->getName() == $route){
 | |
|         //     return true;
 | |
|         // }else{
 | |
|         //     return false;
 | |
|         // }
 | |
| 
 | |
|         if (\Str::is($route, request()->route()->getName())) {
 | |
|             return true;
 | |
|         } else {
 | |
|             return false;
 | |
|         }
 | |
|     }
 | |
|     
 | |
| }
 | |
| 
 | |
| if (!function_exists('renderMenu')) {
 | |
|     
 | |
|     /**
 | |
|      * Loops through a folder and requires all PHP files
 | |
|      * Searches sub-directories as well.
 | |
|      *
 | |
|      * @param $folder
 | |
|      */
 | |
|     function renderMenu()
 | |
|     {
 | |
|         
 | |
|         $parent = MasterMenu::where('status',true)->where('menu_type','sidebar')->where('parent_id',0)->orderBy('ordering','ASC')->get();
 | |
|         $html = '';
 | |
|         foreach ($parent as $p1) {
 | |
|             // echo $p1->MsMenuId.'<br>';
 | |
|             $child2 = MasterMenu::where('status',true)->where('menu_type','sidebar')->where('parent_id',$p1->MsMenuId)->get();
 | |
|             $access1 = permission('is_read', $p1->MsMenuId, 'menu', true);
 | |
| 
 | |
|             $ch1 = count($child2) > 0 ? '' : '';
 | |
|             $link1 = count($child2) > 0 ? '' : 'menu-link';
 | |
|             $active = activeMenuClass($p1->module) ? 'active' : '';
 | |
|             // dd($p1->route);
 | |
| 
 | |
|             if ($access1) {
 | |
|                 $active1 = activeMenuClass($p1->module) ? 'active' : '';
 | |
| 
 | |
|                 $html .= '<li class="' . $ch1 . $active1 . '"><a class="' . $link1 . '" href="' . url($p1->url) . '"><i class="' . $p1->menu_icons . '"></i> <span class="nav-link-text" data-i18n="nav.application_intel">' . @$p1->title.'</span>';
 | |
|                 if (count($child2) > 0) {
 | |
|                     $html .= '</a>';
 | |
|                     $html .= '<ul class="menu-subs">';
 | |
|                     foreach ($child2 as $p2) {
 | |
|                         $child3 = MasterMenu::where('status',true)->where('menu_type','sidebar')->where('parent_id',$p2->MsMenuId)->get();
 | |
|                         $access2 = permission('is_read', $p2->MsMenuId, 'menu', true);
 | |
|                         $ch2 = count($child3) > 0 ? '' : '';
 | |
|                         $link2 = count($child3) > 0 ? '' : 'menu-link';
 | |
|                         if ($access2) {
 | |
|                             $active2 = activeMenuClass($p2->module) ? 'active' : '';
 | |
|                             $html .= '<li class="' . $ch2 .$active2. '"><a class="' . $link2 . '" href="' . url($p2->url) . '"> <i class="' . $p2->menu_icons . '"></i> <span class="nav-link-text" data-i18n="nav.application_intel">' . @$p2->title.'<span>';
 | |
|                             if (count($child3) > 0) {
 | |
|                                 $html .= '</a>';
 | |
|                                 $html .= '<ul>';
 | |
|                                 foreach ($child3 as $p3) {
 | |
|                                     $child4 = MasterMenu::where('status',true)->where('menu_type','sidebar')->where('parent_id',$p3->MsMenuId)->get();
 | |
|                                     $access3 = permission('is_read', $p3->MsMenuId, 'menu', true);
 | |
|                                     $ch3 = count($child4) > 0 ? '' : '';
 | |
|                                     $link3 = count($child4) > 0 ? '' : 'menu-link';
 | |
|                                     if ($access3) {
 | |
|                                         $active3 = activeMenuClass($p3->module) ? 'active' : '';
 | |
|                                         // $active3 = $active ? ' ' . null : null;
 | |
|                                         $html .= '<li class="' . $ch3 . $active3.'"><a class="' . $link3 . '" href="' . url($p3->url) . '"> <span class="nav-link-text" data-i18n="nav.application_intel">' . @$p3->title.'</span>';
 | |
|                                         if (count($child4) > 0) {
 | |
|                                             $html .= '</a>';
 | |
|                                             $html .= '<ul class="menu-subs">';
 | |
|                                             foreach ($child4 as $p4) {
 | |
|                                                 $html .= '<li class=" ' . null . '"><a class="menu-link" href="' . url($p4->url) . '"> <span class="nav-link-text" data-i18n="nav.application_intel">' . @$p4->title.'<span>';
 | |
|                                             }
 | |
|                                             $html .= '</ul>';
 | |
|                                         } else {
 | |
|                                             $html .= '</a>';
 | |
|                                         }
 | |
|                                         $html .= '</li>';
 | |
|                                     }
 | |
|                                 }
 | |
|                                 $html .= '</ul>';
 | |
|                             } else {
 | |
|                                 $html .= '</a>';
 | |
|                             }
 | |
|                             $html .= '</li>';
 | |
|                         }
 | |
|                     }
 | |
|                     $html .= '</ul>';
 | |
|                 } else {
 | |
|                     $html .= '</a>';
 | |
|                 }
 | |
|                 $html .= '</li>';
 | |
|             }
 | |
|         }
 | |
|         return $html;
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('include_route_files')) {
 | |
|     /**
 | |
|      * Loops through a folder and requires all PHP files
 | |
|      * Searches sub-directories as well.
 | |
|      *
 | |
|      * @param $folder
 | |
|      */
 | |
|     function include_route_files($folder)
 | |
|     {
 | |
|         include_files_in_folder($folder);
 | |
|     }
 | |
| }
 | |
| 
 | |
| if (!function_exists('include_files_in_folder')) {
 | |
|     /**
 | |
|      * Loops through a folder and requires all PHP files
 | |
|      * Searches sub-directories as well.
 | |
|      *
 | |
|      * @param $folder
 | |
|      */
 | |
|     function include_files_in_folder($folder)
 | |
|     {
 | |
|         try {
 | |
|             $rdi = new RecursiveDirectoryIterator($folder);
 | |
|             $it = new RecursiveIteratorIterator($rdi);
 | |
| 
 | |
|             while ($it->valid()) {
 | |
|                 if (!$it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') {
 | |
|                     require $it->key();
 | |
|                 }
 | |
| 
 | |
|                 $it->next();
 | |
|             }
 | |
|         } catch (Exception $e) {
 | |
|             echo $e->getMessage();
 | |
|         }
 | |
|     }
 | |
| } |