UserLogic.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * 用户操作逻辑
  4. * @author cp
  5. */
  6. class UserLogic extends BaseLogic {
  7. private $categorydao;
  8. private $articledao;
  9. function __construct() {
  10. Doo::loadModel ( 'CategoryDao' );
  11. Doo::loadModel ( 'ArticleDao' );
  12. $this->articledao = new ArticleDao ();
  13. $this->categorydao = new CategoryDao ();
  14. }
  15. /**
  16. * 获取首页显示信息
  17. */
  18. function get_category_info() {
  19. $restul = $this->categorydao->get_category_by_grade ( 1 );
  20. $i = 1;
  21. sort ( $restul );
  22. foreach ( $restul as $key => $value ) {
  23. $restul [$key] ['menu'] = $i;
  24. $rsort_c=$rsort_a=$rsortt = array ();
  25. $rsort_c = $this->categorydao->get_category_by_pid ( $value ['cid'] );
  26. $rsort_a = $this->articledao->get_article_by_cid ( $value ['cid'] );
  27. foreach ( $rsort_c as $keys => $valuess ) {
  28. $valuess ['type'] = "CATEGORY";
  29. array_push ( $rsortt, $valuess );
  30. }
  31. foreach ( $rsort_a as $keyss => $values ) {
  32. $values ['type'] = "ARTICLE";
  33. array_push ( $rsortt, $values );
  34. }
  35. sort ( $rsortt );
  36. $restul [$key] ['rsort'] = $rsortt;
  37. $restul [$key] ['child_category'] = $rsort_c;
  38. $restul [$key] ['article'] = $rsort_a;
  39. $i ++;
  40. }
  41. return $restul;
  42. }
  43. /**
  44. * 获取文章
  45. * @param unknown_type $aid
  46. */
  47. function get_article_by_aid($aid) {
  48. $restul = $this->articledao->get_article_by_aid ( $aid );
  49. return $restul;
  50. }
  51. /**
  52. * 根据id获取分类
  53. * @param unknown_type $cid
  54. */
  55. function get_category_by_cid($cid) {
  56. $restul = $this->categorydao->get_category_by_cid ( $cid );
  57. return $restul;
  58. }
  59. /**
  60. * 获取子类的所有信息
  61. * @param unknown_type $cid
  62. */
  63. function get_category_by_pid($cid) {
  64. $restul ['child_category'] = $this->categorydao->get_category_by_pid ( $cid );
  65. $restul ['article'] = $this->articledao->get_article_by_cid ( $cid );
  66. $sort = array ();
  67. foreach ( $restul ['child_category'] as $key => $value ) {
  68. $value ['type'] = "CATEGORY";
  69. array_push ( $sort, $value );
  70. }
  71. foreach ( $restul ['article'] as $key => $value ) {
  72. $value ['type'] = "ARTICLE";
  73. array_push ( $sort, $value );
  74. }
  75. sort ( $sort );
  76. $restul ['sort'] = $sort;
  77. $restul ['title'] = $this->categorydao->get_category_by_cid ( $cid );
  78. return $restul;
  79. }
  80. /**
  81. * 获取分类等级
  82. * @param unknown_type $grade
  83. */
  84. function get_category_by_grade($grade = 1) {
  85. $restul = $this->categorydao->get_category_by_grade ( $grade );
  86. foreach ( $restul as $key => $value ) {
  87. $restul [$key] ['category_lv2'] = $this->categorydao->get_category_by_grade ( 2 );
  88. }
  89. return $restul;
  90. }
  91. /**
  92. * 获取文章列表
  93. * @param unknown_type $data
  94. * @param unknown_type $condition
  95. * @param unknown_type $limit
  96. */
  97. function get_article_list($data = array(), $condition, $limit, $table) {
  98. $result = $this->get_list ( $data, $condition, $limit, $table );
  99. foreach ( $result as $key => $value ) {
  100. $result [$key] ['category'] = $this->categorydao->get_category_by_cid ( $value ['cid'] );
  101. }
  102. return $result;
  103. }
  104. /**
  105. * 添加文章
  106. * @param unknown_type $data
  107. */
  108. function add_article($data = array()) {
  109. $this->articledao->title = $data ['title'];
  110. $this->articledao->content = $data ['content'];
  111. $this->articledao->cid = $data ['cid'];
  112. $this->articledao->time = time ();
  113. $this->articledao->displayorder = $data ['order'];
  114. $id = $this->db ()->insert ( $this->articledao );
  115. return $id;
  116. }
  117. /**
  118. * 更新文章
  119. * @param unknown_type $data
  120. */
  121. function edit_article($data=array()){
  122. $this->articledao->aid=$data['aid'];
  123. $this->articledao->title = $data ['title'];
  124. $this->articledao->content = $data ['content'];
  125. if (!empty($data ['cid'])||empty($data ['cid'])!=0)
  126. $this->articledao->cid = $data ['cid'];
  127. $this->articledao->displayorder = $data ['order'];
  128. $this->db ()->update( $this->articledao );
  129. }
  130. /**
  131. * 添加分类
  132. * @param unknown_type $data
  133. */
  134. function add_categroy($data = array()) {
  135. $this->categorydao->name = $data ['name'];
  136. $this->categorydao->pid = $data ['pid'];
  137. $this->categorydao->grade = $data ['grade'];
  138. $this->categorydao->displayorder = $data ['displayorder'];
  139. $id = $this->db ()->insert ( $this->categorydao );
  140. return $id;
  141. }
  142. /**
  143. * 删除分类
  144. * @param unknown_type $cid
  145. */
  146. function delete_categroy($cid = 0) {
  147. $this->categorydao->cid = $cid;
  148. $this->db ()->delete ( $this->categorydao );
  149. }
  150. /**
  151. * 删除文章
  152. * @param unknown_type $aid
  153. */
  154. function delete_article($aid) {
  155. $this->articledao->aid = $aid;
  156. $this->db ()->delete ( $this->articledao );
  157. }
  158. }
  159. ?>