account_recommlist.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Account_Recommlist extends Account
00010 {
00016     protected $_sThisTemplate = 'page/account/recommendationlist.tpl';
00017 
00023     protected $_blSavedEntry = false;
00024 
00030     protected $_oActRecommListArticles = null;
00031 
00037     protected $_aUserRecommLists = null;
00038 
00044     protected $_oActRecommList = null;
00045 
00051     protected $_iAllArtCnt = 0;
00052 
00057     protected $_oPageNavigation = null;
00058 
00067     public function render()
00068     {
00069         parent::render();
00070 
00071         // is logged in ?
00072         if ( !( $oUser = $this->getUser() ) ) {
00073             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00074         }
00075 
00076         $oLists   = $this->getRecommLists();
00077         $oActList = $this->getActiveRecommList();
00078 
00079         // list of found oxrecommlists
00080         if ( !$oActList && $oLists->count() ) {
00081             $this->_iAllArtCnt = $oUser->getRecommListsCount();
00082             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00083             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00084             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00085         }
00086 
00087         return $this->_sThisTemplate;
00088     }
00089 
00095     public function getNavigationParams()
00096     {
00097         $aParams = parent::getNavigationParams();
00098 
00099         // adding recommendation list id to list product urls
00100         if ( ( $oList = $this->getActiveRecommList() ) ) {
00101             $aParams['recommid'] = $oList->getId();
00102         }
00103 
00104         return $aParams;
00105     }
00106 
00112     public function getRecommLists()
00113     {
00114         if ( $this->_aUserRecommLists === null ) {
00115             $this->_aUserRecommLists = false;
00116             if ( ( $oUser = $this->getUser() ) ) {
00117                 // recommendation list
00118                 $this->_aUserRecommLists = $oUser->getUserRecommLists();
00119             }
00120         }
00121         return $this->_aUserRecommLists;
00122     }
00123 
00129     public function getArticleList()
00130     {
00131         if ( $this->_oActRecommListArticles === null ) {
00132             $this->_oActRecommListArticles = false;
00133 
00134             if ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00135                 $oItemList = $oRecommList->getArticles();
00136 
00137                 if ( $oItemList->count() ) {
00138                     foreach ( $oItemList as $key => $oItem ) {
00139                         if ( !$oItem->isVisible() ) {
00140                             $oRecommList->removeArticle( $oItem->getId() );
00141                             $oItemList->offsetUnset( $key );
00142                             continue;
00143                         }
00144 
00145                         $oItem->text = $oRecommList->getArtDescription( $oItem->getId() );
00146                     }
00147                     $this->_oActRecommListArticles = $oItemList;
00148                 }
00149             }
00150         }
00151 
00152         return $this->_oActRecommListArticles;
00153     }
00154 
00160     public function getActiveRecommList()
00161     {
00162         if (!$this->getViewConfig()->getShowListmania()) {
00163             return false;
00164         }
00165 
00166         if ( $this->_oActRecommList === null ) {
00167             $this->_oActRecommList = false;
00168 
00169             if ( ( $oUser = $this->getUser() ) &&
00170                  ( $sRecommId = oxConfig::getParameter( 'recommid' ) )) {
00171 
00172                 $oRecommList = oxNew( 'oxrecommlist' );
00173                 if ( ( $oRecommList->load( $sRecommId ) ) && $oUser->getId() === $oRecommList->oxrecommlists__oxuserid->value ) {
00174                     $this->_oActRecommList = $oRecommList;
00175                 }
00176             }
00177         }
00178 
00179         return $this->_oActRecommList;
00180     }
00181 
00189     public function setActiveRecommList( $oRecommList )
00190     {
00191         $this->_oActRecommList = $oRecommList;
00192     }
00193 
00199     public function saveRecommList()
00200     {
00201         if (!$this->getViewConfig()->getShowListmania()) {
00202             return;
00203         }
00204 
00205         if ( ( $oUser = $this->getUser() ) ) {
00206             if ( !( $oRecommList = $this->getActiveRecommList() ) ) {
00207                 $oRecommList = oxNew( 'oxrecommlist' );
00208                 $oRecommList->oxrecommlists__oxuserid = new oxField( $oUser->getId());
00209                 $oRecommList->oxrecommlists__oxshopid = new oxField( $this->getConfig()->getShopId() );
00210             } else {
00211                 $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00212             }
00213 
00214             $sTitle  = trim( ( string ) oxConfig::getParameter( 'recomm_title', 1 ) );
00215             $sAuthor = trim( ( string ) oxConfig::getParameter( 'recomm_author', 1 ) );
00216             $sText   = trim( ( string ) oxConfig::getParameter( 'recomm_desc', 1 ) );
00217 
00218             $oRecommList->oxrecommlists__oxtitle  = new oxField( $sTitle );
00219             $oRecommList->oxrecommlists__oxauthor = new oxField( $sAuthor );
00220             $oRecommList->oxrecommlists__oxdesc   = new oxField( $sText );
00221 
00222             try {
00223                 // marking entry as saved
00224                 $this->_blSavedEntry = (bool) $oRecommList->save();
00225                 $this->setActiveRecommList( $this->_blSavedEntry ? $oRecommList : false );
00226             } catch (oxObjectException $oEx ) {
00227                 //add to display at specific position
00228                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true, 'user' );
00229             }
00230         }
00231     }
00232 
00238     public function isSavedList()
00239     {
00240         return $this->_blSavedEntry;
00241     }
00242 
00248     public function editList()
00249     {
00250         if (!$this->getViewConfig()->getShowListmania()) {
00251             return;
00252         }
00253 
00254         // deleting on demand
00255         if ( ( $sAction = oxConfig::getParameter( 'deleteList' ) ) &&
00256              ( $oRecommList = $this->getActiveRecommList() ) ) {
00257             $oRecommList->delete();
00258             $this->setActiveRecommList( false );
00259         } else {
00260             $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00261         }
00262     }
00263 
00269     public function removeArticle()
00270     {
00271         if (!$this->getViewConfig()->getShowListmania()) {
00272             return;
00273         }
00274 
00275         if ( ( $sArtId = oxConfig::getParameter( 'aid' ) ) &&
00276              ( $oRecommList = $this->getActiveRecommList() ) ) {
00277             $oRecommList->removeArticle( $sArtId );
00278         }
00279         $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00280     }
00281 
00287     public function getPageNavigation()
00288     {
00289         if ( $this->_oPageNavigation === null ) {
00290             $this->_oPageNavigation = false;
00291             if ( !$this->getActiveRecommlist() ) {
00292                 $this->_oPageNavigation = $this->generatePageNavigation();
00293             }
00294         }
00295         return $this->_oPageNavigation;
00296     }
00297 
00303     public function getBreadCrumb()
00304     {
00305         $aPaths = array();
00306         $aPath = array();
00307 
00308         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_ACCOUNT_MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
00309         $aPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00310         $aPaths[] = $aPath;
00311 
00312         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_ACCOUNT_RECOMMENDATIONLIST_TITLE', oxRegistry::getLang()->getBaseLanguage(), false );
00313         $aPath['link']  = $this->getLink();
00314         $aPaths[] = $aPath;
00315 
00316         return $aPaths;
00317     }
00318 
00324     public function getArticleCount()
00325     {
00326         return $this->_iAllArtCnt;
00327     }
00328 
00329 }