6 use yii\data\ActiveDataProvider;
9 * Эта модель используется для формирования сводныз данных на стартовой странице,
10 * исполшьзуя данные из связанных аблиц ({%items}), {{%types}}, {{%locations}}, {{%regions}}/
12 * @property ActiveDataProvider|null regionsDataProvider Сводная таблица, содержащая количество оборудования по регионам
13 * @property ActiveDataProvider|null typesDataProvider Сводная таблица, содержащая количество оборудования по типам
16 class Site extends \yii\data\ActiveDataProvider
19 public static function regionsDataProvider()
22 $subQuery = Moving::find()
23 ->select('MAX(id) AS id')
25 ->groupBy(['item_id']);
27 $query = Regions::find()
28 ->select(Regions::tableName() . '.name, count(' . Items::tableName() . '.id) AS icount, count(c.tid) AS ccount')
29 ->joinWith(['locations', 'moving', 'items'])
30 ->leftJoin(['c' => Regions::find()
31 ->select(Regions::tableName() . '.id, ' . Items::tableName() . '.id AS tid')
32 ->joinWith(['locations', 'moving', 'items'])
33 ->where(['in', Moving::tableName() . '.id', $subQuery])
34 ->andWhere(Items::tableName() . '.checked = 1')
35 ], Regions::tableName() . '.id = c.id AND ' . Items::tableName() . '.id = c.tid')
36 ->groupBy(Regions::tableName() . '.id')
37 ->where(['in', Moving::tableName() . '.id', $subQuery]);
39 $dataProvider = new ActiveDataProvider([
42 $dataProvider->setSort([
51 public static function typesDataProvider()
54 $query = Types::find()
55 ->select(Types::tableName() . '.name, count(' . Items::tableName() . '.id) AS icount, count( c.tid ) AS ccount')
56 ->joinWith([ 'items', 'models' ])
57 ->leftJoin(['c' => Items::find()
59 ->where(['checked' => 1 ])
60 ], Items::tableName() . '.id = c.tid')
61 ->groupBy(Types::tableName() . '.id');
63 $dataProvider = new ActiveDataProvider([
66 $dataProvider->setSort([