0 ? $count : count($items);
$firstType = $items[0]['type'] ?? ($items[0]['grid']['type'] ?? '');
$shapeClass = in_array($firstType, ['books', 'movies', 'tv']) ? 'vertical' : 'square';
echo '
';
}
}
if (!function_exists('renderAssociatedMedia')) {
function renderAssociatedMedia(
array $artists = [],
array $books = [],
array $genres = [],
array $movies = [],
array $posts = [],
array $shows = [],
)
{
$sections = [
"artists" => ["icon" => "headphones", "css_class" => "music", "label" => "Related artist(s)", "hasGrid" => true],
"books" => ["icon" => "books", "css_class" => "books", "label" => "Related book(s)", "hasGrid" => true],
"genres" => ["icon" => "headphones", "css_class" => "music", "label" => "Related genre(s)", "hasGrid" => false],
"movies" => ["icon" => "movie", "css_class" => "movies", "label" => "Related movie(s)", "hasGrid" => true],
"posts" => ["icon" => "article", "css_class" => "article", "label" => "Related post(s)", "hasGrid" => false],
"shows" => ["icon" => "device-tv-old", "css_class" => "tv", "label" => "Related show(s)", "hasGrid" => true]
];
$allMedia = compact('artists', 'books', 'genres', 'movies', 'posts', 'shows');
echo '';
}
}
if (!function_exists('renderMediaLinks')) {
function renderMediaLinks(array $data, string $type, int $count = 10): string {
if (empty($data) || empty($type)) return "";
$slice = array_slice($data, 0, $count);
if (count($slice) === 0) return "";
$buildLink = function ($item) use ($type) {
switch ($type) {
case "genre":
return '' . htmlspecialchars($item['genre_name']) . '';
case "artist":
return '' . htmlspecialchars($item['name']) . '';
case "book":
return '' . htmlspecialchars($item['title']) . '';
default:
return '';
}
};
if (count($slice) === 1) return $buildLink($slice[0]);
$links = array_map($buildLink, $slice);
$last = array_pop($links);
return implode(', ', $links) . ' and ' . $last;
}
}
?>