1 | <?php |
||
22 | class SelectScope implements QueryScopeInterface |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * The table being managed. |
||
27 | * |
||
28 | * @var \Cake\ORM\Table |
||
29 | */ |
||
30 | protected $_table = null; |
||
31 | |||
32 | /** |
||
33 | * Instance of toolbox. |
||
34 | * |
||
35 | * @var \Eav\Model\Behavior\EavToolbox |
||
36 | */ |
||
37 | protected $_toolbox = null; |
||
38 | |||
39 | /** |
||
40 | * {@inheritDoc} |
||
41 | */ |
||
42 | public function __construct(Table $table) |
||
47 | |||
48 | /** |
||
49 | * {@inheritDoc} |
||
50 | * |
||
51 | * If "SELECT *" is performed |
||
52 | * this behavior will fetch all virtual columns its values. |
||
53 | * |
||
54 | * Column aliasing are fully supported, allowing to create alias for virtual |
||
55 | * columns. For instance: |
||
56 | * |
||
57 | * ```php |
||
58 | * $article = $this->Articles->find() |
||
59 | * ->select(['aliased_virtual' => 'some_eav_column', 'body']) |
||
60 | * ->where(['Articles.id' => $id]) |
||
61 | * ->limit(1) |
||
62 | * ->first(); |
||
63 | * |
||
64 | * echo $article->get('aliased_virtual'); |
||
65 | * ``` |
||
66 | */ |
||
67 | public function scope(Query $query, $bundle = null) |
||
72 | |||
73 | /** |
||
74 | * Gets a list of all virtual columns present in given $query's SELECT clause. |
||
75 | * |
||
76 | * This method will alter the given Query object removing any virtual column |
||
77 | * present in its SELECT clause in order to avoid incorrect SQL statements. |
||
78 | * Selected virtual columns should be fetched after query is executed using |
||
79 | * mapReduce or similar. |
||
80 | * |
||
81 | * @param \Cake\ORM\Query $query The query object to be scoped |
||
82 | * @param string|null $bundle Consider attributes only for a specific bundle |
||
83 | * @return array List of virtual columns names |
||
84 | */ |
||
85 | public function getVirtualColumns(Query $query, $bundle = null) |
||
118 | } |
||
119 |