forked from noumo/easyii
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathActiveQuery.php
62 lines (57 loc) · 1.17 KB
/
ActiveQuery.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
namespace yii\easyii\components;
/**
* Base active query class for models
* @package yii\easyii\components
*/
class ActiveQuery extends \yii\db\ActiveQuery
{
/**
* Apply condition by status
* @param $status
* @return $this
*/
public function status($status)
{
$this->andWhere(['status' => (int)$status]);
return $this;
}
/**
* Order by primary key DESC
* @return $this
*/
public function desc()
{
$model = $this->modelClass;
$this->orderBy([$model::primaryKey()[0] => SORT_DESC]);
return $this;
}
/**
* Order by primary key ASC
* @return $this
*/
public function asc()
{
$model = $this->modelClass;
$this->orderBy([$model::primaryKey()[0] => SORT_ASC]);
return $this;
}
/**
* Order by order_num
* @return $this
*/
public function sort()
{
$this->orderBy(['order_num' => SORT_DESC]);
return $this;
}
/**
* Order by date
* @return $this
*/
public function sortDate()
{
$this->orderBy(['time' => SORT_DESC]);
return $this;
}
}