/** * Lists all HarvestPlant models. * @return mixed */ public function actionIndex() { $harvestToolsReportSearch = new HarvestToolsReportSearch(); $harvestToolsReportSearch->yearStart = date('Y'); $harvestToolsReportSearch->yearEnd = $harvestToolsReportSearch->yearStart; $harvestToolsReportSearch->quarterStart = 1; if (date('m') >= 9) { $harvestToolsReportSearch->quarterEnd = 4; } else { if (date('m') >= 6) { $harvestToolsReportSearch->quarterEnd = 3; } else { if (date('m') >= 3) { $harvestToolsReportSearch->quarterEnd = 2; } else { $harvestToolsReportSearch->quarterEnd = 1; } } } $typeToolses = TypeTools::find()->all(); $stateCount = State::find()->count(); $years = []; $quarters = []; $states = State::find()->select('name')->column(); $typeToolses2 = TypeTools::find()->select('name')->column(); $stateIds = []; if ($harvestToolsReportSearch->load(Yii::$app->request->post())) { $stateIds = $harvestToolsReportSearch->stateIds; if (!empty($stateIds)) { $stateCount = State::find()->where(['id' => $stateIds])->count(); $states = State::find()->select('name')->where(['id' => $stateIds])->column(); } $typeToolsIds = $harvestToolsReportSearch->typeToolsIds; if (!empty($typeToolsIds)) { $typeToolses = TypeTools::find()->where(['id' => $typeToolsIds])->all(); $typeToolses2 = TypeTools::find()->select('name')->where(['id' => $typeToolsIds])->column(); } $yearStart = $harvestToolsReportSearch->yearStart; $yearEnd = $harvestToolsReportSearch->yearEnd; for ($i = $yearStart; $i <= $yearEnd; $i++) { $years[] = $i; } $quarterStart = $harvestToolsReportSearch->quarterStart; $quarterEnd = $harvestToolsReportSearch->quarterEnd; for ($i = $quarterStart; $i <= $quarterEnd; $i++) { $quarters[] = $i; } } $renders['typeToolses'] = $typeToolses; $renders['stateCount'] = $stateCount; $renders['stateIds'] = $stateIds; $renders['years'] = $years; $renders['quarters'] = $quarters; $renders['states'] = $states; $renders['typeToolses2'] = $typeToolses2; $session = Yii::$app->session; $session->set('renderHarvestToolsReport', $renders); $renders['harvestToolsReportSearch'] = $harvestToolsReportSearch; return $this->render('index', $renders); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = TypeTools::find(); // add conditions that should always apply here $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } // grid filtering conditions $query->andFilterWhere(['id' => $this->id, 'name' => $this->name, 'sort' => $this->sort, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'params', $this->params])->andFilterWhere(['like', 'units', $this->units]); return $dataProvider; }
?> </div> </div> <div class="row"> <div class="col-xs-12 col-sm-8 col-md-5"> <?php $data = ArrayHelper::map(State::find()->select(['id', 'name'])->asArray()->all(), 'id', 'name'); echo $form->field($model, 'stateIds')->widget(Select2::classname(), ['data' => $data, 'options' => ['placeholder' => 'Pilih Kecamatan ...'], 'pluginOptions' => ['allowClear' => true, 'multiple' => true]])->label('Kecamatan'); ?> </div> </div> <div class="row"> <div class="col-xs-12 col-sm-8 col-md-5"> <?php $data = ArrayHelper::map(TypeTools::find()->select(['id', 'name'])->asArray()->all(), 'id', 'name'); echo $form->field($model, 'typeToolsIds')->widget(Select2::classname(), ['data' => $data, 'options' => ['placeholder' => 'Pilih Jenis Alat ...'], 'pluginOptions' => ['allowClear' => true, 'multiple' => true]])->label('Jenis Alat'); ?> </div> </div> <div class="form-group"> <?php echo Html::submitButton('Tampilkan', ['class' => 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>