@@ -379,7 +379,7 @@ public function store(Request $request)
379379 'scope ' => 'max:32 ' ,
380380 'objective ' => 'required ' ,
381381 'plan_date ' => 'required ' ,
382- 'periodicity ' => 'required|integer ' ,
382+ 'periodicity ' => 'required|integer|in:-1,0,1,3,6,12 ' ,
383383 ]
384384 );
385385
@@ -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
@@ -1285,7 +1299,7 @@ public function doPlan(Request $request)
12851299 // Validate fields
12861300 $ this ->validate ($ request , [
12871301 'plan_date ' => 'required ' ,
1288- 'periodicity ' => 'required ' ,
1302+ 'periodicity ' => 'required|integer|in:-1,0,1,3,6,12 ' ,
12891303 ]);
12901304
12911305 // Find the control
@@ -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 ' );
@@ -1523,7 +1549,7 @@ public function save(Request $request)
15231549 'scope ' => 'max:32 ' ,
15241550 'objective ' => 'required ' ,
15251551 'plan_date ' => 'required ' ,
1526- 'periodicity ' => 'required|integer ' ,
1552+ 'periodicity ' => 'required|integer|in:-1,0,1,3,6,12 ' ,
15271553 ]
15281554 );
15291555
@@ -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 );
0 commit comments