From ed3edd181b0a3ce0e1c95614c93a62cb61bce07c Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Tue, 26 Oct 2021 16:12:47 +0200 Subject: [PATCH 01/16] Fix --- app/Http/Controllers/HomeController.php | 46 +++++++++++++++++++++++++ resources/views/home.blade.php | 33 ++++-------------- 2 files changed, 52 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index bb6838f3..aa979a65 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\UsefulLink; +use App\Models\Configuration; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -13,6 +14,8 @@ class HomeController extends Controller $this->middleware('auth'); } + + /** Show the application dashboard. */ public function index(Request $request) { @@ -27,4 +30,47 @@ class HomeController extends Controller 'useful_links' => UsefulLink::all()->sortBy('id') ]); } + + public static function CreditsLeftBox(){ + $usage = 0; + $CREDITS_DISPLAY_NAME = Configuration::getValueByKey('CREDITS_DISPLAY_NAME'); + foreach (Auth::user()->servers as $server){ + $usage += $server->product->price; + } + + if(Auth::user()->Credits() > 0.01 and $usage > 0){ + $Days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); + $Hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); + echo ' +
+
'; + if($Days >= 15){ + echo ''; + } + elseif ($Days >= 8 && $Days <= 14){ + echo ''; + } + elseif ($Days <= 7){ + echo ''; + } + + echo ' + +
+ Out of '.$CREDITS_DISPLAY_NAME.' in '; + if($Days < "1"){ + if($Hours < "1"){ + echo 'You ran out of Credits '; + } + else{ + echo ' '.$Hours.' hours'; + } + }else{ + echo ''.number_format($Days,0).' days'; + } + } + echo' +
+
'; + } } diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 50b2d0db..9ec07792 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -1,5 +1,8 @@ + + @extends('layouts.main') + @section('content')
@@ -67,36 +70,12 @@
- @if(Auth::user()->Credits() > 0.01 and $useage > 0) -
-
- @if(number_format((Auth::user()->Credits()*30)/$useage,0,'.','') >= 15) - - @elseif (number_format((Auth::user()->Credits()*30)/$useage,0,'.','') >= 8 && number_format((Auth::user()->Credits()*30)/$useage,0,'.','') <= 14) - - @elseif (number_format((Auth::user()->Credits()*30)/$useage,0,'.','') <= 7) - - @endif - - -
- Out of {{CREDITS_DISPLAY_NAME}} in - @if(number_format((Auth::user()->Credits()*30)/$useage,2,'.','') < "1") - @if(number_format(Auth::user()->Credits()/($useage/30/24),2,'.','') < "1") - You ran out of Credits - @else - {{number_format(Auth::user()->Credits()/($useage/30/24),0,'.','')}} hours - @endif - @else - {{number_format((Auth::user()->Credits()*30)/$useage,0,'.','')}} days - @endif -
- -
+ {{ HomeController::CreditsLeftBox() }} +
- @endif + From 70b937324e8b9e56c66b33986b6a17f7bd52c248 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Tue, 26 Oct 2021 16:18:16 +0200 Subject: [PATCH 02/16] formatting? --- app/Http/Controllers/HomeController.php | 73 +++++++++++++------------ 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index aa979a65..4f6f57ce 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -31,46 +31,47 @@ class HomeController extends Controller ]); } - public static function CreditsLeftBox(){ + public static function CreditsLeftBox(){ $usage = 0; - $CREDITS_DISPLAY_NAME = Configuration::getValueByKey('CREDITS_DISPLAY_NAME'); + foreach (Auth::user()->servers as $server){ $usage += $server->product->price; } - + if(Auth::user()->Credits() > 0.01 and $usage > 0){ - $Days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); - $Hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); - echo ' -
-
'; - if($Days >= 15){ - echo ''; - } - elseif ($Days >= 8 && $Days <= 14){ - echo ''; - } - elseif ($Days <= 7){ - echo ''; - } - - echo ' - -
- Out of '.$CREDITS_DISPLAY_NAME.' in '; - if($Days < "1"){ - if($Hours < "1"){ - echo 'You ran out of Credits '; - } - else{ - echo ' '.$Hours.' hours'; - } - }else{ - echo ''.number_format($Days,0).' days'; + $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); + $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); + echo ' +
+
'; + if($days >= 15){ + echo ''; } - } - echo' -
-
'; - } + elseif ($days >= 8 && $days <= 14){ + echo ''; + } + elseif ($days <= 7){ + echo ''; + } + + echo ' + +
+ Out of '. Configuration::getValueByKey('CREDITS_DISPLAY_NAME').' in '; + //IF TIME IS LESS THAN 1 DAY CHANGE TO "hours" + if($days < "1"){ + if($hours < "1"){ + echo 'You ran out of Credits '; + } + else{ + echo ' '.$hours.' hours'; + } + }else{ + echo ''.number_format($days,0).' days'; + } + } + echo' +
+
'; + } } From 3055c2f55094518eef09766665cc06bcfc46594c Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Tue, 26 Oct 2021 16:24:57 +0200 Subject: [PATCH 03/16] Fixed Redundant code --- app/Http/Controllers/HomeController.php | 27 ++++++++++++------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 4f6f57ce..b2c4384a 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -37,25 +37,24 @@ class HomeController extends Controller foreach (Auth::user()->servers as $server){ $usage += $server->product->price; } - + if(Auth::user()->Credits() > 0.01 and $usage > 0){ $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); + + if($days >= 15){ + $bg = "success"; + }elseif ($days >= 8 && $days <= 14){ + $bg = "warning"; + }elseif ($days <= 7){ + $bg = "danger"; + } + echo '
-
'; - if($days >= 15){ - echo ''; - } - elseif ($days >= 8 && $days <= 14){ - echo ''; - } - elseif ($days <= 7){ - echo ''; - } - - echo ' - +
+ +
Out of '. Configuration::getValueByKey('CREDITS_DISPLAY_NAME').' in '; //IF TIME IS LESS THAN 1 DAY CHANGE TO "hours" From 903ca36b7b825d98f76b51fc931357048a349c37 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Tue, 26 Oct 2021 16:53:53 +0200 Subject: [PATCH 04/16] The ways supposed to be --- app/Http/Controllers/HomeController.php | 77 ++++++++++++------------- resources/views/home.blade.php | 14 ++++- 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index b2c4384a..bafa8fac 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -20,57 +20,52 @@ class HomeController extends Controller public function index(Request $request) { $usage = 0; + $bg=""; + $boxText=""; + $unit = ""; foreach (Auth::user()->servers as $server){ $usage += $server->product->price; } - - return view('home')->with([ - 'useage' => $usage, - 'useful_links' => UsefulLink::all()->sortBy('id') - ]); - } - - public static function CreditsLeftBox(){ - $usage = 0; - - foreach (Auth::user()->servers as $server){ - $usage += $server->product->price; - } - if(Auth::user()->Credits() > 0.01 and $usage > 0){ $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); + if($days >= 15){ - $bg = "success"; + $bg = "success"; }elseif ($days >= 8 && $days <= 14){ - $bg = "warning"; + $bg = "warning"; }elseif ($days <= 7){ - $bg = "danger"; - } - - echo ' -
-
- - -
- Out of '. Configuration::getValueByKey('CREDITS_DISPLAY_NAME').' in '; - //IF TIME IS LESS THAN 1 DAY CHANGE TO "hours" - if($days < "1"){ - if($hours < "1"){ - echo 'You ran out of Credits '; - } - else{ - echo ' '.$hours.' hours'; - } - }else{ - echo ''.number_format($days,0).' days'; - } - } - echo' -
-
'; + $bg = "danger"; } + + if($days < "1"){ + if($hours < "1"){ + $boxText = 'You ran out of Credits '; + } + else{ + $boxText = $hours; + $unit = "hours"; + } + }else{ + $boxText = number_format($days,0); + $unit = "days"; + } + } + + + return view('home')->with([ + 'useage' => $usage, + 'useful_links' => UsefulLink::all()->sortBy('id'), + 'bg' => $bg, + 'boxText' => $boxText, + 'unit' => $unit + ]); } + + + +} + + diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 9ec07792..c109075e 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -70,9 +70,18 @@
- {{ HomeController::CreditsLeftBox() }} + @if(Auth::user()->Credits() > 0.01 and $useage > 0) +
+
+ + +
+ Out of {{CREDITS_DISPLAY_NAME}} in + {{$boxText}}{{$unit}} +
+
- + @endif
@@ -80,6 +89,7 @@ +
From c92b435f659b14622991efd6e9e64547b6484fc7 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Tue, 26 Oct 2021 16:54:51 +0200 Subject: [PATCH 05/16] Comments --- app/Http/Controllers/HomeController.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index bafa8fac..23fb9504 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -27,11 +27,13 @@ class HomeController extends Controller foreach (Auth::user()->servers as $server){ $usage += $server->product->price; } + + // START OF THE TIME-REMAINING-BOX if(Auth::user()->Credits() > 0.01 and $usage > 0){ $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); - + // DEFINE THE BACKGROUND COLOR if($days >= 15){ $bg = "success"; }elseif ($days >= 8 && $days <= 14){ @@ -39,7 +41,7 @@ class HomeController extends Controller }elseif ($days <= 7){ $bg = "danger"; } - + // DEFINE WETHER DAYS OR HOURS REMAIN if($days < "1"){ if($hours < "1"){ $boxText = 'You ran out of Credits '; @@ -54,7 +56,7 @@ class HomeController extends Controller } } - + // RETURN ALL VALUES return view('home')->with([ 'useage' => $usage, 'useful_links' => UsefulLink::all()->sortBy('id'), From fe588c50694b272ba8c66175d1020a80bf76fc48 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Tue, 26 Oct 2021 17:51:15 +0200 Subject: [PATCH 06/16] more variables --- app/Http/Controllers/HomeController.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 23fb9504..9111c649 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -19,19 +19,17 @@ class HomeController extends Controller /** Show the application dashboard. */ public function index(Request $request) { - $usage = 0; + $usage = Auth::user()->creditUsage(); + $credits = Auth::user()->Credits(); $bg=""; $boxText=""; $unit = ""; - foreach (Auth::user()->servers as $server){ - $usage += $server->product->price; - } // START OF THE TIME-REMAINING-BOX - if(Auth::user()->Credits() > 0.01 and $usage > 0){ - $days = number_format((Auth::user()->Credits()*30)/$usage,2,'.',''); - $hours = number_format(Auth::user()->Credits()/($usage/30/24),2,'.',''); + if($credits > 0.01 and $usage > 0){ + $days = number_format(($credits*30)/$usage,2,'.',''); + $hours = number_format($credits/($usage/30/24),2,'.',''); // DEFINE THE BACKGROUND COLOR if($days >= 15){ From a2e4798b3dcd3f497b477a4bb712da7948c37c54 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Tue, 26 Oct 2021 17:55:55 +0200 Subject: [PATCH 07/16] PSR12 --- app/Http/Controllers/HomeController.php | 73 +++++++++++++------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 9111c649..7c6fc069 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -1,5 +1,4 @@ middleware('auth'); } - - /** Show the application dashboard. */ public function index(Request $request) { $usage = Auth::user()->creditUsage(); $credits = Auth::user()->Credits(); - $bg=""; - $boxText=""; + $bg = ""; + $boxText = ""; $unit = ""; - // START OF THE TIME-REMAINING-BOX - if($credits > 0.01 and $usage > 0){ - $days = number_format(($credits*30)/$usage,2,'.',''); - $hours = number_format($credits/($usage/30/24),2,'.',''); + if ($credits > 0.01 and $usage > 0) + { + $days = number_format(($credits * 30) / $usage, 2, '.', ''); + $hours = number_format($credits / ($usage / 30 / 24) , 2, '.', ''); + + // DEFINE THE BACKGROUND COLOR + if ($days >= 15) + { + $bg = "success"; + } + elseif ($days >= 8 && $days <= 14) + { + $bg = "warning"; + } + elseif ($days <= 7) + { + $bg = "danger"; + } - // DEFINE THE BACKGROUND COLOR - if($days >= 15){ - $bg = "success"; - }elseif ($days >= 8 && $days <= 14){ - $bg = "warning"; - }elseif ($days <= 7){ - $bg = "danger"; - } // DEFINE WETHER DAYS OR HOURS REMAIN - if($days < "1"){ - if($hours < "1"){ + if ($days < "1") + { + if ($hours < "1") + { $boxText = 'You ran out of Credits '; - } - else{ - $boxText = $hours; - $unit = "hours"; - } - }else{ - $boxText = number_format($days,0); - $unit = "days"; } + else + { + $boxText = $hours; + $unit = "hours"; + } + } + else + { + $boxText = number_format($days, 0); + $unit = "days"; + } } - - // RETURN ALL VALUES + + // RETURN ALL VALUES return view('home')->with([ 'useage' => $usage, 'useful_links' => UsefulLink::all()->sortBy('id'), 'bg' => $bg, - 'boxText' => $boxText, + 'boxText' => $boxText, 'unit' => $unit ]); -} - - + } } - From 72165b0d95638bcb74066a42a12fc70cd2aabbad Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 26 Oct 2021 19:24:08 +0200 Subject: [PATCH 08/16] fix strings to int --- app/Http/Controllers/HomeController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 7c6fc069..36715693 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -43,9 +43,9 @@ class HomeController extends Controller } // DEFINE WETHER DAYS OR HOURS REMAIN - if ($days < "1") + if ($days < 1) { - if ($hours < "1") + if ($hours < 1) { $boxText = 'You ran out of Credits '; } From 1edb4eb583226f712405f7441a18af4e7b54da9a Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 26 Oct 2021 19:26:41 +0200 Subject: [PATCH 09/16] pass credits --- app/Http/Controllers/HomeController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 36715693..4bbfe0ed 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -65,6 +65,7 @@ class HomeController extends Controller // RETURN ALL VALUES return view('home')->with([ 'useage' => $usage, + 'credits' => $credits, 'useful_links' => UsefulLink::all()->sortBy('id'), 'bg' => $bg, 'boxText' => $boxText, From 82a2dace25f65bf74bcdd5f94eb5fb5306ec771f Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 26 Oct 2021 19:27:19 +0200 Subject: [PATCH 10/16] use $credits --- resources/views/home.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index c109075e..5e1a43c7 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -70,7 +70,7 @@
- @if(Auth::user()->Credits() > 0.01 and $useage > 0) + @if($credits > 0.01 and $useage > 0)
From a024d7ce6a03d309ed1aebb9a5859cee3ca47783 Mon Sep 17 00:00:00 2001 From: Dennis Date: Tue, 26 Oct 2021 19:28:51 +0200 Subject: [PATCH 11/16] removed old code --- resources/views/home.blade.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 5e1a43c7..03bc8d06 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -1,8 +1,5 @@ - - @extends('layouts.main') - @section('content')
From 46173d7bfb3bcf79439990363c6ba6c49d0eb436 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Wed, 27 Oct 2021 07:48:00 +0200 Subject: [PATCH 12/16] Beautify --- app/Http/Controllers/HomeController.php | 90 ++++++++++++++++--------- resources/views/home.blade.php | 2 +- 2 files changed, 59 insertions(+), 33 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 4bbfe0ed..8189efc4 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -8,11 +8,65 @@ use Illuminate\Support\Facades\Auth; class HomeController extends Controller { + const TIME_LEFT_BG_SUCCESS = "bg-success"; + const TIME_LEFT_BG_WARNING = "bg-warning"; + const TIME_LEFT_BG_DANGER = "bg-danger"; + + public function __construct() { $this->middleware('auth'); } +/** Get the Background Color for the Days-Left-Box in HomeView */ + public function getTimeLeftBoxBackground($days){ + switch($days){ + case ($days >= 15): + return $this::TIME_LEFT_BG_SUCCESS; + break; + case ($days >= 8 && $days <= 14): + return $this::TIME_LEFT_BG_WARNING; + break; + case ($days <= 7): + return $this::TIME_LEFT_BG_DANGER; + break; + default: + return $this::TIME_LEFT_BG_WARNING; + } + } + +/** Get the Text for the Days-Left-Box in HomeView */ + public function getTimeLeftBoxText($days,$hours){ + if ($days < 1) + { + if ($hours < 1) + { + return 'You ran out of Credits '; + } + else + { + return $hours; + } + } + else + { + return number_format($days, 0); + } + } + + public function getTimeLeftUnit($days){ + switch($days){ + case ($days < 1): + return "hours"; + break; + case ($days > 1): + return "days"; + break; + default: + return "days"; + } + } + /** Show the application dashboard. */ public function index(Request $request) { @@ -22,44 +76,16 @@ class HomeController extends Controller $boxText = ""; $unit = ""; - // START OF THE TIME-REMAINING-BOX + /** Build our Time-Left-Box */ if ($credits > 0.01 and $usage > 0) { $days = number_format(($credits * 30) / $usage, 2, '.', ''); $hours = number_format($credits / ($usage / 30 / 24) , 2, '.', ''); - // DEFINE THE BACKGROUND COLOR - if ($days >= 15) - { - $bg = "success"; - } - elseif ($days >= 8 && $days <= 14) - { - $bg = "warning"; - } - elseif ($days <= 7) - { - $bg = "danger"; - } + $bg = $this->getTimeLeftBoxBackground($days); + $boxText = $this->getTimeLeftBoxText($days,$hours); + $unit = $this->getTimeLeftUnit($days,$hours); - // DEFINE WETHER DAYS OR HOURS REMAIN - if ($days < 1) - { - if ($hours < 1) - { - $boxText = 'You ran out of Credits '; - } - else - { - $boxText = $hours; - $unit = "hours"; - } - } - else - { - $boxText = number_format($days, 0); - $unit = "days"; - } } // RETURN ALL VALUES diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 03bc8d06..ee44e0e4 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -70,7 +70,7 @@ @if($credits > 0.01 and $useage > 0)
- +
Out of {{CREDITS_DISPLAY_NAME}} in From d2705cb838eb20a00bd42a0e4e3970158120ec4e Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Wed, 27 Oct 2021 07:48:41 +0200 Subject: [PATCH 13/16] Space space space enter --- app/Http/Controllers/HomeController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index 8189efc4..c728d1f4 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -24,12 +24,15 @@ class HomeController extends Controller case ($days >= 15): return $this::TIME_LEFT_BG_SUCCESS; break; + case ($days >= 8 && $days <= 14): return $this::TIME_LEFT_BG_WARNING; break; + case ($days <= 7): return $this::TIME_LEFT_BG_DANGER; break; + default: return $this::TIME_LEFT_BG_WARNING; } @@ -54,14 +57,16 @@ class HomeController extends Controller } } - public function getTimeLeftUnit($days){ + public function getTimeLeftUnit($days){ switch($days){ case ($days < 1): return "hours"; break; + case ($days > 1): return "days"; break; + default: return "days"; } From 85c188182d3d12ad2f1a857b80908196ac4ea449 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Wed, 27 Oct 2021 08:41:07 +0200 Subject: [PATCH 14/16] PSR12 --- app/Http/Controllers/HomeController.php | 96 +++++++++++++++---------- 1 file changed, 60 insertions(+), 36 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index c728d1f4..b5c3cddb 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -11,66 +11,88 @@ class HomeController extends Controller const TIME_LEFT_BG_SUCCESS = "bg-success"; const TIME_LEFT_BG_WARNING = "bg-warning"; const TIME_LEFT_BG_DANGER = "bg-danger"; - + const TIME_LEFT_TEXT = "You ran out of Credits"; public function __construct() { $this->middleware('auth'); } -/** Get the Background Color for the Days-Left-Box in HomeView */ - public function getTimeLeftBoxBackground($days){ - switch($days){ + /** + * @description Get the Background Color for the Days-Left-Box in HomeView + * + * @param float $days + * + * @return string + */ + public function getTimeLeftBoxBackground($days) + { + switch ($days) + { case ($days >= 15): return $this::TIME_LEFT_BG_SUCCESS; - break; + break; case ($days >= 8 && $days <= 14): return $this::TIME_LEFT_BG_WARNING; - break; + break; case ($days <= 7): return $this::TIME_LEFT_BG_DANGER; - break; + break; default: - return $this::TIME_LEFT_BG_WARNING; - } - } - -/** Get the Text for the Days-Left-Box in HomeView */ - public function getTimeLeftBoxText($days,$hours){ - if ($days < 1) + return $this::TIME_LEFT_BG_WARNING; + } + } + + /** + * @description Get the Text for the Days-Left-Box in HomeView + * + * @param string $days + * @param string $hours + * + * @return string + */ + public function getTimeLeftBoxText(string $days, string $hours) + { + if ($days < 1) + { + if ($hours < 1) { - if ($hours < 1) - { - return 'You ran out of Credits '; - } - else - { - return $hours; - } + return $this::TIME_LEFT_BG_WARNING; } else { - return number_format($days, 0); + return strval($hours); } } + return strval(number_format($days, 0)); + } - public function getTimeLeftUnit($days){ - switch($days){ - case ($days < 1): - return "hours"; - break; + /** + * @description Return either "days" or "hours" to use on the front-end + * + * @param float $days + * + * @return string + */ + public function getTimeLeftUnit($days) + { + switch ($days) + { + case ($days < 1): + return "hours"; + break; - case ($days > 1): - return "days"; - break; + case ($days > 1): + return "days"; + break; - default: - return "days"; - } + default: + return "days"; } + } /** Show the application dashboard. */ public function index(Request $request) @@ -88,10 +110,12 @@ class HomeController extends Controller $hours = number_format($credits / ($usage / 30 / 24) , 2, '.', ''); $bg = $this->getTimeLeftBoxBackground($days); - $boxText = $this->getTimeLeftBoxText($days,$hours); - $unit = $this->getTimeLeftUnit($days,$hours); + $boxText = $this->getTimeLeftBoxText($days, $hours); + $unit = $this->getTimeLeftUnit($days, $hours); } + + // RETURN ALL VALUES return view('home')->with([ From aca06b5441ca137b1e458e0fc4a4c47110324cd4 Mon Sep 17 00:00:00 2001 From: WBLKLeipe Date: Wed, 27 Oct 2021 09:13:52 +0200 Subject: [PATCH 15/16] Fixing OUT_OF_CREDITS Text --- app/Http/Controllers/HomeController.php | 28 ++++++++++++------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index b5c3cddb..e2283412 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -8,19 +8,19 @@ use Illuminate\Support\Facades\Auth; class HomeController extends Controller { - const TIME_LEFT_BG_SUCCESS = "bg-success"; - const TIME_LEFT_BG_WARNING = "bg-warning"; - const TIME_LEFT_BG_DANGER = "bg-danger"; - const TIME_LEFT_TEXT = "You ran out of Credits"; + const TIME_LEFT_BG_SUCCESS = "bg-success"; + const TIME_LEFT_BG_WARNING = "bg-warning"; + const TIME_LEFT_BG_DANGER = "bg-danger"; + const TIME_LEFT_OUT_OF_CREDITS_TEXT = "You ran out of Credits"; public function __construct() { $this->middleware('auth'); } - /** + /** * @description Get the Background Color for the Days-Left-Box in HomeView - * + * * @param float $days * * @return string @@ -46,9 +46,9 @@ class HomeController extends Controller } } - /** - * @description Get the Text for the Days-Left-Box in HomeView - * + /** + * @description Get the Text for the Days-Left-Box in HomeView + * * @param string $days * @param string $hours * @@ -60,7 +60,7 @@ class HomeController extends Controller { if ($hours < 1) { - return $this::TIME_LEFT_BG_WARNING; + return $this::TIME_LEFT_OUT_OF_CREDITS_TEXT; } else { @@ -70,9 +70,9 @@ class HomeController extends Controller return strval(number_format($days, 0)); } - /** + /** * @description Return either "days" or "hours" to use on the front-end - * + * * @param float $days * * @return string @@ -114,7 +114,7 @@ class HomeController extends Controller $unit = $this->getTimeLeftUnit($days, $hours); } - + // RETURN ALL VALUES @@ -123,7 +123,7 @@ class HomeController extends Controller 'credits' => $credits, 'useful_links' => UsefulLink::all()->sortBy('id'), 'bg' => $bg, - 'boxText' => $boxText, + 'boxText' => $boxText, 'unit' => $unit ]); } From 1056e1db8bf8e4f5fca6aedc4e5b76a8449718f6 Mon Sep 17 00:00:00 2001 From: 1day2die Date: Wed, 27 Oct 2021 19:09:09 +0200 Subject: [PATCH 16/16] let magic make this even better Right DataTypes, Removed unnessecary function --- app/Http/Controllers/HomeController.php | 34 ++++--------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php index e2283412..fa8611d4 100644 --- a/app/Http/Controllers/HomeController.php +++ b/app/Http/Controllers/HomeController.php @@ -25,7 +25,7 @@ class HomeController extends Controller * * @return string */ - public function getTimeLeftBoxBackground($days) + public function getTimeLeftBoxBackground(float $days) { switch ($days) { @@ -49,12 +49,12 @@ class HomeController extends Controller /** * @description Get the Text for the Days-Left-Box in HomeView * - * @param string $days - * @param string $hours + * @param float $days + * @param float $hours * * @return string */ - public function getTimeLeftBoxText(string $days, string $hours) + public function getTimeLeftBoxText(float $days, float $hours) { if ($days < 1) { @@ -70,30 +70,6 @@ class HomeController extends Controller return strval(number_format($days, 0)); } - /** - * @description Return either "days" or "hours" to use on the front-end - * - * @param float $days - * - * @return string - */ - public function getTimeLeftUnit($days) - { - switch ($days) - { - case ($days < 1): - return "hours"; - break; - - case ($days > 1): - return "days"; - break; - - default: - return "days"; - } - } - /** Show the application dashboard. */ public function index(Request $request) { @@ -111,7 +87,7 @@ class HomeController extends Controller $bg = $this->getTimeLeftBoxBackground($days); $boxText = $this->getTimeLeftBoxText($days, $hours); - $unit = $this->getTimeLeftUnit($days, $hours); + $unit = $days < 1 ? 'hours' : 'days'; }