account_recommlist.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Account_Recommlist extends Account
00010 {
00011 
00017     protected $_sThisTemplate = 'page/account/recommendationlist.tpl';
00018 
00024     protected $_blSavedEntry = false;
00025 
00031     protected $_oActRecommListArticles = null;
00032 
00038     protected $_aUserRecommLists = null;
00039 
00045     protected $_oActRecommList = null;
00046 
00052     protected $_iAllArtCnt = 0;
00053 
00059     protected $_oPageNavigation = null;
00060 
00069     public function render()
00070     {
00071         parent::render();
00072 
00073         // is logged in ?
00074         if (!($oUser = $this->getUser())) {
00075             return $this->_sThisTemplate = $this->_sThisLoginTemplate;
00076         }
00077 
00078         $oLists = $this->getRecommLists();
00079         $oActList = $this->getActiveRecommList();
00080 
00081         // list of found oxrecommlists
00082         if (!$oActList && $oLists->count()) {
00083             $this->_iAllArtCnt = $oUser->getRecommListsCount();
00084             $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
00085             $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
00086             $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
00087         }
00088 
00089         return $this->_sThisTemplate;
00090     }
00091 
00097     public function getNavigationParams()
00098     {
00099         $aParams = parent::getNavigationParams();
00100 
00101         // adding recommendation list id to list product urls
00102         if (($oList = $this->getActiveRecommList())) {
00103             $aParams['recommid'] = $oList->getId();
00104         }
00105 
00106         return $aParams;
00107     }
00108 
00114     public function getRecommLists()
00115     {
00116         if ($this->_aUserRecommLists === null) {
00117             $this->_aUserRecommLists = false;
00118             if (($oUser = $this->getUser())) {
00119                 // recommendation list
00120                 $this->_aUserRecommLists = $oUser->getUserRecommLists();
00121             }
00122         }
00123 
00124         return $this->_aUserRecommLists;
00125     }
00126 
00132     public function getArticleList()
00133     {
00134         if ($this->_oActRecommListArticles === null) {
00135             $this->_oActRecommListArticles = false;
00136 
00137             if (($oRecommList = $this->getActiveRecommList())) {
00138                 $oItemList = $oRecommList->getArticles();
00139 
00140                 if ($oItemList->count()) {
00141                     foreach ($oItemList as $key => $oItem) {
00142                         if (!$oItem->isVisible()) {
00143                             $oRecommList->removeArticle($oItem->getId());
00144                             $oItemList->offsetUnset($key);
00145                             continue;
00146                         }
00147 
00148                         $oItem->text = $oRecommList->getArtDescription($oItem->getId());
00149                     }
00150                     $this->_oActRecommListArticles = $oItemList;
00151                 }
00152             }
00153         }
00154 
00155         return $this->_oActRecommListArticles;
00156     }
00157 
00163     public function getActiveRecommList()
00164     {
00165         if (!$this->getViewConfig()->getShowListmania()) {
00166             return false;
00167         }
00168 
00169         if ($this->_oActRecommList === null) {
00170             $this->_oActRecommList = false;
00171 
00172             if (($oUser = $this->getUser()) &&
00173                 ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid'))
00174             ) {
00175 
00176                 $oRecommList = oxNew('oxrecommlist');
00177                 $sUserIdField = 'oxrecommlists__oxuserid';
00178                 if (($oRecommList->load($sRecommId)) && $oUser->getId() === $oRecommList->$sUserIdField->value) {
00179                     $this->_oActRecommList = $oRecommList;
00180                 }
00181             }
00182         }
00183 
00184         return $this->_oActRecommList;
00185     }
00186 
00192     public function setActiveRecommList($oRecommList)
00193     {
00194         $this->_oActRecommList = $oRecommList;
00195     }
00196 
00202     public function saveRecommList()
00203     {
00204         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00205             return;
00206         }
00207 
00208         if (!$this->getViewConfig()->getShowListmania()) {
00209             return;
00210         }
00211 
00212         if (($oUser = $this->getUser())) {
00213             if (!($oRecommList = $this->getActiveRecommList())) {
00214                 $oRecommList = oxNew('oxrecommlist');
00215                 $oRecommList->oxrecommlists__oxuserid = new oxField($oUser->getId());
00216                 $oRecommList->oxrecommlists__oxshopid = new oxField($this->getConfig()->getShopId());
00217             } else {
00218                 $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00219             }
00220 
00221             $sTitle = trim(( string ) oxRegistry::getConfig()->getRequestParameter('recomm_title', true));
00222             $sAuthor = trim(( string ) oxRegistry::getConfig()->getRequestParameter('recomm_author', true));
00223             $sText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('recomm_desc', true));
00224 
00225             $oRecommList->oxrecommlists__oxtitle = new oxField($sTitle);
00226             $oRecommList->oxrecommlists__oxauthor = new oxField($sAuthor);
00227             $oRecommList->oxrecommlists__oxdesc = new oxField($sText);
00228 
00229             try {
00230                 // marking entry as saved
00231                 $this->_blSavedEntry = (bool) $oRecommList->save();
00232                 $this->setActiveRecommList($this->_blSavedEntry ? $oRecommList : false);
00233             } catch (oxObjectException $oEx) {
00234                 //add to display at specific position
00235                 oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'user');
00236             }
00237         }
00238     }
00239 
00245     public function isSavedList()
00246     {
00247         return $this->_blSavedEntry;
00248     }
00249 
00255     public function editList()
00256     {
00257         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00258             return;
00259         }
00260 
00261         if (!$this->getViewConfig()->getShowListmania()) {
00262             return;
00263         }
00264 
00265         // deleting on demand
00266         if (($sAction = oxRegistry::getConfig()->getRequestParameter('deleteList')) &&
00267             ($oRecommList = $this->getActiveRecommList())
00268         ) {
00269             $oRecommList->delete();
00270             $this->setActiveRecommList(false);
00271         } else {
00272             $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00273         }
00274     }
00275 
00281     public function removeArticle()
00282     {
00283         if (!oxRegistry::getSession()->checkSessionChallenge()) {
00284             return;
00285         }
00286 
00287         if (!$this->getViewConfig()->getShowListmania()) {
00288             return;
00289         }
00290 
00291         if (($sArtId = oxRegistry::getConfig()->getRequestParameter('aid')) &&
00292             ($oRecommList = $this->getActiveRecommList())
00293         ) {
00294             $oRecommList->removeArticle($sArtId);
00295         }
00296         $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
00297     }
00298 
00304     public function getPageNavigation()
00305     {
00306         if ($this->_oPageNavigation === null) {
00307             $this->_oPageNavigation = false;
00308             if (!$this->getActiveRecommlist()) {
00309                 $this->_oPageNavigation = $this->generatePageNavigation();
00310             }
00311         }
00312 
00313         return $this->_oPageNavigation;
00314     }
00315 
00321     public function getBreadCrumb()
00322     {
00323         $aPaths = array();
00324         $aPath = array();
00325 
00326         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00327         $sSelfLink = $this->getViewConfig()->getSelfLink();
00328         $aPath['title'] = oxRegistry::getLang()->translateString('MY_ACCOUNT', $iBaseLanguage, false);
00329         $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($sSelfLink . 'cl=account');
00330         $aPaths[] = $aPath;
00331 
00332         $aPath['title'] = oxRegistry::getLang()->translateString('LISTMANIA', $iBaseLanguage, false);
00333         $aPath['link'] = $this->getLink();
00334         $aPaths[] = $aPath;
00335 
00336         return $aPaths;
00337     }
00338 
00344     public function getArticleCount()
00345     {
00346         return $this->_iAllArtCnt;
00347     }
00348 }