Completed
Push — master ( dc9b8a...1415c3 )
by Maxence
02:30
created

MembersRequestBuilder::limitToMemberLevel()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 2
1
<?php
2
3
/**
4
 * Circles - Bring cloud-users closer together.
5
 *
6
 * This file is licensed under the Affero General Public License version 3 or
7
 * later. See the COPYING file.
8
 *
9
 * @author Maxence Lange <[email protected]>
10
 * @copyright 2017
11
 * @license GNU AGPL version 3 or any later version
12
 *
13
 * This program is free software: you can redistribute it and/or modify
14
 * it under the terms of the GNU Affero General Public License as
15
 * published by the Free Software Foundation, either version 3 of the
16
 * License, or (at your option) any later version.
17
 *
18
 * This program is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21
 * GNU Affero General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License
24
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25
 *
26
 */
27
28
namespace OCA\Circles\Db;
29
30
31
use OCP\DB\QueryBuilder\IQueryBuilder;
32
use Doctrine\DBAL\Query\QueryBuilder;
33
34
class MembersRequestBuilder extends CoreRequestBuilder {
35
36
37
//	/**
38
//	 * Limit the request to a minimum member level.
39
//	 *
40
//	 * @param IQueryBuilder $qb
41
//	 * @param integer $level
42
//	 */
43
//	protected function limitToMemberLevel(IQueryBuilder & $qb, $level) {
44
//		$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->default_select_alias . '.' : '';
45
//		$qb->andWhere(
46
//			$qb->expr()
47
//			   ->gte($pf . 'level', $qb->createNamedParameter($level))
48
//		);
49
//	}
50
51
52
	/**
53
	 * @return IQueryBuilder
54
	 */
55
	protected function getGroupsSelectSql() {
56
		$qb = $this->dbConnection->getQueryBuilder();
57
58
		/** @noinspection PhpMethodParametersCountMismatchInspection */
59
		$qb->select('g.circle_id', 'g.group_id', 'g.level', 'g.note', 'g.joined')
60
		   ->from(CoreRequestBuilder::TABLE_GROUPS, 'g');
61
		$this->default_select_alias = 'g';
62
63
		return $qb;
64
	}
65
66
67
	/**
68
	 * Base of the Sql Insert request for Shares
69
	 *
70
	 * @return IQueryBuilder
71
	 */
72
	protected function getGroupsInsertSql() {
73
		$qb = $this->dbConnection->getQueryBuilder();
74
		$qb->insert(CoreRequestBuilder::TABLE_GROUPS)
75
		   ->setValue('joined', $qb->createFunction('NOW()'));
76
77
		return $qb;
78
	}
79
80
81
	/**
82
	 * Base of the Sql Insert request for Shares
83
	 *
84
	 * @param int $circleId
85
	 * @param string $groupId
86
	 *
87
	 * @return IQueryBuilder
88
	 */
89
	protected function getGroupsUpdateSql($circleId, $groupId) {
90
		$qb = $this->dbConnection->getQueryBuilder();
91
		$expr = $qb->expr();
92
93
		/** @noinspection PhpMethodParametersCountMismatchInspection */
94
		$qb->update(CoreRequestBuilder::TABLE_GROUPS)
95
		   ->where(
96
			   $expr->andX(
97
				   $expr->eq('circle_id', $qb->createNamedParameter($circleId)),
98
				   $expr->eq('group_id', $qb->createNamedParameter($groupId))
99
			   )
100
		   );
101
102
		return $qb;
103
	}
104
105
106
	/**
107
	 * Base of the Sql Insert request for Shares
108
	 *
109
	 * @param string $groupId
110
	 *
111
	 * @return IQueryBuilder
112
	 */
113 View Code Duplication
	protected function getGroupsDeleteSql($groupId) {
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...
114
		$qb = $this->dbConnection->getQueryBuilder();
115
		$expr = $qb->expr();
116
117
		$qb->delete(CoreRequestBuilder::TABLE_GROUPS)
118
		   ->where($expr->eq('group_id', $qb->createNamedParameter($groupId)));
119
120
		return $qb;
121
	}
122
123
124
}