OSDN Git Service

Добавлен тест модели типов.
[invent/invent.git] / models / Types.php
1 <?php
2
3 namespace app\models;
4
5 use Yii;
6
7 /**
8  * Это класс модели типов.
9  *
10  * @property int         $id     Идентификатор типа (неизменяемое)
11  * @property string|null $name   наименование типа оборудования
12  * @property int         $icount Количество предметов/оборудования для конкретного типа
13  * @property int         $ccount Количество проинвентаризированных предметов/оборудования для конкретного типа
14  * @property string|null $tname  Наименование типа оборудования
15  *
16  * @property Items[]     $items
17  */
18 class Types extends \yii\db\ActiveRecord
19 {
20     public $icount;
21     public $tname;
22     public $ccount;
23     /**
24      * {@inheritdoc}
25      */
26     public static function tableName()
27     {
28         return '{{%types}}';
29     }
30
31     /**
32      * {@inheritdoc}
33      */
34     public function rules()
35     {
36         return [
37             [[ 'id' ], 'integer' ],
38             [[ 'name' ], 'string', 'max' => 100, ],
39             [[ 'name' ], 'required' ],
40         ];
41     }
42
43     /**
44      * {@inheritdoc}
45      */
46     public function attributeLabels()
47     {
48         return [
49             'id'     => Yii::t('app',   'Identifire'),
50             'name'   => Yii::t('types', 'Type'),
51             'tname'  => Yii::t('types', 'Types'),
52             'icount' => Yii::t('items', 'Total items count'),
53             'ccount' => Yii::t('items', 'Total items checked')
54         ];
55     }
56
57     /**
58      * Gets query for [[Items]].
59      *
60      * @return \yii\db\ActiveQuery
61      */
62     public function getModels()
63     {
64         return $this->hasMany(Models::className(), [ 'type_id' => 'id' ]);
65     }
66
67     public function getItems()
68     {
69         return $this->getModels()->select(Items::tableName() . '.*')->joinWith('items');
70     }
71 }