Go to the documentation of this file.00001 <?php
00002
00006 class oxUtilsCount extends oxSuperCfg
00007 {
00013 private static $_instance = null;
00014
00020 protected $_sUserViewId = null;
00021
00029 public static function getInstance()
00030 {
00031 return oxRegistry::get("oxUtilsCount");
00032 }
00033
00041 public function getCatArticleCount( $sCatId )
00042 {
00043
00044 $sActIdent = $this->_getUserViewId();
00045
00046
00047 $aCatData = $this->_getCatCache();
00048
00049 if ( !$aCatData || !isset( $aCatData[$sCatId][$sActIdent] ) ) {
00050 $iCnt = $this->setCatArticleCount( $aCatData, $sCatId, $sActIdent );
00051 } else {
00052 $iCnt = $aCatData[$sCatId][$sActIdent];
00053 }
00054 return $iCnt;
00055 }
00056
00066 public function getPriceCatArticleCount( $sCatId, $dPriceFrom, $dPriceTo )
00067 {
00068
00069 $sActIdent = $this->_getUserViewId();
00070
00071
00072 $aCatData = $this->_getCatCache();
00073
00074 if ( !$aCatData || !isset( $aCatData[$sCatId][$sActIdent] ) ) {
00075 $iCnt = $this->setPriceCatArticleCount( $aCatData, $sCatId, $sActIdent, $dPriceFrom, $dPriceTo );
00076 } else {
00077 $iCnt = $aCatData[$sCatId][$sActIdent];
00078 }
00079
00080 return $iCnt;
00081 }
00082
00090 public function getVendorArticleCount( $sVendorId )
00091 {
00092
00093 $sActIdent = $this->_getUserViewId();
00094
00095
00096 $aVendorData = $this->_getVendorCache();
00097
00098 if ( !$aVendorData || !isset( $aVendorData[$sVendorId][$sActIdent] ) ) {
00099 $iCnt = $this->setVendorArticleCount( $aVendorData, $sVendorId, $sActIdent );
00100 } else {
00101 $iCnt = $aVendorData[$sVendorId][$sActIdent];
00102 }
00103 return $iCnt;
00104 }
00105
00113 public function getManufacturerArticleCount( $sManufacturerId )
00114 {
00115
00116 $sActIdent = $this->_getUserViewId();
00117
00118
00119 $aManufacturerData = $this->_getManufacturerCache();
00120 if ( !$aManufacturerData || !isset( $aManufacturerData[$sManufacturerId][$sActIdent] ) ) {
00121 $iCnt = $this->setManufacturerArticleCount( $aManufacturerData, $sManufacturerId, $sActIdent );
00122 } else {
00123 $iCnt = $aManufacturerData[$sManufacturerId][$sActIdent];
00124 }
00125 return $iCnt;
00126 }
00127
00137 public function setCatArticleCount( $aCache, $sCatId, $sActIdent )
00138 {
00139 $oArticle = oxNew( 'oxarticle' );
00140 $sTable = $oArticle->getViewName();
00141 $sO2CView = getViewName( 'oxobject2category' );
00142 $oDb = oxDb::getDb();
00143
00144
00145 $sQ = "SELECT count(*) FROM (
00146 SELECT count(*) FROM $sO2CView LEFT JOIN $sTable ON $sO2CView.oxobjectid=$sTable.oxid
00147 WHERE $sO2CView.oxcatnid = ".$oDb->quote( $sCatId ) ." AND
00148 $sTable.oxparentid='' AND
00149 ".$oArticle->getSqlActiveSnippet() ."
00150 GROUP BY $sTable.oxid
00151 ) AS ox2cat";
00152
00153 $aCache[$sCatId][$sActIdent] = $oDb->getOne( $sQ );
00154
00155 $this->_setCatCache( $aCache );
00156 return $aCache[$sCatId][$sActIdent];
00157 }
00158
00170 public function setPriceCatArticleCount( $aCache, $sCatId, $sActIdent, $dPriceFrom, $dPriceTo )
00171 {
00172 $oArticle = oxNew( 'oxarticle' );
00173 $sTable = $oArticle->getViewName();
00174
00175 $sSelect = "select count({$sTable}.oxid) from {$sTable} where oxvarminprice >= 0 ";
00176 $sSelect .= $dPriceTo ? "and oxvarminprice <= " . (double)$dPriceTo . " " : " ";
00177 $sSelect .= $dPriceFrom ? "and oxvarminprice >= " . (double)$dPriceFrom . " " : " ";
00178 $sSelect .= "and {$sTable}.oxissearch = 1 and ".$oArticle->getSqlActiveSnippet();
00179
00180 $aCache[$sCatId][$sActIdent] = oxDb::getDb()->getOne( $sSelect );
00181
00182 $this->_setCatCache( $aCache );
00183 return $aCache[$sCatId][$sActIdent];
00184 }
00185
00195 public function setVendorArticleCount( $aCache, $sCatId, $sActIdent )
00196 {
00197
00198 if ( $sCatId == 'root' ) {
00199 return 0;
00200 }
00201
00202 $oArticle = oxNew( 'oxarticle' );
00203 $sTable = $oArticle->getViewName();
00204
00205
00206 $sQ = "select $sTable.oxvendorid AS vendorId, count(*) from $sTable where ";
00207 $sQ .= "$sTable.oxvendorid <> '' and $sTable.oxparentid = '' and ".$oArticle->getSqlActiveSnippet()." group by $sTable.oxvendorid ";
00208 $aDbResult = oxDb::getDb()->getAssoc( $sQ );
00209
00210 foreach ( $aDbResult as $sKey => $sValue ) {
00211 $aCache[$sKey][$sActIdent] = $sValue;
00212 }
00213
00214 $this->_setVendorCache( $aCache );
00215 return $aCache[$sCatId][$sActIdent];
00216 }
00217
00227 public function setManufacturerArticleCount( $aCache, $sMnfId, $sActIdent )
00228 {
00229
00230 if ( $sMnfId == 'root' ) {
00231 return 0;
00232 }
00233
00234 $oArticle = oxNew( 'oxarticle' );
00235 $sArtTable = $oArticle->getViewName();
00236 $sManTable = getViewName('oxmanufacturers');
00237
00238
00239
00240 $sQ = "select count($sArtTable.oxid) from $sArtTable where $sArtTable.oxparentid = '' and oxmanufacturerid = '$sMnfId' and ".$oArticle->getSqlActiveSnippet();
00241
00242 $iValue = oxDb::getDb()->getOne( $sQ );
00243
00244 $aCache[$sMnfId][$sActIdent] = (int) $iValue;
00245
00246 $this->_setManufacturerCache( $aCache );
00247
00248 return $aCache[$sMnfId][$sActIdent];
00249 }
00250
00258 public function resetCatArticleCount( $sCatId = null )
00259 {
00260 if ( !$sCatId ) {
00261 $this->getConfig()->setGlobalParameter( 'aLocalCatCache', null );
00262 oxRegistry::getUtils()->toFileCache( 'aLocalCatCache', '' );
00263 } else {
00264
00265 $aCatData = $this->_getCatCache();
00266 if ( isset( $aCatData[$sCatId] ) ) {
00267 unset( $aCatData[$sCatId] );
00268 $this->_setCatCache( $aCatData );
00269 }
00270 }
00271
00272 }
00273
00281 public function resetPriceCatArticleCount( $iPrice )
00282 {
00283
00284 if ( $aCatData = $this->_getCatCache() ) {
00285
00286 $sTable = getViewName( 'oxcategories' );
00287 $sSelect = "select $sTable.oxid from $sTable where " . (double)$iPrice . " >= $sTable.oxpricefrom and " . (double)$iPrice . " <= $sTable.oxpriceto ";
00288
00289 $rs = oxDb::getDb()->select( $sSelect, false, false );
00290 if ( $rs != false && $rs->recordCount() > 0 ) {
00291 while ( !$rs->EOF ) {
00292 if ( isset( $aCatData[$rs->fields[0]] ) ) {
00293 unset( $aCatData[$rs->fields[0]] );
00294 }
00295 $rs->moveNext();
00296 }
00297
00298
00299 $this->_setCatCache( $aCatData );
00300 }
00301
00302 }
00303 }
00304
00313 public function getTagArticleCount( $sTag, $iLang )
00314 {
00315 $oDb = oxDb::getDb();
00316
00317 $oArticle = oxNew("oxarticle");
00318 $sArticleTable = $oArticle->getViewName();
00319 $sActiveSnippet = $oArticle->getSqlActiveSnippet();
00320 $sViewName = getViewName( 'oxartextends', $iLang );
00321
00322 $sQ = "select count(*) from {$sViewName} inner join {$sArticleTable} on ".
00323 "{$sArticleTable}.oxid = {$sViewName}.oxid where {$sArticleTable}.oxparentid = '' and {$sArticleTable}.oxissearch = 1 AND match ( {$sViewName}.oxtags ) ".
00324 "against( ".$oDb->quote( "\"".$sTag."\"" )." IN BOOLEAN MODE ) and {$sActiveSnippet}";
00325
00326 return $oDb->getOne( $sQ );
00327 }
00328
00336 public function resetVendorArticleCount( $sVendorId = null )
00337 {
00338 if ( !$sVendorId ) {
00339 $this->getConfig()->setGlobalParameter( 'aLocalVendorCache', null );
00340 oxRegistry::getUtils()->toFileCache( 'aLocalVendorCache', '' );
00341 } else {
00342
00343 $aVendorData = $this->_getVendorCache();
00344 if ( isset( $aVendorData[$sVendorId] ) ) {
00345 unset( $aVendorData[$sVendorId] );
00346 $this->_setVendorCache( $aVendorData );
00347 }
00348 }
00349
00350 }
00351
00359 public function resetManufacturerArticleCount( $sManufacturerId = null )
00360 {
00361 if ( !$sManufacturerId ) {
00362 $this->getConfig()->setGlobalParameter( 'aLocalManufacturerCache', null );
00363 oxRegistry::getUtils()->toFileCache( 'aLocalManufacturerCache', '' );
00364 } else {
00365
00366 $aManufacturerData = $this->_getManufacturerCache();
00367 if ( isset( $aManufacturerData[$sManufacturerId] ) ) {
00368 unset( $aManufacturerData[$sManufacturerId] );
00369 $this->_setManufacturerCache( $aManufacturerData );
00370 }
00371 }
00372
00373 }
00374
00380 protected function _getCatCache()
00381 {
00382 $myConfig = $this->getConfig();
00383
00384
00385 $aLocalCatCache = $myConfig->getGlobalParameter( 'aLocalCatCache' );
00386
00387
00388 if ( !$aLocalCatCache ) {
00389 $sLocalCatCache = oxRegistry::getUtils()->fromFileCache( 'aLocalCatCache');
00390 if ( $sLocalCatCache ) {
00391 $aLocalCatCache = $sLocalCatCache;
00392 } else {
00393 $aLocalCatCache = null;
00394 }
00395 $myConfig->setGlobalParameter( 'aLocalCatCache', $aLocalCatCache );
00396 }
00397 return $aLocalCatCache;
00398 }
00399
00407 protected function _setCatCache( $aCache )
00408 {
00409 $this->getConfig()->setGlobalParameter( 'aLocalCatCache', $aCache );
00410 oxRegistry::getUtils()->toFileCache( 'aLocalCatCache', $aCache );
00411 }
00412
00420 protected function _setVendorCache( $aCache )
00421 {
00422 $this->getConfig()->setGlobalParameter( 'aLocalVendorCache', $aCache );
00423 oxRegistry::getUtils()->toFileCache( 'aLocalVendorCache', $aCache );
00424 }
00425
00433 protected function _setManufacturerCache( $aCache )
00434 {
00435 $this->getConfig()->setGlobalParameter( 'aLocalManufacturerCache', $aCache );
00436 oxRegistry::getUtils()->toFileCache( 'aLocalManufacturerCache', $aCache );
00437 }
00438
00444 protected function _getVendorCache()
00445 {
00446 $myConfig = $this->getConfig();
00447
00448
00449 $aLocalVendorCache = $myConfig->getGlobalParameter('aLocalVendorCache');
00450
00451 if ( !$aLocalVendorCache ) {
00452 $sLocalVendorCache = oxRegistry::getUtils()->fromFileCache( 'aLocalVendorCache' );
00453 if ( $sLocalVendorCache ) {
00454 $aLocalVendorCache = $sLocalVendorCache;
00455 } else {
00456 $aLocalVendorCache = null;
00457 }
00458 $myConfig->setGlobalParameter( 'aLocalVendorCache', $aLocalVendorCache );
00459 }
00460 return $aLocalVendorCache;
00461 }
00462
00468 protected function _getManufacturerCache()
00469 {
00470 $myConfig = $this->getConfig();
00471
00472
00473 $aLocalManufacturerCache = $myConfig->getGlobalParameter('aLocalManufacturerCache');
00474
00475 if ( !$aLocalManufacturerCache ) {
00476 $sLocalManufacturerCache = oxRegistry::getUtils()->fromFileCache( 'aLocalManufacturerCache' );
00477 if ( $sLocalManufacturerCache ) {
00478 $aLocalManufacturerCache = $sLocalManufacturerCache;
00479 } else {
00480 $aLocalManufacturerCache = null;
00481 }
00482 $myConfig->setGlobalParameter( 'aLocalManufacturerCache', $aLocalManufacturerCache );
00483 }
00484 return $aLocalManufacturerCache;
00485 }
00486
00494 protected function _getUserViewId( $blReset = false )
00495 {
00496 if ( $this->_sUserViewId != null && !$blReset ) {
00497 return $this->_sUserViewId;
00498 }
00499
00500
00501 $aRRIdx = null;
00502
00503 $this->_sUserViewId = md5($this->getConfig()->getShopID().oxRegistry::getLang()->getLanguageTag().serialize($aRRIdx).(int) $this->isAdmin() );
00504 return $this->_sUserViewId;
00505 }
00506
00507 }