diff --git a/app/Http/Controllers/ControlController.php b/app/Http/Controllers/ControlController.php index 2308b5a3..e58a8c2b 100644 --- a/app/Http/Controllers/ControlController.php +++ b/app/Http/Controllers/ControlController.php @@ -554,6 +554,79 @@ public function edit(int $id) ->with('users', $users); } + /** + * Clone a control. + * + * @param int Control id + * + * @return \Illuminate\Http\Response + */ + public function clone(Request $request) + { + // Only for admin and users + abort_if( + (Auth::User()->role !== 1) && (Auth::User()->role !== 2), + Response::HTTP_FORBIDDEN, + '403 Forbidden' + ); + + // get all clauses + $all_measures = DB::table('measures') + ->select('id', 'clause') + ->orderBy('id') + ->get(); + + // get all scopes + $scopes = DB::table('controls') + ->select('scope') + ->whereNotNull('scope') + ->where('scope', '<>', '') + ->whereIn('status', [0, 1]) + ->distinct() + ->orderBy('scope') + ->get() + ->pluck('scope') + ->toArray(); + + // get all attributes + $values = []; + $attributes = DB::table('measures')->select('attributes')->get(); + foreach ($attributes as $key) { + foreach (explode(' ', $key->attributes) as $value) { + array_push($values, $value); + } + } + sort($values); + $values = array_unique($values); + + $users = User::orderBy('name')->get(); + + // Get Control + $control = Control::find($request->id); + + // Workstation not found + abort_if($control === null, Response::HTTP_NOT_FOUND, '404 Not Found'); + + $request->merge($control->only( + [ + "name","scope", "objective", + "input", "periodicity", "model", "action_plan", + "plan_date" + ] + ) + ); + $request->merge(['measures' => $control->measures()->pluck('id')->toArray()]); + $request->merge(['attributes' => explode(' ', $control->attributes)]); + $request->merge(['owners' => $control->owners()->pluck('id')->toArray()]); + $request->flash(); + + return view('controls.create') + ->with('scopes', $scopes) + ->with('all_measures', $all_measures) + ->with('attributes', $values) + ->with('users', $users); + } + /** * Remove the specified resource from storage. * diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index dd9eb0ba..0a0ab7f1 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -115,7 +115,7 @@ public function edit(User $user) // Allow only admin or the owner of the profile to edit $this->authorizeAdminOrOwner($user); - $controls = Control::select('id', 'clause')->whereNull('realisation_date')->orderBy('clause')->get(); + $controls = Control::select('id', 'name')->whereNull('realisation_date')->orderBy('name')->get(); return view('users.edit', compact('user', 'controls')); } diff --git a/resources/views/controls/create.blade.php b/resources/views/controls/create.blade.php index c0e69197..40287bca 100644 --- a/resources/views/controls/create.blade.php +++ b/resources/views/controls/create.blade.php @@ -70,9 +70,9 @@ diff --git a/resources/views/controls/index.blade.php b/resources/views/controls/index.blade.php index 9cccccfa..7756c5ed 100644 --- a/resources/views/controls/index.blade.php +++ b/resources/views/controls/index.blade.php @@ -148,7 +148,7 @@ > - {{ trans("cruds.control.fields.measure") }} + {{ trans("cruds.control.fields.clauses") }} {{ trans("cruds.control.fields.name") }} {{ trans("cruds.control.fields.scope") }} {{ trans("cruds.control.fields.score") }} diff --git a/resources/views/controls/show.blade.php b/resources/views/controls/show.blade.php index c2f70679..f85a07ce 100644 --- a/resources/views/controls/show.blade.php +++ b/resources/views/controls/show.blade.php @@ -289,6 +289,14 @@   +
+ +
+  
-   +   @endif