Completed
Pull Request — master (#516)
by Maxence
02:25
created

AccountsRequestBuilder::getAccountsInsertSql()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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 daita\MySmallPhpTools\Traits\TArrayTools;
33
use OCP\DB\QueryBuilder\IQueryBuilder;
34
35
36
/**
37
 * Class AccountsRequestBuilder
38
 *
39
 * @package OCA\Circles\Db
40
 */
41
class AccountsRequestBuilder extends CoreRequestBuilder {
42
43
44
	use TArrayTools;
45
46
47
	/**
48
	 * Base of the Sql Insert request for Accounts
49
	 *
50
	 * @return IQueryBuilder
51
	 */
52
	protected function getAccountsInsertSql() {
53
		$qb = $this->dbConnection->getQueryBuilder();
54
		$qb->insert(self::NC_TABLE_ACCOUNTS);
55
56
		return $qb;
57
	}
58
59
60
	/**
61
	 * Base of the Sql Update request for Accounts
62
	 *
63
	 * @return IQueryBuilder
64
	 */
65
	protected function getAccountsUpdateSql() {
66
		$qb = $this->dbConnection->getQueryBuilder();
67
		$qb->update(self::NC_TABLE_ACCOUNTS);
68
69
		return $qb;
70
	}
71
72
73
	/**
74
	 * @return IQueryBuilder
75
	 */
76
	protected function getAccountsSelectSql() {
77
		$qb = $this->dbConnection->getQueryBuilder();
78
79
		/** @noinspection PhpMethodParametersCountMismatchInspection */
80
		$qb->select('a.uid', 'a.data')
81
		   ->from(self::NC_TABLE_ACCOUNTS, 'a');
82
83
		$this->default_select_alias = 'a';
84
85
		return $qb;
86
	}
87
88
89
	/**
90
	 * Base of the Sql Delete request
91
	 *
92
	 * @return IQueryBuilder
93
	 */
94
	protected function getAccountsDeleteSql() {
95
		$qb = $this->dbConnection->getQueryBuilder();
96
		$qb->delete(self::NC_TABLE_ACCOUNTS);
97
98
		return $qb;
99
	}
100
101
102
	/**
103
	 * @param array $entry
104
	 *
105
	 * @return array
106
	 */
107
	protected function parseAccountsSelectSql(array $entry): array {
108
		$data = json_decode($entry['data'], true);
109
		if (!is_array($data)) {
110
			$data = [];
111
		}
112
113
		return [
114
			'userId'      => $entry['uid'],
115
			'displayName' => $this->get('displayname.value', $data)
116
		];
117
	}
118
119
}
120
121