table_home_pic.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: table_home_pic.php 31180 2012-07-24 03:51:03Z chenmengshu $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_home_pic extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'home_pic';
  15. $this->_pk = 'picid';
  16. parent::__construct();
  17. }
  18. public function update_click($picid, $clickid, $incclick) {
  19. $clickid = intval($clickid);
  20. if($clickid < 1 || $clickid > 8 || empty($picid) || empty($incclick)) {
  21. return false;
  22. }
  23. return DB::query('UPDATE %t SET click'.$clickid.' = click'.$clickid.'+\'%d\' WHERE picid = %d', array($this->_table, $incclick, $picid));
  24. }
  25. public function update_hot($picid, $num = 1) {
  26. return DB::query('UPDATE %t SET hot=hot+\'%d\' WHERE picid=%d', array($this->_table, $num, $picid));
  27. }
  28. public function update_sharetimes($picid, $num = 1) {
  29. return DB::query('UPDATE %t SET sharetimes=sharetimes+\'%d\' WHERE picid=%d', array($this->_table, $num, $picid));
  30. }
  31. public function fetch_all_by_uid($uids, $start = 0, $limit = 0, $picids = 0) {
  32. if(empty($uids)) {
  33. return array();
  34. }
  35. $picidsql = $picids ? DB::field('picid', $picids).' AND ' : '';
  36. return DB::fetch_all("SELECT * FROM %t WHERE $picidsql ".DB::field('uid', $uids).DB::limit($start, $limit), array($this->_table));
  37. }
  38. public function update_for_uid($uids, $picids, $data) {
  39. if(!empty($data) && is_array($data)) {
  40. return DB::update($this->_table, $data, DB::field('picid', $picids).' AND '.DB::field('uid', $uids));
  41. }
  42. return 0;
  43. }
  44. public function fetch_all_by_albumid($albumids, $start = 0, $limit = 0, $picids = 0, $orderbypicid = 0, $orderbydateline = 0, $uid = 0, $count = false) {
  45. $albumids = $albumids < 0 ? 0 : $albumids;
  46. $picidsql = $picids ? DB::field('picid', $picids).' AND ' : '';
  47. if($orderbypicid) {
  48. $ordersql = 'ORDER BY picid DESC ';
  49. } elseif($orderbydateline) {
  50. $ordersql = 'ORDER BY dateline DESC ';
  51. }
  52. $uidsql = $uid ? ' AND '.DB::field('uid', $uid) : '';
  53. if ($count) {
  54. return DB::result_first("SELECT COUNT(*) FROM %t WHERE $picidsql ".DB::field('albumid', $albumids)." $uidsql", array($this->_table));
  55. } else {
  56. return DB::fetch_all("SELECT * FROM %t WHERE $picidsql ".DB::field('albumid', $albumids)." $uidsql $ordersql".DB::limit($start, $limit), array($this->_table));
  57. }
  58. }
  59. public function update_for_albumid($albumid, $data) {
  60. if(!empty($data) && is_array($data)) {
  61. return DB::update($this->_table, $data, DB::field('albumid', $albumid));
  62. }
  63. return 0;
  64. }
  65. public function delete_by_uid($uids) {
  66. return DB::query("DELETE FROM %t WHERE ".DB::field('uid', $uids), array($this->_table));
  67. }
  68. public function delete_by_albumid($albumids) {
  69. return DB::query("DELETE FROM %t WHERE ".DB::field('albumid', $albumids), array($this->_table));
  70. }
  71. public function fetch_all_by_sql($where = '1', $orderby = '', $start = 0, $limit = 0, $count = 0, $joinalbum = 1) {
  72. if(!$where) {
  73. $where = '1';
  74. }
  75. if($count) {
  76. return DB::result_first("SELECT count(*) FROM ".DB::table($this->_table)." p WHERE %i", array($where));
  77. }
  78. return DB::fetch_all("SELECT ".($joinalbum ? 'a.*, ' : '')."p.* FROM ".DB::table($this->_table)." p ".($joinalbum ? "LEFT JOIN ".DB::table('home_album')." a USING(albumid)" : '')." WHERE %i ".($orderby ? "ORDER BY $orderby " : '').DB::limit($start, $limit), array($where));
  79. }
  80. public function fetch_albumpic($albumid, $uid) {
  81. return DB::fetch_first("SELECT filepath, thumb FROM %t WHERE albumid=%d AND uid=%d ORDER BY thumb DESC, dateline DESC LIMIT 0,1", array($this->_table, $albumid, $uid));
  82. }
  83. public function check_albumpic($albumid, $status = NULL, $uid = 0) {
  84. $sql = is_numeric($albumid) ? DB::field('albumid', $albumid) : '';
  85. $sql .= $uid ? ($sql ? ' AND ' : '').DB::field('uid', $uid) : '';
  86. $sql .= $status === NULL ? '' : ($sql ? ' AND ' : '').DB::field('status', $status);
  87. return DB::result_first("SELECT COUNT(*) FROM %t WHERE $sql", array($this->_table));
  88. }
  89. public function count_size_by_uid($uid) {
  90. return DB::result_first("SELECT SUM(size) FROM %t WHERE uid=%d", array($this->_table, $uid));
  91. }
  92. public function fetch_by_id_idtype($id) {
  93. if(!$id) {
  94. return false;
  95. }
  96. return DB::fetch_first('SELECT * FROM %t WHERE %i', array($this->_table, DB::field('picid', $id)));
  97. }
  98. public function update_dateline_by_id_idtype_uid($id, $idtype, $dateline, $uid) {
  99. if(empty($id) || empty($idtype) || empty($dateline) || empty($uid)) {
  100. return false;
  101. }
  102. return DB::update($this->_table, array('dateline' => intval($dateline)), array($idtype => intval($id), 'uid' => intval($uid)));
  103. }
  104. }
  105. ?>