account_recommlist.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Account_Recommlist extends Account
00010 {
00016     protected $_sThisTemplate = 'account_recommlist.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 
00070     public function render()
00071     {
00072         parent::render();
00073 
00074         // is logged in ?
00075         if ( !( $oUser = $this->getUser() ) ) {
00076             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00077         }
00078 
00079         $this->_aViewData['recommlists']    = $oLists   = $this->getRecommLists();
00080         $this->_aViewData['actvrecommlist'] = $oActList = $this->getActiveRecommList();
00081         $this->_aViewData['itemList']       = $this->getActiveRecommItems();
00082 
00083         // list of found oxrecommlists
00084         if ( !$oActList && $oLists->count() ) {
00085             $this->_iAllArtCnt = $oUser->getRecommListsCount();
00086             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00087             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00088             $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00089         }
00090 
00091         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00092         return $this->_sThisTemplate;
00093     }
00094 
00100     public function getNavigationParams()
00101     {
00102         $aParams = parent::getNavigationParams();
00103 
00104         // adding recommendation list id to list product urls
00105         if ( ( $oList = $this->getActiveRecommList() ) ) {
00106             $aParams['recommid'] = $oList->getId();
00107         }
00108 
00109         return $aParams;
00110     }
00111 
00117     public function getRecommLists()
00118     {
00119         if ( $this->_aUserRecommLists === null ) {
00120             $this->_aUserRecommLists = false;
00121             if ( ( $oUser = $this->getUser() ) ) {
00122                 // recommendation list
00123                 $this->_aUserRecommLists = $oUser->getUserRecommLists();
00124             }
00125         }
00126         return $this->_aUserRecommLists;
00127     }
00128 
00134     public function getActiveRecommItems()
00135     {
00136         if ( $this->_oActRecommListArticles === null ) {
00137             $this->_oActRecommListArticles = false;
00138 
00139             if ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00140                 $oItemList = $oRecommList->getArticles();
00141 
00142                 if ( $oItemList->count() ) {
00143                     foreach ( $oItemList as $oItem ) {
00144                         $oItem->text = $oRecommList->getArtDescription( $oItem->getId() );
00145                     }
00146                     $this->_oActRecommListArticles = $oItemList;
00147                 }
00148             }
00149         }
00150 
00151         return $this->_oActRecommListArticles;
00152     }
00153 
00159     public function getActiveRecommList()
00160     {
00161         if (!$this->getViewConfig()->getShowListmania()) {
00162             return false;
00163         }
00164 
00165         if ( $this->_oActRecommList === null ) {
00166             $this->_oActRecommList = false;
00167 
00168             if ( ( $oUser = $this->getUser() ) &&
00169                  ( $sRecommId = oxConfig::getParameter( 'recommid' ) )) {
00170 
00171                 $oRecommList = oxNew( 'oxrecommlist' );
00172                 if ( ( $oRecommList->load( $sRecommId ) ) && $oUser->getId() === $oRecommList->oxrecommlists__oxuserid->value ) {
00173                     $this->_oActRecommList = $oRecommList;
00174                 }
00175             }
00176         }
00177 
00178         return $this->_oActRecommList;
00179     }
00180 
00188     public function setActiveRecommList( $oRecommList )
00189     {
00190         $this->_oActRecommList = $oRecommList;
00191     }
00192 
00198     public function saveRecommList()
00199     {
00200         if (!$this->getViewConfig()->getShowListmania()) {
00201             return;
00202         }
00203 
00204         if ( ( $oUser = $this->getUser() ) ) {
00205             if ( !( $oRecommList = $this->getActiveRecommList() ) ) {
00206                 $oRecommList = oxNew( 'oxrecommlist' );
00207                 $oRecommList->oxrecommlists__oxuserid = new oxField( $oUser->getId());
00208                 $oRecommList->oxrecommlists__oxshopid = new oxField( $this->getConfig()->getShopId() );
00209             }
00210 
00211             $sTitle  = trim( ( string ) oxConfig::getParameter( 'recomm_title', 1 ) );
00212             $sAuthor = trim( ( string ) oxConfig::getParameter( 'recomm_author', 1 ) );
00213             $sText   = trim( ( string ) oxConfig::getParameter( 'recomm_desc', 1 ) );
00214 
00215             $oRecommList->oxrecommlists__oxtitle  = new oxField( $sTitle );
00216             $oRecommList->oxrecommlists__oxauthor = new oxField( $sAuthor );
00217             $oRecommList->oxrecommlists__oxdesc   = new oxField( $sText );
00218 
00219             try {
00220                 // marking entry as saved
00221                 $this->_blSavedEntry = (bool) $oRecommList->save();
00222             } catch (oxObjectException $oEx ) {
00223                 //add to display at specific position
00224                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'user' );
00225             }
00226         }
00227     }
00228 
00234     public function isSavedList()
00235     {
00236         return $this->_blSavedEntry;
00237     }
00238 
00244     public function editList()
00245     {
00246         if (!$this->getViewConfig()->getShowListmania()) {
00247             return;
00248         }
00249 
00250         // deleting on demand
00251         if ( ( $sAction = oxConfig::getParameter( 'deleteList' ) ) &&
00252              ( $oRecommList = $this->getActiveRecommList() ) ) {
00253             $oRecommList->delete();
00254             $this->setActiveRecommList( false );
00255         }
00256     }
00257 
00263     public function removeArticle()
00264     {
00265         if (!$this->getViewConfig()->getShowListmania()) {
00266             return;
00267         }
00268 
00269         if ( ( $sArtId = oxConfig::getParameter( 'aid' ) ) &&
00270              ( $oRecommList = $this->getActiveRecommList() ) ) {
00271             $oRecommList->removeArticle( $sArtId );
00272         }
00273     }
00274 
00280     public function getPageNavigation()
00281     {
00282         if ( $this->_oPageNavigation === null ) {
00283             $this->_oPageNavigation = false;
00284             if ( !$this->getActiveRecommlist() ) {
00285                 $this->_oPageNavigation = $this->generatePageNavigation();
00286             }
00287         }
00288         return $this->_oPageNavigation;
00289     }
00290 }