/** * Store a newly created resource in storage. * * @return Response */ public function store(CommentsRequest $request) { $comment = new Comments(); $comment->text = $request->text; $comment->ads_id = $request->ads_id; $comment->user_id = Auth::user()->id; $comment->save(); Event::fire(new CreateComment($request->type, $request->ads_id, $request->user_id, $comment->id)); return \Redirect::to('/ads/' . $request->ads_id); }
public function postComment(CommentsCreateRequest $req) { $comment = new Comments(); $comment->comment = $req->input('comment'); $comment->status = 1; $comment->diary_id = $req->input('diary_id'); $comment->user_id = Auth::user()->id; if ($comment->save()) { return redirect('diary/read/' . $req->input('diary_id') . '#comment')->with('msg', 'Successfully comment posted'); } }
/** * 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 actionAddComment() { $comment = Yii::$app->request->post(); $model = new Comments(); $model->article_id = $comment['article']; $model->user_id = $comment['user']; $model->comment = $comment['comment']; $model->enable = 1; $model->save(); $user = Comments::find()->with('user')->where(['id' => $model->id])->one(); $array = array('comment' => $model->comment, 'user' => $user->user->name_fml); echo json_encode($array); // print_r($user->user->name_fml); }
public static function index() { $posts = Posts::all()->fetchAll(\PDO::FETCH_CLASS); $categories = Categories::all()->fetchAll(\PDO::FETCH_CLASS); $comments = Comments::all()->fetchAll(\PDO::FETCH_CLASS); View::render('admin/home', ['posts' => $posts, 'categories' => $categories, 'comments' => $comments]); }
public function init() { parent::init(); if ($this->article_id != null) { $this->comments = Comments::find()->where('article_content_id =' . $this->article_id)->orderBy(['id' => SORT_DESC])->all(); } }
public function searchItemComments($itemId) { $query = Comments::find(); $query->andFilterWhere(['id_item' => $itemId]); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
/** * Shows user's profile. * @param integer $id * @return \yii\web\Response * @throws \yii\web\NotFoundHttpException */ public function actionShow($id) { $this->enableCsrfValidation = false; $profile = $this->finder->findProfileById($id); if ($profile === null) { throw new NotFoundHttpException(); } $query = Comments::find()->where(['deleted' => Comments::NO_DELETED, 'user_id' => $id])->orderBy('created_at'); $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count()]); $pages->setPageSize(10); $comments = $query->offset($pages->offset)->limit($pages->limit)->all(); $model = new Comments(); $this->performAjaxValidation($model); $user = User::findOne(Yii::$app->user->getId()); if ($model->load(Yii::$app->request->post())) { $model->created_at = time(); $model->user_id = $profile->user->getId(); $model->sender_id = Yii::$app->user->getId(); $model->save(); return $this->refresh(); } else { return $this->render('show', ['profile' => $profile, 'model' => $model, 'user' => $user, 'comments' => $comments, 'pages' => $pages]); } return $this->render('show', ['profile' => $profile]); }
public function actionProduct($id = null) { $product = Products::find()->where(['id' => $id])->one(); $sec = Sections::find(['title'])->where(['id' => $product->section_id])->one(); $others = Products::find()->orderBy(['date' => SORT_DESC])->where(['section_id' => $product->section_id])->andWhere(['not in', 'id', [$id]])->limit(4)->all(); $comments = Comments::find()->where(['product_id' => $id])->orderBy(['id' => SORT_DESC])->all(); $model = new CommentForm(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { $com = new Comments(); $com->product_id = $id; $com->login = Yii::$app->session->get('login'); $com->comment = $model->comment; $com->save(); return $this->redirect(Yii::$app->request->referrer); } return $this->render('product', ['product' => $product, 'section_title' => $sec, 'others' => $others, 'model' => $model, 'comments' => $comments]); }
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]); } } }
public function actionComments() { $comments = Comments::find(); $pagination = new Pagination(['defaultPageSize' => 2, 'totalCount' => $comments->count()]); $comments = $comments->offset($pagination->offset)->limit($pagination->limit)->all(); $cookies = Yii::$app->request->cookies; return $this->render('comments', ['comments' => $comments, 'pagination' => $pagination, 'name' => $cookies->getValue('name'), 'boldCookie' => $cookies->getValue('bold'), 'bold' => Yii::$app->session->get('bold')]); }
/** * @param $id * * @return \PDOStatement */ public static function read($id) { $sql = sprintf("SELECT A.*, B.username, B.name, B.id as account_id, B.photo as account_photo,\n C.name as category_name, C.id as category_id\n FROM posts A LEFT JOIN accounts B\n ON A.id_account = B.id\n LEFT JOIN categories C ON\n A.id_category = C.id\n WHERE A.id = :id"); $bindArray = [':id' => $id]; $data = self::query($sql, $bindArray)->fetch(); $data['comments'] = Comments::findByPost($id); return $data; }
/** * Run the database seeds. * * @return void */ public function run() { Comments::truncate(); $time = Carbon::now('Asia/Taipei')->subweeks(2); foreach (range(1, 10) as $value) { $time->addDay(); Comments::create(['name' => '路人甲' . rand(1, 10), 'content' => '假留言' . $value, 'article_id' => rand(1, 8), 'created_at' => $time, 'updated_at' => $time]); } }
protected function addComment($name, $email, $website, $body, $postId, &$errors) { $success = false; $comment = Comments::create(array('name' => $name, 'email' => $email, 'website' => $website, 'body' => $body, 'post_id' => $postId)); if (!($success = $comment->save())) { $errors = $comment->errors(); } return $success; }
public function actionView() { $id = Yii::$app->request->get('id', 0); if ($id > 0) { $comments = Comments::findTree($id); \Yii::$app->response->format = 'json'; return $comments; } return false; }
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(); } }
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]); } }
/** * 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(['CommentID' => $this->CommentID, 'AttachmentTypeID' => $this->AttachmentTypeID, 'UserID' => $this->UserID, 'PostID' => $this->PostID, 'Like' => $this->Like, 'TimeStamp' => $this->TimeStamp]); $query->andFilterWhere(['like', 'CommentContent', $this->CommentContent])->andFilterWhere(['like', 'Attachment', $this->Attachment]); return $dataProvider; }
public function actionUpdate($id) { $comment = Comments::findOne($id); if (Yii::$app->user->identity->level > 1 or Yii::$app->user->identity->id == $comment->id_user) { $login = new login(); if ($comment->load(Yii::$app->request->post()) && $comment->save()) { return $this->redirect(['/news/view', 'id' => $comment->id_new]); } else { return $this->render('update', ['comment' => $comment, 'login' => $login]); } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function findReplies($params) { $query = Comments::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query = Comments::find()->andFilterWhere(['api' => $this->api, 'object' => $this->object, 'property' => $this->property]); $query->andFilterWhere(['not', ['reply_to_comment' => null]]); $dataProvider = new ActiveDataProvider(['query' => $query]); return $dataProvider; }
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]); }
/** * 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]); } }
/** * 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]); $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, 'product_id' => $this->product_id, 'moder' => $this->moder]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * 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]); $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, 'user_id' => $this->user_id, 'wine_id' => $this->wine_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'comment', $this->comment]); return $dataProvider; }
/** * 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]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'post_id' => $this->post_id, 'active' => $this->active, 'parent_id' => $this->parent_id, 'image_id' => $this->image_id, 'ip' => $this->ip]); $query->andFilterWhere(['like', 'text', $this->text])->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'agent', $this->agent]); return $dataProvider; }
/** * Bootstrap any application services. * * @return void */ public function boot() { Comments::created(function ($comment) { Event::fire(new CommentSentEvent($comment)); }); Messages::created(function ($message) { Event::fire(new MessageSentEvent($message)); }); User::updated(function ($user) { Event::fire(new ChangeRoleEvent($user)); }); User::created(function ($user) { Event::fire(new NewUserEvent($user)); }); }
/** * Handle the event. * * @param MakeCommentsEvent $event * @return void */ public function handle(MakeCommentsEvent $event) { $comment = $event->comment; $user = $comment->user->toArray(); $comments = Comments::with('user')->where('diary_id', $comment->diary_id)->groupBy('user_id')->get(); Mail::queue('email.new_comment_for_poster', ['comment' => $comment->toArray(), 'user' => $user], function ($m) use($user) { $m->to($user['email'], $user['name'])->subject("New Comment Was Posted On Your Post | nahid.co"); }); $comment = $comment->toArray(); foreach ($comments as $comnt) { $users = $comnt->user->toArray(); Mail::queue('email.new_comment', compact('comment', 'users'), function ($m) use($users) { $m->to($users['email'], $users['name'])->subject("New Comment Was Posted | nahid.co"); }); } }
/** * @param $id */ public static function delete($id) { $comment = Comments::findByPK($id); if (!Request::is_authenticated()) { Response::redirect(''); } else { if (Request::user()->id !== $comment['id_account'] and !Request::is_admin()) { Session::push('flash-message', 'You does not have permission to delete the other Member\'s post!'); Response::redirect(''); } } # perform the post deletion Comments::delete($id); # redirect to main page Response::redirect(''); }
/** * Добавление комментариев * @return string */ public function actionAddcomment() { $model = new Comments(); $model->body = Yii::$app->request->post('Comments')['body']; if (Yii::$app->getRequest()->getQueryParam('name')) { $model->name = Yii::$app->getRequest()->getQueryParam('name'); } if (Yii::$app->getRequest()->getQueryParam('body')) { $model->body = Yii::$app->getRequest()->getQueryParam('body'); } if (Yii::$app->getRequest()->getQueryParam('content_id')) { self::$content_id = $model->article_content_id = (int) Yii::$app->getRequest()->getQueryParam('content_id'); } $model->status = 'published'; if ($model->save(false)) { return "<script>\n if(\$.cookie('name')) \$('.field-comments-name').html( 'Привет, ' + \$.cookie('name'));\n\n </script><p style='color: green'>Ответ опубликован</p>"; } return "<p style='color: red'>Попробуйте ещё раз чуть позже</p>"; }
/** * Устанавливает коды стран отправителей исходя из IP адресов * @throws \Exception */ function actionIndex() { if (!extension_loaded('geoip')) { throw new \Exception(Console::ansiFormat('Расширение GeoIP недоступно')); } $comments = Comments::find()->where(['country_code' => null])->all(); $geoip = new GeoIP(); foreach ($comments as $item) { if (!$item->country_code) { $ip = long2ip($item->ip); try { $geoip->setHost($ip); $code = $geoip->getCountryCode(); $item->country_code = $code; $item->save(); echo Console::ansiFormat($item->id . ': ' . $ip . ' - ' . $code, [Console::FG_GREEN]) . PHP_EOL; } catch (\Exception $e) { echo Console::ansiFormat($item->id . ': ' . $ip . ' - ' . 'host не обнаружен!', [Console::FG_RED]) . PHP_EOL; } } } }