]> git.mxchange.org Git - friendica.git/blob - src/Moderation/Factory/Report.php
Merge pull request #12311 from matthiasmoritz/event-details-do-not-render-correctly...
[friendica.git] / src / Moderation / Factory / Report.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Moderation\Factory;
23
24 use Friendica\Capabilities\ICanCreateFromTableRow;
25 use Friendica\Moderation\Entity;
26
27 class Report extends \Friendica\BaseFactory implements ICanCreateFromTableRow
28 {
29         /**
30          * @param array $row        `report` table row
31          * @param array $postUriIds List of post URI ids from the `report-post` table
32          * @return Entity\Report
33          * @throws \Exception
34          */
35         public function createFromTableRow(array $row, array $postUriIds = []): Entity\Report
36         {
37                 return new Entity\Report(
38                         $row['uid'],
39                         $row['cid'],
40                         new \DateTime($row['created'] ?? 'now', new \DateTimeZone('UTC')),
41                         $row['comment'],
42                         $row['forward'],
43                         $postUriIds,
44                         $row['id'],
45                 );
46         }
47
48         /**
49          * Creates a Report entity from a Mastodon API /reports request
50          *
51          * @see \Friendica\Module\Api\Mastodon\Reports::post()
52          *
53          * @param int    $uid
54          * @param int    $cid
55          * @param string $comment
56          * @param bool   $forward
57          * @param array  $postUriIds
58          * @return Entity\Report
59          * @throws \Exception
60          */
61         public function createFromReportsRequest(int $uid, int $cid, string $comment = '', bool $forward = false, array $postUriIds = []): Entity\Report
62         {
63                 return new Entity\Report(
64                         $uid,
65                         $cid,
66                         new \DateTime('now', new \DateTimeZone('UTC')),
67                         $comment,
68                         $forward,
69                         $postUriIds,
70                 );
71         }
72 }