OSDN Git Service

Изменено меню
[invent/invent.git] / models / Regions.php
1 <?php
2
3 namespace app\models;
4
5 use Yii;
6
7 /**
8  * Это класс модели для таблицы регионов '{{%regions}}'.
9  *
10  * @property int    $id     Идентификатор региона (неизменяемое)
11  * @property string $name   Наименование региона (подразделения)
12  * @property string $lname  Наименование места/размещения
13  * @property int    $icount Количество предметов/оборудования в регионе/подразделении
14  * @property int    $icount Количество проинвентаризарованных предметов/оборудования в регионе/подразделении
15  *
16  * @property Locations[] $locations Места/размежения
17  * @property Items[]     $items     Предметы/оборудование
18  */
19 class Regions extends \yii\db\ActiveRecord
20 {
21     public $lname;
22     public $icount;
23     public $ccount;
24     /**
25      * {@inheritdoc}
26      */
27     public static function tableName()
28     {
29         return '{{%regions}}';
30     }
31
32     /**
33      * {@inheritdoc}
34      */
35     public function rules()
36     {
37         return [
38             [['name'], 'required'],
39             [['name'], 'string', 'max' => 120],
40             [['name'], 'unique'],
41         ];
42     }
43
44     /**
45      * {@inheritdoc}
46      */
47     public function attributeLabels()
48     {
49         return [
50             'id'     => Yii::t('app',     'Identifier'),
51             'name'   => Yii::t('regions', 'Region'),
52             'icount' => Yii::t('items',   'Total items count'),
53             'ccount' => Yii::t('items',   'Total items checked'),
54         ];
55     }
56
57     /**
58      * Выполнение запроса для [[Locations]].
59      *
60      * @return \yii\db\ActiveQuery
61      */
62     public function getLocations()
63     {
64         return $this->hasMany(Locations::className(), [ 'region_id' => 'id' ]);
65     }
66
67     /**
68      * Выполнение запроса для [[Items]].
69      *
70      * @return \yii\db\ActiveQuery
71      */
72     public function getMoving()
73     {
74         return $this->getLocations()->select(Moving::tableName() . '.*')->joinWith('moving');
75     }
76     public function getItems()
77     {
78         return $this->getMoving()->select(Items::tableName() . '.*')->joinWith('items');
79     }
80 }