Browse and delete polls from a numbered list in the polls menu
CI / Deploy / PHP 8.5 (push) Successful in 1m7s
CI / Deploy / PHP 8.4 (push) Successful in 1m12s
CI / Deploy / test (push) Successful in 1s
CI / Deploy / deploy (push) Skipped

Paged list with pick by number (open) and "d 1,3" to delete several at
once after one confirmation. List query and table moved into the shared
base command.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
gnilebeinandClaude Sonnet 5.5 committed 2026-11-16 13:35:38 +01:00
1 parent 6e8fef022b
commit 7b83cf2f2c
6 files changed
+202 -39

No files matched your search

+55
View File
@@ -26,6 +26,61 @@ abstract class PollsCommand extends Command
return $polls;
}
/**
* @param bool $expiredOnly Only expired polls
* @param string $email Only polls whose e-mail address contains this text (case-insensitive)
* @return list<\App\Model\Entity\Poll> Oldest first
*/
protected function findPolls(bool $expiredOnly = false, string $email = ''): array
{
$query = $this->polls()->find()
->select([
'Polls.id', 'Polls.title', 'Polls.email', 'Polls.join_code', 'Polls.current_slide_id',
'Polls.paused_slide_id', 'Polls.last_admin_access', 'Polls.expiry_reminded_at', 'Polls.created',
])
->orderBy(['Polls.id' => 'ASC']);
if ($expiredOnly) {
$query->find('expired');
}
if ($email !== '') {
$query->where(['Polls.email LIKE' => '%' . addcslashes(strtolower($email), '%_\\') . '%']);
}
/** @var list<\App\Model\Entity\Poll> $polls */
$polls = $query->all()->toList();
return $polls;
}
/**
* Prints polls as a table, optionally with a running number to pick from.
*
* @param list<\App\Model\Entity\Poll> $polls Polls
* @param \Cake\Console\ConsoleIo $io Console
* @param int $firstNumber Number of the first row (with $numbered)
* @param bool $numbered Add the number column
* @return void
*/
protected function printPolls(array $polls, ConsoleIo $io, int $firstNumber = 1, bool $numbered = false): void
{
$header = [__('ID'), __('Code'), __('Titel'), __('E-Mail'), __('Angelegt'), __('Letzter Admin-Besuch'), __('Läuft ab'), __('Erinnert')];
$rows = [$numbered ? array_merge(['#'], $header) : $header];
foreach ($polls as $i => $poll) {
$row = [
(string)$poll->id,
$poll->join_code,
mb_strimwidth($poll->title, 0, 40, '…'),
$poll->email,
$this->formatDate($poll->created),
$this->formatDate($poll->last_admin_access),
$this->formatExpiry($poll),
$this->formatDate($poll->expiry_reminded_at),
];
$rows[] = $numbered ? array_merge([(string)($firstNumber + $i)], $row) : $row;
}
$io->helper('Table')->output($rows);
}
/**
* Finds a poll by numeric id or join code ("K7P2QX", "k7p-2qx").
*