SurveyHasStatus::create()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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