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 $this->_aViewData['pageNavigation'] = $this->getPageNavigation();
00083
00084 if ( !( $this->getActiveRecommList() ) ) {
00085
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 }
00094
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 ( $sOxid = oxConfig::getParameter( 'recommid' ) ) {
00168 $this->_oActRecommList = oxNew( 'oxrecommlist' );
00169 if ( !$this->_oActRecommList->load( $sOxid) ) {
00170 $this->_oActRecommList = false;
00171 }
00172 }
00173 }
00174
00175 return $this->_oActRecommList;
00176 }
00177
00183 public function saveRecommList()
00184 {
00185 $oUser = $this->getUser();
00186 if ( !$oUser ) {
00187 return;
00188 }
00189
00190 $sTitle = trim( ( string ) oxConfig::getParameter( 'recomm_title', 1 ) );
00191 $sAuthor = trim( ( string ) oxConfig::getParameter( 'recomm_author', 1 ) );
00192 $sText = trim( ( string ) oxConfig::getParameter( 'recomm_desc', 1 ) );
00193
00194 $oRecommList = oxNew( 'oxrecommlist' );
00195 $sOxid = oxConfig::getParameter( 'recommid' );
00196 if ($sOxid) {
00197 $oRecommList->load( $sOxid);
00198 } else {
00199 $oRecommList->oxrecommlists__oxuserid = new oxField($oUser->getId());
00200 $oRecommList->oxrecommlists__oxshopid = new oxField($this->getConfig()->getShopId());
00201 }
00202 $oRecommList->oxrecommlists__oxtitle = new oxField($sTitle, oxField::T_RAW);
00203 $oRecommList->oxrecommlists__oxauthor = new oxField($sAuthor, oxField::T_RAW);
00204 $oRecommList->oxrecommlists__oxdesc = new oxField($sText, oxField::T_RAW);
00205
00206
00207 $this->_blSavedEntry = (bool) $oRecommList->save();
00208 }
00209
00215 public function isSavedList()
00216 {
00217 return $this->_blSavedEntry;
00218 }
00219
00225 public function editList()
00226 {
00227
00228 if ( $oUser = $this->getUser() ) {
00229 $sRecommId = oxConfig::getParameter( 'recommid' );
00230 $sAction = oxConfig::getParameter( 'deleteList' );
00231 if ( isset( $sAction ) && $sRecommId ) {
00232 $oRecommList = oxNew( 'oxrecommlist' );
00233 $oRecommList->delete( $sRecommId );
00234 }
00235 }
00236 }
00237
00243 public function removeArticle()
00244 {
00245 $oUser = $this->getUser();
00246 if ( !$oUser ) {
00247 return;
00248 }
00249
00250 $sArtId = oxConfig::getParameter( 'aid' );
00251 $sOxid = oxConfig::getParameter( 'recommid' );
00252 if ( $sOxid && $sArtId) {
00253 $oRecommList = oxNew( 'oxrecommlist' );
00254 $oRecommList->load( $sOxid );
00255 $oRecommList->removeArticle( $sArtId );
00256 }
00257 }
00258
00264 public function getPageNavigation()
00265 {
00266 if ( $this->_oPageNavigation === null ) {
00267 $this->_oPageNavigation = false;
00268 if ( !$this->getActiveRecommlist() ) {
00269 $this->_oPageNavigation = $this->generatePageNavigation();
00270 }
00271 }
00272 return $this->_oPageNavigation;
00273 }
00274
00275 }