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']    = $this->getRecommLists();
00080         $this->_aViewData['itemList']       = $this->getActiveRecommItems();
00081         $this->_aViewData['actvrecommlist'] = $this->getActiveRecommList();
00082         $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00083 
00084         if ( !( $this->getActiveRecommList() ) ) {
00085             // list of found oxrecommlists
00086             if ( $this->getRecommLists()->count() ) {
00087                 $this->_iAllArtCnt = $oUser->getRecommListsCount();
00088 
00089                 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00090                 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00091                 $this->_iCntPages  = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00092             }
00093         } else {
00094             // adding recommendation list id to list product urls
00095             $oViewConf = $this->getViewConfig();
00096             $sNavurlparams = $oViewConf->getNavUrlParams();
00097             $sNavurlparams = ( $sNavurlparams ? $sNavurlparams : '' ) . "&amp;recommid=".$this->getActiveRecommlist()->getId();
00098 
00099             $oViewConf->setViewConfigParam( 'navurlparams', $sNavurlparams );
00100         }
00101 
00102         return $this->_sThisTemplate;
00103     }
00104 
00110     public function getRecommLists()
00111     {
00112         if ( $this->_aUserRecommLists === null ) {
00113             $this->_aUserRecommLists = false;
00114             if ( $oUser = $this->getUser() ) {
00115                 // recommendation list
00116                 $this->_aUserRecommLists = $oUser->getUserRecommLists();
00117             }
00118         }
00119         return $this->_aUserRecommLists;
00120     }
00121 
00127     public function getActiveRecommItems()
00128     {
00129         if ( $this->_oActRecommListArticles === null ) {
00130             $this->_oActRecommListArticles = false;
00131 
00132             if ( $oRecommList = $this->getActiveRecommList() ) {
00133                 $oItemList = $oRecommList->getArticles();
00134 
00135                 if ( $oItemList->count() ) {
00136                     foreach ( $oItemList as $oItem ) {
00137                         $oItem->text = $oRecommList->getArtDescription( $oItem->getId() );
00138                     }
00139                     $this->_oActRecommListArticles = $oItemList;
00140                 }
00141             }
00142         }
00143 
00144         return $this->_oActRecommListArticles;
00145     }
00146 
00152     public function getActiveRecommList()
00153     {
00154         if ( $this->_oActRecommList === null ) {
00155             $this->_oActRecommList = false;
00156 
00157             if ( $sOxid = oxConfig::getParameter( 'recommid' ) ) {
00158                 $this->_oActRecommList = oxNew( 'oxrecommlist' );
00159                 if ( !$this->_oActRecommList->load( $sOxid) ) {
00160                     $this->_oActRecommList = false;
00161                 }
00162             }
00163         }
00164 
00165         return $this->_oActRecommList;
00166     }
00167 
00173     public function saveRecommList()
00174     {
00175         $oUser = $this->getUser();
00176         if ( !$oUser ) {
00177             return;
00178         }
00179 
00180         $sTitle  = trim( ( string ) oxConfig::getParameter( 'recomm_title' , 1 ) );
00181         $sAuthor = trim( ( string ) oxConfig::getParameter( 'recomm_author', 1 ) );
00182         $sText   = trim( ( string ) oxConfig::getParameter( 'recomm_desc', 1 ) );
00183 
00184         $oRecommList = oxNew( 'oxrecommlist' );
00185         $sOxid = oxConfig::getParameter( 'recommid' );
00186         if ($sOxid) {
00187             $oRecommList->load( $sOxid);
00188         } else {
00189             $oRecommList->oxrecommlists__oxuserid = new oxField($oUser->getId());
00190             $oRecommList->oxrecommlists__oxshopid = new oxField($this->getConfig()->getShopId());
00191         }
00192         $oRecommList->oxrecommlists__oxtitle  = new oxField($sTitle, oxField::T_RAW);
00193         $oRecommList->oxrecommlists__oxauthor = new oxField($sAuthor, oxField::T_RAW);
00194         $oRecommList->oxrecommlists__oxdesc   = new oxField($sText, oxField::T_RAW);
00195 
00196         // marking entry as saved
00197         $this->_blSavedEntry = (bool) $oRecommList->save();
00198     }
00199 
00205     public function isSavedList()
00206     {
00207         return $this->_blSavedEntry;
00208     }
00209 
00215     public function editList()
00216     {
00217         // deleting on demand
00218         if ( $oUser = $this->getUser() ) {
00219             $sRecommId = oxConfig::getParameter( 'recommid' );
00220             $sAction = oxConfig::getParameter( 'deleteList' );
00221             if ( isset( $sAction ) && $sRecommId ) {
00222                 $oRecommList = oxNew( 'oxrecommlist' );
00223                 $oRecommList->delete( $sRecommId );
00224             }
00225         }
00226     }
00227 
00233     public function removeArticle()
00234     {
00235         $oUser = $this->getUser();
00236         if ( !$oUser ) {
00237             return;
00238         }
00239 
00240         $sArtId = oxConfig::getParameter( 'aid' );
00241         $sOxid  = oxConfig::getParameter( 'recommid' );
00242         if ( $sOxid && $sArtId) {
00243             $oRecommList = oxNew( 'oxrecommlist' );
00244             $oRecommList->load( $sOxid );
00245             $oRecommList->removeArticle( $sArtId );
00246         }
00247     }
00248 
00254     public function getPageNavigation()
00255     {
00256         if ( $this->_oPageNavigation === null ) {
00257             $this->_oPageNavigation = false;
00258             if ( !$this->getActiveRecommlist() ) {
00259                 $this->_oPageNavigation = $this->generatePageNavigation();
00260             }
00261         }
00262         return $this->_oPageNavigation;
00263     }
00264 
00265 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5