Skip to content

Commit 0911d11

Browse files
authored
Merge pull request #31 from REZ1DENT3/orderBy
add method orderBy
2 parents 872bb13 + a6ea7f2 commit 0911d11

File tree

3 files changed

+171
-28
lines changed

3 files changed

+171
-28
lines changed

src/PHPixie/ORM/Models/Type/Database/Implementation/Query.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ public function clearOffset()
8686
return $this;
8787
}
8888

89+
public function orderBy($field, $direction)
90+
{
91+
$this->orderBy[] = $this->values->orderBy($field, $direction);
92+
return $this;
93+
}
94+
8995
public function orderAscendingBy($field)
9096
{
9197
$this->orderBy[] = $this->values->orderBy($field, 'asc');

src/PHPixie/ORM/Models/Type/Database/Query.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ public function getOffset();
4040
*/
4141
public function clearOffset();
4242

43+
/**
44+
* @param $field
45+
* @param $direction
46+
*
47+
* @return static
48+
*/
49+
public function orderBy($field, $direction);
50+
4351
/**
4452
* @return static
4553
*/

src/PHPixie/ORM/Wrappers/Type/Database/Query.php

Lines changed: 157 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,148 +9,277 @@ class Query extends \PHPixie\ORM\Conditions\Builder\Proxy
99
* @type \PHPixie\ORM\Drivers\Driver\PDO\Query|\PHPixie\ORM\Drivers\Driver\Mongo\Query
1010
*/
1111
protected $query;
12-
12+
13+
/**
14+
* Query constructor.
15+
*
16+
* @param $query
17+
*/
1318
public function __construct($query)
1419
{
1520
parent::__construct($query);
1621
$this->query = $query;
1722
}
18-
23+
24+
/**
25+
* @return string
26+
*/
1927
public function modelName()
2028
{
2129
return $this->query->modelName();
2230
}
23-
31+
32+
/**
33+
* @param $limit
34+
*
35+
* @return $this
36+
* @throws \PHPixie\ORM\Exception\Query
37+
*/
2438
public function limit($limit)
2539
{
2640
$this->query->limit($limit);
2741
return $this;
2842
}
29-
43+
44+
/**
45+
* @return static
46+
*/
3047
public function getLimit()
3148
{
3249
return $this->query->getLimit();
3350
}
34-
51+
52+
/**
53+
* @return $this
54+
*/
3555
public function clearLimit()
3656
{
3757
$this->query->clearLimit();
3858
return $this;
3959
}
40-
41-
60+
61+
62+
/**
63+
* @param $offset
64+
*
65+
* @return $this
66+
* @throws \PHPixie\ORM\Exception\Query
67+
*/
4268
public function offset($offset)
4369
{
4470
$this->query->offset($offset);
4571
return $this;
4672
}
47-
73+
74+
/**
75+
* @return static
76+
*/
4877
public function getOffset()
4978
{
5079
return $this->query->getOffset();
5180
}
52-
81+
82+
/**
83+
* @return $this
84+
*/
5385
public function clearOffset()
5486
{
5587
$this->query->clearOffset();
5688
return $this;
5789
}
58-
90+
91+
/**
92+
* @param $field
93+
* @param $direction
94+
*
95+
* @return $this
96+
*/
97+
public function orderBy($field, $direction)
98+
{
99+
$this->query->orderBy($field, $direction);
100+
return $this;
101+
}
102+
103+
/**
104+
* @param $field
105+
*
106+
* @return $this
107+
*/
59108
public function orderAscendingBy($field)
60109
{
61110
$this->query->orderAscendingBy($field);
62111
return $this;
63112
}
64-
113+
114+
/**
115+
* @param $field
116+
*
117+
* @return $this
118+
*/
65119
public function orderDescendingBy($field)
66120
{
67121
$this->query->orderDescendingBy($field);
68122
return $this;
69123
}
70-
124+
125+
/**
126+
* @return array|static
127+
*/
71128
public function getOrderBy()
72129
{
73130
return $this->query->getOrderBy();
74131
}
75-
132+
133+
/**
134+
* @return $this
135+
*/
76136
public function clearOrderBy()
77137
{
78138
$this->query->clearOrderBy();
79139
return $this;
80140
}
81-
141+
142+
/**
143+
* @return array
144+
*/
82145
public function getConditions()
83146
{
84147
return $this->query->getConditions();
85148
}
86-
149+
150+
/**
151+
* @param array $preload
152+
* @param null $fields
153+
*
154+
* @return \PHPixie\ORM\Plans\Plan
155+
*/
87156
public function planFind($preload = array(), $fields = null)
88157
{
89158
return $this->query->planFind($preload, $fields);
90159
}
91-
160+
161+
/**
162+
* @param array $preload
163+
* @param null $fields
164+
*
165+
* @return \PHPixie\ORM\Loaders\Loader|void
166+
*/
92167
public function find($preload = array(), $fields = null)
93168
{
94169
return $this->query->find($preload, $fields);
95170
}
96-
171+
172+
/**
173+
* @param array $preload
174+
* @param null $fields
175+
*
176+
* @return null|\PHPixie\ORM\Models\Type\Database\Implementation\Entity
177+
* @throws \PHPixie\ORM\Exception\Query
178+
*/
97179
public function findOne($preload = array(), $fields = null)
98180
{
99181
return $this->query->findOne($preload, $fields);
100182
}
101-
183+
184+
/**
185+
* @return \PHPixie\ORM\Plans\Plan
186+
*/
102187
public function planDelete()
103188
{
104189
return $this->query->planDelete();
105190
}
106-
191+
192+
/**
193+
* @return $this
194+
*/
107195
public function delete()
108196
{
109197
$this->query->delete();
110198
return $this;
111199
}
112-
200+
201+
/**
202+
* @param $data
203+
*
204+
* @return \PHPixie\ORM\Plans\Plan
205+
*/
113206
public function planUpdate($data)
114207
{
115208
return $this->query->planUpdate($data);
116209
}
117-
210+
211+
/**
212+
* @param $data
213+
*
214+
* @return $this
215+
*/
118216
public function update($data)
119217
{
120218
$this->query->update($data);
121219
return $this;
122220
}
123-
221+
222+
/**
223+
* @param $update
224+
*
225+
* @return \PHPixie\ORM\Plans\Plan
226+
*/
124227
public function planUpdateValue($update)
125228
{
126229
return $this->query->planUpdateValue($update);
127230
}
128-
231+
232+
/**
233+
* @return \PHPixie\ORM\Values\Update\Builder
234+
*/
129235
public function getUpdateBuilder()
130236
{
131237
return $this->query->getUpdateBuilder();
132238
}
133-
239+
240+
/**
241+
* @return \PHPixie\ORM\Plans\Plan
242+
*/
134243
public function planCount()
135244
{
136245
return $this->query->planCount();
137246
}
138-
247+
248+
/**
249+
* @return int|void
250+
*/
139251
public function count()
140252
{
141253
return $this->query->count();
142254
}
143-
255+
256+
/**
257+
* @param $name
258+
*
259+
* @return \PHPixie\ORM\Relationships\Relationship\Property
260+
* @throws \PHPixie\ORM\Exception\Relationship
261+
*/
144262
public function getRelationshipProperty($name)
145263
{
146264
return $this->query->getRelationshipProperty($name);
147265
}
148-
266+
267+
/**
268+
* @param $name
269+
*
270+
* @return \PHPixie\ORM\Relationships\Relationship\Property
271+
*/
149272
public function __get($name)
150273
{
151274
return $this->query->__get($name);
152275
}
153-
276+
277+
/**
278+
* @param $method
279+
* @param $params
280+
*
281+
* @return mixed
282+
*/
154283
public function __call($method, $params)
155284
{
156285
return $this->query->__call($method, $params);

0 commit comments

Comments
 (0)