Completed
Push — master ( 8de354...4e0f9f )
by Maxence
01:38
created

CoreRequestBuilder::limitToDBField()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 3
1
<?php
2
declare(strict_types=1);
3
4
5
/**
6
 * Files_FullTextSearch - Index the content of your files
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2018
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
31
namespace OCA\Files_FullTextSearch\Db;
32
33
34
use Doctrine\DBAL\Query\QueryBuilder;
35
use OCA\Files_FullTextSearch\Service\MiscService;
36
use OCP\DB\QueryBuilder\IQueryBuilder;
37
use OCP\IDBConnection;
38
39
40
/**
41
 * Class CoreRequestBuilder
42
 *
43
 * @package OCA\Files_FullTextSearch\Db
44
 */
45
class CoreRequestBuilder {
46
47
48
	const TABLE_SHARES = 'share';
49
50
51
	/** @var IDBConnection */
52
	protected $dbConnection;
53
54
	/** @var MiscService */
55
	protected $miscService;
56
57
	/** @var string */
58
	protected $defaultSelectAlias;
59
60
61
	/**
62
	 * CoreRequestBuilder constructor.
63
	 *
64
	 * @param IDBConnection $connection
65
	 * @param MiscService $miscService
66
	 */
67
	public function __construct(
68
		IDBConnection $connection, MiscService $miscService
69
	) {
70
		$this->dbConnection = $connection;
71
		$this->miscService = $miscService;
72
	}
73
74
75
	/**
76
	 * Limit the request to the Id
77
	 *
78
	 * @param IQueryBuilder $qb
79
	 * @param $fileSource
80
	 */
81
	protected function limitToFileSource(IQueryBuilder &$qb, int $fileSource) {
82
		$this->limitToDBFieldInt($qb, 'file_source', $fileSource);
83
	}
84
85
86
	/**
87
	 * @param IQueryBuilder $qb
88
	 * @param string $field
89
	 * @param string $value
90
	 */
91
	private function limitToDBField(IQueryBuilder &$qb, string $field, string $value) {
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
92
		$expr = $qb->expr();
93
		$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
94
		$qb->andWhere($expr->eq($pf . $field, $qb->createNamedParameter($value)));
95
	}
96
97
98
	/**
99
	 * @param IQueryBuilder $qb
100
	 * @param string $field
101
	 * @param int $value
102
	 */
103
	private function limitToDBFieldInt(IQueryBuilder &$qb, string $field, int $value) {
104
		$expr = $qb->expr();
105
		$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->defaultSelectAlias . '.' : '';
106
		$qb->andWhere($expr->eq($pf . $field, $qb->createNamedParameter($value)));
107
	}
108
109
110
}
111
112