/**
  * Returns object instance
  *
  * @return oxUtilsCount
  */
 public static function getInstance()
 {
     // disable caching for test modules
     if (defined('OXID_PHP_UNIT')) {
         self::$_instance = modInstances::getMod(__CLASS__);
     }
     if (!self::$_instance instanceof oxUtilsCount) {
         self::$_instance = oxNew('oxUtilsCount');
         if (defined('OXID_PHP_UNIT')) {
             modInstances::addMod(__CLASS__, self::$_instance);
         }
     }
     return self::$_instance;
 }
 /**
  * Resets counters values from cache. Resets price category articles, category articles,
  * vendor articles, manufacturer articles count.
  *
  * @param string $sCounterType counter type
  * @param string $sValue       reset value
  *
  * @return null
  */
 public function resetCounter($sCounterType, $sValue = null)
 {
     $blDeleteCacheOnLogout = $this->getConfig()->getConfigParam('blClearCacheOnLogout');
     $myUtilsCount = oxUtilsCount::getInstance();
     if (!$blDeleteCacheOnLogout) {
         switch ($sCounterType) {
             case 'priceCatArticle':
                 $myUtilsCount->resetPriceCatArticleCount($sValue);
                 break;
             case 'catArticle':
                 $myUtilsCount->resetCatArticleCount($sValue);
                 break;
             case 'vendorArticle':
                 $myUtilsCount->resetVendorArticleCount($sValue);
                 break;
             case 'manufacturerArticle':
                 $myUtilsCount->resetManufacturerArticleCount($sValue);
                 break;
         }
     }
 }
 /**
  * Resets count of vendor/manufacturer category items
  *
  * @param string $aIds array to reset type => id
  *
  * @return null
  */
 protected function _resetCounts($aIds)
 {
     $oUtils = oxUtilsCount::getInstance();
     foreach ($aIds as $sType => $aResetInfo) {
         foreach ($aResetInfo as $sResetId => $iPos) {
             switch ($sType) {
                 case 'vendor':
                     $this->resetCounter("vendorArticle", $sResetId);
                     break;
                 case 'manufacturer':
                     $this->resetCounter("manufacturerArticle", $sResetId);
                     break;
             }
         }
     }
 }
 /**
  * Loads a list of articles having
  *
  * @param string $sTag  Searched tag
  * @param int    $iLang Active language
  *
  * @return int
  */
 public function loadTagArticles($sTag, $iLang)
 {
     $oListObject = $this->getBaseObject();
     $sArticleTable = $oListObject->getViewName();
     $sArticleFields = $oListObject->getSelectFields();
     $sViewName = getViewName('oxartextends', $iLang);
     $oTagHandler = oxNew('oxtagcloud');
     $sTag = $oTagHandler->prepareTags($sTag);
     $sQ = "select {$sArticleFields} from {$sViewName} inner join {$sArticleTable} on " . "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' AND match ( {$sViewName}.oxtags ) " . "against( " . oxDb::getDb()->quote("\"" . $sTag . "\"") . " IN BOOLEAN MODE )";
     // checking stock etc
     if ($sActiveSnippet = $oListObject->getSqlActiveSnippet()) {
         $sQ .= " and {$sActiveSnippet}";
     }
     if ($this->_sCustomSorting) {
         $sSort = $this->_sCustomSorting;
         if (strpos($sSort, '.') === false) {
             $sSort = $sArticleTable . '.' . $sSort;
         }
         $sQ .= " order by {$sSort} ";
     }
     $this->selectString($sQ);
     // calc count - we can not use count($this) here as we might have paging enabled
     return oxUtilsCount::getInstance()->getTagArticleCount($sTag, $iLang);
 }
 /**
  * returns number or articles in category
  *
  * @return integer
  */
 public function getNrOfArticles()
 {
     $myConfig = $this->getConfig();
     if (!isset($this->_iNrOfArticles) && !$this->isAdmin() && ($myConfig->getConfigParam('bl_perfShowActionCatArticleCnt') || $myConfig->getConfigParam('blDontShowEmptyCategories'))) {
         if ($this->isPriceCategory()) {
             $this->_iNrOfArticles = oxUtilsCount::getInstance()->getPriceCatArticleCount($this->getId(), $this->oxcategories__oxpricefrom->value, $this->oxcategories__oxpriceto->value);
         } else {
             $this->_iNrOfArticles = oxUtilsCount::getInstance()->getCatArticleCount($this->getId());
         }
     }
     return (int) $this->_iNrOfArticles;
 }
 /**
  * Returns the OXID counting utilities object.
  *
  * @return oxUtilsCount
  */
 public function getUtilsCount()
 {
     return oxUtilsCount::getInstance();
 }
 /**
  * Assigns to $this object some base parameters/values.
  *
  * @param array $dbRecord parameters/values
  *
  * @return null
  */
 public function assign($dbRecord)
 {
     parent::assign($dbRecord);
     // vendor article count is stored in cache
     if ($this->_blShowArticleCnt && !$this->isAdmin()) {
         $this->_iNrOfArticles = oxUtilsCount::getInstance()->getVendorArticleCount($this->getId());
     }
     $this->oxvendor__oxnrofarticles = new oxField($this->_iNrOfArticles, oxField::T_RAW);
 }
 /**
  * Resets category and vendor counts. This method is supposed to be called on article change triger.
  *
  * @param string $sOxid           object to reset id ID
  * @param string $sVendorId       Vendor ID
  * @param string $sManufacturerId Manufacturer ID
  *
  * @return null
  */
 protected function _onChangeResetCounts($sOxid, $sVendorId = null, $sManufacturerId = null)
 {
     $myUtilsCount = oxUtilsCount::getInstance();
     if ($sVendorId) {
         $myUtilsCount->resetVendorArticleCount($sVendorId);
     }
     if ($sManufacturerId) {
         $myUtilsCount->resetManufacturerArticleCount($sManufacturerId);
     }
     //also reseting category counts
     $oDb = oxDb::getDb();
     $sQ = "select oxcatnid from oxobject2category where oxobjectid = " . $oDb->quote($sOxid);
     $oRs = $oDb->execute($sQ);
     if ($oRs !== false && $oRs->recordCount() > 0) {
         while (!$oRs->EOF) {
             $myUtilsCount->resetCatArticleCount($oRs->fields[0]);
             $oRs->moveNext();
         }
     }
 }