151 lines
6.6 KiB
PHP
151 lines
6.6 KiB
PHP
<?php
|
||
|
||
|
||
|
||
if (! defined('ABSPATH')) {
|
||
exit;
|
||
}
|
||
|
||
$tid = isset($args['id']) ? (int) $args['id'] : 0;
|
||
if (! $tid) {
|
||
return;
|
||
}
|
||
|
||
|
||
$cta_label = isset($args['cta_label']) && $args['cta_label'] !== '' ? (string) $args['cta_label'] : 'Записаться к преподавателю';
|
||
$cta_goal = isset($args['cta_goal']) && $args['cta_goal'] !== '' ? (string) $args['cta_goal'] : 'teacher_card_form';
|
||
|
||
$teacher_review_counts = function_exists('dekart_teacher_review_counts') ? dekart_teacher_review_counts() : array();
|
||
$current_year = (int) current_time('Y');
|
||
$city = get_option('branch_city') ?: carbon_get_theme_option('site_city');
|
||
$map_dirs = function_exists('dekart_teacher_directions_map') ? dekart_teacher_directions_map() : array();
|
||
|
||
$full_name = get_the_title($tid);
|
||
$permalink = get_permalink($tid);
|
||
$cat = carbon_get_post_meta($tid, 'teacher_category');
|
||
$direction = carbon_get_post_meta($tid, 'teacher_direction');
|
||
$badge = carbon_get_post_meta($tid, 'teacher_badge');
|
||
$start_year = carbon_get_post_meta($tid, 'teacher_start_year');
|
||
$rating = carbon_get_post_meta($tid, 'teacher_rating');
|
||
$avatar_id = carbon_get_post_meta($tid, 'teacher_avatar');
|
||
$avatar_url = $avatar_id ? wp_get_attachment_url($avatar_id) : '';
|
||
$avatar_srcset = $avatar_id ? (string) wp_get_attachment_image_srcset($avatar_id, 'medium_large') : '';
|
||
$avatar_src = $avatar_id ? wp_get_attachment_image_src($avatar_id, 'medium_large') : null;
|
||
$avatar_w = $avatar_src ? (int) $avatar_src[1] : 480;
|
||
$avatar_h = $avatar_src ? (int) $avatar_src[2] : 384;
|
||
$avatar_img = $avatar_src ? (string) $avatar_src[0] : $avatar_url;
|
||
|
||
$tenure = '';
|
||
if ($start_year && absint($start_year) > 1900) {
|
||
$tenure = max(0, (int) $current_year - (int) $start_year);
|
||
}
|
||
|
||
$t_desc = trim((string) carbon_get_post_meta($tid, 'teacher_description'));
|
||
$rating_num = (float) $rating;
|
||
$teacher_rc = isset($teacher_review_counts[ $tid ]) ? (int) $teacher_review_counts[ $tid ] : 0;
|
||
|
||
// alt: ФИО + предмет + город
|
||
$alt_photo = implode(', ', array_filter(array( $full_name, $direction, $city )));
|
||
|
||
$rc_word = '';
|
||
if ($teacher_rc > 0) {
|
||
$rc_mod10 = $teacher_rc % 10;
|
||
$rc_mod100 = $teacher_rc % 100;
|
||
if ($rc_mod10 === 1 && $rc_mod100 !== 11) {
|
||
$rc_word = 'отзыв';
|
||
} elseif ($rc_mod10 >= 2 && $rc_mod10 <= 4 && ( $rc_mod100 < 12 || $rc_mod100 > 14 )) {
|
||
$rc_word = 'отзыва';
|
||
} else {
|
||
$rc_word = 'отзывов';
|
||
}
|
||
}
|
||
|
||
// Анкор ссылки: предмет + город
|
||
$link_anchor = trim((string) $direction . ( $city ? ' в ' . $city : '' ));
|
||
if ('' === $link_anchor) {
|
||
$link_anchor = 'Подробнее о преподавателе';
|
||
}
|
||
|
||
$dir_slugs = array();
|
||
if (! empty($map_dirs['by_teacher'][ $tid ])) {
|
||
$dir_slugs = $map_dirs['by_teacher'][ $tid ];
|
||
} elseif (! empty($cat)) {
|
||
$dir_slugs = array($cat);
|
||
} else {
|
||
$terms = wp_get_post_terms($tid, 'trainingCategory', array('fields' => 'slugs'));
|
||
if (! is_wp_error($terms)) {
|
||
$dir_slugs = $terms;
|
||
}
|
||
}
|
||
$dir_slugs = array_values(array_unique(array_filter(array_map('sanitize_title', (array) $dir_slugs))));
|
||
$cat_filter = implode(' ', $dir_slugs);
|
||
?>
|
||
<article class="teachers-card reveal" data-category="<?php echo esc_attr($cat_filter); ?>">
|
||
<div class="teachers-card__media">
|
||
<?php if ($avatar_url) : ?>
|
||
<img class="teachers-card__photo" loading="lazy" decoding="async"
|
||
src="<?php echo esc_url($avatar_img); ?>"
|
||
<?php if ($avatar_srcset) : ?>srcset="<?php echo esc_attr($avatar_srcset); ?>" sizes="(max-width: 640px) 92vw, 320px"<?php endif; ?>
|
||
alt="<?php echo esc_attr($alt_photo); ?>"
|
||
width="<?php echo esc_attr($avatar_w); ?>" height="<?php echo esc_attr($avatar_h); ?>">
|
||
<?php else : ?>
|
||
<?php
|
||
$initials = '';
|
||
foreach (array_slice(preg_split('/\s+/u', trim($full_name)), 0, 2) as $np) {
|
||
$initials .= mb_substr((string) $np, 0, 1);
|
||
}
|
||
?>
|
||
<div class="teachers-card__photo teachers-card__photo--empty" aria-hidden="true"><?php echo esc_html(mb_strtoupper($initials)); ?></div>
|
||
<?php endif; ?>
|
||
<?php if ($badge) : ?>
|
||
<span class="teachers-card__badge"><?php echo esc_html($badge); ?></span>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="teachers-card__body">
|
||
<h3 class="teachers-card__name"><a href="<?php echo esc_url($permalink); ?>"><?php echo esc_html($full_name); ?></a></h3>
|
||
|
||
<?php if ($direction) : ?>
|
||
<div class="teachers-card__direction"><?php echo esc_html($direction); ?></div>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($t_desc !== '') : ?>
|
||
<p class="teachers-card__about"><?php echo esc_html(wp_strip_all_tags($t_desc)); ?></p>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($tenure || $rating_num > 0 || $teacher_rc > 0) : ?>
|
||
<div class="teachers-card__meta">
|
||
<?php if ($tenure) : ?>
|
||
<span class="teachers-card__tenure">Стаж: <strong><?php echo esc_html($tenure); ?></strong> лет</span>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($rating_num > 0) : ?>
|
||
<span class="teachers-card__rating" aria-label="Оценка: <?php echo esc_attr($rating_num); ?> из 5">
|
||
<span class="teachers-card__stars" aria-hidden="true">
|
||
<?php for ($s = 1; $s <= 5; $s++) : ?>
|
||
<svg class="teachers-card__star<?php echo $s <= round($rating_num) ? ' is-filled' : ''; ?>" width="13" height="13" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"><path d="M10 1l2.39 4.84 5.34.78-3.87 3.77.92 5.34L10 13.27l-4.78 2.51.92-5.34L2.27 6.6l5.34-.78L10 1z"/></svg>
|
||
<?php endfor; ?>
|
||
</span>
|
||
<span class="teachers-card__rating-num"><?php echo esc_html(rtrim(rtrim(number_format($rating_num, 1), '0'), '.')); ?></span>
|
||
</span>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($teacher_rc > 0) : ?>
|
||
<a class="teachers-card__reviews" href="<?php echo esc_url($permalink); ?>">
|
||
<?php echo esc_html($teacher_rc . ' ' . $rc_word); ?>
|
||
</a>
|
||
<?php endif; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<div class="teachers-card__actions">
|
||
<a class="teachers-card__btn btn-write open-bitrix-form" href="#" onclick="return false;" data-goal="<?php echo esc_attr($cta_goal); ?>">
|
||
<?php echo esc_html($cta_label); ?>
|
||
</a>
|
||
<a class="teachers-card__link" href="<?php echo esc_url($permalink); ?>">
|
||
<?php echo esc_html($link_anchor); ?> →
|
||
</a>
|
||
</div>
|
||
</div>
|
||
</article>
|