2026-10-03 08:18:05 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
2026-10-07 11:35:31 +08:00
|
|
|
|
* 纪念日(v24 用户第 13 条;2026-10-03 第 9 条重排;**2026-10-07 第 2 条加「关联人」列**)
|
2026-10-03 08:18:05 +08:00
|
|
|
|
*
|
2026-10-03 15:01:38 +08:00
|
|
|
|
* 第 9 条原话:「纪念日中,手动添加的纪念日和来自其他模块的,例如生日的纪念日,
|
|
|
|
|
|
* 要分开,手动纪念日在上面。在新建纪念日和右侧,也增加设置按钮,
|
|
|
|
|
|
* 可以设置纪念日的分类。」
|
2026-10-03 08:18:05 +08:00
|
|
|
|
*
|
2026-10-07 11:35:31 +08:00
|
|
|
|
* 第 2 条原话:「纪念日模块,每个纪念日现在只能关联一个人,应该可以关联多个人。
|
|
|
|
|
|
* 和选择观影人一样,多选模式。自己添加的纪念日,右侧按钮,和其他模块的按钮
|
|
|
|
|
|
* 样式保持一致,修改用蓝色,删除用黄色。再加一列,关联人。列表中,
|
|
|
|
|
|
* 人的前面,都加头像。」
|
|
|
|
|
|
*
|
|
|
|
|
|
* ⇒ 三块(顺序按用户第 9 条要求):
|
|
|
|
|
|
* ① 接下来的日子(未来 60 天)
|
|
|
|
|
|
* ② **手动添加的**纪念日(在上)—— 可改可删;右侧按钮:改=蓝(.btn)、删=黄(.btn-warn)
|
2026-10-03 15:01:38 +08:00
|
|
|
|
* ③ 来自名册生日的(在下,实时派生、不能改删)
|
2026-10-03 08:18:05 +08:00
|
|
|
|
*
|
2026-10-07 11:35:31 +08:00
|
|
|
|
* @param array $custom 用户自建的(行上带 person_ids)
|
|
|
|
|
|
* @param array $derived 从名册生日派生的(行上也有 person_ids)
|
2026-10-03 15:01:38 +08:00
|
|
|
|
* @param array $upcoming 接下来 60 天的
|
|
|
|
|
|
* @param array $kinds 分类清单(设置里维护)
|
2026-10-07 11:35:31 +08:00
|
|
|
|
* @param array $people 名册(把 person id 换成头像 + 称呼)
|
2026-10-03 08:18:05 +08:00
|
|
|
|
*/
|
|
|
|
|
|
$canWrite = \App\Auth::canWrite();
|
|
|
|
|
|
$kindBadge = static function (array $r): string {
|
|
|
|
|
|
$k = (string)($r['kind'] ?? '');
|
|
|
|
|
|
return $k === '' ? '' : '<span class="node-badge">' . e($k) . '</span>';
|
|
|
|
|
|
};
|
|
|
|
|
|
$srcWord = static function (array $r): string {
|
|
|
|
|
|
$src = (string)($r['source'] ?? 'custom');
|
|
|
|
|
|
if ($src === 'birthday_solar') {
|
|
|
|
|
|
return '名册生日(阳历)';
|
|
|
|
|
|
}
|
|
|
|
|
|
if ($src === 'birthday_lunar') {
|
|
|
|
|
|
return '名册生日(农历)';
|
|
|
|
|
|
}
|
|
|
|
|
|
return \App\Anniversary::repeatWord((string)($r['repeat_type'] ?? 'solar'));
|
|
|
|
|
|
};
|
2026-10-03 15:01:38 +08:00
|
|
|
|
|
2026-10-07 11:35:31 +08:00
|
|
|
|
/* 关联人(用户第 2 条:「再加一列,关联人。列表中,人的前面,都加头像。」)
|
|
|
|
|
|
—— 用全站统一的 person_chip()(它自带头像 + 我对他/她的称呼 + 本人底色)。
|
|
|
|
|
|
⚠️ chips 一律**不传 href**:这一格在一张表格里,`<a>` 套 `<a>` 是非法 HTML,
|
|
|
|
|
|
浏览器会把外层结构切开(person_chip 的注释里记过这个坑)。
|
|
|
|
|
|
⚠️ $peopleMap 由路由层传进来(一次查全,避免逐行查库);缺失时退化成"有几个显示几个"。 */
|
|
|
|
|
|
$peopleMap = $peopleMap ?? [];
|
|
|
|
|
|
$peopleCell = static function (array $r) use ($peopleMap): string {
|
|
|
|
|
|
$ids = (array)($r['person_ids'] ?? []);
|
|
|
|
|
|
if (!$ids) {
|
|
|
|
|
|
return '<span class="small muted">—</span>';
|
|
|
|
|
|
}
|
|
|
|
|
|
$out = '';
|
|
|
|
|
|
$n = 0;
|
|
|
|
|
|
foreach ($ids as $pid) {
|
|
|
|
|
|
$pid = (int)$pid;
|
|
|
|
|
|
$p = $peopleMap[$pid] ?? null;
|
|
|
|
|
|
if ($p === null) {
|
|
|
|
|
|
continue;
|
|
|
|
|
|
}
|
|
|
|
|
|
// 一个人时正常画;多人时最多画 4 个 + 「+N」,免得一行被撑爆
|
|
|
|
|
|
if ($n >= 4) {
|
|
|
|
|
|
$rest = count($ids) - 4;
|
|
|
|
|
|
$out .= '<span class="node-badge" title="还有 ' . $rest . ' 人">+' . $rest . '</span>';
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
$out .= person_chip($p);
|
|
|
|
|
|
$n++;
|
|
|
|
|
|
}
|
|
|
|
|
|
return $out === '' ? '<span class="small muted">—</span>' : $out;
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-10-03 15:01:38 +08:00
|
|
|
|
/* 画一张纪念日表。两块(手动 / 派生)共用同一个渲染 —— 复制一遍迟早改漏一处。 */
|
2026-10-07 11:35:31 +08:00
|
|
|
|
$renderTable = function (array $rows, bool $editable) use ($canWrite, $kindBadge, $srcWord, $peopleCell): void {
|
2026-10-03 15:01:38 +08:00
|
|
|
|
if (!$rows) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
?>
|
|
|
|
|
|
<div class="table-wrap">
|
|
|
|
|
|
<table class="table">
|
|
|
|
|
|
<thead>
|
2026-10-07 11:35:31 +08:00
|
|
|
|
<tr><th>日期</th><th>纪念日</th><th>关联人</th><th>分类</th><th>重复</th><th></th></tr>
|
2026-10-03 15:01:38 +08:00
|
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
|
|
|
<?php foreach ($rows as $r): ?>
|
|
|
|
|
|
<tr>
|
|
|
|
|
|
<td class="nowrap"><?= (int)$r['month'] ?> 月 <?= (int)$r['day'] ?> 日</td>
|
|
|
|
|
|
<td>
|
|
|
|
|
|
<?= e((string)$r['title']) ?>
|
|
|
|
|
|
<?php if (!empty($r['is_leap'])): ?><span class="small muted">(闰月)</span><?php endif; ?>
|
|
|
|
|
|
</td>
|
2026-10-07 11:35:31 +08:00
|
|
|
|
<td class="ann-people"><?= $peopleCell($r) ?></td>
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<td><?= $kindBadge($r) ?></td>
|
|
|
|
|
|
<td class="small muted"><?= e($srcWord($r)) ?></td>
|
2026-10-07 11:35:31 +08:00
|
|
|
|
<td class="nowrap ann-acts">
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<?php if ($editable && $canWrite): ?>
|
2026-10-07 11:35:31 +08:00
|
|
|
|
<?php /* 用户第 2 条:「右侧按钮,和其他模块的按钮样式保持一致,
|
|
|
|
|
|
修改用蓝色,删除用黄色。」
|
|
|
|
|
|
→ 改 = `.btn`(主按钮的**蓝**),删 = `.btn-warn`(**黄**实心)。
|
|
|
|
|
|
⚠️ 原来用的是 `.link-quiet`(纯文字链接)+ `.btn-ghost`(白底描边),
|
|
|
|
|
|
两者都"看不出来是什么动作",与观影/旅程行上那套不一致。 */ ?>
|
|
|
|
|
|
<a class="btn btn-sm" href="<?= e(url('days/edit', ['id' => (int)$r['id']])) ?>">修改</a>
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<form method="post" action="<?= e(url('days/destroy')) ?>" class="res-inline">
|
|
|
|
|
|
<?= csrf_field() ?>
|
|
|
|
|
|
<input type="hidden" name="id" value="<?= (int)$r['id'] ?>">
|
2026-10-07 11:35:31 +08:00
|
|
|
|
<button class="btn btn-warn btn-sm" type="submit"
|
|
|
|
|
|
onclick="return confirm('删掉这条纪念日?')">删除</button>
|
2026-10-03 15:01:38 +08:00
|
|
|
|
</form>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<span class="small muted">来自名册</span>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</td>
|
|
|
|
|
|
</tr>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</tbody>
|
|
|
|
|
|
</table>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
};
|
2026-10-03 08:18:05 +08:00
|
|
|
|
?>
|
|
|
|
|
|
<div class="page-head">
|
|
|
|
|
|
<h1>纪念日</h1>
|
|
|
|
|
|
<span class="sub">生日本身就是一种纪念日 · 阳历与农历都能记</span>
|
|
|
|
|
|
<div class="actions">
|
|
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
<a class="btn" href="<?= e(url('days/new')) ?>">新建纪念日</a>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
<a class="btn btn-ghost" href="<?= e(url('calendar')) ?>">看日历</a>
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<?php /* 用户第 9 条:设置按钮就在「新建纪念日」右边(☰,排最右) */ ?>
|
|
|
|
|
|
<?php $setCurrent = 'kinds'; require __DIR__ . '/_settings_menu.php'; ?>
|
2026-10-03 08:18:05 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="card card-pad">
|
|
|
|
|
|
<h2 class="cinema-h2">接下来的日子</h2>
|
|
|
|
|
|
<?php if (!$upcoming): ?>
|
|
|
|
|
|
<p class="empty-hint">未来 60 天里没有纪念日。</p>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<ul class="ann-up">
|
|
|
|
|
|
<?php foreach ($upcoming as $u): ?>
|
|
|
|
|
|
<li class="ann-up-item">
|
|
|
|
|
|
<span class="ann-days"><?= (int)$u['days'] === 0 ? '今天' : ((int)$u['days'] . ' 天后') ?></span>
|
|
|
|
|
|
<span class="ann-date"><?= e(substr((string)$u['date'], 5)) ?></span>
|
|
|
|
|
|
<span class="ann-title"><?= e((string)$u['title']) ?></span>
|
|
|
|
|
|
<?php if ($u['age'] !== null): ?><span class="small muted"><?= (int)$u['age'] ?> 岁</span><?php endif; ?>
|
|
|
|
|
|
<?= $kindBadge($u) ?>
|
|
|
|
|
|
</li>
|
|
|
|
|
|
<?php endforeach; ?>
|
|
|
|
|
|
</ul>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<?php /* ==================== ② 手动添加的(在上,用户第 9 条)==================== */ ?>
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<div class="card card-pad">
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<h2 class="cinema-h2">
|
|
|
|
|
|
我自己添加的(<?= count($custom) ?>)
|
|
|
|
|
|
<span class="hint">只有这些能改能删</span>
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<?php if (!$custom): ?>
|
|
|
|
|
|
<p class="empty-hint">
|
|
|
|
|
|
还没有自己添加的纪念日。
|
|
|
|
|
|
<?php if ($canWrite): ?>
|
|
|
|
|
|
结婚纪念日、忌日、相识的日子…点右上角「新建纪念日」加一条。
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</p>
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php else: ?>
|
2026-10-03 15:01:38 +08:00
|
|
|
|
<?php $renderTable($custom, true); ?>
|
|
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<?php /* ==================== ③ 来自名册的生日(在下)==================== */ ?>
|
|
|
|
|
|
<div class="card card-pad">
|
|
|
|
|
|
<h2 class="cinema-h2">
|
|
|
|
|
|
来自名册的(<?= count($derived) ?>)
|
|
|
|
|
|
<span class="hint">实时读出来的,改生日这里跟着变</span>
|
|
|
|
|
|
</h2>
|
|
|
|
|
|
<?php if (!$derived): ?>
|
|
|
|
|
|
<p class="empty-hint">
|
|
|
|
|
|
名册里还没有人填过生日。到「名册 → 编辑成员」把生日填上,这里就会自动出现。
|
|
|
|
|
|
</p>
|
|
|
|
|
|
<?php else: ?>
|
|
|
|
|
|
<?php $renderTable($derived, false); ?>
|
|
|
|
|
|
<p class="tip" style="margin-top:10px">
|
|
|
|
|
|
这一块是**实时派生**的 —— 改生日,这里跟着变,不用重复维护。
|
|
|
|
|
|
不需要在这里新建,也没法单独删(删掉生日就等于删了它)。
|
|
|
|
|
|
</p>
|
2026-10-03 08:18:05 +08:00
|
|
|
|
<?php endif; ?>
|
|
|
|
|
|
</div>
|