Completed
Pull Request — master (#94)
by Maxence
02:28
created

CoreRequestBuilder::limitToGroupId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: maxence
5
 * Date: 7/4/17
6
 * Time: 5:01 PM
7
 */
8
9
namespace OCA\Circles\Db;
10
11
12
use OCP\DB\QueryBuilder\IQueryBuilder;
13
use Doctrine\DBAL\Query\QueryBuilder;
14
use OC\L10N\L10N;
15
use OCA\Circles\Service\MiscService;
16
use OCP\IDBConnection;
17
18
class CoreRequestBuilder {
0 ignored issues
show
Coding Style introduced by
The property $default_select_alias is not named in camelCase.

This check marks property names that have not been written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes databaseConnectionString.

Loading history...
19
20
	/** @var IDBConnection */
21
	protected $dbConnection;
22
23
	/** @var L10N */
24
	protected $l10n;
25
26
	/** @var MiscService */
27
	protected $miscService;
28
29
	/** @var string */
30
	protected $default_select_alias;
31
32
33
	/**
34
	 * CirclesRequest constructor.
35
	 *
36
	 * @param L10N $l10n
37
	 * @param IDBConnection $connection
38
	 * @param MiscService $miscService
39
	 */
40
	public function __construct(L10N $l10n, IDBConnection $connection, MiscService $miscService) {
41
		$this->l10n = $l10n;
42
		$this->dbConnection = $connection;
43
		$this->miscService = $miscService;
44
	}
45
46
47
	/**
48
	 * Limit the request to the Circle by its Id.
49
	 *
50
	 * @param IQueryBuilder $qb
51
	 * @param int $circleId
52
	 */
53
	protected function limitToCircleId(IQueryBuilder & $qb, $circleId) {
54
		$this->limitToDBField($qb, 'circle_id', $circleId);
55
	}
56
57
58
	/**
59
	 * Limit the request to the Group by its Id.
60
	 *
61
	 * @param IQueryBuilder $qb
62
	 * @param int $groupId
63
	 */
64
	protected function limitToGroupId(IQueryBuilder & $qb, $groupId) {
65
		$this->limitToDBField($qb, 'group_id', $groupId);
66
	}
67
68
69
	/**
70
	 * @param IQueryBuilder $qb
71
	 * @param string $field
72
	 * @param string|integer $value
73
	 */
74
	private function limitToDBField(IQueryBuilder & $qb, $field, $value) {
75
		$expr = $qb->expr();
76
		$pf = ($qb->getType() === QueryBuilder::SELECT) ? $this->default_select_alias . '.' : '';
77
		$qb->andWhere($expr->eq($pf . $field, $qb->createNamedParameter($value)));
78
	}
79
80
}