CategoryDao.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. class CategoryDao {
  3. public $id;
  4. public $name;
  5. public $dir;
  6. public $pid;
  7. public $grade;
  8. public $displayorder;
  9. public $questions;
  10. public $_table = t_category;
  11. public $_primarykey = "id";
  12. public $_fields = array ('id', 'name', 'dir', 'pid', 'grade', 'displayorder', 'questions' );
  13. /**
  14. * 获取擅长分类信息
  15. * @param unknown_type $cids
  16. */
  17. function get_expert_category_list($cids = "") {
  18. $sql = "select * from " . t_category . " where id in (" . $cids . ")";
  19. $query = Doo::db ()->query ( $sql );
  20. $result = $query->fetchAll ();
  21. return $result;
  22. }
  23. /**
  24. * 获取分类信息
  25. * @param unknown_type $data
  26. * @param unknown_type $condition
  27. * @param unknown_type $limit
  28. */
  29. function get_category_list($data = array(), $condition = "", $limit = "") {
  30. foreach ( $data as $key => $value ) {
  31. if (is_numeric ( $value ))
  32. $condition .= " and " . $key . " = " . $value;
  33. else
  34. $condition .= " and " . $key . " like '%" . $value . "%' ";
  35. }
  36. $condition = ' where 1 ' . $condition . $limit;
  37. $sql = "select * from " . t_category . $condition;
  38. $query = Doo::db ()->query ( $sql );
  39. $result = $query->fetchAll ();
  40. return $result;
  41. }
  42. /**
  43. * 批量删除分类和分类下的问题
  44. * @param unknown_type $id
  45. */
  46. function delete_category_list($id = array()) {
  47. $id = implode ( ",", $id );
  48. $sql = "delete from " . t_category . " where id in ( " . $id . " )";
  49. Doo::db ()->query ( $sql );
  50. $sql="delete ".t_question.",".t_answer." from ".t_question." left join ".t_answer." on (".t_question.".id=".t_answer.".qid) where ".t_question.".cid in (".$id.")";
  51. Doo::db ()->query ( $sql );
  52. }
  53. /**
  54. * 获取分类 根据ID
  55. * @param unknown_type $id
  56. */
  57. function get_category_by_id ( $id=0 ){
  58. $sql = "select * from " . t_category . " where id=".$id;
  59. $query = Doo::db ()->query ( $sql );
  60. $result = $query->fetch ();
  61. return $result;
  62. }
  63. }
  64. ?>