Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module2 task2 #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 запроса и переданных данных
*
Expand All @@ -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) {
Expand All @@ -39,7 +50,7 @@ function db_get_prepare_stmt($link, $sql, $data = []) {

if ($data) {
$types = '';
$stmt_data = [];
$stmtData = [];

foreach ($data as $value) {
$type = 's';
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 = '';

Expand All @@ -141,6 +152,4 @@ function include_template($name, array $data = []) {
$result = ob_get_clean();

return $result;
}


}
32 changes: 21 additions & 11 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
<?php
$is_auth = rand(0, 1);
$user_name = 'Даниил'; // укажите здесь ваше имя
$isAuth = rand(0, 1);
$userName = 'Даниил'; // укажите здесь ваше имя
/**
* Форматирует cумму лота и добавляет знак рубля
* @param int|float $price
* @return string
*/
function formatAmount(int|float $price): string
{
$price = number_format($price, 0, '.', ' ');
return $price . ' ₽';
}
$categories = ['Доски и лыжи', 'Крепления', 'Ботинки', 'Одежда', 'Инструменты', 'Разное'];
$lots = [
[
Expand Down Expand Up @@ -39,7 +49,7 @@
'price' => 5400,
'pic' => 'img/lot-6.jpg'
]
];
];
?>
<!DOCTYPE html>
<html lang="ru">
Expand All @@ -65,9 +75,9 @@
<a class="main-header__add-lot button" href="pages/add-lot.html">Добавить лот</a>

<nav class="user-menu">
<?php if ($is_auth===1): ?>
<?php if ($isAuth===1): ?>
<div class="user-menu__logged">
<p><?=$user_name; ?></p>
<p><?=$userName; ?></p>
<a class="user-menu__bets" href="pages/my-bets.html">Мои ставки</a>
<a class="user-menu__logout" href="#">Выход</a>
</div>
Expand Down Expand Up @@ -104,18 +114,18 @@
</div>
<ul class="lots__list">
<!--заполните этот список из массива с товарами-->
<?php foreach ($lots as $value): ?>
<?php foreach ($lots as $lot): ?>
<li class="lots__item lot">
<div class="lot__image">
<img src="<?=$value['pic']; ?>" width="350" height="260" alt="<?=$value['title']; ?>">
<img src="<?=$lot['pic']; ?>" width="350" height="260" alt="<?=$lot['title']; ?>">
</div>
<div class="lot__info">
<span class="lot__category"><?=$value['сategory']; ?></span>
<h3 class="lot__title"><a class="text-link" href="pages/lot.html"><?=$value['title']; ?></a></h3>
<span class="lot__category"><?=$lot['сategory']; ?></span>
<h3 class="lot__title"><a class="text-link" href="pages/lot.html"><?=$lot['title']; ?></a></h3>
<div class="lot__state">
<div class="lot__rate">
<span class="lot__amount"><?=$value['price']; ?></span>
<span class="lot__cost">цена<b class="rub">р</b></span>
<span class="lot__amount"><?=$lot['price']; ?></span>
<span class="lot__cost"><?= formatAmount($lot["price"]) ?></span>
</div>
<div class="lot__timer timer">
12:23
Expand Down