-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
50 lines (42 loc) · 1.24 KB
/
functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* Подключает шаблон, передает туда данные и возвращает итоговый HTML контент
* @param string $name Путь к файлу шаблона относительно папки templates
* @param array $data Ассоциативный массив с данными для шаблона
* @return string Итоговый HTML
*/
function includeTemplate($name, array $data = []) {
$name = 'templates/' . $name;
$result = '';
if (!is_readable($name)) {
return $result;
}
ob_start();
extract($data);
require $name;
$result = ob_get_clean();
return $result;
}
/**
*@param string $data
*@return int
*/
function remainingTime(string $date) {
$timeDifference = strtotime($date) - time();
if ($timeDifference<=0){
return [0,0];
}
$hours = floor($timeDifference / 3600);
$minutes = floor(($timeDifference / 3600) % 60);
return [$hours, $minutes];
}
/**
* Форматирует cумму лота и добавляет знак рубля
* @param int|float $price
* @return string
*/
function formatAmount(int|float $price): string
{
$price = number_format($price, 0, '.', ' ');
return $price . ' ₽';
}