Skip to content

Commit ffdbe18

Browse files
committed
add weekly periodicity
1 parent ea8b4e9 commit ffdbe18

File tree

12 files changed

+93
-43
lines changed

12 files changed

+93
-43
lines changed

app/Http/Controllers/ControlController.php

Lines changed: 56 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -791,17 +791,31 @@ public function history()
791791
foreach ($controls as $control) {
792792
$expandedControls->push($control);
793793

794-
if (($control->realisation_date === null) &&
795-
($control->periodicity > 0) && ($control->periodicity <= 12)) {
796-
for ($i = 1; $i <= 12 / $control->periodicity; $i++) {
797-
$repeatedControl = clone $control;
798-
$repeatedControl->id = null;
799-
$repeatedControl->score = null;
800-
$repeatedControl->observations = null;
801-
$repeatedControl->realisation_date = null;
802-
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addMonthsNoOverflow($i * $control->periodicity);
803-
$expandedControls->push($repeatedControl);
794+
if ($control->realisation_date === null) {
795+
if ($control->periodicity === -1) {
796+
// weekly
797+
for ($i = 1; $i <= 52; $i++) {
798+
$repeatedControl = clone $control;
799+
$repeatedControl->id = null;
800+
$repeatedControl->score = null;
801+
$repeatedControl->observations = null;
802+
$repeatedControl->realisation_date = null;
803+
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addDays($i * 7);
804+
$expandedControls->push($repeatedControl);
805+
}
804806
}
807+
else if (($control->periodicity > 0) && ($control->periodicity <= 12)) {
808+
// Monthly
809+
for ($i = 1; $i <= 12 / $control->periodicity; $i++) {
810+
$repeatedControl = clone $control;
811+
$repeatedControl->id = null;
812+
$repeatedControl->score = null;
813+
$repeatedControl->observations = null;
814+
$repeatedControl->realisation_date = null;
815+
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addMonthsNoOverflow($i * $control->periodicity);
816+
$expandedControls->push($repeatedControl);
817+
}
818+
}
805819
}
806820
}
807821
// Return view with controls
@@ -1357,10 +1371,19 @@ public function make(Request $request)
13571371
$next_date = null;
13581372
} else {
13591373
// Computer next Date
1360-
$next_date =
1361-
Carbon::createFromFormat('Y-m-d', $control->plan_date)
1362-
->addMonthsNoOverflow($control->periodicity)
1363-
->format('Y-m-d');
1374+
if ($control->periodicity === -1) {
1375+
// One week
1376+
$next_date =
1377+
Carbon::createFromFormat('Y-m-d', $control->plan_date)
1378+
->addDays(7)
1379+
->format('Y-m-d');
1380+
}
1381+
else
1382+
// Add months
1383+
$next_date =
1384+
Carbon::createFromFormat('Y-m-d', $control->plan_date)
1385+
->addMonthsNoOverflow($control->periodicity)
1386+
->format('Y-m-d');
13641387
}
13651388

13661389
// return view
@@ -1461,16 +1484,19 @@ public function doMake(Request $request)
14611484
$new_control->score = null;
14621485
$new_control->status = 0;
14631486
// only admin and user can update the plan_date, realisation_date and action_plan
1464-
if (Auth::User()->role === 1 || Auth::User()->role === 2) {
1487+
if (Auth::User()->isAdmin() || Auth::User()->isUser()) {
14651488
$new_control->plan_date = request('next_date');
14661489
} else {
1467-
$new_control->plan_date = date(
1468-
'Y-m-d',
1469-
strtotime(
1470-
$control->periodicity . ' months',
1471-
strtotime($control->plan_date)
1472-
)
1473-
);
1490+
if ($control->periodicity === -1)
1491+
// One week
1492+
$new_control->plan_date = Carbon::parse($control->plan_date)
1493+
->addDays(7)
1494+
->toDateString();
1495+
else
1496+
// Months
1497+
$new_control->plan_date = Carbon::parse($control->plan_date)
1498+
->addMonths($control->periodicity)
1499+
->toDateString();
14741500
}
14751501
$new_control->save();
14761502

@@ -1505,13 +1531,13 @@ public function save(Request $request)
15051531
{
15061532
// Only for CISO
15071533
abort_if(
1508-
Auth::User()->role !== 1,
1534+
! Auth::User()->isAdmin(),
15091535
Response::HTTP_FORBIDDEN,
15101536
'403 Forbidden'
15111537
);
15121538

15131539
// Get the control
1514-
$control = Control::find($request->id);
1540+
$control = Control::query()->find($request->id);
15151541

15161542
// Control not found
15171543
abort_if($control === null, Response::HTTP_NOT_FOUND, '404 Not Found');
@@ -1583,7 +1609,7 @@ public function draft(Request $request)
15831609
{
15841610
// Not for API
15851611
abort_if(
1586-
Auth::User()->role === 4,
1612+
Auth::User()->isAPI(),
15871613
Response::HTTP_FORBIDDEN,
15881614
'403 Forbidden'
15891615
);
@@ -1611,7 +1637,7 @@ public function draft(Request $request)
16111637
$control->score = request('score') === 0 ? null : request('score');
16121638

16131639
// only admin and user can update the plan_date and action_plan
1614-
if (Auth::User()->role === 1 || Auth::User()->role === 2) {
1640+
if (Auth::User()->isAdmin() || Auth::User()->isUser()) {
16151641
$control->plan_date = request('plan_date');
16161642
$control->action_plan = request('action_plan');
16171643
// do not save the realisation date as it is in draft
@@ -1632,7 +1658,7 @@ public function reject(Request $request)
16321658
{
16331659
// Only for Admin and user
16341660
abort_if(
1635-
! (Auth::User()->role === 1 || Auth::User()->role === 2),
1661+
! (Auth::User()->isAdmin() || Auth::User()->isUser()),
16361662
Response::HTTP_FORBIDDEN,
16371663
'403 Forbidden'
16381664
);
@@ -1766,15 +1792,15 @@ public function tempo(Request $request)
17661792
{
17671793
// For administrators and users only
17681794
abort_if(
1769-
Auth::User()->role !== 1 && Auth::User()->role !== 2,
1795+
! Auth::User()->isAdmin() && !Auth::User()->isUser(),
17701796
Response::HTTP_FORBIDDEN,
17711797
'403 Forbidden'
17721798
);
17731799

17741800
// get measures
17751801
if ($request->id !== null) {
17761802
// Find associate control
1777-
$measures = Measure::where('clause', '=', $request->id)->get();
1803+
$measures = Measure::query()->where('clause', '=', $request->id)->get();
17781804
} else {
17791805
$measures = Collect();
17801806
}
@@ -1795,7 +1821,7 @@ public function template(Request $request)
17951821
{
17961822
// Not for API
17971823
abort_if(
1798-
Auth::User()->role === 4,
1824+
Auth::User()->isAPI(),
17991825
Response::HTTP_FORBIDDEN,
18001826
'403 Forbidden'
18011827
);

app/Http/Controllers/HomeController.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -419,18 +419,30 @@ private function getExpandedControls()
419419
return $controls->flatMap(function ($control) {
420420
$expanded = collect([$control]);
421421

422-
if ($control->realisation_date === null && $control->periodicity > 0 && $control->periodicity <= 12) {
423-
for ($i = 1; $i <= 12 / $control->periodicity; $i++) {
424-
$repeatedControl = clone $control;
425-
$repeatedControl->id = null;
426-
$repeatedControl->score = null;
427-
$repeatedControl->observations = null;
428-
$repeatedControl->realisation_date = null;
429-
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addMonthsNoOverflow($i * $control->periodicity);
430-
$expanded->push($repeatedControl);
422+
if ($control->realisation_date === null) {
423+
if ($control->periodicity === -1) {
424+
for ($i = 1; $i <= 32; $i++) {
425+
$repeatedControl = clone $control;
426+
$repeatedControl->id = null;
427+
$repeatedControl->score = null;
428+
$repeatedControl->observations = null;
429+
$repeatedControl->realisation_date = null;
430+
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addDays($i * 7);
431+
$expanded->push($repeatedControl);
432+
}
433+
}
434+
else if ($control->periodicity > 0 && $control->periodicity <= 12) {
435+
for ($i = 1; $i <= 12 / $control->periodicity; $i++) {
436+
$repeatedControl = clone $control;
437+
$repeatedControl->id = null;
438+
$repeatedControl->score = null;
439+
$repeatedControl->observations = null;
440+
$repeatedControl->realisation_date = null;
441+
$repeatedControl->plan_date = Carbon::parse($control->plan_date)->addMonthsNoOverflow($i * $control->periodicity);
442+
$expanded->push($repeatedControl);
443+
}
431444
}
432445
}
433-
434446
return $expanded;
435447
});
436448
}

resources/lang/de/common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'validate' => 'Validieren',
2222

2323
'once' => 'einmalig',
24+
'weekly' => 'wöchentlich',
2425
'monthly' => 'monatlich',
2526
'quarterly' => 'quartal',
2627
'biannually' => 'halbjährlich',

resources/lang/en/common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'validate' => 'Validate',
2525

2626
'once' => 'Once',
27+
'weekly' => 'Weekly',
2728
'monthly' => 'Monthly',
2829
'quarterly' => 'Quarterly',
2930
'biannually' => 'Biannually',

resources/lang/fr/common.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
'validate' => 'Valider',
2525

2626
'once' => 'Une fois',
27+
'weekly' => 'Hebdomadaire',
2728
'monthly' => 'Mensuel',
2829
'quarterly' => 'Trimestriel',
2930
'biannually' => 'Bisanuel',

resources/views/actions/index.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@
9898
@foreach($actions as $action)
9999
<tr>
100100
<td>
101-
<b id="{{ $action->reference }}"><a href="/action/show/{{ $action->id }}">{{ $action->reference==null ? ("ACT-".$action->id) : $action->reference }}<a>
101+
<b id="{{ $action->reference }}">
102+
<a href="/action/show/{{ $action->id }}">{{ $action->reference==null ? ("ACT-".$action->id) : $action->reference }}</a>
103+
</b>
102104
</td>
103105
<td>
104106
<p id="{{ $action->type }}">

resources/views/controls/create.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@
117117
<div class="cell-lg-2 cell-md-4">
118118
<select data-role="select" id='periodicity' name="periodicity">
119119
<option value="0" {{ old("periodicity")=="0" ? "selected" : ""}}>{{ trans('common.once') }}</option>
120+
<option value="-1" {{ old("periodicity")=="-1" ? "selected" : ""}}>{{ trans('common.weekly') }}</option>
120121
<option value="1" {{ old("periodicity")=="1" ? "selected" : ""}}>{{ trans('common.monthly') }}</option>
121122
<option value="3" {{ old("periodicity")=="3" ? "selected" : ""}}>{{ trans('common.quarterly') }}</option>
122123
<option value="6" {{ old("periodicity")=="6" ? "selected" : ""}}>{{ trans('common.biannually') }}</option>

resources/views/controls/edit.blade.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@
189189
<div class="cell-lg-2 cell-md-2">
190190
<select data-role="select" id="periodicity" name="periodicity">
191191
<option value="0" {{ $control->periodicity==0 ? "selected" : ""}}>{{ trans('common.once') }}</option>
192+
<option value="2" {{ $control->periodicity==-1 ? "selected" : ""}}>{{ trans('common.weekly') }}</option>
192193
<option value="1" {{ $control->periodicity==1 ? "selected" : ""}}>{{ trans('common.monthly') }}</option>
193194
<option value="3" {{ $control->periodicity==3 ? "selected" : ""}}>{{ trans('common.quarterly') }}</option>
194195
<option value="6" {{ $control->periodicity==6 ? "selected" : ""}}>{{ trans('common.biannually') }}</option>

resources/views/controls/make.blade.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@
209209
{{ $next_date }}
210210
@endif
211211
(
212-
@if ($control->periodicity==1)
212+
@if ($control->periodicity==-1)
213+
{{ trans("common.weekly") }}
214+
@elseif ($control->periodicity==1)
213215
{{ trans("common.monthly") }}
214216
@elseif ($control->periodicity==3)
215217
{{ trans("common.quarterly") }}

resources/views/controls/plan.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
</div>
7777
<div class="cell-lg-2 cell-md-3">
7878
<select name="periodicity" data-role="select">
79-
<option value="1" {{ $control->periodicity==0 ? "selected" : ""}}>{{ trans('common.once') }}</option>
79+
<option value="0" {{ $control->periodicity==0 ? "selected" : ""}}>{{ trans('common.once') }}</option>
80+
<option value="-1" {{ $control->periodicity==-1 ? "selected" : ""}}>{{ trans('common.weekly') }}</option>
8081
<option value="1" {{ $control->periodicity==1 ? "selected" : ""}}>{{ trans('common.monthly') }}</option>
8182
<option value="3" {{ $control->periodicity==3 ? "selected" : ""}}>{{ trans('common.quarterly') }}</option>
8283
<option value="6" {{ $control->periodicity==6 ? "selected" : ""}}>{{ trans('common.biannually') }}</option>

0 commit comments

Comments
 (0)