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
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
00083 if ( !( $this->getActiveRecommList() ) ) {
00084
00085 if ( $this->getRecommLists()->count() ) {
00086 $this->_iAllArtCnt = $oUser->getRecommListsCount();
00087
00088 $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
00089 $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00090 $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
00091 }
00092 }
00093
00094 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00095 return $this->_sThisTemplate;
00096 }
00097
00103 public function getNavigationParams()
00104 {
00105 $aParams = parent::getNavigationParams();
00106
00107
00108 if ( ( $oList = $this->getActiveRecommList() ) ) {
00109 $aParams['recommid'] = $oList->getId();
00110 }
00111
00112 return $aParams;
00113 }
00114
00120 public function getRecommLists()
00121 {
00122 if ( $this->_aUserRecommLists === null ) {
00123 $this->_aUserRecommLists = false;
00124 if ( ( $oUser = $this->getUser() ) ) {
00125
00126 $this->_aUserRecommLists = $oUser->getUserRecommLists();
00127 }
00128 }
00129 return $this->_aUserRecommLists;
00130 }
00131
00137 public function getActiveRecommItems()
00138 {
00139 if ( $this->_oActRecommListArticles === null ) {
00140 $this->_oActRecommListArticles = false;
00141
00142 if ( ( $oRecommList = $this->getActiveRecommList() ) ) {
00143 $oItemList = $oRecommList->getArticles();
00144
00145 if ( $oItemList->count() ) {
00146 foreach ( $oItemList as $oItem ) {
00147 $oItem->text = $oRecommList->getArtDescription( $oItem->getId() );
00148 }
00149 $this->_oActRecommListArticles = $oItemList;
00150 }
00151 }
00152 }
00153
00154 return $this->_oActRecommListArticles;
00155 }
00156
00162 public function getActiveRecommList()
00163 {
00164 if ( $this->_oActRecommList === null ) {
00165 $this->_oActRecommList = false;
00166
00167 if ( ( $oUser = $this->getUser() ) &&
00168 ( $sRecommId = oxConfig::getParameter( 'recommid' ) )) {
00169
00170 $oRecommList = oxNew( 'oxrecommlist' );
00171 if ( ( $oRecommList->load( $sRecommId ) ) && $oUser->getId() === $oRecommList->oxrecommlists__oxuserid->value ) {
00172 $this->_oActRecommList = $oRecommList;
00173 }
00174 }
00175 }
00176
00177 return $this->_oActRecommList;
00178 }
00179
00180 public function setActiveRecommList( $oRecommList )
00181 {
00182 $this->_oActRecommList = $oRecommList;
00183 }
00184
00190 public function saveRecommList()
00191 {
00192 if ( ( $oUser = $this->getUser() ) ) {
00193 if ( !( $oRecommList = $this->getActiveRecommList() ) ) {
00194 $oRecommList = oxNew( 'oxrecommlist' );
00195 $oRecommList->oxrecommlists__oxuserid = new oxField( $oUser->getId());
00196 $oRecommList->oxrecommlists__oxshopid = new oxField( $this->getConfig()->getShopId() );
00197 }
00198
00199 $sTitle = trim( ( string ) oxConfig::getParameter( 'recomm_title', 1 ) );
00200 $sAuthor = trim( ( string ) oxConfig::getParameter( 'recomm_author', 1 ) );
00201 $sText = trim( ( string ) oxConfig::getParameter( 'recomm_desc', 1 ) );
00202
00203 $oRecommList->oxrecommlists__oxtitle = new oxField( $sTitle, oxField::T_RAW );
00204 $oRecommList->oxrecommlists__oxauthor = new oxField( $sAuthor, oxField::T_RAW );
00205 $oRecommList->oxrecommlists__oxdesc = new oxField( $sText, oxField::T_RAW );
00206
00207 try {
00208
00209 $this->_blSavedEntry = (bool) $oRecommList->save();
00210 } catch (oxObjectException $oEx ) {
00211
00212 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'user' );
00213 }
00214 }
00215 }
00216
00222 public function isSavedList()
00223 {
00224 return $this->_blSavedEntry;
00225 }
00226
00232 public function editList()
00233 {
00234
00235 if ( ( $sAction = oxConfig::getParameter( 'deleteList' ) ) &&
00236 ( $oRecommList = $this->getActiveRecommList() ) ) {
00237 $oRecommList->delete();
00238 $this->setActiveRecommList( false );
00239 }
00240 }
00241
00247 public function removeArticle()
00248 {
00249 if ( ( $sArtId = oxConfig::getParameter( 'aid' ) ) &&
00250 ( $oRecommList = $this->getActiveRecommList() ) ) {
00251 $oRecommList->removeArticle( $sArtId );
00252 }
00253 }
00254
00260 public function getPageNavigation()
00261 {
00262 if ( $this->_oPageNavigation === null ) {
00263 $this->_oPageNavigation = false;
00264 if ( !$this->getActiveRecommlist() ) {
00265 $this->_oPageNavigation = $this->generatePageNavigation();
00266 }
00267 }
00268 return $this->_oPageNavigation;
00269 }
00270 }