/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Sublocal::find(); $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; } $query->andFilterWhere(['idSubLocal' => $this->idSubLocal, 'idLocal' => $this->idLocal]); $query->andFilterWhere(['like', 'Nome', $this->Nome]); return $dataProvider; }
public function actionSublocalselected($idLocal, $idSublocal) { $countSublocais = SubLocal::find()->where(['idLocal' => $idLocal])->count(); $subLocal = Sublocal::find()->where(['idLocal' => $idLocal])->all(); if ($countSublocais > 0) { foreach ($subLocal as $branch) { if ($branch->idSubLocal == $idSublocal) { echo "<option value='" . $branch->idSubLocal . "' selected>" . $branch->Nome . "</option>"; } else { echo "<option value='" . $branch->idSubLocal . "'>" . $branch->Nome . "</option>"; } } } else { echo "<options>Não possui sublocal</options>"; } }
public function relatorio($params) { $query = Ocorrencia::find(); $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; } $databkp = $this->data; if ($this->dataInicial != null) { list($dia, $mes, $ano) = split('[/]', $this->dataInicial); $this->dataInicial = $ano . '-' . $mes . '-' . $dia; } if ($this->dataFinal != null) { list($dia, $mes, $ano) = split('[/]', $this->dataFinal); $this->dataFinal = $ano . '-' . $mes . '-' . $dia; } // if ($this->idLocal!=null) $sublocal = Sublocal::find()->where(['=', 'idLocal', $this->idLocal])->all(); //$model->idSubLocal = $sublocal->Nome; $query->andFilterWhere(['status' => $this->status, 'idCategoria' => $this->idCategoria, 'idNatureza' => $this->idNatureza, 'periodo' => $this->periodo]); $query->andFilterWhere(['>=', 'data', $this->dataInicial]); $query->andFilterWhere(['<=', 'data', $this->dataFinal]); if ($this->idLocal != null) { $connection = \Yii::$app->db; $stringsql = "SELECT idSubLocal as idsublocal FROM sublocal WHERE idLocal = " . $this->idLocal; $sqlOcorrencia = $connection->createCommand($stringsql); $rstocorencia = $sqlOcorrencia->queryAll(); $arraysublocal = array(); $i = 0; foreach ($rstocorencia as $reg) { $arraysublocal[$i] = $reg['idsublocal']; $i = $i + 1; } $query->andFilterWhere(['IN', 'idSubLocal', $arraysublocal]); } return $dataProvider; }