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 
00034     public function setArticleId( $sArticleId )
00035     {
00036         $this->setId( $sArticleId );
00037     }
00038 
00044     public function getArticleId()
00045     {
00046         return $this->getId();
00047     }
00048 
00054     public function getCacheId()
00055     {
00056         return null;
00057     }
00058 
00066     public function load( $sArticleId )
00067     {
00068         $this->setArticleId( $sArticleId );
00069         $oDb = oxDb::getDb();
00070         $sViewName = getViewName( "oxartextends", $this->getLanguage() );
00071         $sQ = "select oxtags from {$sViewName} where oxid = ".$oDb->quote( $sArticleId );
00072 
00073         $this->set( "" );
00074         // adding tags to list. Tags does not need to be checked again, but dashes needs to be removed
00075         $aTags = explode( $this->get()->getSeparator(), $oDb->getOne( $sQ ) );
00076         foreach ( $aTags as $sTag ) {
00077             $oTag = oxNew( "oxtag" );
00078             $oTag->set( $sTag, false );
00079             $oTag->removeUnderscores();
00080             $this->addTag( $oTag );
00081         }
00082         return $this->_isLoaded = true;
00083     }
00084 
00092     public function loadList( $sArticleId = null )
00093     {
00094         if ( $sArticleId === null && ( $sArticleId = $this->getArticleId() ) === null) {
00095             return false;
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->_updateTagDependency();
00125             return true;
00126         }
00127         return false;
00128     }
00129 
00137     public function set( $sTags )
00138     {
00139         return $this->_oTagSet->set( $sTags );
00140     }
00141 
00147     public function get()
00148     {
00149         return $this->_oTagSet;
00150     }
00151 
00157     public function getArray()
00158     {
00159         return $this->_oTagSet->get();
00160     }
00161 
00169     public function addTag( $mTag )
00170     {
00171         return $this->_oTagSet->addTag( $mTag );
00172     }
00173 
00181     public function getStdTagLink( $sTag )
00182     {
00183         $sStdTagLink = $this->getConfig()->getShopHomeURL( $this->getLanguage(), false );
00184         return $sStdTagLink . "cl=details&amp;anid=".$this->getId()."&amp;listtype=tag&amp;searchtag=".rawurlencode( $sTag );
00185     }
00186 
00194     public function canBeTagged( $sTagTitle )
00195     {
00196         $aProducts = oxRegistry::getSession()->getVariable("aTaggedProducts");
00197         if ( isset($aProducts) && $aTags = $aProducts[$this->getArticleId()] ) {
00198             if ( $aTags[$sTagTitle] == 1 ) {
00199                 return false;
00200             }
00201         }
00202         return true;
00203     }
00204 
00210     protected function _updateTagDependency()
00211     {
00212         // reset tags cloud cache
00213         $oTagList = oxNew( "oxtaglist" );
00214         $oTagList->setLanguage( $this->getLanguage() );
00215         $oTagCloud = oxNew( "oxTagCloud" );
00216         $oTagCloud->setTagList($oTagList);
00217         $oTagCloud->resetCache();
00218 
00219     }
00220 }