Beispiel #1
0
 public function aGetBlogList($uid, $tag, $start, $num, &$total)
 {
     $option = new Ko_Tool_SQL();
     $offset = $start > 0 ? $start - 1 : $start;
     $addnum = $start > 0 ? 2 : 1;
     $limit = $num + $addnum;
     $option->oOffset($offset)->oLimit($limit)->oOrderBy('blogid desc')->oCalcFoundRows(true);
     $list = $this->taglistDao->aGetList($option->oWhere('uid = ? and tag = ?', $uid, $tag));
     if ($count = count($list)) {
         if ($start > 0) {
             $prev = array_shift($list);
             $count--;
             $prev = $prev['blogid'];
         } else {
             $prev = 0;
         }
         if ($count > $num) {
             $next = array_pop($list);
             $count--;
             $next = $next['blogid'];
         } else {
             $next = 0;
         }
     }
     $infos = $this->blogDao->aGetDetails($list);
     $storageApi = new KStorage_Api();
     foreach ($list as $k => &$v) {
         $update = array();
         if ($k != 0) {
             if ($list[$k - 1]['blogid'] != $v['prev']) {
                 $update['prev'] = $v['prev'] = $list[$k - 1]['blogid'];
             }
         } else {
             if ($prev != $v['prev']) {
                 $update['prev'] = $v['prev'] = $prev;
             }
         }
         if ($k != $count - 1) {
             if ($list[$k + 1]['blogid'] != $v['next']) {
                 $update['next'] = $v['next'] = $list[$k + 1]['blogid'];
             }
         } else {
             if ($next != $v['next']) {
                 $update['next'] = $v['next'] = $next;
             }
         }
         if (!empty($update)) {
             $this->taglistDao->iUpdate($v, $update);
         }
         $v = $infos[$v['blogid']];
         if (strlen($v['cover'])) {
             $v['cover'] = $storageApi->sGetUrl($v['cover'], 'imageView2/1/w/300/h/200');
         }
     }
     unset($v);
     $total = $option->iGetFoundRows();
     $taginfokey = compact('uid', 'tag');
     $taginfo = $this->taginfoDao->aGet($taginfokey);
     if ($taginfo['bcount'] != $total) {
         $data = array('uid' => $uid, 'tag' => $tag, 'bcount' => $total, 'mtime' => date('Y-m-d H:i:s'));
         $update = array('bcount' => $total);
         $this->taginfoDao->aInsert($data, $update);
     }
     return $list;
 }