OXID eShop CE  4.8.12
 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 
34  public function setArticleId( $sArticleId )
35  {
36  $this->setId( $sArticleId );
37  }
38 
44  public function getArticleId()
45  {
46  return $this->getId();
47  }
48 
54  public function getCacheId()
55  {
56  return null;
57  }
58 
66  public function load( $sArticleId )
67  {
68  $this->setArticleId( $sArticleId );
69  $oDb = oxDb::getDb();
70  $sViewName = getViewName( "oxartextends", $this->getLanguage() );
71  $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $sArticleId );
72 
73  $this->set( "" );
74  // adding tags to list. Tags does not need to be checked again, but dashes needs to be removed
75  $aTags = explode( $this->get()->getSeparator(), $oDb->getOne( $sQ ) );
76  foreach ( $aTags as $sTag ) {
77  $oTag = oxNew( "oxtag" );
78  $oTag->set( $sTag, false );
79  $oTag->removeUnderscores();
80  $this->addTag( $oTag );
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  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  return true;
126  }
127  return false;
128  }
129 
130 
138  public function set( $sTags )
139  {
140  return $this->_oTagSet->set( $sTags );
141  }
142 
148  public function get()
149  {
150  return $this->_oTagSet;
151  }
152 
158  public function getArray()
159  {
160  return $this->_oTagSet->get();
161  }
162 
170  public function addTag( $mTag )
171  {
172  return $this->_oTagSet->addTag( $mTag );
173  }
174 
182  public function getStdTagLink( $sTag )
183  {
184  $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
185  return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
186  }
187 
195  public function canBeTagged( $sTagTitle )
196  {
197  $aProducts = oxRegistry::getSession()->getVariable("aTaggedProducts");
198  if ( isset($aProducts) && $aTags = $aProducts[$this->getArticleId()] ) {
199  if ( $aTags[$sTagTitle] == 1 ) {
200  return false;
201  }
202  }
203  return true;
204  }
205 
211  public function executeDependencyEvent()
212  {
213  $this->_updateTagDependency();
214 
215  }
216 
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 }