1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: VITALYIEGOROV |
5
|
|
|
* Date: 08.12.15 |
6
|
|
|
* Time: 22:14 |
7
|
|
|
*/ |
8
|
|
|
namespace samsoncms\api\query; |
9
|
|
|
|
10
|
|
|
use samsonframework\orm\QueryInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Generic SamsonCMS query for retrieving entities that have relation between each other |
14
|
|
|
* through other relational entity. |
15
|
|
|
* |
16
|
|
|
* @package samsoncms\api |
17
|
|
|
*/ |
18
|
|
|
class Base |
19
|
|
|
{ |
20
|
|
|
/** Deletion flag field name */ |
21
|
|
|
const DELETE_FLAG_FIELD = 'Active'; |
22
|
|
|
|
23
|
|
|
/** @var QueryInterface Database query instance */ |
24
|
|
|
protected $query; |
25
|
|
|
|
26
|
|
|
/** @var string Entity identifier */ |
27
|
|
|
protected $identifier; |
28
|
|
|
|
29
|
|
|
/** @var string Entity primary field name */ |
30
|
|
|
protected $primaryField; |
31
|
|
|
|
32
|
|
|
/** @var array Collection of entity identifiers for filtering */ |
33
|
|
|
protected $filteringIDs; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Entity constructor. |
37
|
|
|
* @param QueryInterface $query Database query instance |
38
|
|
|
* @param string $identifier Entity identifier |
39
|
|
|
* @param array $filteringIDs Collection of entity identifiers for filtering |
40
|
|
|
*/ |
41
|
|
|
public function __construct( |
42
|
|
|
QueryInterface $query, |
43
|
|
|
$identifier, |
44
|
|
|
$filteringIDs = array() |
45
|
|
|
) { |
46
|
|
|
$this->query = $query; |
47
|
|
|
$this->identifier = $identifier; |
48
|
|
|
$this->primaryField = $identifier::$_primary; |
49
|
|
|
$this->filteringIDs = $filteringIDs; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Get current entity instances collection by their identifiers. |
54
|
|
|
* Method can accept different query executors. |
55
|
|
|
* |
56
|
|
|
* @param string|array $entityIDs Entity identifier or their collection |
57
|
|
|
* @param string $executor Method name for query execution |
58
|
|
|
* @return mixed[] Collection of entity instances |
59
|
|
|
*/ |
60
|
|
|
public function byIDs($entityIDs, $executor) |
61
|
|
|
{ |
62
|
|
|
return $this->query |
63
|
|
|
->entity($this->identifier) |
64
|
|
|
->where($this->primaryField, $entityIDs) |
|
|
|
|
65
|
|
|
->where(self::DELETE_FLAG_FIELD, 1) |
66
|
|
|
->$executor(); |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check looks at variables that have been passed in as parameters and are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.