diff --git a/helpers.php b/helpers.php index 87b1f62..b0714f8 100644 --- a/helpers.php +++ b/helpers.php @@ -13,13 +13,24 @@ * * @return bool true при совпадении с форматом 'ГГГГ-ММ-ДД', иначе false */ -function is_date_valid(string $date) : bool { - $format_to_check = 'Y-m-d'; - $dateTimeObj = date_create_from_format($format_to_check, $date); +function isDateValid(string $date) : bool { + $formatToCheck = 'Y-m-d'; + $dateTimeObj = date_create_from_format($formatToCheck, $date); return $dateTimeObj !== false && array_sum(date_get_last_errors()) === 0; } +/** + * Форматирует cумму лота и добавляет знак рубля + * @param int|float $price + * @return string + */ +function formatAmount(int|float $price): string +{ + $price = number_format($price, 0, '.', ' '); + return $price . ' ₽'; +} + /** * Создает подготовленное выражение на основе готового SQL запроса и переданных данных * @@ -29,7 +40,7 @@ function is_date_valid(string $date) : bool { * * @return mysqli_stmt Подготовленное выражение */ -function db_get_prepare_stmt($link, $sql, $data = []) { +function dbGetPrepareStmt($link, $sql, $data = []) { $stmt = mysqli_prepare($link, $sql); if ($stmt === false) { @@ -39,7 +50,7 @@ function db_get_prepare_stmt($link, $sql, $data = []) { if ($data) { $types = ''; - $stmt_data = []; + $stmtData = []; foreach ($data as $value) { $type = 's'; @@ -56,11 +67,11 @@ function db_get_prepare_stmt($link, $sql, $data = []) { if ($type) { $types .= $type; - $stmt_data[] = $value; + $stmtData[] = $value; } } - $values = array_merge([$stmt, $types], $stmt_data); + $values = array_merge([$stmt, $types], $stmtDdata); $func = 'mysqli_stmt_bind_param'; $func(...$values); @@ -96,7 +107,7 @@ function db_get_prepare_stmt($link, $sql, $data = []) { * * @return string Рассчитанная форма множественнго числа */ -function get_noun_plural_form (int $number, string $one, string $two, string $many): string +function getNounPluralForm (int $number, string $one, string $two, string $many): string { $number = (int) $number; $mod10 = $number % 10; @@ -126,7 +137,7 @@ function get_noun_plural_form (int $number, string $one, string $two, string $ma * @param array $data Ассоциативный массив с данными для шаблона * @return string Итоговый HTML */ -function include_template($name, array $data = []) { +function includeTemplate($name, array $data = []) { $name = 'templates/' . $name; $result = ''; @@ -141,6 +152,4 @@ function include_template($name, array $data = []) { $result = ob_get_clean(); return $result; -} - - +} \ No newline at end of file diff --git a/index.php b/index.php index a6b7951..544bac2 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,16 @@ 5400, 'pic' => 'img/lot-6.jpg' ] -]; + ]; ?> @@ -65,9 +75,9 @@ Добавить лот