Completed
Push — master ( 8920a6...aff5d0 )
by Maxence
25s
created

SharesRequest::getShares()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
dl 14
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 0
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 OCA\Circles\Model\Member;
32
33
34
/**
35
 * Class SharesRequest
36
 *
37
 * @package OCA\Circles\Db
38
 */
39
class SharesRequest extends SharesRequestBuilder {
40
41
42
	/**
43
	 * remove shares from a member to a circle
44
	 *
45
	 * @param Member $member
46
	 */
47
	public function removeSharesFromMember(Member $member) {
48
		$qb = $this->getSharesDeleteSql();
49
		$expr = $qb->expr();
50
51
		$andX = $expr->andX();
52
		$andX->add($expr->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE)));
53
		$andX->add($expr->eq('share_with', $qb->createNamedParameter($member->getCircleId())));
54
		$andX->add($expr->eq('uid_initiator', $qb->createNamedParameter($member->getUserId())));
55
		$qb->andWhere($andX);
56
57
		$qb->execute();
58
	}
59
60
61
	/**
62
	 * @param string $circleId
63
	 */
64 View Code Duplication
	public function removeSharesToCircleId(string $circleId) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
65
		$qb = $this->getSharesDeleteSql();
66
		$expr = $qb->expr();
67
68
		$andX = $expr->andX();
69
		$andX->add($expr->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE)));
70
		$andX->add($expr->eq('share_with', $qb->createNamedParameter($circleId)));
71
		$qb->andWhere($andX);
72
73
		$qb->execute();
74
	}
75
76
77
	/**
78
	 * @param string $circleId
79
	 *
80
	 * @return array
81
	 */
82 View Code Duplication
	public function getSharesForCircle(string $circleId) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
83
		$qb = $this->getSharesSelectSql();
84
85
		$this->limitToShareWith($qb, $circleId);
86
		$this->limitToShareType($qb, self::SHARE_TYPE);
87
88
		$shares = [];
89
		$cursor = $qb->execute();
90
		while ($data = $cursor->fetch()) {
91
			$shares[] = $data;
92
		}
93
		$cursor->closeCursor();
94
95
		return $shares;
96
	}
97
98
99
	/**
100
	 * @return array
101
	 */
102 View Code Duplication
	public function getShares(): array {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
		$qb = $this->getSharesSelectSql();
104
105
		$this->limitToShareType($qb, self::SHARE_TYPE);
106
107
		$shares = [];
108
		$cursor = $qb->execute();
109
		while ($data = $cursor->fetch()) {
110
			$shares[] = $data;
111
		}
112
		$cursor->closeCursor();
113
114
		return $shares;
115
	}
116
117
}
118
119