oxrecommlist.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxRecommList extends oxBase
00007 {
00013     protected $_sClassName = 'oxRecommList';
00014 
00020     protected $_oArticles  = null;
00021 
00027     protected $_sArticlesFilter = '';
00028 
00034     public function __construct()
00035     {
00036         parent::__construct();
00037         $this->init( 'oxrecommlists' );
00038     }
00039 
00049     public function getArticles(  $iStart = null, $iNrofArticles = null, $blReload = false )
00050     {
00051         // cached ?
00052         if ( $this->_oArticles !== null && !$blReload ) {
00053             return $this->_oArticles;
00054         }
00055 
00056         $this->_oArticles = oxNew( 'oxarticlelist' );
00057 
00058         if ( $iStart !== null && $iNrofArticles !== null ) {
00059             $this->_oArticles->setSqlLimit( $iStart, $iNrofArticles );
00060         }
00061 
00062         // loading basket items
00063         $this->_oArticles->loadRecommArticles( $this->getId(), $this->_sArticlesFilter );
00064 
00065         return $this->_oArticles;
00066     }
00067 
00073     public function getArtCount()
00074     {
00075         $iCnt = 0;
00076         $sSelect = $this->_getArticleSelect();
00077         if ( $sSelect ) {
00078             $iCnt = oxDb::getDb()->getOne( $sSelect );
00079         }
00080         return $iCnt;
00081     }
00082 
00088     protected function _getArticleSelect()
00089     {
00090         $sArtView = getViewName( 'oxarticles' );
00091         $sSelect  = "select count(distinct $sArtView.oxid) from oxobject2list ";
00092         $sSelect .= "left join $sArtView on oxobject2list.oxobjectid = $sArtView.oxid ";
00093         $sSelect .= "where (oxobject2list.oxlistid = '".$this->getId()."') ";
00094 
00095         return $sSelect;
00096     }
00097 
00103     public function getFirstArticle()
00104     {
00105         $oArtList = oxNew( 'oxarticlelist' );
00106         $oArtList->setSqlLimit( 0, 1 );
00107         $oArtList->loadRecommArticles( $this->getId(), $this->_sArticlesFilter );
00108         $oArtList->rewind();
00109         return $oArtList->current();
00110     }
00111 
00119     public function delete( $sOXID = null )
00120     {
00121         if ( !$sOXID ) {
00122             $sOXID = $this->getId();
00123         }
00124         if ( !$sOXID ) {
00125             return false;
00126         }
00127 
00128         if ( ( $blDelete = parent::delete( $sOXID ) ) ) {
00129             // cleaning up related data
00130             $sQ = "delete from oxobject2list where oxlistid = '$sOXID' ";
00131             oxDb::getDb()->execute( $sQ );
00132         }
00133         return $blDelete;
00134     }
00135 
00143     public function getArtDescription( $sOXID )
00144     {
00145         if ( !$sOXID ) {
00146             return false;
00147         }
00148 
00149         $sSelect = 'select oxdesc from oxobject2list where oxlistid = "'.$this->getId().'" and oxobjectid = "'.$sOXID.'"';
00150         $sDesc = oxDb::getDb()->getOne( $sSelect );
00151         return $sDesc;
00152     }
00153 
00161     public function removeArticle( $sOXID )
00162     {
00163         if ( !$sOXID ) {
00164             return false;
00165         }
00166 
00167         $sQ = "delete from oxobject2list where oxobjectid = '$sOXID' ";
00168         return oxDb::getDb()->execute( $sQ );
00169     }
00170 
00179     public function addArticle( $sOXID, $sDesc )
00180     {
00181         $blAdd = false;
00182         if ( $sOXID ) {
00183             $oDB = oxDb::getDb();
00184             if ( !$oDB->getOne( "select oxid from oxobject2list where oxobjectid='$sOXID' and oxlistid='".$this->getId()."'" ) ) {
00185                 $sUid  = oxUtilsObject::getInstance()->generateUID();
00186                 $sDesc = $oDB->quote( $sDesc );
00187                 $sQ    = "insert into oxobject2list ( oxid, oxobjectid, oxlistid, oxdesc ) values ( '$sUid', '$sOXID', '".$this->getId()."', $sDesc )";
00188                 $blAdd = $oDB->execute( $sQ );
00189             }
00190         }
00191         return $blAdd;
00192     }
00193 
00204     public function getRecommListsByIds( $aArticleIds )
00205     {
00206         if ( count( $aArticleIds ) ) {
00207             startProfile(__FUNCTION__);
00208 
00209             $aIds = array();
00210             foreach ( $aArticleIds as $iKey => $sVal ) {
00211                 $aIds[$sVal] = mysql_real_escape_string($sVal);
00212             }
00213 
00214             $sIds = implode("','", $aIds);
00215 
00216             $oRecommList = oxNew( 'oxlist' );
00217             $oRecommList->init( 'oxrecommlist' );
00218 
00219             $iShopId = $this->getConfig()->getShopId();
00220             $iCnt = $this->getConfig()->getConfigParam( 'iNrofCrossellArticles' );
00221 
00222             $oRecommList->setSqlLimit( 0, $iCnt );
00223 
00224             $sSelect = "SELECT distinct lists.* FROM oxobject2list AS o2l_lists";
00225             $sSelect.= " LEFT JOIN oxobject2list AS o2l_count ON o2l_lists.oxlistid = o2l_count.oxlistid";
00226             $sSelect.= " LEFT JOIN oxrecommlists as lists ON o2l_lists.oxlistid = lists.oxid";
00227             $sSelect.= " WHERE o2l_lists.oxobjectid IN ('$sIds') and lists.oxshopid ='$iShopId'";
00228             $sSelect.= " GROUP BY lists.oxid order by (";
00229             $sSelect.= " SELECT count( order1.oxobjectid ) FROM oxobject2list AS order1";
00230             $sSelect.= " WHERE order1.oxobjectid IN ('$sIds') AND o2l_lists.oxlistid = order1.oxlistid";
00231             $sSelect.= " ) DESC, count( lists.oxid ) DESC";
00232 
00233             $oRecommList->selectString( $sSelect );
00234 
00235             stopProfile(__FUNCTION__);
00236 
00237             if ( $oRecommList->count() ) {
00238                 startProfile('_loadFirstArticles');
00239 
00240                 $this->_loadFirstArticles( $oRecommList, $aIds );
00241 
00242                 stopProfile('_loadFirstArticles');
00243 
00244                 return $oRecommList;
00245             }
00246         }
00247     }
00248 
00260     protected function _loadFirstArticles(oxList $oRecommList, $aIds)
00261     {
00262         $aPrevIds = array();
00263         $sArtView = getViewName( 'oxarticles' );
00264         foreach ($oRecommList as $key => $oRecomm) {
00265             $sIds = implode("','", $aIds);
00266             if (count($aPrevIds)) {
00267                 $sNegateSql = " AND $sArtView.oxid not in ( '".implode("','", $aPrevIds)."' ) ";
00268             } else {
00269                 $sNegateSql = '';
00270             }
00271             $sArticlesFilter = "$sNegateSql ORDER BY $sArtView.oxid in ( '$sIds' ) desc";
00272             $oRecomm->setArticlesFilter($sArticlesFilter);
00273             $oArtList = oxNew( 'oxarticlelist' );
00274             $oArtList->setSqlLimit( 0, 1 );
00275             $oArtList->loadRecommArticles( $oRecomm->getId(), $sArticlesFilter );
00276 
00277             if (count($oArtList) == 1) {
00278                 $oArtList->rewind();
00279                 $oArticle = $oArtList->current();
00280                 $sId = $oArticle->getId();
00281                 $aPrevIds[$sId] = $sId;
00282                 unset($aIds[$sId]);
00283             } else {
00284                 unset($oRecommList[$key]);
00285             }
00286         }
00287     }
00288 
00296     public function getSearchRecommLists( $sSearchStr )
00297     {
00298         if ( $sSearchStr ) {
00299             // sets active page
00300             $iActPage = (int) oxConfig::getParameter( 'pgNr' );
00301             $iActPage = ($iActPage < 0) ? 0 : $iActPage;
00302 
00303             // load only lists which we show on screen
00304             $iNrofCatArticles = $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00305             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00306 
00307             $oRecommList = oxNew( 'oxlist' );
00308             $oRecommList->init( 'oxrecommlist' );
00309             $sSelect = $this->_getSearchSelect( $sSearchStr );
00310             $oRecommList->setSqlLimit( $iNrofCatArticles * $iActPage, $iNrofCatArticles );
00311             $oRecommList->selectString( $sSelect );
00312 
00313             return $oRecommList;
00314         }
00315     }
00316 
00324     public function getSearchRecommListCount( $sSearchStr )
00325     {
00326         $iCnt = 0;
00327         $sSelect = $this->_getSearchSelect( $sSearchStr );
00328         if ( $sSelect ) {
00329 
00330             $sPartial = substr( $sSelect, strpos( $sSelect, ' from ' ) );
00331             $sSelect  = "select count( distinct rl.oxid ) $sPartial ";
00332             $iCnt = oxDb::getDb()->getOne( $sSelect );
00333         }
00334         return $iCnt;
00335     }
00336 
00344     protected function _getSearchSelect( $sSearchStr )
00345     {
00346         $iShopId    = $this->getConfig()->getShopId();
00347         $sSearchStr = oxDb::getDb()->quote( "%$sSearchStr%" );
00348 
00349         $sSelect = "select distinct rl.* from oxrecommlists as rl";
00350         $sSelect.= " inner join oxobject2list as o2l on o2l.oxlistid = rl.oxid";
00351         $sSelect.= " where ( rl.oxtitle like $sSearchStr or rl.oxdesc like $sSearchStr";
00352         $sSelect.= " or o2l.oxdesc like $sSearchStr ) and rl.oxshopid = '$iShopId'";
00353 
00354         return $sSelect;
00355     }
00356 
00364     public function addToRatingAverage( $iRating)
00365     {
00366         $dOldRating = $this->oxrecommlists__oxrating->value;
00367         $dOldCnt    = $this->oxrecommlists__oxratingcnt->value;
00368         $this->oxrecommlists__oxrating    = new oxField(( $dOldRating * $dOldCnt + $iRating ) / ($dOldCnt + 1), oxField::T_RAW);
00369         $this->oxrecommlists__oxratingcnt = new oxField($dOldCnt + 1, oxField::T_RAW);
00370         $this->save();
00371     }
00372 
00378     public function getReviews()
00379     {
00380         $oReview = oxNew('oxreview');
00381         $oRevs = $oReview->loadList('oxrecommlist', $this->getId());
00382         //if no review found, return null
00383         if ( $oRevs->count() < 1 ) {
00384             return null;
00385         }
00386         return $oRevs;
00387     }
00388 
00394     public function getLink()
00395     {
00396         $sUrl = $this->getConfig()->getShopHomeURL().'cl=recommlist';
00397         if ( oxUtils::getInstance()->seoIsActive() ) {
00398             $oEncoder = oxSeoEncoder::getInstance();
00399             if ( ( $sStaticUrl = $oEncoder->getStaticUrl( $sUrl ) ) ) {
00400                 $sUrl = $sStaticUrl;
00401             }
00402         }
00403         $sUrl .= ( ( strpos( $sUrl, '?' ) !== false ) ? "&amp;":"?" ) . "recommid=".$this->getId();
00404 
00405         return $sUrl;
00406     }
00407 
00415     public function setArticlesFilter($sArticlesFilter)
00416     {
00417         $this->_sArticlesFilter = $sArticlesFilter;
00418     }
00419 }

Generated on Tue Apr 21 15:45:45 2009 for OXID eShop CE by  doxygen 1.5.5