/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Avisos::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(['id_aviso' => $this->id_aviso, 'tempo_exibicao' => $this->tempo_exibicao, 'data_inicio' => $this->data_inicio, 'data_fim' => $this->data_fim, 'criado_por' => $this->criado_por, 'criado_em' => $this->criado_em, 'modificado_por' => $this->modificado_por, 'modificado_em' => $this->modificado_em, 'ativo' => $this->ativo]); $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'descricao', $this->descricao])->andFilterWhere(['like', 'imagem', $this->imagem]); return $dataProvider; }
public function actionIndex() { $avisos = Avisos::getActiveAvisos(); $usuarios = Usuarios::find()->innerJoinWith('tipoUsuario')->where(["usuarios.ativo" => 1])->andWhere(['not', ["tipos_usuario.nome" => Yii::$app->params['Dev']]])->andWhere(['not', ["tipos_usuario.nome" => Yii::$app->params['Mural']]])->andWhere(['not', ["tipos_usuario.nome" => Yii::$app->params['Tablet']]])->orderBy(['nome_completo' => 'SORT_ASC'])->all(); return $this->render('index', ['usuarios' => $usuarios, 'avisos' => $avisos]); }
/** * Finds the Avisos model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Avisos the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Avisos::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }