Completed
Push — master ( f9a32b...1fc0d2 )
by Maxence
04:23
created

parseLinksSelectSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 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
namespace OCA\Circles\Db;
29
30
31
use OCA\Circles\Model\FederatedLink;
32
use OCA\Circles\Service\ConfigService;
33
use OCA\Circles\Service\MiscService;
34
use OCP\DB\QueryBuilder\IQueryBuilder;
35
use OCP\IDBConnection;
36
use OCP\IL10N;
37
38
class FederatedLinksRequestBuilder extends CoreRequestBuilder {
39
40
41
	/**
42
	 * CirclesRequestBuilder constructor.
43
	 *
44
	 * {@inheritdoc}
45
	 */
46
	public function __construct(
47
		IL10N $l10n, IDBConnection $connection, ConfigService $configService, MiscService $miscService
48
	) {
49
		parent::__construct($l10n, $connection, $configService, $miscService);
50
	}
51
52
53
	/**
54
	 * Base of the Sql Insert request
55
	 *
56
	 * @return IQueryBuilder
57
	 */
58 View Code Duplication
	protected function getLinksInsertSql() {
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...
59
		$qb = $this->dbConnection->getQueryBuilder();
60
		$qb->insert(self::TABLE_LINKS)
61
		   ->setValue('creation', $qb->createFunction('NOW()'));
62
63
		return $qb;
64
	}
65
66
67
	/**
68
	 * Base of the Sql Update request
69
	 *
70
	 * @return IQueryBuilder
71
	 */
72
	protected function getLinksUpdateSql() {
73
		$qb = $this->dbConnection->getQueryBuilder();
74
		$qb->update(self::TABLE_LINKS);
75
76
		return $qb;
77
	}
78
79
80
	/**
81
	 * Base of the Sql Select request for Shares
82
	 *
83
	 * @return IQueryBuilder
84
	 */
85
	protected function getLinksSelectSql() {
86
		$qb = $this->dbConnection->getQueryBuilder();
87
88
		/** @noinspection PhpMethodParametersCountMismatchInspection */
89
		$qb->select(
90
			'l.id', 'l.status', 'l.address', 'l.token', 'l.circle_id', 'l.unique_id', 'l.creation'
91
		)
92
		   ->from(self::TABLE_LINKS, 'l');
93
94
		$this->default_select_alias = 'l';
95
96
		return $qb;
97
	}
98
99
	/**
100
	 * Base of the Sql Delete request
101
	 *
102
	 * @return IQueryBuilder
103
	 */
104
	protected function getLinksDeleteSql() {
105
		$qb = $this->dbConnection->getQueryBuilder();
106
		$qb->delete(self::TABLE_LINKS);
107
108
		return $qb;
109
	}
110
111
	/**
112
	 * @param array $data
113
	 *
114
	 * @return FederatedLink
115
	 */
116
	protected function parseLinksSelectSql($data) {
117
		$link = new FederatedLink();
118
		$link->setId($data['id'])
119
			 ->setUniqueId($data['unique_id'])
120
			 ->setStatus($data['status'])
121
			 ->setCreation($data['creation'])
122
			 ->setAddress($data['address'])
123
			 ->setToken($data['token'])
124
			 ->setCircleId($data['circle_id']);
125
126
		return $link;
127
	}
128
129
}