Files
FamilyBook/templates/movies/index.php
T

62 lines
2.5 KiB
PHP
Raw Normal View History

<?php
/**
* 观影时间线 —— 按年分组倒序(v8,MovieLog 迁入后的新家)。
*
* 没填日期的记录落在键 0,沉到最底下单独一组「日期待补」,
* 不让它混进任何一个年份里(跟名册「未分类」栏是同一个思路)。
*/
$canWrite = \App\Auth::canWrite();
?>
<div class="page-head">
<h1>观影记录</h1>
<span class="sub">一共 <?= (int)$total ?> 场</span>
<div class="actions">
<?php if ($canWrite): ?>
<a class="btn" href="<?= e(url('movies/new')) ?>">记一场电影</a>
<?php endif; ?>
</div>
</div>
<?php if ($total === 0): ?>
<div class="card card-pad empty">
<b>还没有观影记录</b>
一家人一起看过的电影,都会按年份排在这里。
</div>
<?php else: ?>
<?php foreach ($years as $y => $list): ?>
<section class="section">
<h2 class="section-title"><?= $y > 0 ? (int)$y : '日期待补' ?> <span class="hint"><?= count($list) ?> 场</span></h2>
<div class="movie-list">
<?php foreach ($list as $mv): ?>
<?php
// 评分统一一位小数内显示:9 → "9",8.5 → "8.5"(库里是 0-10 整数,这里只做展示兜底)
$rtTxt = $mv['rating'] !== null
? rtrim(rtrim(number_format((float)$mv['rating'], 1, '.', ''), '0'), '.')
: '';
?>
<a class="movie-card" href="<?= e(url('movies/show', ['id' => (int)$mv['id']])) ?>">
<?php if (!empty($mv['poster_key'])): ?>
<img class="m-poster" src="<?= e(media_url($mv['poster_key'])) ?>" alt="" loading="lazy">
<?php else: ?>
<span class="m-poster m-poster-empty" aria-hidden="true">影</span>
<?php endif; ?>
<span class="m-main">
<span class="m-title">
<?= e($mv['title']) ?>
<?php if ($rtTxt !== ''): ?><span class="rating"><?= e($rtTxt) ?></span><?php endif; ?>
</span>
<span class="m-meta">
<?= e((string)($mv['starts_at'] ?? '日期待补')) ?>
<?php if (!empty($mv['cinema_name'])): ?> · <?= e($mv['cinema_name']) ?><?php endif; ?>
</span>
<?php if (!empty($mv['attendee_names'])): ?>
<span class="m-who">和 <?= e($mv['attendee_names']) ?></span>
<?php endif; ?>
</span>
</a>
<?php endforeach; ?>
</div>
</section>
<?php endforeach; ?>
<?php endif; ?>