OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
oxarticletaglist.php
Go to the documentation of this file.
1 <?php
2 
8 class oxArticleTagList extends oxI18n implements oxITagList
9 {
10 
16  protected $_oTagSet = null;
17 
21  public function __construct()
22  {
24  $this->_oTagSet = oxNew('oxTagSet');
25  }
26 
32  public function setArticleId($sArticleId)
33  {
34  $this->setId($sArticleId);
35  }
36 
42  public function getArticleId()
43  {
44  return $this->getId();
45  }
46 
52  public function getCacheId()
53  {
54  return null;
55  }
56 
64  public function load($sArticleId)
65  {
66  $this->setArticleId($sArticleId);
67  $oDb = oxDb::getDb();
68  $sViewName = getViewName("oxartextends", $this->getLanguage());
69  $sQ = "select oxtags from {$sViewName} where oxid = " . $oDb->quote($sArticleId);
70 
71  $this->set("");
72  // adding tags to list. Tags does not need to be checked again, but dashes needs to be removed
73  $aTags = explode($this->get()->getSeparator(), $oDb->getOne($sQ));
74  foreach ($aTags as $sTag) {
75  $oTag = oxNew("oxtag");
76  $oTag->set($sTag, false);
77  $oTag->removeUnderscores();
78  $this->addTag($oTag);
79  }
80 
81  return $this->_isLoaded = true;
82  }
83 
91  public function loadList($sArticleId = null)
92  {
93  if ($sArticleId === null && ($sArticleId = $this->getArticleId()) === null) {
94  return false;
95  }
96 
97  return $this->load($sArticleId);
98  }
99 
105  public function save()
106  {
107  if (!$this->getArticleId()) {
108  return false;
109  }
110  $oTagSet = $this->get();
111  foreach ($oTagSet as $oTag) {
112  $oTag->addUnderscores();
113  }
114  $sTags = oxDb::getInstance()->escapeString($oTagSet);
115  $oDb = oxDb::getDb();
116 
117  $sTable = getLangTableName('oxartextends', $this->getLanguage());
118  $sLangSuffix = oxRegistry::getLang()->getLanguageTag($this->getLanguage());
119 
120  $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (" . $oDb->quote($this->getArticleId()) . ", '{$sTags}')
121  on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
122 
123  if ($oDb->execute($sQ)) {
124  $this->executeDependencyEvent();
125 
126  return true;
127  }
128 
129  return false;
130  }
131 
132 
140  public function set($sTags)
141  {
142  return $this->_oTagSet->set($sTags);
143  }
144 
150  public function get()
151  {
152  return $this->_oTagSet;
153  }
154 
160  public function getArray()
161  {
162  return $this->_oTagSet->get();
163  }
164 
172  public function addTag($mTag)
173  {
174  return $this->_oTagSet->addTag($mTag);
175  }
176 
184  public function getStdTagLink($sTag)
185  {
186  $sStdTagLink = $this->getConfig()->getShopHomeURL($this->getLanguage(), false);
187 
188  return $sStdTagLink . "cl=details&amp;anid=" . $this->getId() . "&amp;listtype=tag&amp;searchtag=" . rawurlencode($sTag);
189  }
190 
198  public function canBeTagged($sTagTitle)
199  {
200  $aProducts = oxRegistry::getSession()->getVariable("aTaggedProducts");
201  if (isset($aProducts) && $aTags = $aProducts[$this->getArticleId()]) {
202  if ($aTags[$sTagTitle] == 1) {
203  return false;
204  }
205  }
206 
207  return true;
208  }
209 
213  public function executeDependencyEvent()
214  {
215  $this->_updateTagDependency();
216 
217  }
218 
222  protected function _updateTagDependency()
223  {
224  // reset tags cloud cache
225  $oTagList = oxNew("oxTagList");
226  $oTagList->setLanguage($this->getLanguage());
227  $oTagCloud = oxNew("oxTagCloud");
228  $oTagCloud->setTagList($oTagList);
229  $oTagCloud->resetCache();
230  }
231 }