|
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 Doctrine\DBAL\Query\QueryBuilder; |
|
32
|
|
|
use OCA\Circles\Model\Member; |
|
33
|
|
|
use OCP\DB\QueryBuilder\IQueryBuilder; |
|
34
|
|
|
use OCP\IDBConnection; |
|
35
|
|
|
use OCP\Share; |
|
36
|
|
|
use OCP\Share\IShare; |
|
37
|
|
|
|
|
38
|
|
|
class CirclesRequestBuilder { |
|
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
|
|
41
|
|
|
/** @var IDBConnection */ |
|
42
|
|
|
protected $dbConnection; |
|
43
|
|
|
|
|
44
|
|
|
private $default_select_alias; |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Limit the request to the Share by its Id. |
|
48
|
|
|
* |
|
49
|
|
|
* @param IQueryBuilder $qb |
|
50
|
|
|
* @param $circleId |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function limitToCircle(& $qb, $circleId) { |
|
53
|
|
|
$expr = $qb->expr(); |
|
54
|
|
|
$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->default_select_alias . '.' : ''; |
|
55
|
|
|
|
|
56
|
|
|
$qb->andWhere($expr->eq($pf . 'circle_id', $qb->createNamedParameter($circleId))); |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Base of the Sql Insert request |
|
62
|
|
|
* |
|
63
|
|
|
* @return IQueryBuilder |
|
64
|
|
|
*/ |
|
65
|
|
|
protected function getSharesInsertSql() { |
|
66
|
|
|
$qb = $this->dbConnection->getQueryBuilder(); |
|
67
|
|
|
$qb->insert('circles_shares') |
|
68
|
|
|
->setValue('creation', $qb->createFunction('NOW()')); |
|
69
|
|
|
|
|
70
|
|
|
return $qb; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param int $level |
|
76
|
|
|
* |
|
77
|
|
|
* @return IQueryBuilder |
|
78
|
|
|
*/ |
|
79
|
|
|
protected function getMembersSelectSql(int $level = Member::LEVEL_MEMBER) { |
|
80
|
|
|
$qb = $this->dbConnection->getQueryBuilder(); |
|
81
|
|
|
$expr = $qb->expr(); |
|
82
|
|
|
|
|
83
|
|
|
$qb->select('user_id', 'circle_id', 'level', 'status', 'joined') |
|
84
|
|
|
->from('circles_members', 'm') |
|
85
|
|
|
->where($expr->gte('m.level', $qb->createNamedParameter($level))); |
|
86
|
|
|
|
|
87
|
|
|
$this->default_select_alias = 'm'; |
|
88
|
|
|
|
|
89
|
|
|
return $qb; |
|
90
|
|
|
|
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
protected function parseMembersSelectSql(array $data) { |
|
94
|
|
|
return [ |
|
95
|
|
|
'uid' => $data['user_id'], |
|
96
|
|
|
'circleId' => $data['circle_id'], |
|
97
|
|
|
'level' => $data['level'], |
|
98
|
|
|
'status' => $data['status'], |
|
99
|
|
|
'joined' => $data['joined'] |
|
100
|
|
|
]; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
} |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString.