Esempio n. 1
0
 /**
  * Lists all Mesaj models.
  * @return mixed
  */
 public function actionIndex($id = NULL)
 {
     $users = User::find()->all();
     if ($id) {
         $model = new Mesaj();
         $konusma = Konusma::findOne(['konusmaci_1' => yii::$app->user->id, 'konusmaci_2' => $id]);
         if (!$konusma) {
             $konusma = Konusma::findOne(['konusmaci_2' => yii::$app->user->id, 'konusmaci_1' => $id]);
         }
         if (!$konusma) {
             $konusma = new Konusma();
             $konusma->konusmaci_1 = yii::$app->user->id;
             $konusma->konusmaci_2 = $id;
             $konusma->save();
         }
         $post = yii::$app->request->post();
         if ($model->load($post)) {
             $model->konusma_id = $konusma->id;
             $model->gonderen_id = yii::$app->user->id;
             date_default_timezone_set("Europe/Istanbul");
             $model->tarih = date("Y-m-d H:i:s");
             if ($model->save()) {
                 return $this->redirect(['index', 'id' => $id]);
             } else {
                 print_r($model);
                 exit;
             }
         }
         $kullanici = User::findOne($id);
         $mesajlar = Mesaj::find()->where(['konusma_id' => $konusma->id])->orderBy(['id' => SORT_ASC])->all();
         return $this->render('index', ['users' => $users, 'mesajlar' => $mesajlar, 'kullanici' => $kullanici, 'model' => $model]);
     } else {
         return $this->render('index', ['users' => $users]);
     }
 }
Esempio n. 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Mesaj::find();
     // add conditions that should always apply here
     $query->joinWith(['alici']);
     $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;
     }
     $dataProvider->sort->attributes['_alici'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]];
     $dataProvider->sort->attributes['_gonderen'] = ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]];
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'gonderen_id' => $this->gonderen_id, 'alici_id' => $this->alici_id, 'tarih' => $this->tarih]);
     $query->andFilterWhere(['like', 'icerik', $this->icerik]);
     $query->andFilterWhere(['like', 'user.username', $this->_alici]);
     $query->andFilterWhere(['like', 'user.username', $this->_gonderen]);
     return $dataProvider;
 }