1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace common\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\helpers\ArrayHelper as AH; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @property integer $id |
10
|
|
|
* @property string $name |
11
|
|
|
*/ |
12
|
|
|
class Category extends \yii\base\BaseObject |
13
|
|
|
{ |
14
|
|
|
|
15
|
|
|
public static $categories = [ |
16
|
|
|
[ "id" => 1, "name" => "Restoration"], |
17
|
|
|
[ "id" => 2, "name" => "Forgetting Priorities"], |
18
|
|
|
[ "id" => 3, "name" => "Anxiety"], |
19
|
|
|
[ "id" => 4, "name" => "Speeding Up"], |
20
|
|
|
[ "id" => 5, "name" => "Ticked Off"], |
21
|
|
|
[ "id" => 6, "name" => "Exhausted"], |
22
|
|
|
[ "id" => 7, "name" => "Relapse/Moral Failure"], |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
public static $colors = [ |
26
|
|
|
1 => [ |
27
|
|
|
"color" => "#008000", |
28
|
|
|
"highlight" => "#199919" |
29
|
|
|
], |
30
|
|
|
2 => [ |
31
|
|
|
"color" => "#4CA100", |
32
|
|
|
"highlight" => "#61B219" |
33
|
|
|
], |
34
|
|
|
3 => [ |
35
|
|
|
"color" => "#98C300", |
36
|
|
|
"highlight" => "#AACC33" |
37
|
|
|
], |
38
|
|
|
4 => [ |
39
|
|
|
"color" => "#E5E500", |
40
|
|
|
"highlight" => "#E5E533" |
41
|
|
|
], |
42
|
|
|
5 => [ |
43
|
|
|
"color" => "#E59900", |
44
|
|
|
"highlight" => "#E5AA33" |
45
|
|
|
], |
46
|
|
|
6 => [ |
47
|
|
|
"color" => "#E54B00", |
48
|
|
|
"highlight" => "#E56D33" |
49
|
|
|
], |
50
|
|
|
7 => [ |
51
|
|
|
"color" => "#CC0000", |
52
|
|
|
"highlight" => "#CC3333" |
53
|
|
|
] |
54
|
|
|
]; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @inheritdoc |
58
|
|
|
*/ |
59
|
|
|
public function rules() |
60
|
|
|
{ |
61
|
|
|
return [ |
62
|
|
|
['name', 'required'], |
63
|
|
|
['name', 'string', 'max' => 255], |
64
|
|
|
]; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* @inheritdoc |
69
|
|
|
*/ |
70
|
|
|
public function attributeLabels() |
71
|
|
|
{ |
72
|
|
|
return [ |
73
|
|
|
'id' => 'ID', |
74
|
|
|
'name' => 'Name', |
75
|
|
|
]; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public static function getCategories() { |
79
|
|
|
return AH::map(\common\models\Category::$categories, 'id', 'name'); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public static function getCategory($key, $val) { |
83
|
|
|
$indexed = AH::index(self::$categories, null, $key); |
84
|
|
|
return AH::getValue($indexed, $val, [false])[0]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public static function getAll() { |
88
|
|
|
$cats = self::getCategories(); |
89
|
|
|
$ret = []; |
90
|
|
|
foreach($cats as $key => $val) { |
91
|
|
|
$ret[$key] = self::$colors[$key]; |
92
|
|
|
$ret[$key]['name'] = $val; |
93
|
|
|
} |
94
|
|
|
return $ret; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|