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