Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
CRAP | |
0.00% |
0 / 58 |
| SurveyQuestion | |
0.00% |
0 / 1 |
|
0.00% |
0 / 9 |
110.00 | |
0.00% |
0 / 58 |
| tableName | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| behaviors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 10 |
|||
| rules | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 11 |
|||
| attributeLabels | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 11 |
|||
| typeLabels | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 7 |
|||
| getSurveyAnswers | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getSurveyOptions | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getSurvey | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| getTypeName | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| <?php | |
| namespace common\models; | |
| use common\components\OrderNumberBehavior; | |
| use Yii; | |
| use yii\behaviors\TimestampBehavior; | |
| use yii\db\Expression; | |
| /** | |
| * This is the model class for table "{{%survey_question}}". | |
| * | |
| * @property integer $id | |
| * @property integer $type | |
| * @property string $content | |
| * @property integer $on | |
| * @property integer $created_at | |
| * @property integer $updated_at | |
| * @property integer $survey_id | |
| * | |
| * @property SurveyAnswer[] $surveyAnswers | |
| * @property SurveyOption[] $surveyOptions | |
| * @property Survey $survey | |
| */ | |
| class SurveyQuestion extends \yii\db\ActiveRecord | |
| { | |
| const TYPE_TEXT = 0; | |
| const TYPE_RADIOLIST = 1; | |
| const TYPE_CHECKLIST = 2; | |
| /** | |
| * @inheritdoc | |
| */ | |
| public static function tableName() | |
| { | |
| return '{{%survey_question}}'; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function behaviors() | |
| { | |
| return [ | |
| TimestampBehavior::className(), | |
| [ | |
| 'class' => OrderNumberBehavior::className(), | |
| 'filter' => function($event, $attribute) { | |
| return ['survey_id' => $this->survey_id]; | |
| }, | |
| ], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['content', 'survey_id'], 'required'], | |
| [['type', 'survey_id'], 'integer'], | |
| [['on'], 'default', 'value' => 0], | |
| [['on'], 'integer', 'min' => 0], | |
| [['content'], 'string', 'max' => 255], | |
| ['type', 'default', 'value' => self::TYPE_TEXT], | |
| ['type', 'in', 'range' => [self::TYPE_TEXT, self::TYPE_RADIOLIST, self::TYPE_CHECKLIST]], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributeLabels() | |
| { | |
| return [ | |
| 'id' => Yii::t('app', 'ID'), | |
| 'type' => Yii::t('app', 'Type'), | |
| 'typeName' => Yii::t('app', 'Type'), | |
| 'content' => Yii::t('app', 'Content'), | |
| 'created_at' => Yii::t('app', 'Created at'), | |
| 'updated_at' => Yii::t('app', 'Updated at'), | |
| 'survey_id' => Yii::t('app', 'Survey'), | |
| ]; | |
| } | |
| /** | |
| * Return array of type filed labels | |
| * @array | |
| */ | |
| public function typeLabels() | |
| { | |
| return [ | |
| self::TYPE_TEXT => Yii::t('app', 'Text'), | |
| self::TYPE_RADIOLIST => Yii::t('app', 'Single choice'), | |
| self::TYPE_CHECKLIST => Yii::t('app', 'Multiple choice'), | |
| ]; | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getSurveyAnswers() | |
| { | |
| return $this->hasMany(SurveyAnswer::className(), ['survey_question_id' => 'id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getSurveyOptions() | |
| { | |
| return $this->hasMany(SurveyOption::className(), ['survey_question_id' => 'id']); | |
| } | |
| /** | |
| * @return \yii\db\ActiveQuery | |
| */ | |
| public function getSurvey() | |
| { | |
| return $this->hasOne(Survey::className(), ['id' => 'survey_id']); | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function getTypeName() | |
| { | |
| $typeList = self::typeLabels(); | |
| if(array_key_exists($this->type, $typeList)) { | |
| return $typeList[$this->type]; | |
| } | |
| return null; | |
| } | |
| } |