|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Circles - Bring cloud-users closer together. |
|
4
|
|
|
* |
|
5
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
6
|
|
|
* later. See the COPYING file. |
|
7
|
|
|
* |
|
8
|
|
|
* @author Maxence Lange <[email protected]> |
|
9
|
|
|
* @copyright 2017 |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
* |
|
25
|
|
|
*/ |
|
26
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
namespace OCA\Circles\Db; |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
use OC\L10N\L10N; |
|
32
|
|
|
use OCA\Circles\Model\Circle; |
|
33
|
|
|
use OCA\Circles\Model\Member; |
|
34
|
|
|
use OCA\Circles\Model\Frame; |
|
35
|
|
|
use OCA\Circles\Service\MiscService; |
|
36
|
|
|
use OCP\IDBConnection; |
|
37
|
|
|
|
|
38
|
|
|
class CirclesRequest extends CirclesRequestBuilder { |
|
39
|
|
|
|
|
40
|
|
|
/** @var MiscService */ |
|
41
|
|
|
private $miscService; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* CirclesRequest constructor. |
|
45
|
|
|
* |
|
46
|
|
|
* @param L10N $l10n |
|
47
|
|
|
* @param IDBConnection $connection |
|
48
|
|
|
* @param MiscService $miscService |
|
49
|
|
|
*/ |
|
50
|
|
|
public function __construct(L10N $l10n, IDBConnection $connection, MiscService $miscService) { |
|
51
|
|
|
$this->l10n = $l10n; |
|
52
|
|
|
$this->dbConnection = $connection; |
|
53
|
|
|
$this->miscService = $miscService; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @param int $circleId |
|
59
|
|
|
* @param int $userId |
|
|
|
|
|
|
60
|
|
|
* |
|
61
|
|
|
* @return Circle |
|
|
|
|
|
|
62
|
|
|
*/ |
|
63
|
|
|
public function getDetails($circleId, $userId = '') { |
|
64
|
|
|
$qb = $this->getCirclesSelectSql(); |
|
65
|
|
|
|
|
66
|
|
|
$this->limitToId($qb, $circleId); |
|
67
|
|
|
if ($userId !== '') |
|
68
|
|
|
$this->limitToUserId($qb, $userId); |
|
69
|
|
|
|
|
70
|
|
|
// $this->leftjoinOwner($qb); |
|
|
|
|
|
|
71
|
|
|
// $this->buildWithMemberLevel($qb, 'u.level', $level); |
|
72
|
|
|
// $this->buildWithCircleId($qb, 'c.id', $circleId); |
|
73
|
|
|
// $this->buildWithOrXTypes($qb, $userId, $type, $name, $circleId); |
|
74
|
|
|
|
|
75
|
|
|
$cursor = $qb->execute(); |
|
76
|
|
|
$data = $cursor->fetch(); |
|
77
|
|
|
$entry = $this->parseCirclesSelectSql($data); |
|
78
|
|
|
|
|
79
|
|
|
return $entry; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
|
|
83
|
|
|
public function createShare(Frame $share) { |
|
84
|
|
|
|
|
85
|
|
|
$qb = $this->getSharesInsertSql(); |
|
86
|
|
|
$qb->setValue('circle_id', $qb->createNamedParameter($share->getCircleId())) |
|
87
|
|
|
->setValue('source', $qb->createNamedParameter($share->getSource())) |
|
88
|
|
|
->setValue('type', $qb->createNamedParameter($share->getType())) |
|
89
|
|
|
->setValue('author', $qb->createNamedParameter($share->getAuthor())) |
|
90
|
|
|
->setValue('sharer', $qb->createNamedParameter($share->getSharer())) |
|
91
|
|
|
->setValue('payload', $qb->createNamedParameter($share->getPayload(true))); |
|
92
|
|
|
|
|
93
|
|
|
$qb->execute(); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @param $circleId |
|
99
|
|
|
* @param int $level |
|
100
|
|
|
* |
|
101
|
|
|
* @return Member[] |
|
102
|
|
|
*/ |
|
103
|
|
|
public function getMembers($circleId, $level = Member::LEVEL_MEMBER) { |
|
104
|
|
|
$qb = $this->getMembersSelectSql(); |
|
105
|
|
|
$this->limitToMemberLevel($qb, $level); |
|
106
|
|
|
|
|
107
|
|
|
$this->joinCircles($qb, 'm.circle_id'); |
|
108
|
|
|
$this->limitToCircle($qb, $circleId); |
|
109
|
|
|
|
|
110
|
|
|
$qb->selectAlias('c.name', 'circle_name'); |
|
111
|
|
|
|
|
112
|
|
|
$users = []; |
|
113
|
|
|
$cursor = $qb->execute(); |
|
114
|
|
|
while ($data = $cursor->fetch()) { |
|
115
|
|
|
$member = $this->parseMembersSelectSql($data); |
|
116
|
|
|
if ($member !== null) { |
|
117
|
|
|
$users[] = $member; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
$cursor->closeCursor(); |
|
121
|
|
|
|
|
122
|
|
|
return $users; |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
|
|
126
|
|
|
} |
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.