| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- /**
- * 用户操作逻辑
- * @author cp
- */
- class UserLogic extends BaseLogic {
-
- private $categorydao;
- private $articledao;
-
- function __construct() {
-
- Doo::loadModel ( 'CategoryDao' );
- Doo::loadModel ( 'ArticleDao' );
-
- $this->articledao = new ArticleDao ();
- $this->categorydao = new CategoryDao ();
-
- }
-
- /**
- * 获取首页显示信息
- */
- function get_category_info() {
- $restul = $this->categorydao->get_category_by_grade ( 1 );
- $i = 1;
- sort ( $restul );
-
- foreach ( $restul as $key => $value ) {
- $restul [$key] ['menu'] = $i;
- $rsort_c=$rsort_a=$rsortt = array ();
- $rsort_c = $this->categorydao->get_category_by_pid ( $value ['cid'] );
- $rsort_a = $this->articledao->get_article_by_cid ( $value ['cid'] );
-
- foreach ( $rsort_c as $keys => $valuess ) {
- $valuess ['type'] = "CATEGORY";
- array_push ( $rsortt, $valuess );
- }
-
- foreach ( $rsort_a as $keyss => $values ) {
- $values ['type'] = "ARTICLE";
- array_push ( $rsortt, $values );
- }
-
- sort ( $rsortt );
- $restul [$key] ['rsort'] = $rsortt;
- $restul [$key] ['child_category'] = $rsort_c;
- $restul [$key] ['article'] = $rsort_a;
- $i ++;
- }
-
- return $restul;
- }
-
- /**
- * 获取文章
- * @param unknown_type $aid
- */
- function get_article_by_aid($aid) {
- $restul = $this->articledao->get_article_by_aid ( $aid );
- return $restul;
- }
-
- /**
- * 根据id获取分类
- * @param unknown_type $cid
- */
- function get_category_by_cid($cid) {
- $restul = $this->categorydao->get_category_by_cid ( $cid );
- return $restul;
- }
-
- /**
- * 获取子类的所有信息
- * @param unknown_type $cid
- */
- function get_category_by_pid($cid) {
- $restul ['child_category'] = $this->categorydao->get_category_by_pid ( $cid );
- $restul ['article'] = $this->articledao->get_article_by_cid ( $cid );
- $sort = array ();
-
- foreach ( $restul ['child_category'] as $key => $value ) {
- $value ['type'] = "CATEGORY";
- array_push ( $sort, $value );
- }
-
- foreach ( $restul ['article'] as $key => $value ) {
- $value ['type'] = "ARTICLE";
- array_push ( $sort, $value );
- }
-
- sort ( $sort );
- $restul ['sort'] = $sort;
- $restul ['title'] = $this->categorydao->get_category_by_cid ( $cid );
- return $restul;
- }
-
- /**
- * 获取分类等级
- * @param unknown_type $grade
- */
- function get_category_by_grade($grade = 1) {
- $restul = $this->categorydao->get_category_by_grade ( $grade );
-
- foreach ( $restul as $key => $value ) {
- $restul [$key] ['category_lv2'] = $this->categorydao->get_category_by_grade ( 2 );
- }
-
- return $restul;
- }
-
- /**
- * 获取文章列表
- * @param unknown_type $data
- * @param unknown_type $condition
- * @param unknown_type $limit
- */
- function get_article_list($data = array(), $condition, $limit, $table) {
- $result = $this->get_list ( $data, $condition, $limit, $table );
- foreach ( $result as $key => $value ) {
- $result [$key] ['category'] = $this->categorydao->get_category_by_cid ( $value ['cid'] );
- }
- return $result;
- }
-
- /**
- * 添加文章
- * @param unknown_type $data
- */
- function add_article($data = array()) {
- $this->articledao->title = $data ['title'];
- $this->articledao->content = $data ['content'];
- $this->articledao->cid = $data ['cid'];
- $this->articledao->time = time ();
- $this->articledao->displayorder = $data ['order'];
- $id = $this->db ()->insert ( $this->articledao );
-
- return $id;
- }
-
- /**
- * 更新文章
- * @param unknown_type $data
- */
- function edit_article($data=array()){
- $this->articledao->aid=$data['aid'];
- $this->articledao->title = $data ['title'];
- $this->articledao->content = $data ['content'];
-
- if (!empty($data ['cid'])||empty($data ['cid'])!=0)
- $this->articledao->cid = $data ['cid'];
- $this->articledao->displayorder = $data ['order'];
- $this->db ()->update( $this->articledao );
- }
-
- /**
- * 添加分类
- * @param unknown_type $data
- */
- function add_categroy($data = array()) {
- $this->categorydao->name = $data ['name'];
- $this->categorydao->pid = $data ['pid'];
- $this->categorydao->grade = $data ['grade'];
- $this->categorydao->displayorder = $data ['displayorder'];
- $id = $this->db ()->insert ( $this->categorydao );
-
- return $id;
- }
-
- /**
- * 删除分类
- * @param unknown_type $cid
- */
- function delete_categroy($cid = 0) {
- $this->categorydao->cid = $cid;
- $this->db ()->delete ( $this->categorydao );
- }
-
- /**
- * 删除文章
- * @param unknown_type $aid
- */
- function delete_article($aid) {
- $this->articledao->aid = $aid;
- $this->db ()->delete ( $this->articledao );
- }
- }
- ?>
|