OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
account_recommlist.php
Go to the documentation of this file.
1 <?php
2 
10 {
11 
17  protected $_sThisTemplate = 'page/account/recommendationlist.tpl';
18 
24  protected $_blSavedEntry = false;
25 
31  protected $_oActRecommListArticles = null;
32 
38  protected $_aUserRecommLists = null;
39 
45  protected $_oActRecommList = null;
46 
52  protected $_iAllArtCnt = 0;
53 
59  protected $_oPageNavigation = null;
60 
69  public function render()
70  {
72 
73  // is logged in ?
74  if (!($oUser = $this->getUser())) {
75  return $this->_sThisTemplate = $this->_sThisLoginTemplate;
76  }
77 
78  $oLists = $this->getRecommLists();
79  $oActList = $this->getActiveRecommList();
80 
81  // list of found oxrecommlists
82  if (!$oActList && $oLists->count()) {
83  $this->_iAllArtCnt = $oUser->getRecommListsCount();
84  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
85  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 10;
86  $this->_iCntPages = round($this->_iAllArtCnt / $iNrofCatArticles + 0.49);
87  }
88 
89  return $this->_sThisTemplate;
90  }
91 
97  public function getNavigationParams()
98  {
99  $aParams = parent::getNavigationParams();
100 
101  // adding recommendation list id to list product urls
102  if (($oList = $this->getActiveRecommList())) {
103  $aParams['recommid'] = $oList->getId();
104  }
105 
106  return $aParams;
107  }
108 
114  public function getRecommLists()
115  {
116  if ($this->_aUserRecommLists === null) {
117  $this->_aUserRecommLists = false;
118  if (($oUser = $this->getUser())) {
119  // recommendation list
120  $this->_aUserRecommLists = $oUser->getUserRecommLists();
121  }
122  }
123 
125  }
126 
132  public function getArticleList()
133  {
134  if ($this->_oActRecommListArticles === null) {
135  $this->_oActRecommListArticles = false;
136 
137  if (($oRecommList = $this->getActiveRecommList())) {
138  $oItemList = $oRecommList->getArticles();
139 
140  if ($oItemList->count()) {
141  foreach ($oItemList as $key => $oItem) {
142  if (!$oItem->isVisible()) {
143  $oRecommList->removeArticle($oItem->getId());
144  $oItemList->offsetUnset($key);
145  continue;
146  }
147 
148  $oItem->text = $oRecommList->getArtDescription($oItem->getId());
149  }
150  $this->_oActRecommListArticles = $oItemList;
151  }
152  }
153  }
154 
156  }
157 
163  public function getActiveRecommList()
164  {
165  if (!$this->getViewConfig()->getShowListmania()) {
166  return false;
167  }
168 
169  if ($this->_oActRecommList === null) {
170  $this->_oActRecommList = false;
171 
172  if (($oUser = $this->getUser()) &&
173  ($sRecommId = oxRegistry::getConfig()->getRequestParameter('recommid'))
174  ) {
175 
176  $oRecommList = oxNew('oxrecommlist');
177  $sUserIdField = 'oxrecommlists__oxuserid';
178  if (($oRecommList->load($sRecommId)) && $oUser->getId() === $oRecommList->$sUserIdField->value) {
179  $this->_oActRecommList = $oRecommList;
180  }
181  }
182  }
183 
184  return $this->_oActRecommList;
185  }
186 
192  public function setActiveRecommList($oRecommList)
193  {
194  $this->_oActRecommList = $oRecommList;
195  }
196 
202  public function saveRecommList()
203  {
204  if (!oxRegistry::getSession()->checkSessionChallenge()) {
205  return;
206  }
207 
208  if (!$this->getViewConfig()->getShowListmania()) {
209  return;
210  }
211 
212  if (($oUser = $this->getUser())) {
213  if (!($oRecommList = $this->getActiveRecommList())) {
214  $oRecommList = oxNew('oxrecommlist');
215  $oRecommList->oxrecommlists__oxuserid = new oxField($oUser->getId());
216  $oRecommList->oxrecommlists__oxshopid = new oxField($this->getConfig()->getShopId());
217  } else {
218  $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
219  }
220 
221  $sTitle = trim(( string ) oxRegistry::getConfig()->getRequestParameter('recomm_title', true));
222  $sAuthor = trim(( string ) oxRegistry::getConfig()->getRequestParameter('recomm_author', true));
223  $sText = trim(( string ) oxRegistry::getConfig()->getRequestParameter('recomm_desc', true));
224 
225  $oRecommList->oxrecommlists__oxtitle = new oxField($sTitle);
226  $oRecommList->oxrecommlists__oxauthor = new oxField($sAuthor);
227  $oRecommList->oxrecommlists__oxdesc = new oxField($sText);
228 
229  try {
230  // marking entry as saved
231  $this->_blSavedEntry = (bool) $oRecommList->save();
232  $this->setActiveRecommList($this->_blSavedEntry ? $oRecommList : false);
233  } catch (oxObjectException $oEx) {
234  //add to display at specific position
235  oxRegistry::get("oxUtilsView")->addErrorToDisplay($oEx, false, true, 'user');
236  }
237  }
238  }
239 
245  public function isSavedList()
246  {
247  return $this->_blSavedEntry;
248  }
249 
255  public function editList()
256  {
257  if (!oxRegistry::getSession()->checkSessionChallenge()) {
258  return;
259  }
260 
261  if (!$this->getViewConfig()->getShowListmania()) {
262  return;
263  }
264 
265  // deleting on demand
266  if (($sAction = oxRegistry::getConfig()->getRequestParameter('deleteList')) &&
267  ($oRecommList = $this->getActiveRecommList())
268  ) {
269  $oRecommList->delete();
270  $this->setActiveRecommList(false);
271  } else {
272  $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
273  }
274  }
275 
281  public function removeArticle()
282  {
283  if (!oxRegistry::getSession()->checkSessionChallenge()) {
284  return;
285  }
286 
287  if (!$this->getViewConfig()->getShowListmania()) {
288  return;
289  }
290 
291  if (($sArtId = oxRegistry::getConfig()->getRequestParameter('aid')) &&
292  ($oRecommList = $this->getActiveRecommList())
293  ) {
294  $oRecommList->removeArticle($sArtId);
295  }
296  $this->_sThisTemplate = 'page/account/recommendationedit.tpl';
297  }
298 
304  public function getPageNavigation()
305  {
306  if ($this->_oPageNavigation === null) {
307  $this->_oPageNavigation = false;
308  if (!$this->getActiveRecommlist()) {
309  $this->_oPageNavigation = $this->generatePageNavigation();
310  }
311  }
312 
314  }
315 
321  public function getBreadCrumb()
322  {
323  $aPaths = array();
324  $aPath = array();
325 
326  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
327  $sSelfLink = $this->getViewConfig()->getSelfLink();
328  $aPath['title'] = oxRegistry::getLang()->translateString('MY_ACCOUNT', $iBaseLanguage, false);
329  $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($sSelfLink . 'cl=account');
330  $aPaths[] = $aPath;
331 
332  $aPath['title'] = oxRegistry::getLang()->translateString('LISTMANIA', $iBaseLanguage, false);
333  $aPath['link'] = $this->getLink();
334  $aPaths[] = $aPath;
335 
336  return $aPaths;
337  }
338 
344  public function getArticleCount()
345  {
346  return $this->_iAllArtCnt;
347  }
348 }