Changeset c6b84df for app/Http/Controllers/Dashboard
- Timestamp:
- 10/21/21 23:45:59 (3 years ago)
- Branches:
- develop, master
- Children:
- 4b7e2d3
- Parents:
- 6b95845
- Location:
- app/Http/Controllers/Dashboard
- Files:
-
- 4 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
app/Http/Controllers/Dashboard/DepartmentsController.php
r6b95845 rc6b84df 7 7 use App\Http\Requests\Dashboard\UpdateDepartmentRequest; 8 8 use App\Models\Department; 9 use App\Models\Document;10 9 use App\Models\File; 11 10 use App\Models\User; 11 use App\Notifications\NewDepartmentCreated; 12 12 use Carbon\Carbon; 13 use Illuminate\Http\Request;14 13 use App\Http\Controllers\Controller; 15 use Illuminate\Support\Facades\ Auth;14 use Illuminate\Support\Facades\Notification; 16 15 use Illuminate\Support\Facades\Storage; 17 use function Illuminate\Events\queueable;16 use Illuminate\Filesystem\Filesystem; 18 17 19 18 class DepartmentsController extends Controller … … 40 39 $location = 'Departments' . DIRECTORY_SEPARATOR . $request->code; 41 40 42 if(!Storage::disk(' local')->has($location)){43 Storage::disk(' local')->makeDirectory($location);41 if(!Storage::disk('uploads')->has($location)){ 42 Storage::disk('uploads')->makeDirectory($location); 44 43 45 44 } 46 $department->location = Storage::disk('local')->path('') .$location;45 $department->location = $location; 47 46 $department->user_id = auth()->id(); 47 48 $users = User::all(); 49 Notification::send($users, new NewDepartmentCreated("New department created")); 48 50 49 51 $department->save(); … … 65 67 $department = Department::findOrFail($id); 66 68 67 $ documents = $department->document;69 $folders = $department->folder; 68 70 $oldLocation = DIRECTORY_SEPARATOR . 'Departments' . DIRECTORY_SEPARATOR . $department->code; 69 71 70 72 $department->name = $request->name; 71 73 $department->code = $request->code; 74 $department->updated_at = Carbon::now(); 72 75 73 76 if($department->isDirty('code')) 74 77 { 75 78 $location = 'Departments' . DIRECTORY_SEPARATOR . $request->code; 76 if(!Storage::disk(' local')->has($location)){77 Storage::disk(' local')->move($oldLocation, $location);78 $department->location = Storage::disk('local')->path('') .$location;79 if(!Storage::disk('uploads')->has($location)){ 80 Storage::disk('uploads')->move($oldLocation, $location); 81 $department->location = $location; 79 82 } 80 83 81 foreach ($documents as $document) { 82 foreach($document->files as $file) { 83 $file->location = $location . DIRECTORY_SEPARATOR . $document->name . DIRECTORY_SEPARATOR . $file->name; 84 foreach ($folders as $folder) { 85 $currArchId = explode('/', $folder->arch_id)[1]; 86 $folder->arch_id = $department->code . '/' . $currArchId; 87 $folder->save(); 88 foreach($folder->files as $file) { 89 $file->location = $location . DIRECTORY_SEPARATOR . $folder->name . DIRECTORY_SEPARATOR . $file->name; 84 90 $file->save(); 85 91 } … … 98 104 $department = Department::find($id); 99 105 //$department->delete(); 100 $ documents = $department->document()->count();106 $folders = $department->folder()->count(); 101 107 102 if($ documents > 0){103 Alert::flash($department->name . " has " . $ documents . " document/s associated", "error");108 if($folders > 0){ 109 Alert::flash($department->name . " has " . $folders . " document/s associated", "error"); 104 110 } 105 111 else { … … 111 117 return redirect()->route("dashboard.departments.index"); 112 118 } 119 120 public function downloadAll() 121 { 122 $zip_file=Storage::disk('uploads')->path('Departments.zip'); 123 $zip = new \ZipArchive(); 124 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 125 $path = Storage::disk('uploads')->path('Departments'); 126 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 127 $flag=false; 128 129 foreach ($files as $file) 130 { 131 if(File::all()->count() > 0) { 132 133 // We're skipping all subfolders 134 if (!$file->isDir()) { 135 $filePath = $file->getRealPath(); 136 // extracting filename with substr/strlen 137 $relativePath = substr($filePath, strlen($path) + 1); 138 $zip->addFile($filePath, $relativePath); 139 } 140 } 141 else 142 { 143 $flag=true; 144 break; 145 } 146 } 147 if(!$flag) { 148 $zip->close(); 149 $headers = array('Content-Type' => 'application/octet-stream',); 150 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . '- Departments.zip'; 151 return response()->download($zip_file, $zip_new_name, $headers); 152 } 153 else { 154 Alert::flash("All departments are empty", "warning"); 155 return redirect()->route("dashboard.departments.index"); 156 } 157 } 158 159 public function downloadDepartment($id) 160 { 161 $department = Department::find($id); 162 163 $FileSystem = new Filesystem(); 164 $zip_file = Storage::disk('uploads')->path('Department.zip'); 165 $zip = new \ZipArchive(); 166 $zip->open($zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); 167 $path = Storage::disk('uploads')->path($department->location) . DIRECTORY_SEPARATOR; 168 $files = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path)); 169 170 $filesInDept = $FileSystem->allFiles($path); 171 172 if(!empty($filesInDept)) { 173 foreach ($files as $file) { 174 if (!$file->isDir()) { 175 $filePath = $file->getRealPath(); 176 // extracting filename with substr/strlen 177 $relativePath = substr($filePath, strlen($path) + 1); 178 $zip->addFile($filePath, $relativePath); 179 } 180 } 181 $zip->close(); 182 $headers = array('Content-Type' => 'application/octet-stream',); 183 $zip_new_name = Carbon::now()->format('d.m.Y - H:i') . $department->name . '.zip'; 184 return response()->download($zip_file, $zip_new_name, $headers); 185 } 186 else{ 187 Alert::flash("This department has no files", "warning"); 188 return redirect()->route("dashboard.departments.index"); 189 } 190 191 } 113 192 } -
app/Http/Controllers/Dashboard/IndexController.php
r6b95845 rc6b84df 4 4 5 5 use App\Helpers\Alert; 6 use App\Models\Department; 7 use App\Models\Folder; 8 use App\Models\File; 6 9 use App\Models\User; 7 10 use App\Http\Controllers\Controller; … … 17 20 return view("dashboard.index")->with([ 18 21 "counters" => $counters, 22 "departments" => Department::all(), 23 "folders" => Folder::all(), 24 "files" => File::all() 19 25 ]); 20 26 } -
app/Http/Controllers/Dashboard/SettingsController.php
r6b95845 rc6b84df 5 5 use App\Helpers\Alert; 6 6 use App\Http\Requests\Dashboard\EmailSettingsRequest; 7 use App\Http\Requests\Dashboard\FileTypeRequest; 7 8 use App\Http\Requests\Dashboard\PasswordSettingsRequest; 8 9 use App\Http\Requests\Dashboard\UsernameSettingsRequest; 10 use App\Models\FileType; 9 11 use App\Models\User; 10 12 use App\Http\Controllers\Controller; … … 19 21 public function settings() 20 22 { 23 $fileType = FileType::find("1"); 24 21 25 return view("dashboard.settings.index")->with([ 22 26 "user" => auth()->user(), 23 27 "adminAndReferents" => User::where("role_id", 1)->orWhere("role_id", 2)->get(), 24 "active_tab" => "account" 28 "active_tab" => "account", 29 "fileType" => $fileType 25 30 ]); 26 31 } … … 30 35 $user = auth()->user(); 31 36 $user->username = $request->username; 37 $user->updated_at = Carbon::now(); 32 38 $user->save(); 33 39 … … 42 48 $user = auth()->user(); 43 49 $user->password = bcrypt($request->password); 50 $user->updated_at = Carbon::now(); 44 51 $user->save(); 45 52 … … 58 65 $user->security_code = $user->generateSecurityCode(); 59 66 $user->verify_token = $user->generateVerifyToken(); 67 $user->updated_at = Carbon::now(); 60 68 61 69 $user->save(); … … 69 77 } 70 78 79 80 81 public function fileTypes(FileTypeRequest $request) 82 { 83 $fileType = FileType::find("1"); 84 85 $fileType->mimes = $request->mimes; 86 $fileType->max_size = $request->max_size; 87 $fileType->user_id = auth()->id(); 88 $fileType->updated_at = Carbon::now(); 89 90 if(auth()->user()->hasPermission("manage_file_types")) { 91 $fileType->save(); 92 93 Alert::flash("File validations updated successfully"); 94 95 return redirect()->back(); 96 } 97 else { 98 Alert::flash("You don't have permission to change file validations", "error"); 99 100 return redirect()->back(); 101 } 102 } 103 71 104 } -
app/Http/Controllers/Dashboard/UsersController.php
r6b95845 rc6b84df 24 24 { 25 25 return view("dashboard.users.index")->with([ 26 "users" => User::all() 26 "users" => User::all(), 27 "roles" => Role::all(), 27 28 ]); 28 29 } … … 62 63 $user->avatar = $avatarName; 63 64 } 65 66 $user->created_by = auth()->user()->id; 64 67 $user->save(); 65 68 … … 88 91 $user->phone_number = $request->phone_number; 89 92 $user->role_id = $request->userRole; 90 $user->updated_at = $request->Carbon::now();;93 $user->updated_at = Carbon::now(); 91 94 92 95 if ($request->hasFile("avatar")) {
Note:
See TracChangeset
for help on using the changeset viewer.