table_portal_article_content.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_portal_article_content.php 32272 2012-12-13 07:20:34Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_portal_article_content extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'portal_article_content';
  15. $this->_pk = 'cid';
  16. parent::__construct();
  17. }
  18. public function update_by_aid($aid, $data) {
  19. if(($aid = dintval($aid)) && !empty($data) && is_array($data)) {
  20. return DB::update($this->_table, $data, array('aid' => $aid));
  21. }
  22. return 0;
  23. }
  24. public function fetch_by_aid_page($aid, $page = 1) {
  25. if(($page = dintval($page))<1) $page = 1;
  26. return $aid ? DB::fetch_first('SELECT * FROM %t WHERE aid=%d ORDER BY pageorder'.DB::LIMIT($page-1, 1), array($this->_table, $aid)) : false;
  27. }
  28. public function fetch_all($aid) {
  29. return $aid ? DB::fetch_all('SELECT * FROM %t WHERE aid=%d ORDER BY pageorder', array($this->_table, $aid)) : array();
  30. }
  31. public function fetch_max_pageorder_by_aid($aid) {
  32. return $aid ? DB::result_first('SELECT MAX(pageorder) FROM %t WHERE aid=%d', array($this->_table, $aid)) : 0;
  33. }
  34. public function insert_batch($inserts) {
  35. $sql = array();
  36. foreach($inserts as $value) {
  37. $value['aid'] = dintval($value['aid']);
  38. $sql[] = "('$value[aid]', '".addslashes($value['content'])."', '$value[pageorder]', '$value[dateline]', '$value[id]', '$value[idtype]')";
  39. }
  40. if($sql) {
  41. DB::query('INSERT INTO '.DB::table($this->_table)."(`aid`, `content`, `pageorder`, `dateline`, `id`, `idtype`) VALUES ".implode(', ', $sql));
  42. }
  43. }
  44. public function count_by_aid($aid) {
  45. return $aid ? DB::result_first('SELECT COUNT(*) FROM %t WHERE aid=%d', array($this->_table, $aid)) : 0;
  46. }
  47. public function delete_by_aid($aid) {
  48. return dintval($aid, true) ? DB::delete($this->_table, DB::field('aid', $aid)) : 0;
  49. }
  50. }
  51. ?>