From e517d6a82dba156e12cebf029282ae5f3758e739 Mon Sep 17 00:00:00 2001 From: steven-y-e Date: Thu, 11 Feb 2021 20:02:07 -0500 Subject: [PATCH] refactor(values): created hierarchical 'machine' object --- public/functions.php | 42 +++++++++++++++++-------------------- public/index.php | 14 ++++++------- public/values.php | 50 ++++++++++++++++++++++++++------------------ 3 files changed, 56 insertions(+), 50 deletions(-) diff --git a/public/functions.php b/public/functions.php index c67823a..63e7ffe 100644 --- a/public/functions.php +++ b/public/functions.php @@ -1,4 +1,5 @@ spaceFree = disk_free_space($drive->location); + $drive->spaceTotal = disk_total_space($drive->location); + $drive->spaceUsed = getDifference( + $drive->spaceFree, $drive->spaceTotal); + $drive->spacePercentageUsed = getPercentageUsed( + $drive->spaceTotal, $drive->spaceUsed); } return $drives; } + + /* display functions */ function printDrive($drive) { echo '
-

' . $drive[0] . '

+

' . $drive->name . '

-
Free Space: ' . getByteString($drive[3]) . '
-
Used Space: ' . getByteString($drive[4]) . '
+
Free Space: ' . getByteString($drive->spaceFree) . '
+
Used Space: ' . getByteString($drive->spaceUsed) . '
'; } function printService($service) { echo ' - -
-

' . $service[0] . '

-

' . $service[2] . '

+
+
+

' . $service->name . '

+

' . $service->description . '

'; } diff --git a/public/index.php b/public/index.php index 091eb6c..b5c4f02 100644 --- a/public/index.php +++ b/public/index.php @@ -6,7 +6,7 @@ require 'values.php'; require 'functions.php'; - $driveValues = getDriveValues($drives); + $driveValues = getDriveValues($machine->drives); ?> <?php echo $machine[0] ?> - homo.casa @@ -24,13 +24,13 @@
- ' . $machine[0] . ' -

' . $machine[1] . '

'; ?> + ' . $machine->name . ' +

' . $machine->description . '

'; ?>
" . $driveLabel . ""; + echo "

" . $machine->driveLabel . "

"; foreach ($driveValues as $drive) { printDrive($drive); @@ -40,17 +40,17 @@
" . $serviceLabel . " + echo "

" . $machine->serviceLabel . "

note: authentication required for access.

"; - foreach ($services as $service) { + foreach ($machine->services as $service) { printService($service); } ?>
- ' . $footer[1] . ' + footer->name . '">' . $machine->footer->description . '

';?>
diff --git a/public/values.php b/public/values.php index 54491d1..2975850 100644 --- a/public/values.php +++ b/public/values.php @@ -1,22 +1,32 @@ name = "Machine"; + $machine->description = "machine description"; + + $disk1->name = "disk1"; + $disk1->description = "disk1 description"; + $disk1->location = "/disk1/location/"; + $disk2->name = "disk2"; + $disk2->description = "disk2 description"; + $disk2->location = "/disk2/location/"; + $disk3->name = "disk3"; + $disk3->description = "disk3 description"; + $disk3->location = "/disk3/location/"; + + $service1->name = "service1"; + $service1->description = "service1 description"; + $service1->location = "https://service1.example.com"; + $service2->name = "service2"; + $service2->description = "service2 description"; + $service2->location = "https://service2.example.com"; + $service3->name = "service3"; + $service3->description = "service3 description"; + $service3->location = "https://service3.example.com"; + + $machine->driveLabel = "Drives"; + $machine->drives = array($disk1, $disk2, $disk3); + $machine->serviceLabel = "Services"; + $machine->services = array($service1, $service2, $service3); + + $machine->footer->name = "footer"; + $machine->footer->description = "footer description"; ?>