oxseoencodervendor.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxSeoEncoderVendor extends oxSeoEncoder
00008 {
00014     protected static $_instance = null;
00015 
00021     protected $_aRootVendorUri = null;
00022 
00028     public static function getInstance()
00029     {
00030         if ( defined( 'OXID_PHP_UNIT' ) ) {
00031             self::$_instance = modInstances::getMod( __CLASS__ );
00032         }
00033 
00034         if (!self::$_instance) {
00035             self::$_instance = oxNew("oxSeoEncoderVendor");
00036             if ( defined( 'OXID_PHP_UNIT' ) ) {
00037                 modInstances::addMod( __CLASS__, self::$_instance);
00038             }
00039         }
00040 
00041         if ( defined( 'OXID_PHP_UNIT' ) ) {
00042             // resetting cache
00043             self::$_instance->_aSeoCache = array();
00044         }
00045 
00046         return self::$_instance;
00047     }
00048 
00054     protected function _getUrlExtension()
00055     {
00056         return '/';
00057     }
00058 
00068     public function getVendorUri( $oVendor, $iLang = null, $blRegenerate = false  )
00069     {
00070         if (!isset($iLang)) {
00071             $iLang = $oVendor->getLanguage();
00072         }
00073         // load from db
00074         if ( $blRegenerate || !( $sSeoUrl = $this->_loadFromDb( 'oxvendor', $oVendor->getId(), $iLang ) ) ) {
00075 
00076             if ($iLang != $oVendor->getLanguage()) {
00077                 $sId = $oVendor->getId();
00078                 $oVendor = oxNew('oxvendor');
00079                 $oVendor->loadInLang( $iLang, $sId );
00080             }
00081 
00082             $sSeoUrl = '';
00083             if ( $oVendor->getId() != 'root' ) {
00084                 if ( !isset( $this->_aRootVendorUri[$iLang] ) ) {
00085                     $oRootVendor = oxNew('oxvendor');
00086                     $oRootVendor->loadInLang( $iLang, 'root' );
00087                     $this->_aRootVendorUri[$iLang] = $this->getVendorUri( $oRootVendor, $iLang );
00088                 }
00089                 $sSeoUrl .= $this->_aRootVendorUri[$iLang];
00090             }
00091 
00092             $sSeoUrl .= $this->_prepareTitle( $oVendor->oxvendor__oxtitle->value ) .'/';
00093             $sSeoUrl  = $this->_processSeoUrl( $sSeoUrl, $oVendor->getId(), $iLang );
00094 
00095             // save to db
00096             $this->_saveToDb( 'oxvendor', $oVendor->getId(), $oVendor->getBaseStdLink($iLang), $sSeoUrl, $iLang );
00097         }
00098         return $sSeoUrl;
00099     }
00100 
00111     public function getVendorPageUrl( $oVendor, $iPage, $iLang = null, $blFixed = null )
00112     {
00113         if (!isset($iLang)) {
00114             $iLang = $oVendor->getLanguage();
00115         }
00116         $sStdUrl = $oVendor->getBaseStdLink($iLang) . '&amp;pgNr=' . $iPage;
00117         $sParams = (int) ($iPage + 1);
00118 
00119         $sStdUrl = $this->_trimUrl( $sStdUrl, $iLang );
00120         $sSeoUrl = $this->getVendorUri( $oVendor, $iLang ) . $sParams . "/";
00121 
00122         if ( $blFixed === null ) {
00123             $blFixed = $this->_isFixed( 'oxvendor', $oVendor->getId(), $iLang );
00124         }
00125         return $this->_getFullUrl( $this->_getPageUri( $oVendor, 'oxvendor', $sStdUrl, $sSeoUrl, $sParams, $iLang, $blFixed ), $iLang );
00126     }
00127 
00136     public function getVendorUrl( $oVendor, $iLang = null )
00137     {
00138         if (!isset($iLang)) {
00139             $iLang = $oVendor->getLanguage();
00140         }
00141         return $this->_getFullUrl( $this->getVendorUri( $oVendor, $iLang ), $iLang );
00142     }
00143 
00151     public function onDeleteVendor( $oVendor )
00152     {
00153         $oDb = oxDb::getDb();
00154         $sIdQuoted = $oDb->quote($oVendor->getId());
00155         $oDb->execute("delete from oxseo where oxobjectid = $sIdQuoted and oxtype = 'oxvendor'");
00156         $oDb->execute("delete from oxobject2seodata where oxobjectid = $sIdQuoted");
00157     }
00158 
00167     protected function _getAltUri( $sObjectId, $iLang )
00168     {
00169         $sSeoUrl = null;
00170         $oVendor = oxNew( "oxvendor" );
00171         if ( $oVendor->loadInLang( $iLang, $sObjectId ) ) {
00172             $sSeoUrl = $this->getVendorUri( $oVendor, $iLang, true );
00173         }
00174         return $sSeoUrl;
00175     }
00176 }