public function actionGetStat($dep_id) { //if ( $dep_id >= 0 || count($dep_id)) { if ($dep_id >= 0) { //echo 'asdasdasda'; $stat = []; $conditions = conditions::find()->all(); if ($dep_id === 'all') { $buildings = building::find()->select(['id'])->where(['active' => '1'])->all(); } else { $buildings = building::find()->select(['id'])->where(['department_id' => $dep_id, 'active' => '1'])->all(); } foreach ($buildings as $build) { $rooms = room::find()->select(['id'])->where(['building_id' => $build->id])->all(); foreach ($rooms as $room) { if (isset($room->id)) { $sets = sets::find()->select(['id'])->where(['room_id' => $room->id])->all(); foreach ($sets as $set) { if (isset($set->id)) { $devices = device::find()->select(['id', 'model_id', 'condition_id'])->where(['set_id' => $set->id, 'active' => '1'])->all(); foreach ($devices as $device) { if (isset($device->id)) { $model = model::findOne($device->model_id); if (isset($model->type_id)) { $type = deviceType::findOne($model->type_id); //echo '<br>' . $type -> value; if (isset($stat[$type->id])) { $stat[$type->id]['all']++; //$stat[ $type -> id ][ 'value' ] = $type -> value; foreach ($conditions as $condition) { //switch ( $device -> condition_id ){ if ($condition->id == $device->condition_id) { $stat[$type->id][$device->condition_id]++; } } } else { $stat[$type->id] = []; $stat[$type->id]['value'] = $type->value; $stat[$type->id]['all'] = 1; foreach ($conditions as $condition) { if ($condition->id == $device->condition_id) { $stat[$type->id][$device->condition_id] = 1; } else { $stat[$type->id][$condition->id] = 0; } } } } } } } } } } } //echo '<br>'; //print_r($stat); echo "<table class = 'table table-responsive'>\n\t\t\t\t\t\t<thead>\n\t\t\t\t\t\t<tr>\n\t\t\t\t\t\t\t<td>Тип устройства</td>\n\t\t\t\t\t\t\t<td>Всего</td>"; $tmp = []; // id шники состояний foreach ($conditions as $condition) { $tmp[] = $condition->id; echo "<td>" . $condition->value . "</td>"; } echo "</tr></thead><tbody>"; foreach ($stat as $sta) { echo "<tr>\n\t\t\t\t\t\t\t<td>" . $sta['value'] . "</td>\n\t\t\t\t\t\t\t<td>" . $sta['all'] . "</td>"; foreach ($tmp as $tm) { echo "<td>" . $sta[$tm] . "</td>"; } echo "</tr>"; } echo "</table>"; } }