Add Poll\Delete (poll 10)
This commit is contained in:
parent
ae339fb655
commit
70e9c0d754
2 changed files with 69 additions and 2 deletions
68
app/Models/Poll/Delete.php
Normal file
68
app/Models/Poll/Delete.php
Normal file
|
@ -0,0 +1,68 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace ForkBB\Models\Poll;
|
||||
|
||||
use ForkBB\Models\Action;
|
||||
use ForkBB\Models\DataModel;
|
||||
use ForkBB\Models\Poll\Model as Poll;
|
||||
use ForkBB\Models\Topic\Model as Topic;
|
||||
use PDO;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
|
||||
class Delete extends Action
|
||||
{
|
||||
/**
|
||||
* Удаление индекса
|
||||
*/
|
||||
public function delete(DataModel ...$args): void
|
||||
{
|
||||
if (empty($args)) {
|
||||
throw new InvalidArgumentException('No arguments, expected Poll(s) or Topic(s)');
|
||||
}
|
||||
|
||||
$polls = [];
|
||||
$topics = [];
|
||||
$isPoll = 0;
|
||||
$isTopic = 0;
|
||||
|
||||
foreach ($args as $arg) {
|
||||
if ($arg instanceof Poll) {
|
||||
$arg->parent; // проверка доступности опроса
|
||||
|
||||
$polls[$arg->tid] = $arg;
|
||||
$isPoll = 1;
|
||||
} elseif ($arg instanceof Topic) {
|
||||
if (! $arg->parent instanceof Forum) {
|
||||
throw new RuntimeException('Parent unavailable');
|
||||
}
|
||||
|
||||
$topics[$arg->id] = $arg;
|
||||
$isTopic = 1;
|
||||
} else {
|
||||
throw new InvalidArgumentException('Expected Poll(s) or Topic(s)');
|
||||
}
|
||||
}
|
||||
|
||||
if ($isPoll + $isTopic > 1) {
|
||||
throw new InvalidArgumentException('Expected only Poll(s) or Topic(s)');
|
||||
}
|
||||
|
||||
$vars = [
|
||||
':tids' => \array_keys($polls ?: $topics),
|
||||
];
|
||||
$query = 'DELETE
|
||||
FROM ::poll
|
||||
WHERE tid IN (?ai:tids)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
|
||||
$query = 'DELETE
|
||||
FROM ::poll_voted
|
||||
WHERE tid IN (?ai:tids)';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
}
|
|
@ -108,8 +108,6 @@ class Delete extends Action
|
|||
|
||||
$this->c->posts->delete(...$args);
|
||||
|
||||
//???? опросы, предупреждения
|
||||
|
||||
if ($uids) {
|
||||
$vars = [
|
||||
':users' => $uids,
|
||||
|
@ -144,6 +142,7 @@ class Delete extends Action
|
|||
}
|
||||
|
||||
$this->c->subscriptions->unsubscribe(...$topics);
|
||||
$this->c->polls->delete(...$topics);
|
||||
|
||||
$vars = [
|
||||
':topics' => \array_keys($topics),
|
||||
|
|
Loading…
Add table
Reference in a new issue