Completed
Pull Request — master (#139)
by Maxence
02:21
created

SharingFrameRequestBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 6
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\Circle;
32
use OCA\Circles\Model\SharingFrame;
33
use OCA\Circles\Service\ConfigService;
34
use OCA\Circles\Service\MiscService;
35
use OCP\DB\QueryBuilder\IQueryBuilder;
36
use OCP\IDBConnection;
37
use OCP\IL10N;
38
39
class SharingFrameRequestBuilder extends CoreRequestBuilder {
40
41
	/** @var CirclesRequest */
42
	protected $circlesRequest;
43
44
	/** @var MembersRequest */
45
	protected $membersRequest;
46
47
	/**
48
	 * CirclesRequestBuilder constructor.
49
	 *
50
	 * {@inheritdoc}
51
	 * @param MembersRequest $membersRequest
52
	 */
53
	public function __construct(
54
		IL10N $l10n, IDBConnection $connection, CirclesRequest $circlesRequest,
55
		MembersRequest $membersRequest, ConfigService $configService, MiscService $miscService
56
	) {
57
		parent::__construct($l10n, $connection, $configService, $miscService);
58
		$this->circlesRequest = $circlesRequest;
59
		$this->membersRequest = $membersRequest;
60
	}
61
62
63
	/**
64
	 * Base of the Sql Select request for Shares
65
	 *
66
	 * @return IQueryBuilder
67
	 */
68
	protected function getSharesSelectSql() {
69
		$qb = $this->dbConnection->getQueryBuilder();
70
71
		/** @noinspection PhpMethodParametersCountMismatchInspection */
72
		$qb->select(
73
			's.circle_id', 's.source', 's.type', 's.author', 's.cloud_id', 's.payload',
74
			's.creation', 's.headers', 's.unique_id'
75
		)
76
		   ->from(self::TABLE_SHARES, 's');
77
78
		$this->default_select_alias = 's';
79
80
		return $qb;
81
	}
82
83
84
	/**
85
	 * Base of the Sql Insert request for Shares
86
	 *
87
	 * @return IQueryBuilder
88
	 */
89 View Code Duplication
	protected function getSharesInsertSql() {
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...
90
		$qb = $this->dbConnection->getQueryBuilder();
91
		$qb->insert(self::TABLE_SHARES)
92
		   ->setValue('creation', $qb->createFunction('NOW()'));
93
94
		return $qb;
95
	}
96
97
98
	/**
99
	 * Base of the Sql Update request for Shares
100
	 *
101
	 * @param string $uniqueId
102
	 *
103
	 * @return IQueryBuilder
104
	 */
105 View Code Duplication
	protected function getSharesUpdateSql($uniqueId) {
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...
106
		$qb = $this->dbConnection->getQueryBuilder();
107
		$qb->update(self::TABLE_SHARES)
108
		   ->where(
109
			   $qb->expr()
110
				  ->eq('unique_id', $qb->createNamedParameter((string)$uniqueId))
111
		   );
112
113
		return $qb;
114
	}
115
116
117
	/**
118
	 * @param array $data
119
	 *
120
	 * @return SharingFrame
121
	 */
122
	protected function parseSharesSelectSql($data) {
123
		$frame = new SharingFrame($data['source'], $data['type']);
124
125
		$circle = new Circle();
126
		$circle->setUniqueId($data['circle_id']);
127
		if (key_exists('circle_type', $data)) {
128
			$circle->setType($data['circle_type']);
129
			$circle->setName($data['circle_name']);
130
		}
131
132
		$frame->setCircle($circle);
133
134
		$frame->setAuthor($data['author']);
135
		$frame->setCloudId($data['cloud_id']);
136
		$frame->setPayload(json_decode($data['payload'], true));
137
		$frame->setCreation($data['creation']);
138
		$frame->setHeaders(json_decode($data['headers'], true));
139
		$frame->setUniqueId($data['unique_id']);
140
141
		return $frame;
142
	}
143
144
145
}