oxarticletaglist.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxArticleTagList extends oxI18n implements oxITagList
00009 {
00010 
00016     protected $_oTagSet = null;
00017 
00021     public function __construct()
00022     {
00023         parent::__construct();
00024         $this->_oTagSet = oxNew('oxTagSet');
00025     }
00026 
00032     public function setArticleId($sArticleId)
00033     {
00034         $this->setId($sArticleId);
00035     }
00036 
00042     public function getArticleId()
00043     {
00044         return $this->getId();
00045     }
00046 
00052     public function getCacheId()
00053     {
00054         return null;
00055     }
00056 
00064     public function load($sArticleId)
00065     {
00066         $this->setArticleId($sArticleId);
00067         $oDb = oxDb::getDb();
00068         $sViewName = getViewName("oxartextends", $this->getLanguage());
00069         $sQ = "select oxtags from {$sViewName} where oxid = " . $oDb->quote($sArticleId);
00070 
00071         $this->set("");
00072         // adding tags to list. Tags does not need to be checked again, but dashes needs to be removed
00073         $aTags = explode($this->get()->getSeparator(), $oDb->getOne($sQ));
00074         foreach ($aTags as $sTag) {
00075             $oTag = oxNew("oxtag");
00076             $oTag->set($sTag, false);
00077             $oTag->removeUnderscores();
00078             $this->addTag($oTag);
00079         }
00080 
00081         return $this->_isLoaded = true;
00082     }
00083 
00091     public function loadList($sArticleId = null)
00092     {
00093         if ($sArticleId === null && ($sArticleId = $this->getArticleId()) === null) {
00094             return false;
00095         }
00096 
00097         return $this->load($sArticleId);
00098     }
00099 
00105     public function save()
00106     {
00107         if (!$this->getArticleId()) {
00108             return false;
00109         }
00110         $oTagSet = $this->get();
00111         foreach ($oTagSet as $oTag) {
00112             $oTag->addUnderscores();
00113         }
00114         $sTags = oxDb::getInstance()->escapeString($oTagSet);
00115         $oDb = oxDb::getDb();
00116 
00117         $sTable = getLangTableName('oxartextends', $this->getLanguage());
00118         $sLangSuffix = oxRegistry::getLang()->getLanguageTag($this->getLanguage());
00119 
00120         $sQ = "insert into {$sTable} (oxid, oxtags$sLangSuffix) value (" . $oDb->quote($this->getArticleId()) . ", '{$sTags}')
00121                on duplicate key update oxtags$sLangSuffix = '{$sTags}'";
00122 
00123         if ($oDb->execute($sQ)) {
00124             $this->executeDependencyEvent();
00125 
00126             return true;
00127         }
00128 
00129         return false;
00130     }
00131 
00132 
00140     public function set($sTags)
00141     {
00142         return $this->_oTagSet->set($sTags);
00143     }
00144 
00150     public function get()
00151     {
00152         return $this->_oTagSet;
00153     }
00154 
00160     public function getArray()
00161     {
00162         return $this->_oTagSet->get();
00163     }
00164 
00172     public function addTag($mTag)
00173     {
00174         return $this->_oTagSet->addTag($mTag);
00175     }
00176 
00184     public function getStdTagLink($sTag)
00185     {
00186         $sStdTagLink = $this->getConfig()->getShopHomeURL($this->getLanguage(), false);
00187 
00188         return $sStdTagLink . "cl=details&amp;anid=" . $this->getId() . "&amp;listtype=tag&amp;searchtag=" . rawurlencode($sTag);
00189     }
00190 
00198     public function canBeTagged($sTagTitle)
00199     {
00200         $aProducts = oxRegistry::getSession()->getVariable("aTaggedProducts");
00201         if (isset($aProducts) && $aTags = $aProducts[$this->getArticleId()]) {
00202             if ($aTags[$sTagTitle] == 1) {
00203                 return false;
00204             }
00205         }
00206 
00207         return true;
00208     }
00209 
00213     public function executeDependencyEvent()
00214     {
00215         $this->_updateTagDependency();
00216 
00217     }
00218 
00222     protected function _updateTagDependency()
00223     {
00224         // reset tags cloud cache
00225         $oTagList = oxNew("oxTagList");
00226         $oTagList->setLanguage($this->getLanguage());
00227         $oTagCloud = oxNew("oxTagCloud");
00228         $oTagCloud->setTagList($oTagList);
00229         $oTagCloud->resetCache();
00230     }
00231 }