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