Пример #1
0
 /**
  * Creates a new Comments model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Comments();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates a new Comments model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($id_item = null)
 {
     $model = new Comments();
     if ($model->load(Yii::$app->request->post())) {
         //var_dump($model->id_item); exit();
         $model->id_item = $id_item;
         if ($model->save()) {
             return $this->redirect(['items/view', 'id' => $id_item]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #3
0
 /**
  * Displays a single Post model.
  * Also added functionality of adding comments, related to particular Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $comments = Comments::find()->where(['post_id' => $id])->all();
     $newComment = new Comments();
     if ($newComment->load(Yii::$app->request->post()) && $newComment->validate()) {
         $newComment->created_at = time();
         $newComment->post_id = $id;
         $newComment->save();
         return $this->redirect(['view', 'id' => $id]);
     } else {
         return $this->render('view', ['model' => $this->findModel($id), 'comments' => $comments, 'newComment' => $newComment]);
     }
 }
 public function actionView($id, $ajax = false)
 {
     $login = new login();
     $comment = new Comments();
     $getComments = Comments::find()->where(['id_new' => $id]);
     $pagination = new Pagination(['defaultPageSize' => 10, 'totalCount' => $getComments->count()]);
     $getComments = $getComments->offset($pagination->offset)->limit($pagination->limit)->all();
     if ($comment->load(Yii::$app->request->post()) && $comment->create($id)) {
         return $this->redirect(['view', 'id' => $id]);
     } else {
         if ($ajax == true) {
             return $this->renderAjax('ajaxComment', ['login' => $login, 'comment' => $comment, 'getComments' => $getComments, 'pagination' => $pagination]);
         } else {
             return $this->render('view', ['login' => $login, 'model' => $this->findModel($id), 'comment' => $comment, 'getComments' => $getComments, 'pagination' => $pagination]);
         }
     }
 }
Пример #5
0
 public function actionCreate()
 {
     if (Yii::$app->getRequest()->getQueryParam('name')) {
         var_dump(Yii::$app->getRequest()->getQueryParam('host'));
     } else {
         echo 'no_name';
     }
     if (Yii::$app->getRequest()->getQueryParam('body')) {
         var_dump(Yii::$app->getRequest()->getQueryParam('body'));
     } else {
         echo 'no_body';
     }
     $model = new Comments();
     if ($model->load(Yii::$app->request->post())) {
         $model->name = Yii::$app->request->post('Comments')['name'];
         $model->body = Yii::$app->request->post('Comments')['body'];
         $model->save();
     }
 }
Пример #6
0
 function run()
 {
     // && $model->contact(Yii::$app->params['adminEmail'])
     $this->enable_form = $this->allow_comments();
     $comment = new Comments();
     $comment->parent_id = 0;
     if ($this->enable_form && $comment->load(Yii::$app->request->post()) && $comment->validate()) {
         Yii::$app->session->setFlash('commentFormSubmitted');
         $comment->active = true;
         $comment->user_id = Yii::$app->user->isGuest ? null : Yii::$app->user->identity->id;
         $comment->ip = ip2long(Yii::$app->request->getUserIP());
         $comment->agent = Yii::$app->request->getUserAgent();
         $comment->saveUploadedImage('file');
         $comment->save();
         return Yii::$app->getResponse()->redirect(Yii::$app->getRequest()->getUrl());
     }
     $query = new Query();
     $query->addSelect('c.*, f.filename, f.thumb_filename, f.size, u.username')->from([Comments::tableName() . ' c'])->leftJoin(User::tableName() . ' u', 'u.id = c.user_id')->leftJoin(Files::tableName() . ' f', 'f.id = c.image_id')->where(['c.active' => true])->andWhere(['c.post_id' => $this->post_id]);
     $comment->post_id = $this->post_id;
     return $this->render('comments/comments_box', ['comments' => $this->buildTree($query->all()), 'model' => $comment, 'enable' => $this->enable_form]);
 }
Пример #7
0
 /**
  * Displays a single Posts model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $searchModel = new CommentsSearch();
     $comments = Comments::findAll(['PostID' => $id]);
     $newComment = new Comments();
     $sql = "SELECT MAX(CommentID) AS CommentID FROM comments";
     $max_id = Comments::findBySql($sql)->one();
     $upload_id_comments = $max_id->CommentID;
     if ($newComment->load(Yii::$app->request->post())) {
         $newComment->TimeStamp = date("Y-m-d H:i:s");
         $newComment->Attachment = UploadedFile::getInstance($newComment, 'Attachment');
         if ($newComment->Attachment && $newComment->validate()) {
             $newComment->Attachment->saveAs('../uploads/comments/' . $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension);
             $newComment->Attachment = $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension;
         }
         if ($newComment->save()) {
             return $this->redirect(['view', 'id' => $newComment->PostID]);
         }
     } else {
         return $this->render('view', ['model' => $this->findModel($id), 'newComment' => $newComment, 'comments' => $comments]);
     }
 }
Пример #8
0
 /**
  * Displays a grid containing all Objects of this API.
  * @param integer $id
  * @param boolean $propose
  * @param boolean $followed
  * @param boolean $followersNotified
  * @return mixed
  */
 public function actionView($id, $propose = false, $followed = null, $followersNotified = null)
 {
     $searchModel = new ObjectsSearch();
     $dataProvider = $searchModel->search(['ObjectsSearch' => ['api' => $id]]);
     $commentSearchModel = new CommentsSearch();
     $commentsProvider = $commentSearchModel->findCommentsNotReplies(['CommentsSearch' => ['api' => $id]]);
     $repliesProvider = $commentSearchModel->findReplies(['CommentsSearch' => ['api' => $id]]);
     $repliesProvider->setPagination(false);
     $commentsModel = new Comments();
     $commentsModel->api = $id;
     if ($commentsModel->load(Yii::$app->request->post())) {
         $commentsModel->save();
     }
     $myId = \Yii::$app->user->id;
     $followUserAPI = FollowUserApi::findOne(['follower' => $myId, 'api' => $id]);
     $doIFollow = false;
     if ($followUserAPI) {
         $doIFollow = true;
         $followUserAPI->last_seen = date('Y-m-d H:i:s');
         $followUserAPI->changed_name = false;
         $followUserAPI->changed_descr = false;
         $followUserAPI->changed_version = false;
         $followUserAPI->changed_proposed = false;
         $followUserAPI->changed_published = false;
         $followUserAPI->changed_privacy = false;
         $followUserAPI->changed_upvotes = 0;
         $followUserAPI->changed_downvotes = 0;
         $followUserAPI->changed_objects_number = 0;
         $followUserAPI->save();
     }
     $followers = FollowUserApi::find()->where(['api' => $id])->count();
     $this->view->params['followers_notified'] = $followersNotified;
     $this->view->params['propose'] = $propose;
     $this->view->params['followed'] = $followed;
     // Elastic Search Query for Recommendations
     $esq = new ElasticSearchQuery();
     $api = $this->findModel($id);
     $esq->setApi($api);
     $esq->MakeJSON();
     $recommend = $esq->Build();
     return $this->render('view', ['model' => $this->findModel($id), 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'doIFollow' => $doIFollow, 'followers' => $followers, 'commentsProvider' => $commentsProvider, 'repliesProvider' => $repliesProvider, 'commentsModel' => $commentsModel, 'recommend' => $recommend]);
 }
Пример #9
0
 public function actionSavecomment()
 {
     $model = new Comments();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['site/detailpost', 'id' => $model->post_id]);
     } else {
         return $this->redirect('index.php');
     }
 }
Пример #10
0
 public function actionFeed()
 {
     $query = "SELECT * FROM exams ORDER BY `ExamId` DESC";
     $exams = Exams::findBySql($query)->all();
     $model = new NewsFeed();
     $newComment = new Comments();
     $sql = "SELECT * FROM posts ORDER BY `TimeStamp` DESC";
     $models = NewsFeed::findBySql($sql)->all();
     $sql2 = "SELECT *, MAX(Likes) FROM posts";
     $popular = NewsFeed::findBySql($sql2)->one();
     $comments_popular = $popular->comments;
     $sql3 = "SELECT * FROM posts WHERE Pinned = 1";
     $pinned = NewsFeed::findBySql($sql3)->one();
     $comments_pinned = $pinned->comments;
     $sort = new Sort(['attributes' => ['TimeStamp' => ['asc' => ['TimeStamp' => SORT_ASC], 'desc' => ['TimeStamp' => SORT_DESC], 'default' => SORT_DESC, 'label' => 'Latest']]]);
     $sql4 = "SELECT MAX(PostID) AS PostID FROM posts";
     $max_id = NewsFeed::findBySql($sql4)->one();
     $upload_id_posts = $max_id->PostID;
     $sql5 = "SELECT MAX(CommentID) AS CommentID FROM comments";
     $max_id2 = Comments::findBySql($sql5)->one();
     $upload_id_comments = $max_id2->CommentID;
     $success = false;
     if ($model->load(Yii::$app->request->post())) {
         //$model->PostContent = "Sample na naman";
         $model->TimeStamp = date("Y-m-d H:i:s");
         $post_title = substr($model->PostContent, 0, 15);
         $model->PostTitle = $post_title . "...";
         $user = Users::find()->where(['UserID' => $model->UserID])->one();
         $model->Attachment = UploadedFile::getInstance($model, 'Attachment');
         if ($model->Attachment && $model->validate()) {
             $model->Attachment->saveAs('../uploads/posts/' . $model->Attachment->baseName . '_00000' . $upload_id_posts . '.' . $model->Attachment->extension);
             $model->Attachment = $model->Attachment->baseName . '_00000' . $upload_id_posts . '.' . $model->Attachment->extension;
         }
         if ($model->save()) {
             $success = true;
         }
     }
     if ($newComment->load(Yii::$app->request->post())) {
         $newComment->TimeStamp = date("Y-m-d H:i:s");
         $newComment->Attachment = UploadedFile::getInstance($newComment, 'Attachment');
         if ($newComment->Attachment && $newComment->validate()) {
             $newComment->Attachment->saveAs('../uploads/comments/' . $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension);
             $newComment->Attachment = $newComment->Attachment->baseName . '_11111' . $upload_id_comments . '.' . $newComment->Attachment->extension;
         }
         if ($newComment->save()) {
             $success = true;
         }
     }
     //Yii::info($comments, __METHOD__);
     if ($success) {
         return $this->refresh();
     } else {
         return $this->render('feed', ['model' => $model, 'models' => $models, 'newComment' => $newComment, 'popular' => $popular, 'comments_popular' => $comments_popular, 'pinned' => $pinned, 'comments_pinned' => $comments_pinned, 'sort' => $sort, 'exams' => $exams]);
     }
 }