3 * @copyright Copyright (C) 2010-2023, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Moderation\Factory;
24 use Friendica\Capabilities\ICanCreateFromTableRow;
25 use Friendica\Core\System;
26 use Friendica\Moderation\Collection;
27 use Friendica\Moderation\Entity;
28 use Psr\Clock\ClockInterface;
29 use Psr\Log\LoggerInterface;
31 class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
33 /** @var ClockInterface */
36 public function __construct(LoggerInterface $logger, ClockInterface $clock)
38 parent::__construct($logger);
40 $this->clock = $clock;
44 * @param array $row `report` table row
45 * @param Collection\Report\Posts|null $posts List of posts attached to the report
46 * @param Collection\Report\Rules|null $rules List of rules from the terms of service, see System::getRules()
47 * @return Entity\Report
50 public function createFromTableRow(array $row, Collection\Report\Posts $posts = null, Collection\Report\Rules $rules = null): Entity\Report
52 return new Entity\Report(
56 new \DateTimeImmutable($row['created'], new \DateTimeZone('UTC')),
61 $posts ?? new Collection\Report\Posts(),
62 $rules ?? new Collection\Report\Rules(),
63 $row['public-remarks'],
64 $row['private-remarks'],
65 $row['edited'] ? new \DateTimeImmutable($row['edited'], new \DateTimeZone('UTC')) : null,
69 $row['last-editor-uid'],
75 * Creates a Report entity from a Mastodon API /reports request
77 * @param array $rules Line-number indexed node rules array, see System::getRules(true)
78 * @param int $reporterId
81 * @param string $comment
82 * @param string $category
83 * @param bool $forward
84 * @param array $postUriIds
85 * @param array $ruleIds
87 * @return Entity\Report
88 * @see \Friendica\Module\Api\Mastodon\Reports::post()
90 public function createFromReportsRequest(array $rules, int $reporterId, int $cid, int $gsid, string $comment = '', string $category = '', bool $forward = false, array $postUriIds = [], array $ruleIds = [], int $uid = null): Entity\Report
92 if (count($ruleIds)) {
93 $categoryId = Entity\Report::CATEGORY_VIOLATION;
94 } elseif ($category == 'spam') {
95 $categoryId = Entity\Report::CATEGORY_SPAM;
97 $categoryId = Entity\Report::CATEGORY_OTHER;
100 return new Entity\Report(
109 new Collection\Report\Posts(array_map(function ($uriId) {
110 return new Entity\Report\Post($uriId);
112 new Collection\Report\Rules(array_map(function ($lineId) use ($rules) {
113 return new Entity\Report\Rule($lineId, $rules[$lineId] ?? '');