About   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 160
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 48
dl 0
loc 160
c 0
b 0
f 0
rs 10
wmc 14

12 Methods

Rating   Name   Duplication   Size   Complexity  
A getTechnologies() 0 6 1
A getAboutTechnologies() 0 4 1
A beforeSave() 0 15 3
A attributes() 0 7 1
A getAboutQualities() 0 4 1
A getQualities() 0 6 1
A attributeLabels() 0 7 1
A getDefaultAbout() 0 6 1
A getAboutLanguages() 0 4 1
A tableName() 0 3 1
A getLanguages() 0 6 1
A rules() 0 15 1
1
<?php
2
3
namespace app\models;
4
5
use Yii;
6
use Itstructure\AdminModule\models\{MultilanguageTrait, Language, ActiveRecord};
7
8
/**
9
 * This is the model class for table "about".
10
 *
11
 * @property int $id
12
 * @property int $default
13
 * @property string $created_at
14
 * @property string $updated_at
15
 *
16
 * @property AboutLanguage[] $aboutLanguages
17
 * @property Language[] $languages
18
 * @property AboutTechnology[] $aboutTechnologies
19
 * @property Technology[] $technologies
20
 * @property AboutQuality[] $aboutQualities
21
 * @property Quality[] $qualities
22
 *
23
 * @package app\models
24
 */
25
class About extends ActiveRecord
26
{
27
    use MultilanguageTrait;
0 ignored issues
show
introduced by
The trait Itstructure\AdminModule\models\MultilanguageTrait requires some properties which are not provided by app\models\About: $language, $shortName
Loading history...
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public static function tableName()
33
    {
34
        return 'about';
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function rules()
41
    {
42
        return [
43
            [
44
                [
45
                    'default'
46
                ],
47
                'integer'
48
            ],
49
            [
50
                [
51
                    'created_at',
52
                    'updated_at'
53
                ],
54
                'safe'
55
            ],
56
        ];
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function attributes(): array
63
    {
64
        return [
65
            'id',
66
            'default',
67
            'created_at',
68
            'updated_at'
69
        ];
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function attributeLabels()
76
    {
77
        return [
78
            'id' => 'ID',
79
            'default' => Yii::t('app', 'Default'),
80
            'created_at' => Yii::t('app', 'Created date'),
81
            'updated_at' => Yii::t('app', 'Updated date'),
82
        ];
83
    }
84
85
    /**
86
     * Reset the default about record.
87
     *
88
     * @param boolean $insert
89
     *
90
     * @return mixed
91
     */
92
    public function beforeSave($insert)
93
    {
94
        if ($this->default == 1) {
95
96
            $default = static::findOne([
97
                'default' => 1,
98
            ]);
99
100
            if (null !== $default) {
101
                $default->default = 0;
102
                $default->save();
103
            }
104
        }
105
106
        return parent::beforeSave($insert);
107
    }
108
109
    /**
110
     * Returns the default about record.
111
     *
112
     * @return array|null|\yii\db\ActiveRecord
113
     */
114
    public static function getDefaultAbout()
115
    {
116
        return static::find()
117
            ->where([
118
                'default' => 1
119
            ])->one();
120
    }
121
122
    /**
123
     * @return \yii\db\ActiveQuery
124
     */
125
    public function getAboutLanguages()
126
    {
127
        return $this->hasMany(AboutLanguage::class, [
128
            'about_id' => 'id'
129
        ]);
130
    }
131
132
    /**
133
     * @return \yii\db\ActiveQuery
134
     */
135
    public function getLanguages()
136
    {
137
        return $this->hasMany(Language::class, [
138
            'id' => 'language_id'
139
        ])->viaTable('about_language', [
140
            'about_id' => 'id'
141
        ]);
142
    }
143
144
    /**
145
     * @return \yii\db\ActiveQuery
146
     */
147
    public function getAboutTechnologies()
148
    {
149
        return $this->hasMany(AboutTechnology::class, [
150
            'about_id' => 'id'
151
        ]);
152
    }
153
154
    /**
155
     * @return \yii\db\ActiveQuery
156
     */
157
    public function getTechnologies()
158
    {
159
        return $this->hasMany(Technology::class, [
160
            'id' => 'technologies_id'
161
        ])->viaTable('about_technologies', [
162
            'about_id' => 'id'
163
        ]);
164
    }
165
166
    /**
167
     * @return \yii\db\ActiveQuery
168
     */
169
    public function getAboutQualities()
170
    {
171
        return $this->hasMany(AboutQuality::class, [
172
            'about_id' => 'id'
173
        ]);
174
    }
175
176
    /**
177
     * @return \yii\db\ActiveQuery
178
     */
179
    public function getQualities()
180
    {
181
        return $this->hasMany(Quality::class, [
182
            'id' => 'qualities_id'
183
        ])->viaTable('about_qualities', [
184
            'about_id' => 'id'
185
        ]);
186
    }
187
}
188