|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Circles - Bring cloud-users closer together. |
|
8
|
|
|
* |
|
9
|
|
|
* This file is licensed under the Affero General Public License version 3 or |
|
10
|
|
|
* later. See the COPYING file. |
|
11
|
|
|
* |
|
12
|
|
|
* @author Maxence Lange <[email protected]> |
|
13
|
|
|
* @copyright 2021 |
|
14
|
|
|
* @license GNU AGPL version 3 or any later version |
|
15
|
|
|
* |
|
16
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
17
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
18
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
19
|
|
|
* License, or (at your option) any later version. |
|
20
|
|
|
* |
|
21
|
|
|
* This program is distributed in the hope that it will be useful, |
|
22
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24
|
|
|
* GNU Affero General Public License for more details. |
|
25
|
|
|
* |
|
26
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
27
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
28
|
|
|
* |
|
29
|
|
|
*/ |
|
30
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
namespace OCA\Circles\Db; |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
use daita\MySmallPhpTools\Exceptions\RowNotFoundException; |
|
36
|
|
|
use OCA\Circles\Exceptions\CircleNotFoundException; |
|
37
|
|
|
use OCA\Circles\Model\Circle; |
|
38
|
|
|
|
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Class CircleRequestBuilder |
|
42
|
|
|
* |
|
43
|
|
|
* @package OCA\Circles\Db |
|
44
|
|
|
*/ |
|
45
|
|
|
class CircleRequestBuilder extends CoreRequestBuilder { |
|
46
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @return CoreQueryBuilder |
|
50
|
|
|
*/ |
|
51
|
|
View Code Duplication |
protected function getCircleInsertSql(): CoreQueryBuilder { |
|
|
|
|
|
|
52
|
|
|
$qb = $this->getQueryBuilder(); |
|
53
|
|
|
$qb->insert(self::TABLE_CIRCLE) |
|
54
|
|
|
->setValue('creation', $qb->createNamedParameter($this->timezoneService->getUTCDate())); |
|
55
|
|
|
|
|
56
|
|
|
return $qb; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* @return CoreQueryBuilder |
|
62
|
|
|
*/ |
|
63
|
|
|
protected function getCircleUpdateSql(): CoreQueryBuilder { |
|
64
|
|
|
$qb = $this->getQueryBuilder(); |
|
65
|
|
|
$qb->update(self::TABLE_CIRCLE); |
|
66
|
|
|
|
|
67
|
|
|
return $qb; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* @return CoreQueryBuilder |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function getCircleSelectSql(): CoreQueryBuilder { |
|
75
|
|
|
$qb = $this->getQueryBuilder(); |
|
76
|
|
|
$qb->selectDistinct('c.unique_id') |
|
77
|
|
|
->addSelect( |
|
78
|
|
|
'c.name', 'c.alt_name', 'c.description', 'c.settings', 'c.config', 'contact_addressbook', |
|
79
|
|
|
'contact_groupname', 'c.creation' |
|
80
|
|
|
) |
|
81
|
|
|
->from(self::TABLE_CIRCLE, 'c') |
|
82
|
|
|
->setDefaultSelectAlias('c'); |
|
83
|
|
|
|
|
84
|
|
|
return $qb; |
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Base of the Sql Delete request |
|
90
|
|
|
* |
|
91
|
|
|
* @return CoreQueryBuilder |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function getCircleDeleteSql(): CoreQueryBuilder { |
|
94
|
|
|
$qb = $this->getQueryBuilder(); |
|
95
|
|
|
$qb->delete(self::TABLE_CIRCLE); |
|
96
|
|
|
|
|
97
|
|
|
return $qb; |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* @param CoreQueryBuilder $qb |
|
103
|
|
|
* |
|
104
|
|
|
* @return Circle |
|
105
|
|
|
* @throws CircleNotFoundException |
|
106
|
|
|
*/ |
|
107
|
|
View Code Duplication |
public function getItemFromRequest(CoreQueryBuilder $qb): Circle { |
|
|
|
|
|
|
108
|
|
|
/** @var Circle $circle */ |
|
109
|
|
|
try { |
|
110
|
|
|
$circle = $qb->asItem( |
|
111
|
|
|
Circle::class, |
|
112
|
|
|
[ |
|
113
|
|
|
'local' => $this->configService->getLocalInstance() |
|
114
|
|
|
] |
|
115
|
|
|
); |
|
116
|
|
|
} catch (RowNotFoundException $e) { |
|
117
|
|
|
throw new CircleNotFoundException(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
return $circle; |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
/** |
|
124
|
|
|
* @param CoreQueryBuilder $qb |
|
125
|
|
|
* |
|
126
|
|
|
* @return Circle[] |
|
127
|
|
|
*/ |
|
128
|
|
|
public function getItemsFromRequest(CoreQueryBuilder $qb): array { |
|
129
|
|
|
/** @var Circle[] $result */ |
|
130
|
|
|
return $qb->asItems( |
|
131
|
|
|
Circle::class, |
|
132
|
|
|
[ |
|
133
|
|
|
'local' => $this->configService->getLocalInstance() |
|
134
|
|
|
] |
|
135
|
|
|
); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
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.