]> git.mxchange.org Git - friendica.git/blob - src/Protocol/Diaspora/Factory/DiasporaContact.php
d5c91d200bea97390fe428170b8f5237db047865
[friendica.git] / src / Protocol / Diaspora / Factory / DiasporaContact.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\Protocol\Diaspora\Factory;
23
24 use Friendica\Capabilities\ICanCreateFromTableRow;
25 use Friendica\Database\DBA;
26 use GuzzleHttp\Psr7\Uri;
27
28 class DiasporaContact extends \Friendica\BaseFactory implements ICanCreateFromTableRow
29 {
30         public function createFromTableRow(array $row): \Friendica\Protocol\Diaspora\Entity\DiasporaContact
31         {
32                 return new \Friendica\Protocol\Diaspora\Entity\DiasporaContact(
33                         new Uri($row['url']),
34                         new \DateTime($row['created'], new \DateTimeZone('UTC')),
35                         $row['guid'],
36                         $row['addr'],
37                         $row['alias'] ? new Uri($row['alias']) : null,
38                         $row['nick'],
39                         $row['name'],
40                         $row['given-name'],
41                         $row['family-name'],
42                         $row['photo'] ? new Uri($row['photo']) : null,
43                         $row['photo-medium'] ? new Uri($row['photo-medium']) : null,
44                         $row['photo-small'] ? new Uri($row['photo-small']) : null,
45                         $row['batch'] ? new Uri($row['batch']) : null,
46                         $row['notify'] ? new Uri($row['notify']) : null,
47                         $row['poll'] ? new Uri($row['poll']) : null,
48                         $row['subscribe'] ? new Uri($row['subscribe']) : null,
49                         $row['searchable'],
50                         $row['pubkey'],
51                         $row['baseurl'] ? new Uri($row['baseurl']) : null,
52                         $row['gsid'],
53                         $row['updated'] !== DBA::NULL_DATETIME ? new \DateTime($row['updated'], new \DateTimeZone('UTC')) : null,
54                         $row['interacting_count'],
55                         $row['interacted_count'],
56                         $row['post_count'],
57                         $row['uri-id'],
58                 );
59         }
60
61         /**
62          * @param array     $data              Data returned by \Friendica\Network\Probe::uri()
63          * @param int       $uriId             The URI ID of the Diaspora contact URL + GUID
64          * @param \DateTime $created
65          * @param int       $interacting_count
66          * @param int       $interacted_count
67          * @param int       $post_count
68          * @return \Friendica\Protocol\Diaspora\Entity\DiasporaContact
69          */
70         public function createfromProbeData(array $data, int $uriId, \DateTime $created, int $interacting_count = 0, int $interacted_count = 0, int $post_count = 0): \Friendica\Protocol\Diaspora\Entity\DiasporaContact
71         {
72                 $alias = $data['alias'] != $data['url'] ? $data['alias'] : null;
73
74                 return new \Friendica\Protocol\Diaspora\Entity\DiasporaContact(
75                         new Uri($data['url']),
76                         $created,
77                         $data['guid'],
78                         $data['addr'],
79                         $alias ? new Uri($alias) : null,
80                         $data['nick'],
81                         $data['name'],
82                         $data['given-name'] ?? '',
83                         $data['family-name'] ?? '',
84                         $data['photo'] ? new Uri($data['photo']) : null,
85                         !empty($data['photo_medium']) ? new Uri($data['photo_medium']) : null,
86                         !empty($data['photo_small']) ? new Uri($data['photo_small']) : null,
87                         $data['batch'] ? new Uri($data['batch']) : null,
88                         $data['notify'] ? new Uri($data['notify']) : null,
89                         $data['poll'] ? new Uri($data['poll']) : null,
90                         $data['subscribe'] ? new Uri($data['subscribe']) : null,
91                         !$data['hide'],
92                         $data['pubkey'],
93                         $data['baseurl'] ? new Uri($data['baseurl']) : null,
94                         $data['gsid'],
95                         null,
96                         $interacting_count,
97                         $interacted_count,
98                         $post_count,
99                         $uriId,
100                 );
101         }
102 }