/** * Table Page * @return string */ public function actionIndex() { $params = Yii::$app->request->queryParams; $region = 1; if (!empty($params['MainSearch']['region'])) { $region = $params['MainSearch']['region']; } if (!empty($_POST['random']) && is_numeric($_POST['random'])) { $random = $_POST['random']; if ($region == -1) { $regionWhere = []; } else { $regionWhere = ['region' => $region]; } $ids = ArrayHelper::map(Main::find()->where($regionWhere)->all(), 'id', 'id'); $randomIds = array_rand($ids, $random); Yii::$app->session->set('random', $randomIds); } else { Yii::$app->session->set('random', null); } $searchModel = new MainSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'region' => $region]); }
/** * Lists all Main models. * @return mixed */ public function actionIndex() { $searchModel = new MainSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
$startColumn++; } $data = $pilots; } $sheets[$i] = ExcelHelper::printData($data, $cities, $types, $sheets[$i]); for ($columnItem = 'A'; $columnItem <= $endColumn; $columnItem++) { $sheets[$i]->getColumnDimension($columnItem)->setWidth(15); } $sheets[$i]->getStyle('A1:' . $endColumn . '4')->getAlignment()->setWrapText(true); $i++; } $sheets[$i] = new PHPExcel_Worksheet($objPHPExcel, 'total'); $objPHPExcel->addSheet($sheets[$i]); $main = new Main(); $searchModel = new MainSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); $dataProvider->setPagination(['pageSize' => $dataProvider->getTotalCount()]); $dataArray = [[$main->getAttributeLabel('city'), $main->getAttributeLabel('type'), $main->getAttributeLabel('resident'), $main->getAttributeLabel('children'), $main->getAttributeLabel('employee'), $main->getAttributeLabel('retiree'), $main->getAttributeLabel('dominant'), $main->getAttributeLabel('mainTrashPlaces.trash_place_id'), $main->getAttributeLabel('mainTrashMen.trash_man_id'), $main->getAttributeLabel('filter_trash_out'), $main->getAttributeLabel('filter_trash_count'), $main->getAttributeLabel('filter_summer_1'), $main->getAttributeLabel('filter_summer_2'), $main->getAttributeLabel('filter_summer_3'), $main->getAttributeLabel('filter_summer_4'), $main->getAttributeLabel('filter_winter_1'), $main->getAttributeLabel('filter_winter_2'), $main->getAttributeLabel('filter_winter_3'), $main->getAttributeLabel('filter_winter_4'), $main->getAttributeLabel('paper'), $main->getAttributeLabel('mainTrashRelations.trash_relation_id'), $main->getAttributeLabel('mainTrashRecycles.trash_recycle_id'), $main->getAttributeLabel('mainRubberItems.rubber_item_id'), $main->getAttributeLabel('answer_count'), $main->getAttributeLabel('woman_count'), $main->getAttributeLabel('person'), $main->getAttributeLabel('date'), $main->getAttributeLabel('interrogatory')]]; foreach ($dataProvider->getModels() as $value) { $dataArray[] = [isset($value->city0) ? $value->city0->nameBothShort : '', isset($value->type0) ? $value->type0->nameBothShort : '', $value->resident, $value->children, $value->employee, $value->retiree, isset($value->dominant0) ? $value->dominant0->nameBothShort : '', $value->trashPlaceMulti, $value->trashManMulti, $value->trash_out, $value->trash_count, $value->summer_count_1, $value->summer_count_2, $value->summer_count_3, $value->summer_count_4, $value->winter_count_1, $value->winter_count_2, $value->winter_count_3, $value->winter_count_4, isset($value->paper0) ? $value->paper0->nameBothShort : '', $value->trashRelationMulti, $value->trashRecycleMulti, $value->rubberItemsMulti, $value->answer_count, $value->woman_count, isset($value->person0) ? $value->person0->nameBothShort : '', $value->date, $value->interrogatory]; } $sheets[$i]->fromArray($dataArray, '', 'A1'); header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified header('Cache-Control: cache, must-revalidate'); // HTTP/1.1 header('Pragma: public'); // HTTP/1.0 header("Content-Type: application/vnd.ms-excel; name='excel'");