Completed
Push — master ( 720746...079e9b )
by Maxence
02:35
created

CoreRequestBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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