Completed
Pull Request — master (#332)
by Maxence
01:49
created

SharesRequest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 48
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A removeSharesFromMember() 0 12 1
A getSharesForCircle() 0 15 2
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 daita\MySmallPhpTools\Traits\TArrayTools;
32
use daita\MySmallPhpTools\Traits\TStringTools;
33
use OCA\Circles\Model\Member;
34
35
36
/**
37
 * Class SharesRequest
38
 *
39
 * @package OCA\Circles\Db
40
 */
41
class SharesRequest extends SharesRequestBuilder {
42
43
44
	use TArrayTools;
45
	use TStringTools;
46
47
48
	/**
49
	 * remove shares from a member to a circle
50
	 *
51
	 * @param Member $member
52
	 */
53
	public function removeSharesFromMember(Member $member) {
54
		$qb = $this->getSharesDeleteSql();
55
		$expr = $qb->expr();
56
57
		$andX = $expr->andX();
58
		$andX->add($expr->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE)));
59
		$andX->add($expr->eq('share_with', $qb->createNamedParameter($member->getCircleId())));
60
		$andX->add($expr->eq('uid_initiator', $qb->createNamedParameter($member->getUserId())));
61
		$qb->andWhere($andX);
62
63
		$qb->execute();
64
	}
65
66
67
	/**
68
	 * @param string $circleId
69
	 *
70
	 * @return array
71
	 */
72
	public function getSharesForCircle(string $circleId) {
73
		$qb = $this->getSharesSelectSql();
74
75
		$this->limitToShareWith($qb, $circleId);
76
		$this->limitToShareType($qb, self::SHARE_TYPE);
77
78
		$shares = [];
79
		$cursor = $qb->execute();
80
		while ($data = $cursor->fetch()) {
81
			$shares[] = $data;
82
		}
83
		$cursor->closeCursor();
84
85
		return $shares;
86
	}
87
88
}
89
90