ArticleLike.class.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace Cas\Dao;
  3. use KIF\Dao\AbstractDao;
  4. use KIF\Verify;
  5. /**
  6. * 文章点赞
  7. * @author lishumingoo@gmail.com
  8. */
  9. class ArticleLike extends AbstractDao {
  10. protected $tableName = 'article_like';
  11. /**
  12. * 点赞
  13. * @param int $event_id
  14. * @param int $uid
  15. * @return boolean
  16. */
  17. public function like($event_id, $uid) {
  18. if (!Verify::unsignedInt($event_id)) {
  19. return false;
  20. }
  21. if (!Verify::unsignedInt($uid)) {
  22. return false;
  23. }
  24. $tableInfo = array(
  25. 'event_id' => $event_id,
  26. 'uid' => $uid,
  27. );
  28. $tmpResult = $this->create($tableInfo);
  29. if (!$tmpResult) {
  30. return false;
  31. }
  32. return true;
  33. }
  34. /**
  35. * 取消点赞
  36. * @param int $event_id
  37. * @param int $uid
  38. * @return boolean
  39. */
  40. public function cancalLike($event_id, $uid) {
  41. if (!Verify::unsignedInt($event_id)) {
  42. return false;
  43. }
  44. if (!Verify::unsignedInt($uid)) {
  45. return false;
  46. }
  47. $condition = array(
  48. 'event_id' => $event_id,
  49. 'uid' => $uid,
  50. );
  51. $tmpResult = $this->delete($condition);
  52. if (!$tmpResult) {
  53. return false;
  54. }
  55. return true;
  56. }
  57. /**
  58. * 是否已经喜欢
  59. * @param int $event_id
  60. * @param int $uid
  61. * @return boolean
  62. */
  63. public function isHasLike($event_id, $uid) {
  64. if (!Verify::unsignedInt($event_id)) {
  65. return false;
  66. }
  67. if (!Verify::unsignedInt($uid)) {
  68. return false;
  69. }
  70. $condition = array(
  71. 'event_id' => $event_id,
  72. 'uid' => $uid,
  73. );
  74. $tmpResult = $this->fetchOne($condition);
  75. if (!$tmpResult) {
  76. return false;
  77. }
  78. return true;
  79. }
  80. }