Position::attributeLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
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 "positions".
10
 *
11
 * @property int $id
12
 * @property string $created_at
13
 * @property string $updated_at
14
 *
15
 * @property PositionLanguage[] $positionsLanguages
16
 * @property Language[] $languages
17
 */
18
class Position extends ActiveRecord
19
{
20
    use MultilanguageTrait;
0 ignored issues
show
introduced by
The trait Itstructure\AdminModule\models\MultilanguageTrait requires some properties which are not provided by app\models\Position: $language, $shortName
Loading history...
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public static function tableName()
26
    {
27
        return 'positions';
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function rules()
34
    {
35
        return [
36
            [
37
                [
38
                    'created_at',
39
                    'updated_at'
40
                ],
41
                'safe'
42
            ],
43
        ];
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function attributeLabels()
50
    {
51
        return [
52
            'id' => 'ID',
53
            'created_at' => Yii::t('app', 'Created date'),
54
            'updated_at' => Yii::t('app', 'Updated date'),
55
        ];
56
    }
57
58
    /**
59
     * @return \yii\db\ActiveQuery
60
     */
61
    public function getPositionsLanguages()
62
    {
63
        return $this->hasMany(PositionLanguage::class, [
64
            'positions_id' => 'id'
65
        ]);
66
    }
67
68
    /**
69
     * @return \yii\db\ActiveQuery
70
     */
71
    public function getLanguages()
72
    {
73
        return $this->hasMany(Language::class, [
74
            'id' => 'language_id'
75
        ])->viaTable('positions_language', [
76
            'positions_id' => 'id'
77
        ]);
78
    }
79
80
    /**
81
     * @return array|\yii\db\ActiveRecord[]
82
     */
83
    public static function getPositions()
84
    {
85
        return static::find()
86
            ->orderBy([
87
                'id' => SORT_ASC
88
            ])->all();
89
    }
90
}
91