table_common_advertisement.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_common_advertisement.php 33658 2013-07-29 06:25:15Z nemohou $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_common_advertisement extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'common_advertisement';
  15. $this->_pk = 'advid';
  16. parent::__construct();
  17. }
  18. public function fetch_all_type() {
  19. return DB::fetch_all("SELECT type, COUNT(type) AS count FROM %t GROUP BY type", array($this->_table));
  20. }
  21. public function fetch_all_by_type($type) {
  22. return DB::fetch_all("SELECT * FROM %t WHERE type=%s", array($this->_table, $type));
  23. }
  24. public function fetch_all_old() {
  25. return DB::fetch_all("SELECT * FROM %t WHERE available>0 AND starttime<=%d ORDER BY displayorder", array($this->_table, TIMESTAMP));
  26. }
  27. public function close_endtime() {
  28. $return = DB::result_first("SELECT COUNT(*) FROM %t WHERE endtime>0 AND endtime<='".TIMESTAMP."'", array($this->_table));
  29. DB::update($this->_table, array('available' => 0), "endtime>0 AND endtime<='".TIMESTAMP."'", 'UNBUFFERED');
  30. return $return;
  31. }
  32. public function fetch_all_endtime($endtime) {
  33. return DB::fetch_all("SELECT * FROM %t WHERE endtime=%s", array($this->_table, $endtime));
  34. }
  35. private function _search_conditions($title, $starttime, $endtime, $type, $target) {
  36. $conditions = '';
  37. $conditions .= $title ? " AND ".DB::field('title', '%'.$title.'%', 'like') : '';
  38. $conditions .= $starttime > 0 ? " AND starttime>='".(TIMESTAMP - intval($starttime))."'" : ($starttime == -1 ? " AND starttime='0'" : '');
  39. $conditions .= $endtime > 0 ? " AND endtime>0 AND endtime<'".(TIMESTAMP + intval($endtime))."'" : ($endtime == -1 ? " AND endtime='0'" : '');
  40. $conditions .= $type ? " AND ".DB::field('type', $type) : '';
  41. $conditions .= $target ? " AND ".DB::field('targets', '%'.$target.'%', 'like') : '';
  42. return $conditions;
  43. }
  44. public function fetch_all_search($title, $starttime, $endtime, $type, $target, $orderby, $start_limit, $advppp) {
  45. $conditions = $this->_search_conditions($title, $starttime, $endtime, $type, $target);
  46. $order_by = $orderby == 'starttime' ? 'starttime' : ($orderby == 'type' ? 'type' : ($orderby == 'displayorder' ? 'displayorder' : 'advid DESC'));
  47. $start_limit = intval($start_limit);
  48. $advppp = intval($advppp);
  49. return DB::fetch_all("SELECT * FROM ".DB::table('common_advertisement')." WHERE 1 $conditions ORDER BY available DESC, $order_by LIMIT $start_limit, $advppp");
  50. }
  51. public function count_search($title, $starttime, $endtime, $type, $target) {
  52. $conditions = $this->_search_conditions($title, $starttime, $endtime, $type, $target);
  53. return DB::result_first("SELECT COUNT(*) FROM ".DB::table('common_advertisement')." WHERE 1 $conditions");
  54. }
  55. }
  56. ?>