]> git.mxchange.org Git - friendica.git/blobdiff - src/Moderation/Factory/Report.php
Merge pull request #13696 from annando/invalid-uri
[friendica.git] / src / Moderation / Factory / Report.php
index 1c1e9cfb7f77ee3146517bac90cad7af70f18b7a..4d2e0bb75b90c4606c0540cae06094e4d20c518f 100644 (file)
@@ -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)),
+               );
+       }
 }