Ignore:
Timestamp:
10/23/21 04:03:46 (3 years ago)
Author:
beratkjufliju <kufliju@…>
Branches:
develop, master
Children:
b39afb5
Parents:
c6b84df
Message:

bug fixes, edited export, added fileSeeder for DB testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • app/Http/Controllers/Dashboard/FoldersController.php

    rc6b84df r4b7e2d3  
    3939                $folders = $foldersInDeptSort->orderBy('name', 'asc')->paginate(12);
    4040            }
     41            else if ($request->query('sort') == 'no_of_files') {
     42                $folders = $foldersInDeptSort->orderBy('no_of_files', 'desc')->paginate(12);
     43            }
    4144            else if($request->query('sort') == 'count'){
    4245                $total = $foldersInDeptSort->folder->files->count();
     
    5255            else if ($request->query('sort') == 'name') {
    5356                $folders = Folder::orderBy('name', 'asc')->paginate(12);
     57            }
     58            else if ($request->query('sort') == 'no_of_files') {
     59                $folders = Folder::orderBy('no_of_files', 'desc')->paginate(12);
    5460            }
    5561            else if ($request->query('sort') == 'important') {
     
    97103            "deptName" => $deptName,
    98104            "deptCode" => $deptCode,
    99             "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))
     105            "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes))
    100106        ]);
    101107
     
    117123        $folder->user()->associate($user);
    118124        $folder->department()->associate($department);
     125        $folder->department()->increment('no_of_folders');
    119126
    120127        $folder->arch_id = $request->arch_id;
     
    149156                $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName;
    150157                $newFile->folder()->associate($folder);
     158                $newFile->folder()->increment('no_of_files');
    151159                $newFile->save();
    152160            }
     
    155163        Alert::flash("New folder created successfully");
    156164
    157         return redirect()->route("dashboard.folders.index");
     165        return redirect()->back();
    158166    }
    159167
     
    177185        $department = Department::find($request->department);
    178186
    179         $folder->department()->associate($department);
    180 
    181         $oldLocation = $folder->department->location . DIRECTORY_SEPARATOR . $folder->name;
     187        $folder->department()->increment('no_of_folders');
     188
     189        $oldLocation = $folder->location;
    182190
    183191        $folder->name = $request->name;
     
    186194        $folder->updated_at = Carbon::now();
    187195
    188         $location = $folder->department->location . DIRECTORY_SEPARATOR . $request->name;
    189 
    190         if ($folder->isDirty('name')) {
    191             if (!Storage::disk('uploads')->has($location)) {
    192                 Storage::disk('uploads')->move($oldLocation, $location);
    193                 foreach($files as $file){
    194                     $file->location = $location . DIRECTORY_SEPARATOR . $file->name;
     196       $newLocation = Department::find($request->department)->location . DIRECTORY_SEPARATOR . $request->name;
     197
     198        if($folder->department_id != $request->department){
     199            $folder->department()->decrement('no_of_folders');
     200            if (!Storage::disk('uploads')->has($newLocation)) {
     201                Storage::disk('uploads')->move($oldLocation, $newLocation);
     202                foreach($files as $file) {
     203                    $file->location = $newLocation . DIRECTORY_SEPARATOR . $file->name;
    195204                    $file->save();
    196205                }
    197206            }
    198207        }
     208         if($folder->isDirty('name')) {
     209            if (!Storage::disk('uploads')->has($newLocation)) {
     210                Storage::disk('uploads')->move($oldLocation, $newLocation);
     211                foreach($files as $file) {
     212                    $file->location = $newLocation . DIRECTORY_SEPARATOR . $file->name;
     213                    $file->save();
     214                }
     215            }
     216        }
     217
     218        $folder->department()->associate($department);
     219
     220        $folder->location = $newLocation;
    199221
    200222        if ($request->has('file_item')) {
    201223            foreach ($request->file_item as $file) {
    202224                $fileName = $folder->name . '-' . uniqid() . '.' . $file->getClientOriginalExtension();
    203                     $file->storeAs($location . DIRECTORY_SEPARATOR, $fileName);
     225                    $file->storeAs($newLocation . DIRECTORY_SEPARATOR, $fileName);
    204226                    $newFile = new File();
    205227                    $newFile->name = $fileName;
    206                     $newFile->location = $location . DIRECTORY_SEPARATOR . $fileName;
     228                    $newFile->location = $newLocation . DIRECTORY_SEPARATOR . $fileName;
    207229                    $newFile->folder()->associate($folder);
     230                    $newFile->folder()->increment('no_of_files');
    208231                    $newFile->save();
    209232            }
    210233        }
    211234
    212         $folder->location = $location;
    213 
    214235        $folder->save();
    215 
    216236
    217237        Alert::flash("Folder edited successfully");
     
    246266            $location = $folder->department->location . DIRECTORY_SEPARATOR . $folder->name;
    247267            Storage::disk('uploads')->deleteDirectory($location);
     268            $folder->department()->decrement('no_of_folders');
    248269            Alert::flash($folder->name . " deleted successfully");
     270            return redirect()->back();
    249271        }
    250272        Alert::flash($folder->name . " is important", "error");
    251         return redirect()->route("dashboard.folders.index");
     273        return redirect()->back();
    252274    }
    253275
     
    306328        }
    307329        else {
    308             $files = File::where('folder_id', $id)->paginate(10);
     330            $files = File::where('folder_id', $id)->paginate(12);
    309331        }
    310332
     
    317339            "imageExt" => array("png", "jpg", "jpeg"),
    318340            "folders" => $folders,
    319             "fileTypes" => '.' . implode(',.', explode(',', explode(':', FileType::find('1')->mimes)[1]))
     341            "fileTypes" => '.' . implode(',.', explode(',', FileType::find('1')->mimes))
    320342        ]);
    321343    }
Note: See TracChangeset for help on using the changeset viewer.