示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Mensagens::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['criado_em' => SORT_DESC]]]);
     $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_mensagem' => $this->id_mensagem, 'id_destinatario' => Yii::$app->user->getId(), 'lida' => $this->lida, 'resposta_de' => $this->resposta_de, 'criado_por' => $this->criado_por, 'criado_em' => $this->criado_em, 'ativo' => 1]);
     $query->andFilterWhere(['like', 'texto', $this->texto]);
     $query->andFilterWhere(['like', 'assunto', $this->assunto]);
     return $dataProvider;
 }
示例#2
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMensagens()
 {
     return $this->hasMany(Mensagens::className(), ['resposta_de' => 'id_mensagem']);
 }
示例#3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getMensagensNaoLidas()
 {
     return $this->hasMany(Mensagens::className(), ['id_destinatario' => 'id_usuario'])->where(['lida' => null])->one();
 }
示例#4
0
 /**
  * Finds the Mensagens model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Mensagens the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Mensagens::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }