Completed
Pull Request — master (#362)
by Maxence
01:55 queued 11s
created

GSSharesRequestBuilder   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getGSSharesInsertSql() 0 6 1
A getGSSharesMountpointInsertSql() 0 6 1
A getGSSharesUpdateSql() 0 6 1
A getGSSharesMountpointUpdateSql() 0 6 1
A getGSSharesSelectSql() 0 14 1
A getGSSharesMountpointSelectSql() 0 13 1
A getGSSharesDeleteSql() 0 6 1
A getGSSharesMountpointDeleteSql() 0 6 1
A parseGSSharesSelectSql() 0 6 1
A parseGSSharesMountpointSelectSql() 0 6 1
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
29
namespace OCA\Circles\Db;
30
31
32
use OCA\Circles\Model\GlobalScale\GSShare;
33
use OCA\Circles\Model\GlobalScale\GSShareMountpoint;
34
use OCP\DB\QueryBuilder\IQueryBuilder;
35
36
37
/**
38
 * Class GSSharesRequestBuilder
39
 *
40
 * @package OCA\Circles\Db
41
 */
42
class GSSharesRequestBuilder extends CoreRequestBuilder {
43
44
45
	/**
46
	 * Base of the Sql Insert request for Shares
47
	 *
48
	 * @return IQueryBuilder
49
	 */
50
	protected function getGSSharesInsertSql() {
51
		$qb = $this->dbConnection->getQueryBuilder();
52
		$qb->insert(self::TABLE_GSSHARES);
53
54
		return $qb;
55
	}
56
57
58
	/**
59
	 * Base of the Sql Insert request for Shares Mountpoint
60
	 *
61
	 * @return IQueryBuilder
62
	 */
63
	protected function getGSSharesMountpointInsertSql() {
64
		$qb = $this->dbConnection->getQueryBuilder();
65
		$qb->insert(self::TABLE_GSSHARES_MOUNTPOINT);
66
67
		return $qb;
68
	}
69
70
71
	/**
72
	 * Base of the Sql Update request
73
	 *
74
	 * @return IQueryBuilder
75
	 */
76
	protected function getGSSharesUpdateSql() {
77
		$qb = $this->dbConnection->getQueryBuilder();
78
		$qb->update(self::TABLE_GSSHARES);
79
80
		return $qb;
81
	}
82
83
84
	/**
85
	 * @return IQueryBuilder
86
	 */
87
	protected function getGSSharesMountpointUpdateSql() {
88
		$qb = $this->dbConnection->getQueryBuilder();
89
		$qb->update(self::TABLE_GSSHARES_MOUNTPOINT);
90
91
		return $qb;
92
	}
93
94
95
	/**
96
	 * @return IQueryBuilder
97
	 */
98
	protected function getGSSharesSelectSql() {
99
		$qb = $this->dbConnection->getQueryBuilder();
100
101
		/** @noinspection PhpMethodParametersCountMismatchInspection */
102
		$qb->select(
103
			'gsh.id', 'gsh.circle_id', 'gsh.owner', 'gsh.instance', 'gsh.token', 'gsh.parent',
104
			'gsh.mountpoint', 'gsh.mountpoint_hash'
105
		)
106
		   ->from(self::TABLE_GSSHARES, 'gsh');
107
108
		$this->default_select_alias = 'gsh';
109
110
		return $qb;
111
	}
112
113
114
	/**
115
	 * @return IQueryBuilder
116
	 */
117
	protected function getGSSharesMountpointSelectSql() {
118
		$qb = $this->dbConnection->getQueryBuilder();
119
120
		/** @noinspection PhpMethodParametersCountMismatchInspection */
121
		$qb->select(
122
			'gsmp.user_id', 'gsmp.share_id', 'gsmp.mountpoint', 'gsmp.mountpoint_hash'
123
		)
124
		   ->from(self::TABLE_GSSHARES_MOUNTPOINT, 'gsmp');
125
126
		$this->default_select_alias = 'gsmp';
127
128
		return $qb;
129
	}
130
131
132
	/**
133
	 * Base of the Sql Delete request
134
	 *
135
	 * @return IQueryBuilder
136
	 */
137
	protected function getGSSharesDeleteSql() {
138
		$qb = $this->dbConnection->getQueryBuilder();
139
		$qb->delete(self::TABLE_GSSHARES);
140
141
		return $qb;
142
	}
143
144
145
	/**
146
	 * Base of the Sql Delete request
147
	 *
148
	 * @return IQueryBuilder
149
	 */
150
	protected function getGSSharesMountpointDeleteSql() {
151
		$qb = $this->dbConnection->getQueryBuilder();
152
		$qb->delete(self::TABLE_GSSHARES_MOUNTPOINT);
153
154
		return $qb;
155
	}
156
157
158
	/**
159
	 * @param array $data
160
	 *
161
	 * @return GSShare
162
	 */
163
	protected function parseGSSharesSelectSql($data): GSShare {
164
		$share = new GSShare();
165
		$share->importFromDatabase($data);
166
167
		return $share;
168
	}
169
170
171
	/**
172
	 * @param array $data
173
	 *
174
	 * @return GSShareMountpoint
175
	 */
176
	protected function parseGSSharesMountpointSelectSql($data): GSShareMountpoint {
177
		$share = new GSShareMountpoint();
178
		$share->importFromDatabase($data);
179
180
		return $share;
181
	}
182
183
}
184