/
Question.php
98 lines (87 loc) · 2.26 KB
/
Question.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
namespace common\models;
use Yii;
use common\interfaces\QuestionInterface;
use \common\components\ActiveRecord;
/**
* @property integer $id
* @property integer $user_id
* @property integer $behavior_id
* @property integer $category_id
* @property integer $user_behavior_id
* @property integer $question
* @property string $answer
* @property string $date
*
* @property User $user
* @property UserBehaviorLink $userBehavior
*/
class Question extends ActiveRecord implements QuestionInterface
{
public static $TYPES = [
'a' => 1,
'b' => 2,
'c' => 3
];
public static $QUESTIONS = [
1 => "How does it affect me? How do I act and feel?",
2 => "How does it affect the important people in my life?",
3 => "Why do I do this? What is the benefit for me?"
];
public $question_text;
/**
* @inheritdoc
*/
public static function tableName()
{
return 'question';
}
/**
* @inheritdoc
*/
public function rules()
{
return [
[['user_id', 'behavior_id', 'category_id', 'user_behavior_id', 'question', 'answer', 'date'], 'required'],
[['user_id', 'behavior_id', 'category_id', 'user_behavior_id', 'question'], 'integer'],
['behavior_id', 'in', 'range' => array_column(\common\models\Behavior::$behaviors, 'id')],
['category_id', 'in', 'range' => array_column(\common\models\Category::$categories, 'id')],
['answer', 'string'],
['date', 'safe']
];
}
/**
* @inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'user_id' => 'User ID',
'behavior_id' => 'Behavior ID',
'category_id' => 'Category ID',
'user_behavior_id' => 'User Behavior ID',
'question' => 'Question',
'answer' => 'Answer',
'date' => 'Date',
];
}
public function afterFind()
{
$this->question_text = self::$QUESTIONS[$this->question];
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUser()
{
return $this->hasOne(\common\models\User::class, ['id' => 'user_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getUserBehavior()
{
return $this->hasOne(\common\models\UserBehavior::class, ['id' => 'user_behavior_id']);
}
}