Passed
Pull Request — develop ( #58 )
by
unknown
32:22 queued 14:42
created

DdsQueryHelpers   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 14
rs 10
c 0
b 0
f 0
ccs 0
cts 9
cp 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A addObjectDeletionChecksOnJoin() 0 9 4
1
<?php
2
/**
3
 * @link http://www.newicon.net/neon
4
 * @copyright Copyright (c) 2018 Newicon Ltd
5
 * @license http://www.newicon.net/neon/license/
6
 */
7
8
namespace neon\daedalus\services\ddsHelpers;
9
10
use neon\daedalus\interfaces\IDdsQueryHelpers;
11
12
/**
13
 * Helpers for the (rare) cases when you need to create a yii query for
14
 * the database as Daedalus doesn't provide sufficient control.
15
 */
16
class DdsQueryHelpers implements IDdsQueryHelpers
17
{
18
	/**
19
	 * @inheritdoc
20
	 */
21
	public function addObjectDeletionChecksOnJoin(\yii\db\Query $query, $tables, $join='innerJoin')
22
	{
23
		foreach ($tables as $table) {
24
			if ($join == 'innerJoin') {
25
				$query->innerJoin("dds_object {$table}Obj", "{$table}Obj._uuid = {$table}._uuid");
26
				$query->andWhere("({$table}Obj._deleted = 0)");
27
			} else if ($join == 'leftJoin') {
28
				$query->leftJoin("dds_object {$table}Obj", "{$table}Obj._uuid = {$table}._uuid");
29
				$query->andWhere("({$table}Obj._deleted IS NULL || {$table}Obj._deleted = 0)");
30
			}
31
		}
32
	}
33
}