-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathBaseModel.php
57 lines (48 loc) · 1.21 KB
/
BaseModel.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
<?php
namespace common\models;
use Yii;
/**
* This is the base model class for models which add Status and YesNo
*
* @author funson86 <[email protected]>
* @since 2.0
*/
class BaseModel extends \yii\db\ActiveRecord
{
const STATUS_INACTIVE = 0;
const STATUS_ACTIVE = 1;
const STATUS_DELETED = -1;
const YES = 0;
const NO = 1;
public static function getStatusLabels($id = null)
{
$data = [
self::STATUS_ACTIVE => Yii::t('app', 'STATUS_ACTIVE'),
self::STATUS_INACTIVE => Yii::t('app', 'STATUS_INACTIVE'),
self::STATUS_DELETED => Yii::t('app', 'STATUS_DELETED'),
];
if ($id !== null && isset($data[$id])) {
return $data[$id];
} else {
return $data;
}
}
/**
* return label or labels array
*
* @param integer $id
* @return string or array
*/
public static function getYesNoLabels($id = null)
{
$data = [
self::YES => Yii::t('app', 'YES'),
self::NO => Yii::t('app', 'NO'),
];
if ($id !== null && isset($data[$id])) {
return $data[$id];
} else {
return $data;
}
}
}