wip правки, рефактор, отдельный магазин.

This commit is contained in:
2023-07-07 18:36:23 +03:00
parent 48ca7b4109
commit d2cf95ef55
8 changed files with 847 additions and 363 deletions

View File

@@ -1,7 +1,6 @@
<?php
namespace Core;
class ConversionHelper
{
/** Превращает строку data ('a=1|b=2|c=3') из БД в массив [a=>1, b=>2, c=>3].
@@ -23,4 +22,37 @@ class ConversionHelper
$str = json_encode($dataArray);
return $str ? str_replace(['":', ',"', '{"', '}'], ['=', '|'], $str) : '';
}
}
/** Превращает количество секунд в человекопонятное Х мес. Х дн. Х ч. Х мин. Х сек.,
* используемое обычно для отображения игровых таймаутов.
* @param int|string $seconds
* @return string
*/
public static function secondsToTimeout($seconds): string
{
$seconds = (int)$seconds;
$time = new \DateTime();
$time->setTimestamp($seconds);
$sec = intval($time->format('s'));
$min = intval($time->format('i'));
$hr = intval($time->format('G'));
$day = intval($time->format('j'));
$month = intval($time->format('n'));
$timeout = '';
if ($month > 1) {
$timeout .= $month . ' мес. ';
}
if ($day > 1) {
$timeout .= $day . ' дн. ';
}
if ($hr) {
$timeout .= $hr . ' ч. ';
}
if ($sec && !$min) {
$timeout .= $sec . ' сек. ';
} elseif ($min) {
$timeout .= $min . ' мин. ';
}
return $timeout;
}
}