OSDN Git Service

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