dev-fixes (#14)

Closes #9
This commit was merged in pull request #14.
This commit is contained in:
2022-07-01 12:45:43 +00:00
parent a591872949
commit 9306b5f5d8
108 changed files with 12865 additions and 46114 deletions
+27
View File
@@ -0,0 +1,27 @@
<?php
namespace Insallah;
/** All raw mathematics in one place. */
class Math
{
public static function getPercentage($total, $number)
{
return $total > 0 ? round(($number * 100) / $total, 2) : 0;
}
public static function get100Percentage($total, $number)
{
return min(self::getPercentage($total, $number), 100);
}
/** Number-20% and Number+20% */
public static function get20PercentRange($number)
{
return [
'min' => $number * ((100 - 20) / 100),
'max' => $number * ((100 + 20) / 100)
];
}
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace Insallah;
class Table
{
public static function get($rows, $class = '', $fill = false)
{
$c = '';
$max_rows = sizeof(max($rows));
foreach ($rows as $row) {
if ($fill && sizeof($row) < $max_rows) {
$row = array_merge($row, array_fill(0, $max_rows - sizeof($row), ''));
}
$c .= '<tr><td>' . implode('</td><td>', $row) . '</td></tr>';
}
return (!empty($class) ? "<table class='$class'>" : '<table>') . $c . '</table>' . PHP_EOL;
}
}