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 (!oxRegistry::getSession()->checkSessionChallenge()) {
00202             return;
00203         }
00204 
00205         if (!$this->getViewConfig()->getShowListmania()) {
00206             return;
00207         }
00208 
00209         if ( ( $oUser = $this->getUser() ) ) {
00210             if ( !( $oRecommList = $this->getActiveRecommList() ) ) {
00211                 $oRecommList = oxNew( 'oxrecommlist' );
00212                 $oRecommList->oxrecommlists__oxuserid = new oxField( $oUser->getId());
00213                 $oRecommList->oxrecommlists__oxshopid = new oxField( $this->getConfig()->getShopId() );
00214             } else {
00215                 $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00216             }
00217 
00218             $sTitle  = trim( ( string ) oxRegistry::getConfig()->getRequestParameter( 'recomm_title', true ) );
00219             $sAuthor = trim( ( string ) oxRegistry::getConfig()->getRequestParameter( 'recomm_author', true ) );
00220             $sText   = trim( ( string ) oxRegistry::getConfig()->getRequestParameter( 'recomm_desc', true ) );
00221 
00222             $oRecommList->oxrecommlists__oxtitle  = new oxField( $sTitle );
00223             $oRecommList->oxrecommlists__oxauthor = new oxField( $sAuthor );
00224             $oRecommList->oxrecommlists__oxdesc   = new oxField( $sText );
00225 
00226             try {
00227                 // marking entry as saved
00228                 $this->_blSavedEntry = (bool) $oRecommList->save();
00229                 $this->setActiveRecommList( $this->_blSavedEntry ? $oRecommList : false );
00230             } catch (oxObjectException $oEx ) {
00231                 //add to display at specific position
00232                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true, 'user' );
00233             }
00234         }
00235     }
00236 
00242     public function isSavedList()
00243     {
00244         return $this->_blSavedEntry;
00245     }
00246 
00252     public function editList()
00253     {
00254         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00255             return;
00256         }
00257 
00258         if (!$this->getViewConfig()->getShowListmania()) {
00259             return;
00260         }
00261 
00262         // deleting on demand
00263         if ( ( $sAction = oxConfig::getParameter( 'deleteList' ) ) &&
00264              ( $oRecommList = $this->getActiveRecommList() ) ) {
00265             $oRecommList->delete();
00266             $this->setActiveRecommList( false );
00267         } else {
00268             $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00269         }
00270     }
00271 
00277     public function removeArticle()
00278     {
00279         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00280             return;
00281         }
00282 
00283         if (!$this->getViewConfig()->getShowListmania()) {
00284             return;
00285         }
00286 
00287         if ( ( $sArtId = oxConfig::getParameter( 'aid' ) ) &&
00288              ( $oRecommList = $this->getActiveRecommList() ) ) {
00289             $oRecommList->removeArticle( $sArtId );
00290         }
00291         $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00292     }
00293 
00299     public function getPageNavigation()
00300     {
00301         if ( $this->_oPageNavigation === null ) {
00302             $this->_oPageNavigation = false;
00303             if ( !$this->getActiveRecommlist() ) {
00304                 $this->_oPageNavigation = $this->generatePageNavigation();
00305             }
00306         }
00307         return $this->_oPageNavigation;
00308     }
00309 
00315     public function getBreadCrumb()
00316     {
00317         $aPaths = array();
00318         $aPath = array();
00319 
00320         $aPath['title'] = oxRegistry::getLang()->translateString( 'MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
00321         $aPath['link']  = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
00322         $aPaths[] = $aPath;
00323 
00324         $aPath['title'] = oxRegistry::getLang()->translateString( 'LISTMANIA', oxRegistry::getLang()->getBaseLanguage(), false );
00325         $aPath['link']  = $this->getLink();
00326         $aPaths[] = $aPath;
00327 
00328         return $aPaths;
00329     }
00330 
00336     public function getArticleCount()
00337     {
00338         return $this->_iAllArtCnt;
00339     }
00340 
00341 }