Inheritance: extends Illuminate\Database\Eloquent\Model, implements Illuminate\Contracts\Auth\Authenticatable, use trait Illuminate\Auth\Authenticatable
示例#1
0
 public function actionView($id)
 {
     $note = Note::find()->where(['id' => $id])->with('comments')->with('user')->one();
     if (!$note) {
         throw new NotFoundHttpException();
     }
     if (Yii::$app->user->can('viewNote', ['note' => $note])) {
         $query = Note::find()->with('user');
         $previousNote = $query->where(['<=', 'created_at', $note->created_at])->andWhere(['<', 'id', $note->id])->andWhere(['visibility' => Note::VIS_PUBLIC_LISTED])->orderBy('created_at DESC, id DESC')->one();
         $nextNote = $query->where(['>=', 'created_at', $note->created_at])->andWhere(['>', 'id', $note->id])->andWhere(['visibility' => Note::VIS_PUBLIC_LISTED])->orderBy('created_at ASC, id ASC')->one();
         $comment = new Comment();
         if ($comment->load(Yii::$app->request->post()) && $comment->validate()) {
             $parentId = Yii::$app->request->post('parentId');
             if ($parentId !== null && CommentClosure::find()->where(['child_id' => $parentId])->max('depth') >= Yii::$app->params['maxCommentsDepth']) {
                 throw new ForbiddenHttpException();
             }
             $comment->user_id = Yii::$app->user->getId();
             $comment->note_id = $note->id;
             $comment->save(false);
             CommentClosure::insertComment($comment->id, $parentId);
             return $this->refresh();
         }
         return $this->render('view', ['note' => $note, 'previousNote' => $previousNote, 'nextNote' => $nextNote, 'comment' => $comment]);
     } else {
         throw new ForbiddenHttpException();
     }
 }
 /**
  * Displays a single Journal model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     //var_dump($notify); die();
     $searchModel = new JournalSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $model = $this->findModel($id);
     $comment = new Comment();
     $comment->user_id = \Yii::$app->user->id;
     $commentProvider = new ActiveDataProvider(['query' => Comment::find()->where(['journal_id' => $id])]);
     Yii::$app->notification->viewer($id);
     if ($comment->load(Yii::$app->request->post())) {
         $comment->journal_id = $id;
         $comment->time = date('Y-m-d H:i:s');
         if ($comment->save()) {
             Yii::$app->notification->notify($model->entry, $model, $comment->user, 'comment', $model->shared_with . ',' . $model->user_id);
             Yii::$app->session->setFlash('success', 'Comment posted successfully.');
             return Yii::$app->getResponse()->redirect(array('/journal/view/' . $model->id));
         } else {
             exit;
         }
     } else {
         if (Yii::$app->request->isAjax) {
             return $this->renderAjax('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]);
         } else {
             return $this->render('view', ['model' => $model, 'comment' => $comment, 'dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'commentProvider' => $commentProvider]);
         }
     }
 }
示例#3
0
 /**
  * Displays a single Post model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $page_size = 10;
     $model = new Comment();
     $pages = new Pagination(['totalCount' => $model->find()->where(['post_id' => $id])->count(), 'pageSize' => $page_size]);
     $dataProvider = new ActiveDataProvider(['query' => $model->find()->where(['post_id' => $id]), 'pagination' => ['pagesize' => $page_size]]);
     return $this->render('view', ['data' => $dataProvider, 'model' => $this->findModel($id), 'left_btn' => 'home', 'pages' => $pages]);
 }
示例#4
0
 public function actionDel($id)
 {
     $model = new Comment();
     $cond = ['or', ['id' => $id], ['pid' => $id]];
     $model->deleteAll($cond);
     // Yii::$app->request->referrer;
     return $this->redirect(Yii::$app->request->referrer);
 }
示例#5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function addComment($tour_id)
 {
     $comment = new Comment();
     $comment->id_tour = $tour_id;
     $comment->id_user = Yii::$app->user->id;
     $comment->comment = $this->comment;
     $comment->date = date('Y-m-d h:m:s');
     $comment->save(false);
 }
示例#6
0
 public function actionComment()
 {
     if (Yii::$app->request->isPost) {
         $comment = new Comment();
         if ($comment->addComment()) {
             $this->redirect(Yii::$app->request->referrer);
         }
     }
 }
示例#7
0
 public function binhluan(BinhLuanRequest $request, $id, $xe_id)
 {
     $binhluan = new Comment();
     $binhluan->xe_id = $xe_id;
     $binhluan->nguoidung_id = $id;
     $binhluan->noidung = $request->txtbinhluan;
     $binhluan->save();
     return redirect()->route('chitietsp', $xe_id);
 }
示例#8
0
 public function actionDetail()
 {
     $id = Yii::$app->request->get('id');
     $article = new Article();
     $detail = $article->getDetail($id);
     $comment = new Comment();
     $comments = $comment->getComments($id);
     $visitor = new Visitor();
     echo $this->render('detail', ['detail' => $detail, 'comments' => $comments, 'visitor' => $visitor]);
 }
示例#9
0
 /**
  * Catches and runs operations when a comment is deleted.
  *
  * @param Comment $comment
  */
 public function deleting(Comment $comment)
 {
     // Make sure the model isn't soft deleted.
     if (!$comment->deleted_at) {
         $files = $comment->files()->get();
         foreach ($files as $file) {
             $file->delete();
         }
     }
 }
 /**
  * Seeds the table.
  *
  * @return void
  */
 public function run()
 {
     /** @var Post $post */
     $post = Post::firstOrFail();
     $comment = new Comment();
     $comment->body = 'First!';
     $comment->post_id = $post->id;
     $comment->save();
     $comment = new Comment();
     $comment->body = 'I like XML better';
     $comment->post_id = $post->id;
     $comment->save();
 }
示例#11
0
 public function actionCreate()
 {
     $data = $_POST['data'];
     $time = time();
     $data['create_at'] = $time;
     $data['user_id'] = User::getCurrentId();
     $comment = new Comment();
     $comment->attributes = $data;
     $post = new Post();
     $post->updateAll(['reply_at' => $time, 'last_reply_id' => $data['user_id']], 'id=:id', [':id' => $data['post_id']]);
     $comment->save();
     $this->redirect(array('/post/view', 'id' => $data['post_id']));
 }
示例#12
0
 public function create()
 {
     $newcomment = new Comment($_POST);
     // $newcomment['user_id'] = static::$auth->user()->id;
     if (!$newcomment->isValid()) {
         $_SESSION['comment.form'] = $newcomment;
         header("Location:.\\?page=recipe&id=" . $newcomment->id);
         exit;
     }
     $newcomment->save();
     echo 'here';
     header("Location:.\\?page=recipe&id=" . $newcomment->id . "#comment-" . $newcomment->id);
 }
 public function create()
 {
     $input = $_POST;
     $input['user_id'] = static::$auth->user()->id;
     $newcomment = new Comment($input);
     if (!$newcomment->isValid()) {
         // echo "here";
         $_SESSION['comment.form'] = $newcomment;
         header("Location:.\\?page=movie&id=" . $newcomment->movie_id);
         exit;
     }
     $newcomment->save();
     header("Location: ./?page=movie&id=" . $newcomment->movie_id . "#comment-" . $newcomment->id);
 }
示例#14
0
 public function actionComments($username)
 {
     $user = $this->findUserModel($username, ['userInfo']);
     $pages = new Pagination(['totalCount' => $user['userInfo']['comment_count'], 'pageSize' => $this->settings['list_pagesize'], 'pageParam' => 'p']);
     $comments = Comment::find()->select(['id', 'created_at', 'topic_id', 'content'])->where(['user_id' => $user['id']])->orderBy(['id' => SORT_DESC])->offset($pages->offset)->with(['topic.author'])->limit($pages->limit)->asArray()->all();
     return $this->render('comments', ['user' => $user, 'comments' => $comments, 'pages' => $pages]);
 }
示例#15
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Comment::find()->select('comment.*, video.title, user.username')->innerJoin('video', '`video`.`id` = `comment`.`video_id`')->innerJoin('user', '`user`.`id` = `comment`.`user_id`');
     // echo $query->createCommand()->sql;exit;
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => Yii::$app->params['pageSize']]]);
     /**
      * Setup your sorting attributes
      * Note: This is setup before the $this->load($params) 
      * statement below
      */
     $dataProvider->setSort(['attributes' => ['id', 'text' => ['asc' => ['comment.text' => SORT_ASC], 'desc' => ['comment.text' => SORT_DESC]], 'videoTitle' => ['asc' => ['video.title' => SORT_ASC], 'desc' => ['video.title' => SORT_DESC]], 'username' => ['asc' => ['user.username' => SORT_ASC], 'desc' => ['user.username' => SORT_DESC]], 'created_at' => ['asc' => ['comment.created_at' => SORT_ASC], 'desc' => ['comment.created_at' => SORT_DESC]]]]);
     $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;
     }
     /* ---------------------------------------------------------------------/
      * Filter
      * --------------------------------------------------------------------- */
     $query->andFilterWhere(['comment.id' => $this->id, 'comment.video_id' => $this->video_id, 'comment.user_id' => $this->user_id, 'comment.created_at' => $this->created_at, 'comment.modified_at' => $this->modified_at]);
     $query->andFilterWhere(['like', 'text', $this->text]);
     /**
      * for related column
      */
     $query->andFilterWhere(['like', 'video.title', $this->videoTitle]);
     $query->andFilterWhere(['like', 'user.username', $this->username]);
     return $dataProvider;
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $forum, $thread, $id)
 {
     $comment = Comment::find($id);
     $this->authorize('update', $comment);
     $comment->update($request->all());
     return redirect(route('intern.discuss.threads.show', [$comment->thread->forum->slug, $comment->thread->slug]));
 }
示例#17
0
 public function postSaveComment(Request $request)
 {
     $comment_name = $request->get("comment_name");
     $comment_email = $request->get("comment_email");
     $comment_content = $request->get("comment_content");
     $blog_id = $request->get("blog_id");
     $comment = new Comment();
     $comment->comment_name = $comment_name;
     $comment->comment_email = $comment_email;
     $comment->comment_content = $comment_content;
     $comment->comment_create = date("Y/m/d");
     $comment->comment_blogs_id = $blog_id;
     $comment->save();
     $message = "Saved";
     return redirect('/news/detail/' . $blog_id)->withMessage($message);
 }
示例#18
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     //
     $comment = Comment::find($id);
     $comment->delete();
     return Redirect::to('admin/comments');
 }
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'comment' => 'required', 'post_id' => 'required']);
     $input = $request->all();
     Comment::create($input);
     return redirect()->back();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('comments')->delete();
     Comment::create(array('author' => 'Chris Sevilleja', 'text' => 'Look I am a test comment.'));
     Comment::create(array('author' => 'Nick Cerminara', 'text' => 'This is going to be super crazy.'));
     Comment::create(array('author' => 'Holly Lloyd', 'text' => 'I am a master of Laravel and Angular.'));
 }
示例#21
0
文件: view.php 项目: irying/artist
function showAllComment($aid, $pid = 0, $lastId = 0)
{
    $list = Comment::find()->where(['article_id' => $aid, 'pid' => $pid])->asArray()->orderBy('created_at DESC')->all();
    $len = count($list) - 1;
    if ($len < 0) {
        return;
    } else {
        while (isset($list[$len])) {
            $id = $list[$len]['id'];
            $uid = $list[$len]['user_id'];
            $username = $list[$len]['username'];
            $content = $list[$len]['content'];
            $comment_time = $list[$len]['created_at'];
            $GLOBALS['arr'][0] .= 'aCommentList.push(' . $id . ');' . "\n";
            $styleClass = $pid == 0 ? 'comment' : 'comment sub';
            $GLOBALS['arr'][1] .= '<div class="' . $styleClass . '" id="comment_id_' . $id . '">';
            $GLOBALS['arr'][1] .= '<div class=control><span>删除</span> <span>回复</span></div>';
            if ($lastId != 0) {
                $replyTo = '回复';
                $last_uid = Comment::find()->where(['user_id' => $pid])->one()->pid;
                $last_name = Comment::find()->where(['user_id' => $pid])->one()->username;
                $replyTo .= '<a href="user.php?uid=' . $last_uid . '">' . $last_name . '</a> ';
            } else {
                $replyTo = '';
            }
            $GLOBALS['arr'][1] .= '<p>[#' . $id . '楼]<a href="usr.php?uid=' . $uid . '">' . $username . '</a>' . $replyTo . date('Y-m-d H:i:s', $comment_time);
            $GLOBALS['arr'][1] .= ':</p>';
            $GLOBALS['arr'][1] .= $content;
            $GLOBALS['arr'][1] .= '</div>' . "\n\n";
            showAllComment(1, $id, $id);
            $len--;
        }
    }
}
示例#22
0
 public function show($slug)
 {
     $article = Content::article()->active()->published()->where('slug', $slug)->firstOrFail();
     $comments = Comment::where('content_id', $article['id'])->active()->paginate(10);
     $pageTitle = $article['title'];
     return view('frontend.articles.show', compact('article', 'comments', 'pageTitle'));
 }
示例#23
0
 /**
  * Displays a post detail.
  * @param integer $id
  * @return mixed
  */
 public function actionDetail($id)
 {
     $postModel = new Comment();
     if ($postModel->load(Yii::$app->request->post())) {
         $postModel->status = Comment::STATUS_PENDING;
         $postModel->post_id = $id;
         if ($postModel->save()) {
             $this->added = 1;
         }
     }
     $tags = Tag::findTagWeights(Yii::$app->params['tagCloudCount']);
     $commentModel = new Comment();
     $commentDataProvider = $commentModel->findRecentComments(Yii::$app->params['recentCommentCount']);
     //Yii::$app->params['recentCommentCount']
     return $this->render('detail', ['model' => $this->findModel($id), 'commentDataProvider' => $commentDataProvider, 'tags' => $tags, 'postModel' => $postModel, 'added' => $this->added]);
 }
示例#24
0
 /**
  * Displays a single Items model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $commentsData = comment::getComments($id);
     $model = $this->findModel($id);
     $newComment = new Comment();
     $addToBasket = new basket();
     $description = new Description();
     $description->find()->where(['item_id' => $id])->all();
     $itemRating = ItemsRating::findOne($id);
     if ($model->count == 0) {
         Yii::$app->db->createCommand(" UPDATE `items` SET items.is_aviable=0 WHERE items.id =" . $id)->execute();
     } else {
         if (!Yii::$app->user->isGuest) {
             $uid = Yii::$app->user->identity->getId();
             $get_user = \dektrium\user\models\User::getUser($uid)->getModels()[0]['username'];
             if (isset($_POST['Comment'])) {
                 //            print_r($_POST['Comment']['text']);
                 $newComment = new Comment();
                 $newComment->author = $get_user;
                 $newComment->item_id = $id;
                 $newComment->user_id = $uid;
                 $newComment->date = date("Y-m-d h:i:s");
                 $newComment->text = $_POST['Comment']['text'];
                 $newComment->save();
             }
             if (isset($_POST['Basket'])) {
                 if ($model->is_aviable) {
                     if ($_POST['Basket']['count'] <= $model->count) {
                         $addToBasket = new Basket();
                         $have = $addToBasket->find()->where(['item_id' => $id, 'user_id' => $uid])->all();
                         if (!$have) {
                             $addToBasket->item_id = $id;
                             $addToBasket->user_id = $uid;
                             $addToBasket->name = $model->name;
                             $addToBasket->price = $model->price;
                             $addToBasket->count = $_POST['Basket']['count'];
                             $addToBasket->sum = $model->price * $_POST['Basket']['count'];
                             $addToBasket->save();
                         }
                     }
                 }
                 return $this->redirect(['view', 'id' => $id]);
             }
         }
     }
     return $this->render('view', ['model' => $model, 'commentsData' => $commentsData, 'newComment' => $newComment, 'itemRating' => $itemRating, 'addToBasket' => $addToBasket, 'description' => $description]);
 }
示例#25
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 string $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.');
     }
 }
示例#26
0
 public function index()
 {
     //		$controls = $this->controls();
     //        $airports = Destination::where('type','airport')->get();
     //        $ports    = Destination::where('type','port')->get();
     $comments = Comment::valid();
     return view('pages.home')->with(compact('comments'));
 }
示例#27
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $data = $request->all();
     $data['user_id'] = \Auth::user()->id;
     $comment = \App\Models\Comment::create($data);
     $comment->save();
     return redirect('posts/' . $comment->post->id);
 }
 /**
  * Test samples for all models have been seeded.
  */
 public function testModelSeed()
 {
     $message = 'Haven\'t you forgotten to run artisan migrate and db::seed?';
     $this->assertNotEmpty(Author::all(), $message);
     $this->assertNotEmpty(Comment::all(), $message);
     $this->assertNotEmpty(Post::all(), $message);
     $this->assertNotEmpty(Site::all(), $message);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Comment::truncate();
     $faker = \Faker\Factory::create('zh_TW');
     foreach (range(1, 30) as $number) {
         Comment::create(['name' => $faker->name, 'email' => $faker->email, 'content' => $faker->paragraph, 'post_id' => rand(1, 15)]);
     }
 }
示例#30
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['nickname' => 'required|max:30', 'content' => 'required|max:255', 'articleid' => 'required|numeric', 'email' => 'required']);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $comment = new Comment();
     $comment->nickname = $request->input('nickname');
     $comment->content = $request->input('content');
     $comment->email = $request->input('email');
     $comment->articleid = $request->input('articleid');
     if ($comment->save()) {
         return Redirect::back();
     } else {
         return Redirect::back()->withInput()->withErrors('评论发表失败!');
     }
 }