OSDN Git Service

Добавлен тест модели типов.
[invent/invent.git] / models / Types.php
index 2e91022..dce3125 100644 (file)
@@ -5,15 +5,21 @@ namespace app\models;
 use Yii;
 
 /**
- * This is the model class for table "{{%types}}".
+ * Это класс модели типов.
  *
- * @property int $id Идентификатор типа (неизменяемое)
- * @property string|null $name Тип оборудования
+ * @property int         $id     Идентификатор типа (неизменяемое)
+ * @property string|null $name   наименование типа оборудования
+ * @property int         $icount Количество предметов/оборудования для конкретного типа
+ * @property int         $ccount Количество проинвентаризированных предметов/оборудования для конкретного типа
+ * @property string|null $tname  Наименование типа оборудования
  *
- * @property Items[] $items
+ * @property Items[]     $items
  */
 class Types extends \yii\db\ActiveRecord
 {
+    public $icount;
+    public $tname;
+    public $ccount;
     /**
      * {@inheritdoc}
      */
@@ -28,7 +34,9 @@ class Types extends \yii\db\ActiveRecord
     public function rules()
     {
         return [
-            [['name'], 'string', 'max' => 20],
+            [[ 'id' ], 'integer' ],
+            [[ 'name' ], 'string', 'max' => 100, ],
+            [[ 'name' ], 'required' ],
         ];
     }
 
@@ -38,8 +46,11 @@ class Types extends \yii\db\ActiveRecord
     public function attributeLabels()
     {
         return [
-            'id' => Yii::t('app', 'Идентификатор типа (неизменяемое)'),
-            'name' => Yii::t('app', 'Тип оборудования'),
+            'id'     => Yii::t('app',   'Identifire'),
+            'name'   => Yii::t('types', 'Type'),
+            'tname'  => Yii::t('types', 'Types'),
+            'icount' => Yii::t('items', 'Total items count'),
+            'ccount' => Yii::t('items', 'Total items checked')
         ];
     }
 
@@ -48,8 +59,13 @@ class Types extends \yii\db\ActiveRecord
      *
      * @return \yii\db\ActiveQuery
      */
+    public function getModels()
+    {
+        return $this->hasMany(Models::className(), [ 'type_id' => 'id' ]);
+    }
+
     public function getItems()
     {
-        return $this->hasMany(Items::className(), ['type_id' => 'id']);
+        return $this->getModels()->select(Items::tableName() . '.*')->joinWith('items');
     }
 }