@@ -32,60 +32,7 @@ public function index(Request $request)
3232 '403 Forbidden '
3333 );
3434
35- // get all domains
36- $ domains = Domain::All ();
37-
38- /*
39- // get all attributes
40- $attributes = [];
41- $allAttributes = DB::table('measures')->select('attributes')->get();
42- foreach ($allAttributes as $attribute) {
43- foreach (explode(' ', $attribute->attributes) as $value) {
44- if (strlen($value) > 0) {
45- array_push($attributes, $value);
46- }
47- }
48- }
49- sort($attributes);
50- $attributes = array_unique($attributes);
51- */
52- // get all clauses
53- $ clauses = DB ::table ('measures ' )->select ('clause ' )->get ()->pluck ('clause ' )->toArray ();
54-
55- // get domain base on his title
56- $ domain_title = $ request ->get ('domain_title ' );
57- if ($ domain_title !== null ) {
58- $ domain = Domain::where ('title ' , '= ' , $ domain_title )->get ();
59- if ($ domain !== null ) {
60- $ domain = $ domain ->first ()->id ;
61- $ request ->session ()->put ('domain ' , $ domain );
62- }
63- }
64-
65- // get all scopes
66- $ scopes = DB ::table ('controls ' )
67- ->select ('scope ' )
68- ->whereNotNull ('scope ' )
69- ->where ('scope ' , '<> ' , '' );
70- if (Auth::User ()->role === 5 ) {
71- $ scopes = $ scopes
72- ->leftjoin (
73- 'control_user ' ,
74- 'controls.id ' ,
75- '= ' ,
76- 'control_user.control_id '
77- )
78- ->where ('control_user.user_id ' , '= ' , Auth::User ()->id );
79- }
80- $ scopes = $ scopes
81- //->whereNull('realisation_date')
82- ->whereIn ('status ' , [0 , 1 ])
83- ->distinct ()
84- ->orderBy ('scope ' )
85- ->get ()
86- ->pluck ('scope ' )
87- ->toArray ();
88-
35+ // -----------------------------------------------------
8936 // Domain filter
9037 $ domain = $ request ->get ('domain ' );
9138 if ($ domain !== null ) {
@@ -125,21 +72,6 @@ public function index(Request $request)
12572 $ scope = $ request ->session ()->get ('scope ' );
12673 }
12774
128- // Attribute filter
129- /*
130- $attribute = $request->get('attribute');
131- if ($attribute !== null) {
132- if ($attribute === 'none') {
133- $request->session()->forget('attribute');
134- $attribute = null;
135- } else {
136- $request->session()->put('attribute', $attribute);
137- }
138- } else {
139- $attribute = $request->session()->get('attribute');
140- }
141- */
142-
14375 // Period filter
14476 $ period = $ request ->get ('period ' );
14577 if ($ period !== null ) {
@@ -174,6 +106,52 @@ public function index(Request $request)
174106 $ status = '2 ' ;
175107 }
176108
109+ // -----------------------------------------------------
110+ // get all domains
111+ $ domains = Domain::All ();
112+
113+ // get all clauses
114+ $ clauses = DB ::table ('measures ' )
115+ ->select ('clause ' )
116+ ->when ($ domain !=null , function ($ q ) use ($ domain ) {
117+ return $ q ->where ('domain_id ' , '= ' , $ domain );
118+ })
119+ ->get ()
120+ ->pluck ('clause ' );
121+
122+ // get domain base on his title
123+ $ domain_title = $ request ->get ('domain_title ' );
124+ if ($ domain_title !== null ) {
125+ $ domain = Domain::where ('title ' , '= ' , $ domain_title )->get ();
126+ if ($ domain !== null ) {
127+ $ domain = $ domain ->first ()->id ;
128+ $ request ->session ()->put ('domain ' , $ domain );
129+ }
130+ }
131+
132+ // get all scopes
133+ $ scopes = DB ::table ('controls ' )
134+ ->select ('scope ' )
135+ ->whereNotNull ('scope ' )
136+ ->where ('scope ' , '<> ' , '' );
137+ if (Auth::User ()->role === 5 ) {
138+ $ scopes = $ scopes
139+ ->leftjoin (
140+ 'control_user ' ,
141+ 'controls.id ' ,
142+ '= ' ,
143+ 'control_user.control_id '
144+ )
145+ ->where ('control_user.user_id ' , '= ' , Auth::User ()->id );
146+ }
147+ $ scopes = $ scopes
148+ ->whereIn ('status ' , [0 , 1 ])
149+ ->distinct ()
150+ ->orderBy ('scope ' )
151+ ->get ()
152+ ->pluck ('scope ' );
153+
154+ // -----------------------------------------------------
177155 // Build query
178156 $ controls = DB ::table ('controls as c1 ' )
179157 ->leftjoin ('controls as c2 ' , 'c1.next_id ' , '= ' , 'c2.id ' )
@@ -213,17 +191,6 @@ public function index(Request $request)
213191 $ controls = $ controls ->where ('c1.scope ' , '= ' , $ scope );
214192 }
215193
216- // filter on measure
217- /*
218- if ($request->measure !== null) {
219- $controls = $controls->where(
220- 'control_measure.measure_id',
221- '=',
222- $request->measure
223- );
224- }
225- */
226-
227194 // Filter on period
228195 if ($ period !== null && $ period !== 99 ) {
229196 $ controls = $ controls
@@ -271,17 +238,6 @@ public function index(Request $request)
271238 }
272239 }
273240
274- // Filter on attribute
275- /*
276- if ($attribute !== null) {
277- $controls = $controls->where(
278- 'c1.attributes',
279- 'LIKE',
280- '%' . $attribute . '%'
281- );
282- }
283- */
284-
285241 // get action plan associated
286242 $ controls = $ controls ->leftjoin ('actions ' , 'actions.control_id ' , '= ' , 'c1.id ' );
287243
@@ -363,8 +319,7 @@ public function create()
363319 ->distinct ()
364320 ->orderBy ('scope ' )
365321 ->get ()
366- ->pluck ('scope ' )
367- ->toArray ();
322+ ->pluck ('scope ' );
368323
369324 // get all attributes
370325 $ values = [];
@@ -535,8 +490,7 @@ public function edit(int $id)
535490 ->select ('id ' )
536491 ->orderBy ('id ' )
537492 ->get ()
538- ->pluck ('id ' )
539- ->toArray ();
493+ ->pluck ('id ' );
540494
541495 // get all clauses
542496 $ all_measures = DB ::table ('measures ' )
@@ -618,8 +572,7 @@ public function clone(Request $request)
618572 ->distinct ()
619573 ->orderBy ('scope ' )
620574 ->get ()
621- ->pluck ('scope ' )
622- ->toArray ();
575+ ->pluck ('scope ' );
623576
624577 // get all attributes
625578 $ values = [];
@@ -967,8 +920,7 @@ public function measures(Request $request)
967920 ->distinct ()
968921 ->orderBy ('scope ' )
969922 ->get ()
970- ->pluck ('scope ' )
971- ->toArray ();
923+ ->pluck ('scope ' );
972924
973925 $ cur_scope = $ request ->get ('scope ' );
974926 if ($ cur_scope !== null ) {
@@ -1117,8 +1069,7 @@ public function plan(int $id)
11171069 ->select ('measure_id ' )
11181070 ->where ('control_id ' , $ id )
11191071 ->get ()
1120- ->pluck ('measure_id ' )
1121- ->toArray ();
1072+ ->pluck ('measure_id ' );
11221073
11231074 // Get al active scopes
11241075 $ scopes = DB ::table ('controls ' )
@@ -1127,8 +1078,7 @@ public function plan(int $id)
11271078 ->distinct ()
11281079 ->orderBy ('scope ' )
11291080 ->get ()
1130- ->pluck ('scope ' )
1131- ->toArray ();
1081+ ->pluck ('scope ' );
11321082
11331083 return view ('controls.plan ' , compact ('control ' ))
11341084 ->with ('years ' , $ years )
@@ -1365,14 +1315,14 @@ public function doMake(Request $request)
13651315 $ measures = DB ::table ('control_measure ' )
13661316 ->select ('measure_id ' )
13671317 ->where ('control_id ' , $ control ->id )
1368- ->pluck ('measure_id ' )-> toArray () ;
1318+ ->pluck ('measure_id ' );
13691319 $ action ->measures ()->sync ($ measures );
13701320
13711321 // Sync owners
13721322 $ owners = DB ::table ('control_user ' )
13731323 ->select ('user_id ' )
13741324 ->where ('control_id ' , $ control ->id )
1375- ->pluck ('user_id ' )-> toArray () ;
1325+ ->pluck ('user_id ' );
13761326 $ action ->owners ()->sync ($ owners );
13771327 }
13781328 } else {
@@ -1414,12 +1364,12 @@ public function doMake(Request $request)
14141364 // Set owners
14151365 $ new_control
14161366 ->owners ()
1417- ->sync ($ control ->owners ->pluck ('id ' )-> toArray () );
1367+ ->sync ($ control ->owners ->pluck ('id ' ));
14181368
14191369 // Set measures
14201370 $ new_control
14211371 ->measures ()
1422- ->sync ($ control ->measures ->pluck ('id ' )-> toArray () );
1372+ ->sync ($ control ->measures ->pluck ('id ' ));
14231373
14241374 // make link
14251375 $ control ->next_id = $ new_control ->id ;
0 commit comments