This commit is contained in:
WBLKLeipe 2021-10-27 08:41:07 +02:00
parent d2705cb838
commit 85c188182d

View file

@ -11,66 +11,88 @@ class HomeController extends Controller
const TIME_LEFT_BG_SUCCESS = "bg-success"; const TIME_LEFT_BG_SUCCESS = "bg-success";
const TIME_LEFT_BG_WARNING = "bg-warning"; const TIME_LEFT_BG_WARNING = "bg-warning";
const TIME_LEFT_BG_DANGER = "bg-danger"; const TIME_LEFT_BG_DANGER = "bg-danger";
const TIME_LEFT_TEXT = "You ran out of Credits";
public function __construct() public function __construct()
{ {
$this->middleware('auth'); $this->middleware('auth');
} }
/** Get the Background Color for the Days-Left-Box in HomeView */ /**
public function getTimeLeftBoxBackground($days){ * @description Get the Background Color for the Days-Left-Box in HomeView
switch($days){ *
* @param float $days
*
* @return string
*/
public function getTimeLeftBoxBackground($days)
{
switch ($days)
{
case ($days >= 15): case ($days >= 15):
return $this::TIME_LEFT_BG_SUCCESS; return $this::TIME_LEFT_BG_SUCCESS;
break; break;
case ($days >= 8 && $days <= 14): case ($days >= 8 && $days <= 14):
return $this::TIME_LEFT_BG_WARNING; return $this::TIME_LEFT_BG_WARNING;
break; break;
case ($days <= 7): case ($days <= 7):
return $this::TIME_LEFT_BG_DANGER; return $this::TIME_LEFT_BG_DANGER;
break; break;
default: default:
return $this::TIME_LEFT_BG_WARNING; return $this::TIME_LEFT_BG_WARNING;
} }
} }
/** Get the Text for the Days-Left-Box in HomeView */ /**
public function getTimeLeftBoxText($days,$hours){ * @description Get the Text for the Days-Left-Box in HomeView
if ($days < 1) *
* @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 $this::TIME_LEFT_BG_WARNING;
{
return 'You ran out of Credits ';
}
else
{
return $hours;
}
} }
else else
{ {
return number_format($days, 0); return strval($hours);
} }
} }
return strval(number_format($days, 0));
}
public function getTimeLeftUnit($days){ /**
switch($days){ * @description Return either "days" or "hours" to use on the front-end
case ($days < 1): *
return "hours"; * @param float $days
break; *
* @return string
*/
public function getTimeLeftUnit($days)
{
switch ($days)
{
case ($days < 1):
return "hours";
break;
case ($days > 1): case ($days > 1):
return "days"; return "days";
break; break;
default: default:
return "days"; return "days";
}
} }
}
/** Show the application dashboard. */ /** Show the application dashboard. */
public function index(Request $request) public function index(Request $request)
@ -88,10 +110,12 @@ class HomeController extends Controller
$hours = number_format($credits / ($usage / 30 / 24) , 2, '.', ''); $hours = number_format($credits / ($usage / 30 / 24) , 2, '.', '');
$bg = $this->getTimeLeftBoxBackground($days); $bg = $this->getTimeLeftBoxBackground($days);
$boxText = $this->getTimeLeftBoxText($days,$hours); $boxText = $this->getTimeLeftBoxText($days, $hours);
$unit = $this->getTimeLeftUnit($days,$hours); $unit = $this->getTimeLeftUnit($days, $hours);
} }
// RETURN ALL VALUES // RETURN ALL VALUES
return view('home')->with([ return view('home')->with([