Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 57 additions & 107 deletions app/Http/Controllers/ControlController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,60 +32,7 @@ public function index(Request $request)
'403 Forbidden'
);

// get all domains
$domains = Domain::All();

/*
// get all attributes
$attributes = [];
$allAttributes = DB::table('measures')->select('attributes')->get();
foreach ($allAttributes as $attribute) {
foreach (explode(' ', $attribute->attributes) as $value) {
if (strlen($value) > 0) {
array_push($attributes, $value);
}
}
}
sort($attributes);
$attributes = array_unique($attributes);
*/
// get all clauses
$clauses = DB::table('measures')->select('clause')->get()->pluck('clause')->toArray();

// get domain base on his title
$domain_title = $request->get('domain_title');
if ($domain_title !== null) {
$domain = Domain::where('title', '=', $domain_title)->get();
if ($domain !== null) {
$domain = $domain->first()->id;
$request->session()->put('domain', $domain);
}
}

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '');
if (Auth::User()->role === 5) {
$scopes = $scopes
->leftjoin(
'control_user',
'controls.id',
'=',
'control_user.control_id'
)
->where('control_user.user_id', '=', Auth::User()->id);
}
$scopes = $scopes
//->whereNull('realisation_date')
->whereIn('status', [0, 1])
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();

// -----------------------------------------------------
// Domain filter
$domain = $request->get('domain');
if ($domain !== null) {
Expand Down Expand Up @@ -125,21 +72,6 @@ public function index(Request $request)
$scope = $request->session()->get('scope');
}

// Attribute filter
/*
$attribute = $request->get('attribute');
if ($attribute !== null) {
if ($attribute === 'none') {
$request->session()->forget('attribute');
$attribute = null;
} else {
$request->session()->put('attribute', $attribute);
}
} else {
$attribute = $request->session()->get('attribute');
}
*/

// Period filter
$period = $request->get('period');
if ($period !== null) {
Expand Down Expand Up @@ -174,6 +106,52 @@ public function index(Request $request)
$status = '2';
}

// -----------------------------------------------------
// get all domains
$domains = Domain::All();

// get all clauses
$clauses = DB::table('measures')
->select('clause')
->when($domain!=null, function ($q) use ($domain) {
return $q->where('domain_id', '=', $domain);
})
->get()
->pluck('clause');

// get domain base on his title
$domain_title = $request->get('domain_title');
if ($domain_title !== null) {
$domain = Domain::where('title', '=', $domain_title)->get();
if ($domain !== null) {
$domain = $domain->first()->id;
$request->session()->put('domain', $domain);
}
}

// get all scopes
$scopes = DB::table('controls')
->select('scope')
->whereNotNull('scope')
->where('scope', '<>', '');
if (Auth::User()->role === 5) {
$scopes = $scopes
->leftjoin(
'control_user',
'controls.id',
'=',
'control_user.control_id'
)
->where('control_user.user_id', '=', Auth::User()->id);
}
$scopes = $scopes
->whereIn('status', [0, 1])
->distinct()
->orderBy('scope')
->get()
->pluck('scope');

// -----------------------------------------------------
// Build query
$controls = DB::table('controls as c1')
->leftjoin('controls as c2', 'c1.next_id', '=', 'c2.id')
Expand Down Expand Up @@ -213,17 +191,6 @@ public function index(Request $request)
$controls = $controls->where('c1.scope', '=', $scope);
}

// filter on measure
/*
if ($request->measure !== null) {
$controls = $controls->where(
'control_measure.measure_id',
'=',
$request->measure
);
}
*/

// Filter on period
if ($period !== null && $period !== 99) {
$controls = $controls
Expand Down Expand Up @@ -271,17 +238,6 @@ public function index(Request $request)
}
}

// Filter on attribute
/*
if ($attribute !== null) {
$controls = $controls->where(
'c1.attributes',
'LIKE',
'%' . $attribute . '%'
);
}
*/

// get action plan associated
$controls = $controls->leftjoin('actions', 'actions.control_id', '=', 'c1.id');

Expand Down Expand Up @@ -363,8 +319,7 @@ public function create()
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();
->pluck('scope');

// get all attributes
$values = [];
Expand Down Expand Up @@ -535,8 +490,7 @@ public function edit(int $id)
->select('id')
->orderBy('id')
->get()
->pluck('id')
->toArray();
->pluck('id');

// get all clauses
$all_measures = DB::table('measures')
Expand Down Expand Up @@ -618,8 +572,7 @@ public function clone(Request $request)
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();
->pluck('scope');

// get all attributes
$values = [];
Expand Down Expand Up @@ -967,8 +920,7 @@ public function measures(Request $request)
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();
->pluck('scope');

$cur_scope = $request->get('scope');
if ($cur_scope !== null) {
Expand Down Expand Up @@ -1117,8 +1069,7 @@ public function plan(int $id)
->select('measure_id')
->where('control_id', $id)
->get()
->pluck('measure_id')
->toArray();
->pluck('measure_id');

// Get al active scopes
$scopes = DB::table('controls')
Expand All @@ -1127,8 +1078,7 @@ public function plan(int $id)
->distinct()
->orderBy('scope')
->get()
->pluck('scope')
->toArray();
->pluck('scope');

return view('controls.plan', compact('control'))
->with('years', $years)
Expand Down Expand Up @@ -1365,14 +1315,14 @@ public function doMake(Request $request)
$measures = DB::table('control_measure')
->select('measure_id')
->where('control_id', $control->id)
->pluck('measure_id')->toArray();
->pluck('measure_id');
$action->measures()->sync($measures);

// Sync owners
$owners = DB::table('control_user')
->select('user_id')
->where('control_id', $control->id)
->pluck('user_id')->toArray();
->pluck('user_id');
$action->owners()->sync($owners);
}
} else {
Expand Down Expand Up @@ -1414,12 +1364,12 @@ public function doMake(Request $request)
// Set owners
$new_control
->owners()
->sync($control->owners->pluck('id')->toArray());
->sync($control->owners->pluck('id'));

// Set measures
$new_control
->measures()
->sync($control->measures->pluck('id')->toArray());
->sync($control->measures->pluck('id'));

// make link
$control->next_id = $new_control->id;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/MeasureController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function store(Request $request)
$request,
[
'domain_id' => 'required',
'clause' => 'required|min:3|max:30',
'clause' => 'required|min:3|max:30|unique:measures,clause',
'name' => 'required|min:5|max:255',
'objective' => 'required',
]
Expand Down
3 changes: 1 addition & 2 deletions resources/views/controls/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@
</div>
<div class="cell-1">
<input type="text" name="scope" data-role="input" autocomplete="off" maxlength="32"
value="{{ old('scope') }}" data-autocomplete=" {{ implode(",",$scopes) }} "/>
value="{{ old('scope') }}" data-autocomplete=" {{ $scopes->implode(",") }} "/>
</div>
</div>


<div class="row">
<div class="cell-1">
<strong>{{ trans("cruds.control.fields.objective") }}</strong>
Expand Down