Esempio n. 1
0
 public function actionComment()
 {
     if (Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         $data = Yii::$app->request->post();
         $user = User::findOne(Yii::$app->user->getId());
         $whom = User::findOne($data['whom_id']);
         $rate = $whom->profile->rate;
         if ($rate == 0) {
             $whom->profile->rate = (double) $data['rate'];
         } else {
             $whom->profile->rate = ($rate + (double) $data['rate']) / 2;
         }
         $whom->profile->save();
         $comment = new Comment();
         $comment->rate = $data['rate'];
         $comment->description = $data['comment'];
         $comment->whom_id = $data['whom_id'];
         $comment->link('owner', $user);
         if ($comment->save()) {
             return array('success' => true);
         }
         return array('success' => false);
     }
 }
Esempio n. 2
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $comment = new Comment(['author' => $this->name, 'text' => $this->comment, 'ip' => \Yii::$app->request->getUserIP(), 'email' => $this->email, 'newsID' => $this->newsID, 'published' => $this->published]);
     return $comment->save(false);
 }
 /**
  * @param $id
  * @return string
  * @throws NotFoundHttpException
  */
 public function actionView($id)
 {
     $comment = new Comment();
     $num = $comment->countByUser($id);
     $commentData = $comment->getCommentByNewsId($id);
     $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $commentData->count()]);
     $commentData = $commentData->orderBy('created_at DESC')->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('view', ['model' => $this->findModel($id), 'comment' => $comment, 'commentData' => $commentData, 'commentNum' => $num[0], 'pagination' => $pagination]);
 }
 /**
  * @return \yii\web\Response
  */
 public function actionCreate()
 {
     $model = new Comment();
     $model->ip = Yii::$app->request->userIP;
     $model->username = Yii::$app->session['__username'];
     $model->user_id = User::find()->where(['username' => $model->username])->one()->id;
     $model->created_at = time();
     $model->updated_at = time();
     //$params = FilterForm::filterHtml();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['show/view', 'id' => $model->news_id]);
     }
     echo '发布失败,请重新发表评论!';
 }
 public function actionRemove($id)
 {
     $userId = Yii::$app->user->identity->username;
     $sil = Comment::findOne($id);
     $sil->delete();
     return $this->redirect(['index']);
 }
Esempio n. 6
0
 /**
  * If validation is ok, gets POST data and saves to DB
  * @return bool
  */
 public function addComment()
 {
     if ($this->validate()) {
         $comment = new Comment();
         $comment->comment_writer = $this->comment_writer;
         $comment->comment_w_email = $this->comment_w_email;
         $comment->comment_w_phone = $this->comment_w_phone;
         $comment->comment_w_gender = $this->comment_w_gender;
         $comment->comment_country_id = $this->country;
         $comment->comment_subject = $this->comment_subject;
         $comment->comment_message = $this->comment_message;
         $comment->comment_date_created = time();
         $comment->save();
         return true;
     }
     return false;
 }
Esempio n. 7
0
 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = Post::find()->where(['id' => $id])->one();
     $model->views++;
     $model->save();
     $com = Comment::find()->all();
     Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => $model->description]);
     Yii::$app->view->registerMetaTag(['name' => 'keywords', 'content' => $model->seo_keywords]);
     $model_com = new Comment();
     if ($model_com->load(Yii::$app->request->post()) && $model_com->save()) {
         //return $this->redirect(['view', 'id' => $model->id]);
     } else {
         /*return $this->render('create', [
               'model' => $model,
           ]);*/
     }
     return $this->render('view', ['model' => $this->findModel($id), 'com' => $com, 'model_com' => $model_com]);
 }
 /**
  * Displays page where one can edit comment chosen by id
  * @param $id
  * @return string
  */
 public function actionEdit($id)
 {
     $id = Yii::$app->request->get('id');
     // Checking if line with this id exists
     $check_id = Comment::find()->select(['comment_writer'])->where(['comment_id' => $id])->one();
     if ($check_id != null) {
         $comment = new Comment();
         $comment_to_update = $comment->findModel($id);
         $commentForm = new CommentUpdateForm($id, $comment_to_update);
         if ($commentForm->load(Yii::$app->request->post()) && $commentForm->updateComment($id)) {
             Yii::$app->session->setFlash('messageUpdated');
             $this->redirect(Yii::$app->getUrlManager()->createUrl('comment/view'));
         } else {
             return $this->render('edit', ['commentForm' => $commentForm]);
         }
     } else {
         $this->redirect(Yii::$app->getUrlManager()->createUrl('comment/view'));
     }
 }
Esempio n. 9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::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(['like', '_id', $this->_id])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'post_id', $this->post_id])->andFilterWhere(['like', 'comment', $this->comment])->andFilterWhere(['like', 'status', $this->status])->andFilterWhere(['like', 'created_at', $this->created_at]);
     return $dataProvider;
 }
Esempio n. 10
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::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' => $this->id, 'waktu' => $this->waktu, 'post_id' => $this->post_id]);
     $query->andFilterWhere(['like', 'nama', $this->nama])->andFilterWhere(['like', 'isi', $this->isi]);
     return $dataProvider;
 }
 public function actionPublishcoment()
 {
     $userId = Yii::$app->session->get(FVariable::$session_userId_str);
     if (!$userId) {
         JsonParser::GenerateJsonResult('_0004', '您还没登录,请登录再发表看法');
         exit;
     }
     $ArticleCon = Yii::$app->request->post("ArticleCon");
     if (!$ArticleCon) {
         JsonParser::GenerateJsonResult('_0003', '发表的内容不能为空');
         exit;
     }
     $ArticleId = Yii::$app->request->post("ArticleId");
     $article = new Article();
     $articleCon = $article->findByArticleId($ArticleId);
     if (!$articleCon) {
         return $this->redirect(FVariable::$error404_view);
     }
     $comment = new Comment();
     $comment->findByIdArticleInsert($userId, 0, $ArticleId, $ArticleCon);
     JsonParser::GenerateJsonResult('_0000', '发表成功');
     exit;
 }
Esempio n. 12
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::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, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     return $dataProvider;
 }
 /**
  * If validation is ok, gets POST data and updates data in DB
  * @param $id
  * @return bool
  */
 public function updateComment($id)
 {
     if ($this->validate()) {
         $comment = Comment::findOne($id);
         $comment->comment_writer = $this->comment_writer;
         $comment->comment_w_email = $this->comment_w_email;
         $comment->comment_w_phone = $this->comment_w_phone;
         $comment->comment_w_gender = $this->comment_w_gender;
         $comment->comment_country_id = $this->country;
         $comment->comment_subject = $this->comment_subject;
         $comment->comment_message = $this->comment_message;
         $comment->save();
         return true;
     }
     return false;
 }
Esempio n. 14
0
 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     Yii::$app->session['post_id'] = $id;
     $querykomen = Comment::find()->where(['post_id' => $id]);
     $hitungkomen = clone $querykomen;
     $page = new Pagination(['totalCount' => $hitungkomen->count()]);
     $komen = $querykomen->offset($page->offset)->limit($page->limit)->all();
     $namaKomen = "";
     foreach ($komen as $komens) {
         $namaKomen = $komens->nama;
     }
     $nama = $this->findModel($id)->nama;
     $usr = new \common\models\User();
     $fotoPost = $usr->find()->where(['nama' => $nama])->all();
     $fotoKomen = $usr->find()->where(['nama' => $namaKomen])->all();
     return $this->render('view', ['model' => $this->findModel($id), 'komen' => $komen, 'fotoPost' => $fotoPost, 'fotoKomen' => $fotoKomen, 'page' => $page]);
 }
Esempio n. 15
0
 public function getOrderDetailComment()
 {
     return $this->hasOne(Comment::className(), ['typeId' => 'id']);
 }
Esempio n. 16
0
 /**
  * Finds the Comment model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Comment the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Comment::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Esempio n. 17
0
 /**
  * @inheritdoc
  */
 public function getAllComment()
 {
     $comments = Comment::find();
     return $comments;
 }
Esempio n. 18
0
 public function getComment()
 {
     return $this->hasMany(Comment::className(), ['postId' => 'id']);
 }
Esempio n. 19
0
ActiveForm::end();
Pjax::end();
?>
  </div>
</div>

<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title"><?php 
echo Yii::t('app', 'All comments');
?>
</h3>
  </div>
  <div class="panel-body">
   <?php 
$comment = \frontend\models\Comment::findAll(['post_id' => $model->id, 'status' => 1]);
foreach ($comment as $k => $v) {
    ?>

  <div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title"><a href="<?php 
    echo $v['url'];
    ?>
"><?php 
    echo $v['author'];
    ?>
</a> - <?php 
    echo date('Y/m/d H:i', $v['create_time']);
    ?>
</h3>
Esempio n. 20
0
 /**
  * Gets model to further update
  * @param $id
  * @return array|null|ActiveRecord
  */
 public function findModel($id)
 {
     return $comment = Comment::find()->where(['comment_id' => $id])->asArray()->one();
 }
Esempio n. 21
0
 public function actionTest()
 {
     $comment = new Comment();
     $orderDetail = new OrderDetail();
     $commentList = $comment->SelectAllProductCom();
     $count = 0;
     $num = 0;
     foreach ($commentList as $k => $v) {
         $orderDetailProductId = $orderDetail->findIdOrderDetailIsEvaluate($v['typeId']);
         if ($orderDetailProductId->productId == GlobalArray::$productIdArray['0']) {
             $count++;
             $num += $comment->findByIdCom($orderDetailProductId->id)->score;
         }
     }
     echo $num / $count;
 }
Esempio n. 22
0
 /**
  * @return ActiveQuery
  */
 public function getComments()
 {
     return $this->hasMany(Comment::className(), ['newsID' => 'id']);
 }
Esempio n. 23
0
 public function findByIdCom($orderDetailId)
 {
     $comment = Comment::find()->where(['typeId' => $orderDetailId])->one();
     if (!$comment) {
         return false;
     }
     return $comment;
 }
Esempio n. 24
0
 /**
  * Establishing hasOne relation with Comment table
  * @return \yii\db\ActiveQuery
  */
 public function getComment()
 {
     return $this->hasMany(Comment::classname(), ['comment_country_id' => 'country_id']);
     /*Сначала ключ другой таблицы, потом своей*/
 }
Esempio n. 25
0
 public function actionNews($id, $ignoreLink = false)
 {
     $news = News::find()->andWhere(['id' => filter_var($id, FILTER_SANITIZE_NUMBER_INT)])->with('author')->one();
     if (!$news) {
         throw new NotFoundHttpException();
     }
     if ($news->fullLink != \Yii::$app->request->url && !$ignoreLink) {
         return $this->redirect($news->fullLink, 301);
     }
     if (\Yii::$app->request->isAjax) {
         \Yii::$app->response->format = 'json';
         switch (\Yii::$app->request->post('action')) {
             case 'voteComment':
                 $commentID = \Yii::$app->request->post('commentID');
                 $comment = Comment::findOne($commentID);
                 if (!$comment) {
                     throw new NotFoundHttpException("Комментарий с идентификатором {$commentID} не найден!");
                 }
                 $isGood = \Yii::$app->request->post('isGood') == 'true';
                 if (!empty($comment->myVote) && $comment->myVote->operation == ($isGood ? CommentVote::OPERATION_GOOD : CommentVote::OPERATION_BAD)) {
                     return ['result' => $comment->rating];
                 }
                 $comment->vote($isGood);
                 $comment = Comment::findOne($commentID);
                 return ['result' => $comment->rating];
                 break;
         }
     }
     if ($date = \Yii::$app->request->headers->get('If-Modified-Since', 0)) {
         if ($date = strtotime($date) && ($date >= $news->updated || $date >= $news->publishDate)) {
             header('HTTP/1.1 304 Not Modified');
             die;
         }
     }
     \Yii::$app->response->headers->add('Last-Modified', gmdate('D, d M Y H:i:s', $news->updated ? $news->updated : $news->publishDate) . ' GMT');
     if (!preg_match('/(googlebot|google.com\\/bot|yandex(\\w+|)bot|yandex\\.com\\/bots)/im', \Yii::$app->request->userAgent)) {
         (new Query())->createCommand(\Yii::$app->db)->setSql("UPDATE `news` SET `hits` = `hits` + 1 WHERE `id` = '{$news->id}'")->execute();
         NewsViews::addView($news->id);
     }
     $commentForm = new CommentForm();
     if (\Yii::$app->request->post('CommentForm')) {
         $commentForm->load(\Yii::$app->request->post());
         $commentForm->news = $news;
         if ($commentForm->save()) {
             \Yii::$app->session->setFlash('saved', 'Комментарий успешно добавлен!' . ($news->moderatedComments == 1 ? ' Он будет опубликован после проверки модератором.' : ''));
             $commentForm = new CommentForm();
         }
     }
     if (!empty($news->category)) {
         if (!empty($news->category->parentCategory)) {
             $this->getView()->params['breadcrumbs'][] = ['label' => $news->category->parentCategory->title, 'url' => yii\helpers\Url::toRoute(['/' . $news->category->parentCategory->fullLink], true)];
         }
         $this->getView()->params['breadcrumbs'][] = ['label' => $news->category->title, 'url' => yii\helpers\Url::toRoute(['/' . $news->category->fullLink], true)];
     }
     $today = strtotime(date('Y-m-d'));
     $interestNews = [];
     if ($news->category->showPopular) {
         $interestNews = NewsViews::find()->select('newsID')->where(['date' => $today])->andWhere(['not in', 'newsID', $news->id])->orderBy('views DESC')->limit(5)->asArray()->all();
         if (empty($interestNews)) {
             $interestNews = NewsViews::find()->select('newsID')->where(['date' => $today - 86400])->andWhere(['not in', 'newsID', $news->id])->orderBy('views DESC')->limit(5)->asArray()->all();
         }
         $interestNews = News::find()->andWhere(['in', 'id', ArrayHelper::getColumn($interestNews, 'newsID')])->andWhere(['not in', 'categoryID', '49'])->with('category')->limit(3)->all();
     }
     return $this->render('article', ['article' => $news, 'interest' => $interestNews, 'commentForm' => $commentForm, 'categoryNews' => $news->category->showSimilar ? $news->category->getPossibleNews(3, [$news->id]) : []]);
 }