Passed
Push — master ( a04c07...bfd5dc )
by Tõnis
03:46
created

SurveyHasStatus::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 9.4285
1
<?php
2
3
namespace andmemasin\surveybasemodels;
4
5
use andmemasin\myabstract\HasStatusModel;
6
7
/**
8
 * This is the model class for table "survey_has_status".
9
 *
10
 * @property integer $survey_has_status_id
11
 * @property integer $survey_id
12
 * @property string $status
13
 *
14
 */
15
class SurveyHasStatus extends HasStatusModel
16
{
17
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function init()
22
    {
23
        $this->parentClassName = Survey::class;
24
        parent::init();
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public static function tableName()
31
    {
32
        return 'survey_has_status';
33
    }
34
35
36
    /**
37
     * @param Survey $survey
38
     * @param string $status if not set Status will be taken from Email
39
     * @return boolean
40
     */
41
    public static function create($survey,$status = null){
42
        $model = new static();
43
        $model->survey_id = $survey->primaryKey;
44
        $model->status =$survey->status;
45
        if($status){
46
            $model->status =$status;
47
        }
48
        return $model->save();
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function rules()
55
    {
56
        return array_merge([
57
            [['survey_id','status'], 'required'],
58
            [['status'], 'string', 'max' => 32],
59
            [['survey_id'], 'integer'],
60
        ],  parent::rules());
61
    }
62
}
63