Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.9 kB
1
Indexable
Never
function download_zip($id_user)
    {
        $rules = MstMenu::join('mst_rules', 'mst_menu.id', '=', 'mst_rules.id')
                ->where('route', 'lulusmhs.bebaspustakamhs')
                ->get();
        
            $data['mhs'] = DetailPemberkasan::where('id_user', '=', decrypt($id_user))
                ->first(['id_user', 'prodi_mhs', 'fakultas_mhs', 'bebas_pustaka'])
                ->toArray();
        
            $mhs = PublicService::getmahasiswanim($data['mhs']['id_user']);
            $detail_pemberkasan = DetailPemberkasan::where('id_user', decrypt($id_user))->first();
            $getfiledb = BerkasPustaka::join('mst_rules', 'berkas_pustaka.id_rules', '=', 'mst_rules.id')
            ->where('id_pemberkasan', $detail_pemberkasan->id)
            ->get(['berkas_pustaka.*', 'mst_rules.*', 'berkas_pustaka.id as idp'])
            ->toArray();
            
            $getuploaddoc = PublicService::getuploaddoc(decrypt($id_user), 'lulus');
            $uploaddoc_custom = PublicService::getuploaddoc_custom($rules, $getuploaddoc);
        
            $datas = [
                'rules'                 => $rules,
                'detail_pemberkasan'    => $detail_pemberkasan,
                'getfiledb'             => $getfiledb,
                'getuploaddoc'          => $getuploaddoc,
                'uploaddoc_custom'      => $uploaddoc_custom
            ];
    
            $downloadzip = $datas['getuploaddoc']['result']['data'];
    
            $files = [];
            foreach ($downloadzip as $key => $dz) {
                if (!empty($dz['filedoc'])) {

                    $iddoc_col_key = array_search($dz['iddoc'], array_column($getfiledb, 'iddoc'));

                    $fname = explode('/', $dz['name']);
                    if (count($fname) > 1) 
                    {
                        $fname = $fname[0];
                    } else {
                        $fname = $dz['name'];
                    }

                    $ftype = explode('|', $getfiledb[$iddoc_col_key]['type']);
                    if (count($ftype) > 1) 
                    {
                        $ftype = $ftype[0];
                    } else {
                        $ftype = $getfiledb[$iddoc_col_key]['type'];
                    }

                    $files[$key]['url'] = $dz['filedoc'];
                    $files[$key]['name'] = $fname;
                    $files[$key]['type'] = $ftype;
                }
            }
    
            $tmp_file = $this->download_files($files);
            $mhs_data = $mhs['result']['data'][0];
            $short_zip_name = $mhs_data['nim'] . '_' . $mhs_data['nama'] . '_' . date('Y-m-d H:i:s') . '.zip';
    
            $response = response()->download($tmp_file, $short_zip_name);

            if (File::exists($tmp_file)) {
                File::delete($tmp_file);
            }

            return $response;
    }
Leave a Comment