|
1
|
|
|
<?php namespace Anomaly\Streams\Platform\Entry; |
|
2
|
|
|
|
|
3
|
|
|
use Anomaly\Streams\Platform\Model\EloquentCriteria; |
|
4
|
|
|
use Anomaly\Streams\Platform\Stream\Contract\StreamInterface; |
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* Class EntryCriteria |
|
9
|
|
|
* |
|
10
|
|
|
* @link http://pyrocms.com/ |
|
11
|
|
|
* @author PyroCMS, Inc. <[email protected]> |
|
12
|
|
|
* @author Ryan Thompson <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class EntryCriteria extends EloquentCriteria |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* The stream instance. |
|
19
|
|
|
* |
|
20
|
|
|
* @var StreamInterface |
|
21
|
|
|
*/ |
|
22
|
|
|
protected $stream; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Create a new EntryCriteria instance. |
|
26
|
|
|
* |
|
27
|
|
|
* @param Builder $query |
|
28
|
|
|
* @param StreamInterface $stream |
|
29
|
|
|
* @param string $method |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct(Builder $query, StreamInterface $stream, $method) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->stream = $stream; |
|
34
|
|
|
|
|
35
|
|
|
parent::__construct($query, $method); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Return sorted entries. |
|
40
|
|
|
* |
|
41
|
|
|
* @param string $direction |
|
42
|
|
|
* @return $this |
|
43
|
|
|
*/ |
|
44
|
|
|
public function sorted($direction = 'ASC') |
|
45
|
|
|
{ |
|
46
|
|
|
$this->query->orderBy('sort_order', $direction); |
|
|
|
|
|
|
47
|
|
|
|
|
48
|
|
|
return $this; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Route through __call. |
|
53
|
|
|
* |
|
54
|
|
|
* @param $name |
|
55
|
|
|
* @return Builder|null |
|
56
|
|
|
*/ |
|
57
|
|
|
public function __get($name) |
|
58
|
|
|
{ |
|
59
|
|
|
if ($assignment = $this->stream->getAssignment(snake_case($name))) { |
|
60
|
|
|
$this->query->where($assignment->getColumnName(), null); |
|
61
|
|
|
|
|
62
|
|
|
return $this; |
|
|
|
|
|
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return parent::__get($name); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Call the method on the query. |
|
70
|
|
|
* |
|
71
|
|
|
* @param $name |
|
72
|
|
|
* @param $arguments |
|
73
|
|
|
* @return Builder|null |
|
74
|
|
|
*/ |
|
75
|
|
|
public function __call($name, $arguments) |
|
76
|
|
|
{ |
|
77
|
|
|
if ($assignment = $this->stream->getAssignment(snake_case($name))) { |
|
78
|
|
|
$this->query->where($assignment->getColumnName(), $arguments ? array_shift($arguments) : null); |
|
79
|
|
|
|
|
80
|
|
|
return $this; |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
return parent::__call($name, $arguments); |
|
84
|
|
|
} |
|
85
|
|
|
} |
|
86
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: