|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Rougin\Windstorm\Eloquent; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
6
|
|
|
use Rougin\Windstorm\OrderInterface; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Order Query |
|
10
|
|
|
* |
|
11
|
|
|
* @package Windstorm |
|
12
|
|
|
* @author Rougin Gutib <[email protected]> |
|
13
|
|
|
*/ |
|
14
|
|
|
class Order implements OrderInterface |
|
15
|
|
|
{ |
|
16
|
|
|
protected $key; |
|
17
|
|
|
|
|
18
|
|
|
protected $builder; |
|
19
|
|
|
|
|
20
|
|
|
protected $order = 'asc'; |
|
21
|
|
|
|
|
22
|
|
|
protected $query; |
|
23
|
|
|
|
|
24
|
15 |
|
public function __construct(Query $query, Builder $builder, $key) |
|
25
|
|
|
{ |
|
26
|
15 |
|
$this->query = $query; |
|
27
|
|
|
|
|
28
|
15 |
|
$this->builder = $builder; |
|
29
|
|
|
|
|
30
|
15 |
|
$this->key = $key; |
|
31
|
15 |
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Sets the order in ascending. |
|
35
|
|
|
* |
|
36
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
|
37
|
|
|
*/ |
|
38
|
3 |
|
public function ascending() |
|
39
|
|
|
{ |
|
40
|
3 |
|
$this->order = 'asc'; |
|
41
|
|
|
|
|
42
|
3 |
|
return $this; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Sets the order in descending. |
|
47
|
|
|
* |
|
48
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
|
49
|
|
|
*/ |
|
50
|
6 |
|
public function descending() |
|
51
|
|
|
{ |
|
52
|
6 |
|
$this->order = 'desc'; |
|
53
|
|
|
|
|
54
|
6 |
|
return $this; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Calls a method from a QueryInterface instance. |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $method |
|
61
|
|
|
* @param array $parameters |
|
62
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
|
63
|
|
|
*/ |
|
64
|
12 |
|
public function __call($method, $parameters) |
|
65
|
|
|
{ |
|
66
|
12 |
|
return call_user_func_array(array($this->set(), $method), $parameters); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Calls a __toString() from a QueryInterface instance. |
|
71
|
|
|
* |
|
72
|
|
|
* @return string |
|
73
|
|
|
*/ |
|
74
|
3 |
|
public function __toString() |
|
75
|
|
|
{ |
|
76
|
3 |
|
return $this->set()->__toString(); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Sets the query builder instance. |
|
81
|
|
|
* |
|
82
|
|
|
* @return \Rougin\Windstorm\QueryInterface |
|
83
|
|
|
*/ |
|
84
|
15 |
|
protected function set() |
|
85
|
|
|
{ |
|
86
|
15 |
|
$this->builder = $this->builder->orderBy($this->key, $this->order); |
|
87
|
|
|
|
|
88
|
15 |
|
return $this->query->builder($this->builder); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|