OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
account_recommlist.php
Go to the documentation of this file.
1 <?php
2 
10 {
16  protected $_sThisTemplate = 'page/account/recommendationlist.tpl';
17 
23  protected $_blSavedEntry = false;
24 
30  protected $_oActRecommListArticles = null;
31 
37  protected $_aUserRecommLists = null;
38 
44  protected $_oActRecommList = null;
45 
51  protected $_iAllArtCnt = 0;
52 
57  protected $_oPageNavigation = null;
58 
67  public function render()
68  {
70 
71  // is logged in ?
72  if ( !( $oUser = $this->getUser() ) ) {
73  return $this->_sThisTemplate = $this->_sThisLoginTemplate;
74  }
75 
76  $oLists = $this->getRecommLists();
77  $oActList = $this->getActiveRecommList();
78 
79  // list of found oxrecommlists
80  if ( !$oActList && $oLists->count() ) {
81  $this->_iAllArtCnt = $oUser->getRecommListsCount();
82  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam( 'iNrofCatArticles' );
83  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
84  $this->_iCntPages = round( $this->_iAllArtCnt / $iNrofCatArticles + 0.49 );
85  }
86 
87  return $this->_sThisTemplate;
88  }
89 
95  public function getNavigationParams()
96  {
97  $aParams = parent::getNavigationParams();
98 
99  // adding recommendation list id to list product urls
100  if ( ( $oList = $this->getActiveRecommList() ) ) {
101  $aParams['recommid'] = $oList->getId();
102  }
103 
104  return $aParams;
105  }
106 
112  public function getRecommLists()
113  {
114  if ( $this->_aUserRecommLists === null ) {
115  $this->_aUserRecommLists = false;
116  if ( ( $oUser = $this->getUser() ) ) {
117  // recommendation list
118  $this->_aUserRecommLists = $oUser->getUserRecommLists();
119  }
120  }
122  }
123 
129  public function getArticleList()
130  {
131  if ( $this->_oActRecommListArticles === null ) {
132  $this->_oActRecommListArticles = false;
133 
134  if ( ( $oRecommList = $this->getActiveRecommList() ) ) {
135  $oItemList = $oRecommList->getArticles();
136 
137  if ( $oItemList->count() ) {
138  foreach ( $oItemList as $key => $oItem ) {
139  if ( !$oItem->isVisible() ) {
140  $oRecommList->removeArticle( $oItem->getId() );
141  $oItemList->offsetUnset( $key );
142  continue;
143  }
144 
145  $oItem->text = $oRecommList->getArtDescription( $oItem->getId() );
146  }
147  $this->_oActRecommListArticles = $oItemList;
148  }
149  }
150  }
151 
153  }
154 
160  public function getActiveRecommList()
161  {
162  if (!$this->getViewConfig()->getShowListmania()) {
163  return false;
164  }
165 
166  if ( $this->_oActRecommList === null ) {
167  $this->_oActRecommList = false;
168 
169  if ( ( $oUser = $this->getUser() ) &&
170  ( $sRecommId = oxConfig::getParameter( 'recommid' ) )) {
171 
172  $oRecommList = oxNew( 'oxrecommlist' );
173  if ( ( $oRecommList->load( $sRecommId ) ) && $oUser->getId() === $oRecommList->oxrecommlists__oxuserid->value ) {
174  $this->_oActRecommList = $oRecommList;
175  }
176  }
177  }
178 
179  return $this->_oActRecommList;
180  }
181 
189  public function setActiveRecommList( $oRecommList )
190  {
191  $this->_oActRecommList = $oRecommList;
192  }
193 
199  public function saveRecommList()
200  {
201  if (!oxRegistry::getSession()->checkSessionChallenge()) {
202  return;
203  }
204 
205  if (!$this->getViewConfig()->getShowListmania()) {
206  return;
207  }
208 
209  if ( ( $oUser = $this->getUser() ) ) {
210  if ( !( $oRecommList = $this->getActiveRecommList() ) ) {
211  $oRecommList = oxNew( 'oxrecommlist' );
212  $oRecommList->oxrecommlists__oxuserid = new oxField( $oUser->getId());
213  $oRecommList->oxrecommlists__oxshopid = new oxField( $this->getConfig()->getShopId() );
214  } else {
215  $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
216  }
217 
218  $sTitle = trim( ( string ) oxRegistry::getConfig()->getRequestParameter( 'recomm_title', true ) );
219  $sAuthor = trim( ( string ) oxRegistry::getConfig()->getRequestParameter( 'recomm_author', true ) );
220  $sText = trim( ( string ) oxRegistry::getConfig()->getRequestParameter( 'recomm_desc', true ) );
221 
222  $oRecommList->oxrecommlists__oxtitle = new oxField( $sTitle );
223  $oRecommList->oxrecommlists__oxauthor = new oxField( $sAuthor );
224  $oRecommList->oxrecommlists__oxdesc = new oxField( $sText );
225 
226  try {
227  // marking entry as saved
228  $this->_blSavedEntry = (bool) $oRecommList->save();
229  $this->setActiveRecommList( $this->_blSavedEntry ? $oRecommList : false );
230  } catch (oxObjectException $oEx ) {
231  //add to display at specific position
232  oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false, true, 'user' );
233  }
234  }
235  }
236 
242  public function isSavedList()
243  {
244  return $this->_blSavedEntry;
245  }
246 
252  public function editList()
253  {
254  if (!oxRegistry::getSession()->checkSessionChallenge()) {
255  return;
256  }
257 
258  if (!$this->getViewConfig()->getShowListmania()) {
259  return;
260  }
261 
262  // deleting on demand
263  if ( ( $sAction = oxConfig::getParameter( 'deleteList' ) ) &&
264  ( $oRecommList = $this->getActiveRecommList() ) ) {
265  $oRecommList->delete();
266  $this->setActiveRecommList( false );
267  } else {
268  $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
269  }
270  }
271 
277  public function removeArticle()
278  {
279  if (!oxRegistry::getSession()->checkSessionChallenge()) {
280  return;
281  }
282 
283  if (!$this->getViewConfig()->getShowListmania()) {
284  return;
285  }
286 
287  if ( ( $sArtId = oxConfig::getParameter( 'aid' ) ) &&
288  ( $oRecommList = $this->getActiveRecommList() ) ) {
289  $oRecommList->removeArticle( $sArtId );
290  }
291  $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
292  }
293 
299  public function getPageNavigation()
300  {
301  if ( $this->_oPageNavigation === null ) {
302  $this->_oPageNavigation = false;
303  if ( !$this->getActiveRecommlist() ) {
304  $this->_oPageNavigation = $this->generatePageNavigation();
305  }
306  }
308  }
309 
315  public function getBreadCrumb()
316  {
317  $aPaths = array();
318  $aPath = array();
319 
320  $aPath['title'] = oxRegistry::getLang()->translateString( 'MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false );
321  $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl( $this->getViewConfig()->getSelfLink() . 'cl=account' );
322  $aPaths[] = $aPath;
323 
324  $aPath['title'] = oxRegistry::getLang()->translateString( 'LISTMANIA', oxRegistry::getLang()->getBaseLanguage(), false );
325  $aPath['link'] = $this->getLink();
326  $aPaths[] = $aPath;
327 
328  return $aPaths;
329  }
330 
336  public function getArticleCount()
337  {
338  return $this->_iAllArtCnt;
339  }
340 
341 }