mirror of
https://github.com/friendica/friendica
synced 2025-05-01 23:04:24 +02:00
Add Report Create module
WIP
This commit is contained in:
parent
76de49a25c
commit
c312d11dab
13 changed files with 510 additions and 3 deletions
|
@ -23,6 +23,7 @@ namespace Friendica\Moderation\Factory;
|
|||
|
||||
use Friendica\Capabilities\ICanCreateFromTableRow;
|
||||
use Friendica\Core\System;
|
||||
use Friendica\Model\Contact;
|
||||
use Friendica\Moderation\Collection;
|
||||
use Friendica\Moderation\Entity;
|
||||
use Psr\Clock\ClockInterface;
|
||||
|
@ -114,4 +115,33 @@ class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
|
|||
}, $ruleIds)),
|
||||
);
|
||||
}
|
||||
|
||||
public function createFromForm(array $rules, int $cid, int $reporterId, int $categoryId, array $ruleIds, string $comment, array $uriIds, bool $forward): Entity\Report
|
||||
{
|
||||
$contact = Contact::getById($cid, ['gsid']);
|
||||
if (!$contact) {
|
||||
throw new \InvalidArgumentException('Contact with id: ' . $cid . ' not found');
|
||||
}
|
||||
|
||||
if (!in_array($categoryId, Entity\Report::CATEGORIES)) {
|
||||
throw new \OutOfBoundsException('Category with id: ' . $categoryId . ' not found in set: [' . implode(', ', Entity\Report::CATEGORIES) . ']');
|
||||
}
|
||||
|
||||
return new Entity\Report(
|
||||
Contact::getPublicIdByUserId($reporterId),
|
||||
$cid,
|
||||
$contact['gsid'],
|
||||
$this->clock->now(),
|
||||
$categoryId,
|
||||
$reporterId,
|
||||
$comment,
|
||||
$forward,
|
||||
new Collection\Report\Posts(array_map(function ($uriId) {
|
||||
return new Entity\Report\Post($uriId);
|
||||
}, $uriIds)),
|
||||
new Collection\Report\Rules(array_map(function ($lineId) use ($rules) {
|
||||
return new Entity\Report\Rule($lineId, $rules[$lineId] ?? '');
|
||||
}, $ruleIds)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue