public function actionComment()
 {
     $frm = new Comments();
     if ($frm->load(Yii::$app->request->post())) {
         //TODO: this is considered as given
         $frm->idtodo = 1;
         $frm->iduser = Yii::$app->user->id;
         if ($frm->save()) {
             echo "success";
         } else {
             print_r($frm->getErrors());
         }
     }
 }
 public function actionSave()
 {
     $comment = new Comments();
     if (Yii::$app->request->isPost) {
         $comment->text = Yii::$app->request->post('text');
         $comment->user_id = Yii::$app->user->id;
         if ($comment->save()) {
             return $this->redirect('/user/profile');
         } else {
             throw new ForbiddenHttpException('Ошибка сохранения комментария!', 404);
         }
     } else {
         return $this->goHome();
     }
 }
Beispiel #3
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function addComment()
 {
     try {
         $comments = new Comments();
         $comments->author = $this->author;
         $comments->content = $this->content;
         $comments->created = date('Y-m-d');
         $comments->updated = null;
         $comments->article_id = $this->article_id;
         $comments->status = 0;
         $comments->save();
     } catch (ErrorException $e) {
         return false;
     }
     return true;
 }
 protected function findModel($id)
 {
     if (($model = Comments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Beispiel #5
0
 public function run()
 {
     $model = new Comments();
     $query = Comments::find()->where(['class_name' => $this->class_name, 'item_id' => $this->item_id])->orderBy('id DESC');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]);
     echo $this->render('commentsWidget/view', ['dataProvider' => $dataProvider]);
     echo $this->render('commentsWidget/_form', ['model' => $model]);
 }
 public function actionView()
 {
     if (User::isAdmin(Yii::$app->user->identity->username)) {
         $link = new ActiveDataProvider(['query' => Comments::find(), 'pagination' => ['pageSize' => 50]]);
         return $this->render('view', compact('link'));
     } else {
         throw new ForbiddenHttpException('У вас нет прав администратора!', 404);
     }
 }
Beispiel #7
0
 public function getComments($id)
 {
     $query = Comments::find()->where(['status' => 10, 'article_id' => $id]);
     if (!$query->count()) {
         return false;
     }
     $pagination = new Pagination(['defaultPageSize' => 20, 'totalCount' => $query->count(), 'forcePageParam' => false, 'pageSizeParam' => false]);
     $comments = $query->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all();
     return ['comments' => $comments, 'pagination' => $pagination];
 }
Beispiel #8
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comments::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['idcomments' => $this->idcomments, 'idtodo' => $this->idtodo, 'iduser' => $this->iduser, 'parent' => $this->parent, 'cdate' => $this->cdate, 'mdate' => $this->mdate]);
     $query->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comments::find()->with('article');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['status' => SORT_ASC, 'id' => SORT_DESC]], 'pagination' => ['pagesize' => 15, 'forcePageParam' => false, 'pageSizeParam' => false]]);
     $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' => $this->id, 'created' => $this->created, 'approved' => $this->updated, 'article_id' => $this->article_id, 'status' => $this->status]);
     $query->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
Beispiel #10
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comments::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, 'user_id' => $this->user_id, 'parent_id' => $this->parent_id, 'datetime' => $this->datetime, 'item_id' => $this->item_id]);
     $query->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'class_name', $this->class_name]);
     return $dataProvider;
 }
 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $comments = new Comments();
     $comments->id_post = $id;
     return $this->render('view', ['model' => $this->findModel($id), 'comments' => $comments, 'commentsProvider' => new ActiveDataProvider(['query' => Comments::find()->where(['id_post' => $id])])]);
 }
Beispiel #12
0
    </div>
    <br>

    <div class="meta">
        <p>Автор: <b><?php 
echo $model->author->username;
?>
</b>; Дата публикации: <?php 
echo $model->publish_date;
?>
; Категория: <?php 
echo Html::a($model->category->title, ['category/view', 'id' => $model->category->id]);
?>
</p>
    </div>

    <h4>Коментарии:</h4>
    <?php 
echo ListView::widget(['dataProvider' => new ActiveDataProvider(['query' => Comments::find()->where(['id_post' => $model->id])]), 'itemView' => function ($comments) {
    return $this->render('_comments', ['model' => $comments]);
}, 'emptyText' => 'Комментариев нету']);
?>

    <h3>Добавить комментарий:</h3>

    <?php 
echo $this->render('/comments/_form', ['model' => $comments, 'actionComments' => '/comments/create']);
?>

</div>
Beispiel #13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comments::className(), ['idtodo' => 'idtodo']);
 }
Beispiel #14
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comments::className(), ['article_id' => 'id']);
 }
 /**
  * Finds the Comments model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comments the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Сторінки, яку Ви шукаєте не існує.');
     }
 }