Completed
Pull Request — master (#546)
by Maxence
03:01
created

CircleRequest::getCircle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
6
/**
7
 * Circles - Bring cloud-users closer together.
8
 *
9
 * This file is licensed under the Affero General Public License version 3 or
10
 * later. See the COPYING file.
11
 *
12
 * @author Maxence Lange <[email protected]>
13
 * @copyright 2021
14
 * @license GNU AGPL version 3 or any later version
15
 *
16
 * This program is free software: you can redistribute it and/or modify
17
 * it under the terms of the GNU Affero General Public License as
18
 * published by the Free Software Foundation, either version 3 of the
19
 * License, or (at your option) any later version.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU Affero General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU Affero General Public License
27
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
28
 *
29
 */
30
31
32
namespace OCA\Circles\Db;
33
34
35
use OCA\Circles\Exceptions\CircleNotFoundException;
36
use OCA\Circles\Model\Circle;
37
use OCA\Circles\Model\Member;
38
39
40
/**
41
 * Class CircleRequest
42
 *
43
 * @package OCA\Circles\Db
44
 */
45
class CircleRequest extends CircleRequestBuilder {
46
47
48
	/**
49
	 * @param Circle $circle
50
	 */
51
	public function save(Circle $circle): void {
52
		$qb = $this->getCircleInsertSql();
53
		$qb->setValue('id', $qb->createNamedParameter($circle->getId()));
54
//		   ->setValue('instance', $qb->createNamedParameter($circle->getInstance()))
55
//		   ->setValue('href', $qb->createNamedParameter($remote->getId()))
56
//		   ->setValue('item', $qb->createNamedParameter(json_encode($remote->getOrigData())));
57
58
		$qb->execute();
59
	}
60
61
62
	/**
63
	 * @param Circle $circle
64
	 */
65
	public function update(Circle $circle) {
66
		$qb = $this->getCircleUpdateSql();
67
//		$qb->set('uid', $qb->createNamedParameter($circle->getUid(true)))
68
//		   ->set('href', $qb->createNamedParameter($circle->getId()))
69
//		   ->set('item', $qb->createNamedParameter(json_encode($circle->getOrigData())));
70
71
		$qb->limitToUniqueId($circle->getId());
72
73
		$qb->execute();
74
	}
75
76
77
	/**
78
	 * @param Member|null $viewer
79
	 * @param string $ownerUserId
80
	 *
81
	 * @return Circle[]
82
	 */
83
	public function getCircles(?Member $viewer = null, string $ownerUserId = ''): array {
84
		$qb = $this->getCircleSelectSql();
85
		$qb->leftJoinOwner($ownerUserId);
86
87
		if ($viewer !== null) {
88
			$qb->limitToViewer($viewer);
89
		}
90
91
		return $this->getItemsFromRequest($qb);
92
	}
93
94
95
	/**
96
	 * @param string $id
97
	 *
98
	 * @return Circle
99
	 * @throws CircleNotFoundException
100
	 */
101
	public function getCircle(string $id): Circle {
102
		$qb = $this->getCircleSelectSql();
103
		$qb->limitToUniqueId($id);
104
		$qb->leftJoinOwner();
105
106
		return $this->getItemFromRequest($qb);
107
	}
108
109
110
	/**
111
	 * @return Circle[]
112
	 */
113
	public function getFederated(): array {
114
		$qb = $this->getCircleSelectSql();
115
		$qb->leftJoinOwner();
116
117
		return $this->getItemsFromRequest($qb);
118
	}
119
120
}
121
122