Completed
Push — federated-circles ( 450355...2a3998 )
by Maxence
04:51 queued 02:17
created

CirclesRequest::getFrame()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 7
nc 1
nop 1
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\SharingFrame;
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 string $userId
60
	 *
61
	 * @return Circle
0 ignored issues
show
Documentation introduced by
Should the return type not be Circle|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
62
	 */
63
	public function getDetails($circleId, $userId = '') {
64
		$qb = $this->getCirclesSelectSql();
65
66
		$this->limitToId($qb, $circleId);
67
		if ($userId !== '')
68
			$this->leftJoinUserIdAsMember($qb, $userId);
69
70
//		$this->leftjoinOwner($qb);
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
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
	/**
84
	 * saveFrame()
85
	 *
86
	 * Insert a new entry in the database to save the SharingFrame.
87
	 *
88
	 * @param SharingFrame $share
89
	 */
90
	public function saveFrame(SharingFrame $share) {
91
92
		$qb = $this->getSharesInsertSql();
93
		$qb->setValue('circle_id', $qb->createNamedParameter($share->getCircleId()))
94
		   ->setValue('source', $qb->createNamedParameter($share->getSource()))
95
		   ->setValue('type', $qb->createNamedParameter($share->getType()))
96
		   ->setValue('author', $qb->createNamedParameter($share->getAuthor()))
97
		   ->setValue('sharer', $qb->createNamedParameter($share->getSharer()))
98
		   ->setValue('payload', $qb->createNamedParameter($share->getPayload(true)));
99
100
		$qb->execute();
101
	}
102
103
104
105
106
	public function getFrame(string $uniqueId)
107
	{
108
		$qb = $this->getSharesSelectSql();
109
		$this->limitToUniqueId($qb, $uniqueId);
110
111
		$cursor = $qb->execute();
112
		$data = $cursor->fetch();
113
		$entry = $this->parseSharesSelectSql($data);
114
115
		return $entry;
116
	}
117
118
119
120
121
	/**
122
	 * @param $circleId
123
	 * @param int $level
124
	 *
125
	 * @return Member[]
126
	 */
127
	public function getMembers($circleId, $level = Member::LEVEL_MEMBER) {
128
		$qb = $this->getMembersSelectSql();
129
		$this->limitToMemberLevel($qb, $level);
130
131
		$this->joinCircles($qb, 'm.circle_id');
132
		$this->limitToCircle($qb, $circleId);
133
134
		$qb->selectAlias('c.name', 'circle_name');
135
136
		$users = [];
137
		$cursor = $qb->execute();
138
		while ($data = $cursor->fetch()) {
139
			$member = $this->parseMembersSelectSql($data);
140
			if ($member !== null) {
141
				$users[] = $member;
142
			}
143
		}
144
		$cursor->closeCursor();
145
146
		return $users;
147
	}
148
149
150
}