Changeset 976


Ignore:
Timestamp:
01/14/12 19:32:18 (4 months ago)
Author:
fuze
Message:

количество объявлений при просмотре списка категорий: учитываются подкатегории

Location:
branches/fuze
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/fuze/.htaccess

    r961 r976  
    66RewriteRule ^.htaccess$ - [F] 
    77 
    8 RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|ico|gif|png|css|xml|js|pl|txt)$ [NC] 
    98RewriteCond %{REQUEST_FILENAME} !^/admin 
    109RewriteCond %{REQUEST_FILENAME} !^/migrate 
  • branches/fuze/components/board/model.php

    r961 r976  
    231231/* ==================================================================================================== */ 
    232232/* ==================================================================================================== */ 
    233  
     233    /** 
     234     * Возвращает категории 
     235     * @param int $category_id - id категории 
     236     * @return array 
     237     */ 
    234238    public function getSubCats($category_id) { 
    235239        $cats = array(); 
    236240 
    237         $sql = "SELECT c.*, IFNULL(COUNT(i.id), 0) as content_count 
     241        $sql = "SELECT c.* 
    238242                FROM cms_board_cats c 
    239243                LEFT JOIN cms_board_items i ON i.category_id = c.id AND i.published = 1 
    240244                WHERE c.published = 1 AND c.parent_id = '$category_id' 
    241                 GROUP BY c.id 
    242245                ORDER BY title ASC"; 
    243246        $result = $this->inDB->query($sql); 
     
    249252                $cat['obtypes'] = $this->inDB->get_field('cms_board_cats', "NSLeft <= {$cat['NSLeft']} AND NSRight >= {$cat['NSRight']} AND obtypes <> ''", 'obtypes'); 
    250253            } 
     254                        $cat['content_count'] = $this->getAdvertsCountFromCat($cat['NSLeft'], $cat['NSRight']); 
    251255                        $cat['ob_links'] = $this->getTypesLinks($cat['id'], $cat['obtypes']); 
    252256                        $cat['icon'] = $cat['icon'] ? $cat['icon'] : 'folder_grey.png'; 
     
    257261             
    258262        return $cats; 
     263    } 
     264 
     265    /** 
     266     * Возвращает количество объвлений в категории и подкатегориях 
     267     * @return int 
     268     */ 
     269    public function getAdvertsCountFromCat($left_key, $right_key) { 
     270 
     271                $sql = "SELECT i.id 
     272                                FROM cms_board_items i 
     273                                INNER JOIN cms_board_cats cat ON cat.id = i.category_id AND cat.NSLeft >= '$left_key' AND cat.NSRight <= '$right_key' 
     274                                WHERE i.published = 1"; 
     275 
     276        $result = $this->inDB->query($sql); 
     277 
     278        return $this->inDB->num_rows($result); 
     279 
    259280    } 
    260281 
Note: See TracChangeset for help on using the changeset viewer.