Add Report Create module
WIP
This commit is contained in:
@@ -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)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ final class Report extends \Friendica\BaseRepository
|
||||
return $this->_selectOne(['id' => $lastInsertId]);
|
||||
}
|
||||
|
||||
public function save(\Friendica\Moderation\Entity\Report $Report)
|
||||
public function save(\Friendica\Moderation\Entity\Report $Report): \Friendica\Moderation\Entity\Report
|
||||
{
|
||||
$fields = [
|
||||
'reporter-id' => $Report->reporterCid,
|
||||
@@ -95,7 +95,7 @@ final class Report extends \Friendica\BaseRepository
|
||||
$this->db->insert('report-rule', ['rid' => $newReportId, 'line-id' => $rule->lineId, 'text' => $rule->text]);
|
||||
}
|
||||
|
||||
$Report = $this->selectOneById($this->db->lastInsertId());
|
||||
$Report = $this->selectOneById($newReportId);
|
||||
}
|
||||
|
||||
return $Report;
|
||||
|
||||
Reference in New Issue
Block a user