table_portal_article_related.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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_related.php 27833 2012-02-15 08:04:51Z zhangguosheng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class table_portal_article_related extends discuz_table
  12. {
  13. public function __construct() {
  14. $this->_table = 'portal_article_related';
  15. $this->_pk = 'aid';
  16. parent::__construct();
  17. }
  18. public function delete_by_aid_raid($aid, $raid = null) {
  19. return ($aid = dintval($aid, true)) ? DB::delete($this->_table, DB::field('aid', $aid).($raid = dintval($raid) ? ' OR '.DB::field('raid', $raid) : '')) : false;
  20. }
  21. public function insert_batch($aid, $list) {
  22. $replaces = array();
  23. if(($aid = dintval($aid))) {
  24. $displayorder = 0;
  25. unset($list[$aid]);
  26. foreach($list as $value) {
  27. if(($value['aid'] = dintval($value['aid']))) {
  28. $replaces[] = "('$aid', '$value[aid]', '$displayorder')";
  29. $replaces[] = "('$value[aid]', '$aid', '0')";
  30. $displayorder++;
  31. }
  32. }
  33. }
  34. if($replaces) {
  35. DB::query('REPLACE INTO '.DB::table($this->_table).' (aid,raid,displayorder) VALUES '.implode(',', $replaces));
  36. }
  37. }
  38. public function fetch_all_by_aid($aid) {
  39. return ($aid = dintval($aid)) ? DB::fetch_all('SELECT * FROM %t WHERE aid=%d ORDER BY displayorder', array($this->_table, $aid), 'raid') : array();
  40. }
  41. }
  42. ?>