public function AddCommentAction() { $request = Project::getRequest(); $item_name = $request->item_name; $comment_model = new CommentModel($item_name . '_comment', $item_name . '_id', 0); switch ($item_name) { case 'article': $item_model = new ArticleModel(); break; case 'questions': $item_model = new QuestionModel(); break; case 'photo': $item_model = new PhotoModel(); break; case 'bookmarks': $item_model = new BookmarksModel(); break; case 'social': $item_model = new SocialModel(); break; case 'blog': $item_model = new BlogModel('blog_post'); break; } $item_model->load($request->element_id); if ($item_model->id > 0 && $request->add_comment) { $comment_model->addComment(Project::getUser()->getDbUser()->id, $request->avatar_id, 0, $request->element_id, $request->comment, $request->mood_id, $request->mood_text, 0); $item_model->comments++; $item_model->save(); } Project::getResponse()->redirect($request->createUrl($request->cur_controller, $request->cur_action, array($request->element_id))); }
public function comment() { if (!empty($_POST)) { $_POST['userId'] = $_SESSION['qq']['userId']; $arr = $_POST; $comment = new CommentModel(); $row = $comment->addComment($_POST); if ($row) { $user = new UserModel(); $arr['addTime'] = data('Y-m-d H:i:s'); $user = $user->getUser($_POST['userId']); $arr['face'] = $user['face']; $arr['userName'] = $user['userName']; echo json_encode($arr); } else { exit('发表失败'); } } }
/** * 添加评论 * post: blog_id, content */ public function postComment() { if (!$this->hasLoginCheck()) { return; } $blog_id = $_POST['blog_id']; $content = $_POST['content']; $user_id = session('user_id'); $commentModel = new CommentModel(); $commentModel->addComment($blog_id, $content); $userModel = M('user'); $comment_user = $userModel->find($user_id); $comment = array('user_name' => $comment_user['name'], 'user_id' => $comment_user['id'], 'user_homepage' => $this->conf['APP_ROOT'] . 'Home/userblog/user_id/' . $comment_user['id'], 'user_head_picpath' => $comment_user['head_pic_path'], 'user_comment' => $content); $li_html = $this->tpl->getSingleCommentLi($comment, $commentModel->getSomeBlogCommentCount($blog_id)); echo json_encode(array('status' => 'true', 'li_html' => $li_html)); }
public function addalbumComment() { if (!$_SESSION['qq']) { $result['code'] = '021'; $result['message'] = '未登录,请登录账号!'; } else { //实例化model $commentModel = new CommentModel(); $albumModel = new AlbumModel(); $albumId = $_GET['albumId']; $content = $_GET['comment']; //根据相册id查询相册信息 $albumInfo = $albumModel->getAlbumById($albumId); $data = array('userId' => $_SESSION['qq']['userId'], 'albumId' => $albumId, 'content' => $content, 'adminId' => $albumInfo['adminId']); $commentId = $commentModel->addComment($data); if ($commentId) { $commentInfo = $commentModel->getCommentById($commentId); $result['code'] = '0'; $result['message'] = '恭喜,评论成功!'; $result['info'] = $commentInfo; } else { $result['code'] = '022'; $result['message'] = '抱歉,评论失败!'; } } echo json_encode($result); exit; }
public function testAddCommentFail() { $userTable = new UserModel(); $moodTable = new MoodListModel(); $commentTable = new CommentModel(); $findUser['phone'] = '333333'; $user = $userTable->where($findUser)->find(); $findMood['content'] = '我是王五'; $ret = $commentTable->addComment($user['id'], $mood['id'], ''); $this->assertTrue($ret === false && $commentTable->getError() == '内容不能为空'); }
public function addAlbumComment() { if (!$_SESSION['qq']) { $result['code'] = "021"; $result['message'] = "未登录,请登录账号!"; } else { $_POST['content'] = Data::filter($_POST['content'], 9); $_POST['albumId'] = Data::get($_POST['albumId'], Data::Int); $_POST['adminId'] = Data::get($_POST['adminId'], Data::Int); $_POST['userId'] = Data::get($_POST['userId'], Data::Int); $comment = new CommentModel(); $row = $comment->addComment($_POST); if ($row) { $comments = $comment->getCommentById($row); $result['info'] = $comments; $result['code'] = "0"; $result['message'] = "恭喜,评论成功!"; } else { $result['code'] = "022"; $result['message'] = "评论失败"; } } echo json_encode($result); exit; }