src/SearchBundle/objects/db/TShopSearchCache.class.php
public function GetSearchResultCategoryHits($sFilters = '')
    {
        $aHits = array();
        if (!empty($this->fieldCategoryHits) && empty($sFilters)) {
            $aHits = unserialize($this->fieldCategoryHits);
        } else {
            $aCategoryCount = array();
            $sRestrcition = '';

            $query = '';
            if (!empty($sFilters)) {
                $query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS shop_search_cache_item_count, `shop_category`.*
                      FROM `shop_search_cache_item`
                INNER JOIN `shop_article` ON `shop_search_cache_item`.`shop_article_id` = `shop_article`.`id`
                INNER JOIN `shop_article_shop_category_mlt` ON `shop_search_cache_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
                INNER JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`
                     WHERE `shop_search_cache_item`.`shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                       AND {$sFilters}
                  GROUP BY `shop_category`.`id`
                   ";
            } else {
                $query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS shop_search_cache_item_count, `shop_category`.*
                      FROM `shop_search_cache_item`
                INNER JOIN `shop_article_shop_category_mlt` ON `shop_search_cache_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
                INNER JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`
                     WHERE `shop_search_cache_item`.`shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                  GROUP BY `shop_category`.`id`
                   ";
            }
            $oCatList = &TdbShopCategoryList::GetList($query);

            // now organize list into a tree... we trace back each node untill we reach a root node... in the end we
            // will have a collection of rows. then we merge these

            while ($oCat = &$oCatList->Next()) {
                if (!array_key_exists($oCat->id, $aHits)) {
                    $aHits[$oCat->id] = 0;
                }
                $aHits[$oCat->id] += $oCat->sqlData['shop_search_cache_item_count'];
                // add all children to vector
                while ($oParent = $oCat->GetParent()) {
                    $oParent->sqlData['shop_search_cache_item_count'] = $oCat->sqlData['shop_search_cache_item_count'];
                    if (!array_key_exists($oParent->id, $aHits)) {
                        $aHits[$oParent->id] = 0;
                    }
                    $aHits[$oParent->id] += $oParent->sqlData['shop_search_cache_item_count'];

                    $oCat = $oParent;
                }
            }

            if (empty($sFilters)) {
                $this->fieldCategoryHits = serialize($aHits);
                $this->sqlData['category_hits'] = $this->fieldCategoryHits;
                $this->AllowEditByAll(true);
                $this->Save();
            }
        }

        return $aHits;
    }
public function GetSearchResultCategoryHits($sFilters = '')
    {
        $aHits = array();
        if (!empty($this->fieldCategoryHits) && empty($sFilters)) {
            $aHits = unserialize($this->fieldCategoryHits);
        } else {
            $aCategoryCount = array();
            $sRestrcition = '';

            $query = '';
            if (!empty($sFilters)) {
                $query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS shop_search_cache_item_count, `shop_category`.*
                      FROM `shop_search_cache_item`
                INNER JOIN `shop_article` ON `shop_search_cache_item`.`shop_article_id` = `shop_article`.`id`
                INNER JOIN `shop_article_shop_category_mlt` ON `shop_search_cache_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
                INNER JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`
                     WHERE `shop_search_cache_item`.`shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                       AND {$sFilters}
                  GROUP BY `shop_category`.`id`
                   ";
            } else {
                $query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS shop_search_cache_item_count, `shop_category`.*
                      FROM `shop_search_cache_item`
                INNER JOIN `shop_article_shop_category_mlt` ON `shop_search_cache_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
                INNER JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`
                     WHERE `shop_search_cache_item`.`shop_search_cache_id` = '".MySqlLegacySupport::getInstance()->real_escape_string($this->id)."'
                  GROUP BY `shop_category`.`id`
                   ";
            }
            $oCatList = &TdbShopCategoryList::GetList($query);

            // now organize list into a tree... we trace back each node untill we reach a root node... in the end we
            // will have a collection of rows. then we merge these

            while ($oCat = &$oCatList->Next()) {
                if (!array_key_exists($oCat->id, $aHits)) {
                    $aHits[$oCat->id] = 0;
                }
                $aHits[$oCat->id] += $oCat->sqlData['shop_search_cache_item_count'];
                // add all children to vector
                while ($oParent = $oCat->GetParent()) {
                    $oParent->sqlData['shop_search_cache_item_count'] = $oCat->sqlData['shop_search_cache_item_count'];
                    if (!array_key_exists($oParent->id, $aHits)) {
                        $aHits[$oParent->id] = 0;
                    }
                    $aHits[$oParent->id] += $oParent->sqlData['shop_search_cache_item_count'];

                    $oCat = $oParent;
                }
            }

            if (empty($sFilters)) {
                $this->fieldCategoryHits = serialize($aHits);
                $this->sqlData['category_hits'] = $this->fieldCategoryHits;
                $this->AllowEditByAll(true);
                $this->Save();
            }
        }

        return $aHits;
    }
public function GetSearchResultCategoryHits ( $ sFilters = '' ) { $ aHits = array ( ) ; if ( ! empty ( $ this -> fieldCategoryHits ) && empty ( $ sFilters ) ) { $ aHits = unserialize ( $ this -> fieldCategoryHits ) ; } else { $ aCategoryCount = array ( ) ; $ sRestrcition = '' ; $ query = '' ; if ( ! empty ( $ sFilters ) ) { $ query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS shop_search_cache_item_count, `shop_category`.*
                      FROM `shop_search_cache_item`
                INNER JOIN `shop_article` ON `shop_search_cache_item`.`shop_article_id` = `shop_article`.`id`
                INNER JOIN `shop_article_shop_category_mlt` ON `shop_search_cache_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
                INNER JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`
                     WHERE `shop_search_cache_item`.`shop_search_cache_id` = '" . MySqlLegacySupport :: getInstance ( ) -> real_escape_string ( $ this -> id ) . "'
                       AND {$sFilters}
                  GROUP BY `shop_category`.`id`
                   " ; } else { $ query = "SELECT COUNT(DISTINCT `shop_search_cache_item`.`id`) AS shop_search_cache_item_count, `shop_category`.*
                      FROM `shop_search_cache_item`
                INNER JOIN `shop_article_shop_category_mlt` ON `shop_search_cache_item`.`shop_article_id` = `shop_article_shop_category_mlt`.`source_id`
                INNER JOIN `shop_category` ON `shop_article_shop_category_mlt`.`target_id` = `shop_category`.`id`
                     WHERE `shop_search_cache_item`.`shop_search_cache_id` = '" . MySqlLegacySupport :: getInstance ( ) -> real_escape_string ( $ this -> id ) . "'
                  GROUP BY `shop_category`.`id`
                   " ; } $ oCatList = & TdbShopCategoryList :: GetList ( $ query ) ; // now organize list into a tree... we trace back each node untill we reach a root node... in the end we // will have a collection of rows. then we merge these while ( $ oCat = & $ oCatList -> Next ( ) ) { if ( ! array_key_exists ( $ oCat -> id , $ aHits ) ) { $ aHits [ $ oCat -> id ] = 0 ; } $ aHits [ $ oCat -> id ] += $ oCat -> sqlData [ 'shop_search_cache_item_count' ] ; // add all children to vector while ( $ oParent = $ oCat -> GetParent ( ) ) { $ oParent -> sqlData [ 'shop_search_cache_item_count' ] = $ oCat -> sqlData [ 'shop_search_cache_item_count' ] ; if ( ! array_key_exists ( $ oParent -> id , $ aHits ) ) { $ aHits [ $ oParent -> id ] = 0 ; } $ aHits [ $ oParent -> id ] += $ oParent -> sqlData [ 'shop_search_cache_item_count' ] ; $ oCat = $ oParent ; } } if ( empty ( $ sFilters ) ) { $ this -> fieldCategoryHits = serialize ( $ aHits ) ; $ this -> sqlData [ 'category_hits' ] = $ this -> fieldCategoryHits ; $ this -> AllowEditByAll ( true ) ; $ this -> Save ( ) ; } } return $ aHits ; }
return array with categorie ids and number of hits for that category.

@return array
return array with categorie ids and number of hits for that category .