2026-10-12 16:37:51 +00:00

184 lines
8.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// Секция отзывов
if (! defined('ABSPATH')) {
exit;
}
$teacher_filter = ! empty($args['teacher']) ? (int) $args['teacher'] : 0;
$review_ids = ! empty($args['ids']) ? array_map('intval', (array) $args['ids']) : array();
$title_override = isset($args['title']) ? (string) $args['title'] : '';
$head_label = 'Отзывы';
$head_title = 'Узнайте, что говорят о нас родители и ученики';
$__rd_rating = get_option('branch_avg_rating') ?: get_option('branch_rating_yandex');
$__rd_count = get_option('branch_ext_review_count');
$head_desc = ( $__rd_rating && $__rd_count )
? sprintf('%s оценок на внешних площадках — средний балл %s из 5', $__rd_count, $__rd_rating)
: 'Отзывы родителей и учеников о школе';
unset($__rd_rating, $__rd_count);
if ($teacher_filter) {
$teacher_ids = function_exists('dekart_teacher_review_ids') ? dekart_teacher_review_ids($teacher_filter) : array();
$has_reviews = ! empty($teacher_ids);
$reviews_cards = array();
if ($has_reviews) {
$ratings = array();
foreach ($teacher_ids as $rid) {
$star = (int) carbon_get_post_meta($rid, 'review_star');
if ($star >= 1 && $star <= 5) {
$ratings[] = $star;
}
}
foreach ($teacher_ids as $rid) {
$avatar_id = carbon_get_post_meta($rid, 'review_avatar');
$photo_url = '';
if ($avatar_id && is_numeric($avatar_id)) {
$photo_url = (string) wp_get_attachment_image_url((int) $avatar_id, 'full');
}
$reviews_cards[] = array(
'review_author' => get_the_title($rid),
'review_rating' => (int) ( carbon_get_post_meta($rid, 'review_star') ?: 5 ),
'review_text' => (string) carbon_get_post_meta($rid, 'review_text'),
'review_date' => get_the_date('d.m.Y', $rid),
'review_photo' => $photo_url,
);
}
$total_cnt = count($teacher_ids);
if ($ratings) {
$avg = number_format(array_sum($ratings) / count($ratings), 1, '.', ' ');
$n10 = $total_cnt % 10;
$n100 = $total_cnt % 100;
if ($n10 === 1 && $n100 !== 11) {
$word = 'проверенный отзыв';
} elseif (in_array($n10, array( 2, 3, 4 ), true) && ! in_array($n100, array( 12, 13, 14 ), true)) {
$word = 'проверенных отзыва';
} else {
$word = 'проверенных отзывов';
}
$head_desc = 'Средняя оценка ' . $avg . ' из 5 · ' . $total_cnt . ' ' . $word;
} else {
$head_desc = 'Реальные отзывы родителей и учеников о занятиях';
}
$head_title = 'Отзывы о преподавателе';
}
wp_reset_postdata();
} elseif (! empty($review_ids)) {
$reviews_cards = array();
foreach ($review_ids as $rid) {
if (get_post_status($rid) !== 'publish') {
continue;
}
$avatar_id = carbon_get_post_meta($rid, 'review_avatar');
$photo_url = ( $avatar_id && is_numeric($avatar_id) ) ? (string) wp_get_attachment_image_url((int) $avatar_id, 'full') : '';
$reviews_cards[] = array(
'review_author' => get_the_title($rid),
'review_rating' => (int) ( carbon_get_post_meta($rid, 'review_star') ?: 5 ),
'review_text' => (string) carbon_get_post_meta($rid, 'review_text'),
'review_date' => get_the_date('d.m.Y', $rid),
'review_photo' => $photo_url,
);
}
$has_reviews = ! empty($reviews_cards);
if ($has_reviews) {
$head_desc = 'Отзывы родителей о семейном формате обучения';
}
} else {
$reviews_page_id = 91;
$reviews_cards = carbon_get_post_meta($reviews_page_id, 'reviews_cards');
$has_reviews = ! empty($reviews_cards) && is_array($reviews_cards);
if ($has_reviews) {
$reviews_cards = array_slice(dekart_reviews_sort_desc($reviews_cards), 0, 3);
}
}
if ($title_override !== '') {
$head_title = $title_override;
}
if (! $has_reviews) {
return;
}
?>
<section class="reviews-front-section reveal" id="reviews" aria-label="Отзывы">
<div class="container">
<div class="section-header--centered">
<span class="bento-label"><?php echo esc_html($head_label); ?></span>
<h2 class="bento-h2"><?php echo esc_html($head_title); ?></h2>
<p class="bento-p"><?php echo esc_html($head_desc); ?></p>
</div>
<div class="reviews-front__scroll-hint" aria-hidden="true"><?php echo dekart_icon('arrow-down', 16); ?> Листайте отзывы</div>
<div class="reviews-front__wrap">
<div class="reviews-front__grid">
<?php foreach ($reviews_cards as $card) :
$name = $card['review_author'] ?? '';
$stars = (int) ( $card['review_rating'] ?? 5 );
$text = $card['review_text'] ?? '';
$rdate_cf = $card['review_date'] ?? '';
$rdate = $rdate_cf ?: '';
$teacher = $card['review_teacher'] ?? array();
$has_teacher = ! empty($teacher[0]['id']);
$photo_url = $card['review_photo'] ?? '';
?>
<div class="reviews-front__card">
<div class="reviews-front__card-inner">
<div class="reviews-front__header">
<div class="reviews-front__avatar" style="background-color: <?php echo esc_attr(rand_color()); ?>">
<?php if ($photo_url) : ?>
<img class="reviews-front__avatar-img" src="<?php echo esc_url($photo_url); ?>" alt="" loading="lazy" width="57" height="57">
<?php else : ?>
<span class="reviews-front__avatar-letter"><?php echo esc_html(mb_substr($name, 0, 1)); ?></span>
<?php endif; ?>
</div>
<div class="reviews-front__client-data">
<div class="reviews-front__name"><?php echo esc_html($name); ?></div>
</div>
</div>
<div class="reviews-front__stars">
<?php for ($i = 1; $i <= $stars; $i++) : ?>
<svg width="20" height="20" viewBox="0 0 21 19" fill="#FFD43E" aria-hidden="true"><path d="M9.58463 1.50884C9.89101 0.602477 11.1729 0.602476 11.4793 1.50884L13.1158 6.35007C13.2531 6.75637 13.6343 7.02985 14.0631 7.02985H19.2721C20.2504 7.02985 20.6467 8.28958 19.8447 8.84971L15.6995 11.7446C15.335 11.9991 15.1823 12.4636 15.3247 12.8847L16.9239 17.6158C17.233 18.5302 16.1954 19.3085 15.404 18.7559L11.1045 15.7533C10.7606 15.5131 10.3033 15.5131 9.95941 15.7533L5.65991 18.7559C4.86857 19.3085 3.83092 18.5302 4.14001 17.6158L5.73926 12.8847C5.8816 12.4636 5.72891 11.9991 5.36448 11.7446L1.21924 8.84971C0.417196 8.28958 0.813532 7.02985 1.79181 7.02985H7.00081C7.42969 7.02985 7.81081 6.75637 7.94815 6.35007L9.58463 1.50884Z"/></svg>
<?php endfor; ?>
<?php if ($rdate) : ?>
<span class="reviews-front__date"><?php echo esc_html($rdate); ?></span>
<?php endif; ?>
</div>
<?php if ($has_teacher) : ?>
<p class="reviews-front__teacher">
<span>Преподаватель: </span>
<?php echo esc_html(get_the_title((int) $teacher[0]['id'])); ?>
</p>
<?php endif; ?>
<div class="reviews-front__text">
<?php echo wp_kses_post($text); ?>
</div>
<div class="reviews-front__badge">
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/></svg>
Проверенный отзыв
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<div class="reviews-front__all-link">
<a href="/otzyvy/" class="reviews-link__btn">Читать все отзывы →</a>
</div>
</div>
</section>