Comment.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. namespace We7\Table\Article;
  7. class Comment extends \We7Table {
  8. protected $tableName = 'article_comment';
  9. protected $primaryKey = 'id';
  10. protected $field = array(
  11. 'articleid',
  12. 'parentid',
  13. 'uid',
  14. 'content',
  15. 'is_like',
  16. 'is_reply',
  17. 'like_num',
  18. 'createtime',
  19. );
  20. protected $default = array(
  21. 'articleid' => '',
  22. 'parentid' => 0,
  23. 'uid' => '',
  24. 'content' => '',
  25. 'is_like' => 2,
  26. 'is_reply' => 2,
  27. 'like_num' => 0,
  28. 'createtime' => '',
  29. );
  30. public function addComment($comment) {
  31. if (!empty($comment['parentid'])) {
  32. $result = $this->where('id', $comment['parentid'])->fill('is_reply', 1)->save();
  33. if ($result === false) {
  34. return false;
  35. }
  36. }
  37. $comment['createtime'] = TIMESTAMP;
  38. $comment['is_like'] = 2;
  39. return $this->fill($comment)->save();
  40. }
  41. public function getCommentsByArticleid($articleid) {
  42. $comments = $this->where('articleid', $articleid)->where('parentid', 0)->where('is_like', 2)->getall('id');
  43. if (!empty($comments)) {
  44. foreach ($comments as $k => &$comment) {
  45. $comment['createtime'] = date('Y-m-d H:i', $comment['createtime']);
  46. }
  47. }
  48. return $comments;
  49. }
  50. public function getLikeComment($uid, $articleid, $comment_id) {
  51. return $this->where(array('articleid' => $articleid, 'parentid' => $comment_id, 'is_like' => 1, 'uid' => $uid))->get();
  52. }
  53. public function likeComment($uid, $articleid, $comment_id) {
  54. $like_num = $this->where('id', $comment_id)->getcolumn('like_num');
  55. $result = $this->where('id', $comment_id)->fill('like_num', $like_num + 1)->save();
  56. if ($result === false) {
  57. return false;
  58. }
  59. $this->fill(array(
  60. 'uid' => $uid,
  61. 'articleid' => $articleid,
  62. 'parentid' => $comment_id,
  63. 'is_like' => 1,
  64. 'is_reply' => 1,
  65. 'like_num' => 0,
  66. 'content' => '',
  67. 'createtime' => TIMESTAMP,
  68. ));
  69. return $this->save();
  70. }
  71. }