| 1 |
<?php |
| 2 |
/** |
| 3 |
* Trip listing sidebar: checkbox list with optional "Show more / Show less". |
| 4 |
* |
| 5 |
* Expects before include: |
| 6 |
* - $yatra_sidebar_cb_rows — list of rows: value, label, optional count (int) |
| 7 |
* - $yatra_sidebar_cb_input_name — e.g. categories[] |
| 8 |
* - $yatra_sidebar_cb_active — array of selected values (same semantics as listing template) |
| 9 |
* |
| 10 |
* @package Yatra |
| 11 |
*/ |
| 12 |
|
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
$rows = isset($yatra_sidebar_cb_rows) ? array_values((array) $yatra_sidebar_cb_rows) : []; |
| 18 |
$input_name = isset($yatra_sidebar_cb_input_name) ? (string) $yatra_sidebar_cb_input_name : ''; |
| 19 |
$active_vals = isset($yatra_sidebar_cb_active) && is_array($yatra_sidebar_cb_active) ? $yatra_sidebar_cb_active : []; |
| 20 |
|
| 21 |
if ($input_name === '' || $rows === []) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$cap = function_exists('yatra_listing_sidebar_filter_visible_cap') |
| 26 |
? yatra_listing_sidebar_filter_visible_cap() |
| 27 |
: 8; |
| 28 |
$total = count($rows); |
| 29 |
$expand = false; |
| 30 |
|
| 31 |
if ($total > $cap && $active_vals !== []) { |
| 32 |
for ($i = $cap; $i < $total; $i++) { |
| 33 |
if (in_array($rows[$i]['value'], $active_vals)) { |
| 34 |
$expand = true; |
| 35 |
break; |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
$has_more = $total > $cap; |
| 41 |
$wrapper_classes = 'yatra-checkbox-group yatra-filter-collapsible'; |
| 42 |
if ($has_more) { |
| 43 |
$wrapper_classes .= ' has-more'; |
| 44 |
} |
| 45 |
if ($expand) { |
| 46 |
$wrapper_classes .= ' is-expanded'; |
| 47 |
} |
| 48 |
?> |
| 49 |
<div class="<?php echo esc_attr($wrapper_classes); ?>" data-visible-cap="<?php echo esc_attr((string) $cap); ?>"> |
| 50 |
<?php foreach ($rows as $idx => $row) : ?> |
| 51 |
<?php |
| 52 |
$val = $row['value'] ?? ''; |
| 53 |
$label = isset($row['label']) ? (string) $row['label'] : ''; |
| 54 |
$more_class = $idx >= $cap ? ' yatra-filter-option-more' : ''; |
| 55 |
$attr_val = is_scalar($val) ? (string) $val : ''; |
| 56 |
?> |
| 57 |
<label class="yatra-checkbox-label<?php echo esc_attr($more_class); ?>"> |
| 58 |
<input |
| 59 |
type="checkbox" |
| 60 |
name="<?php echo esc_attr($input_name); ?>" |
| 61 |
value="<?php echo esc_attr($attr_val); ?>" |
| 62 |
<?php checked(in_array($val, $active_vals)); ?> |
| 63 |
> |
| 64 |
<span><?php echo esc_html($label); ?></span> |
| 65 |
<?php if (array_key_exists('count', $row) && $row['count'] !== null && $row['count'] !== '') : ?> |
| 66 |
<span class="yatra-filter-count">(<?php echo (int) $row['count']; ?>)</span> |
| 67 |
<?php endif; ?> |
| 68 |
</label> |
| 69 |
<?php endforeach; ?> |
| 70 |
<?php if ($has_more) : ?> |
| 71 |
<button |
| 72 |
type="button" |
| 73 |
class="yatra-filter-show-more-toggle" |
| 74 |
aria-expanded="<?php echo $expand ? 'true' : 'false'; ?>" |
| 75 |
> |
| 76 |
<span class="yatra-filter-show-more-label"><?php esc_html_e('Show more', 'yatra'); ?></span> |
| 77 |
<span class="yatra-filter-show-less-label"><?php esc_html_e('Show less', 'yatra'); ?></span> |
| 78 |
</button> |
| 79 |
<?php endif; ?> |
| 80 |
</div> |
| 81 |
|