コード例 #1
0
 public function indexAction()
 {
     $cache = Zend_Registry::get('cache');
     $id = md5("comrankControllerIndex");
     if (($result = $cache->load($id)) === false) {
         $comment = new Application_Model_DbTable_Comment();
         $db = $comment->getAdapter();
         $select = $db->select();
         $select->from('article', array('title', 'id'));
         $select->joinLeft('comment', 'comment.article_id=article.id', 'count(comment_id) as total');
         //$select->join('article','comment.article_id=article.id','title');
         $select->where('article.account_id = ?', BLOGGER_ID);
         $select->group('article.id');
         $select->order('total desc');
         $select->limit(10);
         $result = $db->fetchAll($select);
         $cache->save($result, $id, array('calendarbox'));
     }
     $this->view->data = $result;
     $user = new Zend_Session_Namespace('user');
     if (isset($user->nickname) && $user->nickname == BLOGGER_NAME) {
         $this->view->show = true;
     } else {
         $this->view->show = false;
     }
 }
コード例 #2
0
 public function searchAction()
 {
     if ($this->getRequest()->isPost()) {
         $keywords = trim($this->_request->getParam('keywords'));
         $result = preg_split("/\\s+/", $keywords);
         $article = new Application_Model_DbTable_Article();
         $db = $article->getAdapter();
         $len = count($result);
         $this->view->keywords = join('--', $result);
         /* $select->from('article', array('id','title','summary' => 'LEFT(article.content,200)','view_counter','add_time'));
         			$select->join('atype', 'article.atype_id = atype.id', 'atype');
         			$select->where('article.account_id = ?', BLOGGER_ID);
         			$select->Where('title LIKE ?' ,'%'.$result[0].'%');
         			$select->orWhere('content LIKE ?','%'.$result[0].'%'); */
         $select_arr = array();
         for ($i = 0; $i < $len; $i++) {
             if ($i == 0) {
                 $temp = 'select' . $i;
                 ${$temp} = $db->select();
                 ${$temp}->from('article', array('id', 'title', 'summary' => 'LEFT(article.content,200)', 'view_counter', 'add_time'));
                 ${$temp}->join('atype', 'article.atype_id = atype.id', 'atype');
                 ${$temp}->where('article.account_id = ?', BLOGGER_ID);
                 ${$temp}->Where('title LIKE ?', '%' . $result[$i] . '%');
                 ${$temp}->orWhere('content LIKE ?', '%' . $result[$i] . '%');
                 $select_arr[] = ${$temp};
             } else {
                 $temp = 'select' . $i;
                 ${$temp} = $db->select();
                 ${$temp}->from('article', array('id', 'title', 'summary' => 'LEFT(article.content,200)', 'view_counter', 'add_time'));
                 ${$temp}->join('atype', 'article.atype_id = atype.id', 'atype');
                 ${$temp}->where('article.account_id = ?', BLOGGER_ID);
                 ${$temp}->Where('title LIKE ?', '%' . $result[$i] . '%');
                 ${$temp}->orWhere('content LIKE ?', '%' . $result[$i] . '%');
                 $select_arr[] = ${$temp};
             }
             $select = $db->select();
             $select->union($select_arr);
             $select->group('article.id');
         }
         $data = $db->fetchAll($select);
         //分页
         $numPerPage = $this->_numPerPage;
         $pageRange = $this->_pageRange;
         $page = $this->_request->getParam('page', 1);
         $offset = $numPerPage * $page;
         $paginator = Zend_Paginator::factory($data);
         $paginator->setCurrentPageNumber($page)->setItemCountPerPage($numPerPage)->setPageRange($pageRange);
         $this->view->paginator = $paginator;
         $comment = new Application_Model_DbTable_Comment();
         $db = $comment->getAdapter();
         $select = $db->select();
         $select->from('comment', array('article_id', 'total' => 'count(*)'));
         $select->group('article_id');
         $comment = $db->fetchAll($select);
         $ca = array();
         foreach ($comment as $arr) {
             $ca[$arr['article_id']] = $arr['total'];
         }
         $this->view->comment = $ca;
         $user = new Zend_Session_Namespace('user');
         if (isset($user->nickname) && $user->nickname == BLOGGER_NAME) {
             $this->view->show = true;
         } else {
             $this->view->show = false;
         }
     }
 }