oxcontent.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxContent extends oxI18n implements oxIUrl
00009 {
00015     protected $_sClassName = 'oxcontent';
00016 
00022     protected $_aSeoUrls = array();
00023 
00029     protected $_sParentCatId = null;
00030 
00036     protected $_blExpanded = null;
00037 
00043     protected $_blIsSeoObject = true;
00044 
00050     protected $_sCategoryId;
00051 
00059     public function __get( $sName )
00060     {
00061         switch ( $sName ) {
00062             case 'expanded':
00063                 return $this->getExpanded();
00064                 break;
00065         }
00066         return parent::__get( $sName );
00067     }
00068 
00072     public function __construct()
00073     {
00074         parent::__construct();
00075         $this->init( 'oxcontents' );
00076     }
00077 
00083     public function getExpanded()
00084     {
00085         if ( !isset( $this->_blExpanded ) ) {
00086             $this->_blExpanded = ( $this->getId() == oxConfig::getParameter( 'oxcid' ) );
00087         }
00088         return $this->_blExpanded;
00089     }
00090 
00096     public function setCategoryId( $sCategoryId )
00097     {
00098         $this->oxcontents__oxcatid = new oxField( $sCategoryId );
00099     }
00100 
00106     public function getCategoryId()
00107     {
00108         return $this->oxcontents__oxcatid->value;
00109     }
00110 
00111 
00119     protected function _loadFromDb( $sLoadId )
00120     {
00121         $sTable = $this->getViewName();
00122         $sShopId = $this->getShopId();
00123         $aParams = array( $sTable . '.oxloadid' => $sLoadId, $sTable . '.oxshopid' => $sShopId );
00124 
00125         $sSelect = $this->buildSelectString( $aParams );
00126 
00127         //Loads "credits" content object and its text (first available)
00128         if ( $sLoadId == 'oxcredits' ) {
00129 
00130             // fetching column names
00131             $sColQ = "SHOW COLUMNS FROM oxcontents WHERE field LIKE  'oxcontent%'";
00132             $aCols = oxDb::getDb()->getAll( $sColQ );
00133 
00134             // building subquery
00135             $sPattern = "IF ( %s != '', %s, %s ) ";
00136             $iCount = count( $aCols ) - 1;
00137 
00138             $sContQ = "SELECT {$sPattern}";
00139             foreach ( $aCols as $iKey => $aCol ) {
00140                 $sContQ = sprintf( $sContQ, $aCol[0], $aCol[0], $iCount != $iKey ? $sPattern : "''" );
00141             }
00142             $sContQ .= " FROM oxcontents WHERE oxloadid = '{$sLoadId}' AND oxshopid = '{$sShopId}'";
00143 
00144             $sSelect = $this->buildSelectString( $aParams );
00145             $sSelect = str_replace( "`{$sTable}`.`oxcontent`", "( $sContQ ) as oxcontent", $sSelect );
00146         }
00147 
00148         $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
00149 
00150         return $aData;
00151     }
00152 
00160     public function loadByIdent( $sLoadId )
00161     {
00162 
00163             $aData = $this->_loadFromDb( $sLoadId );
00164 
00165         if ( $aData ) {
00166             $this->assign( $aData );
00167             return true;
00168         }
00169 
00170         return false;
00171     }
00172 
00173 
00179     public function getLoadId()
00180     {
00181         return $this->oxcontents__oxloadid->value;
00182     }
00183 
00189     public function isActive()
00190     {
00191         return $this->oxcontents__oxactive->value;
00192     }
00193 
00201     public function assign( $dbRecord )
00202     {
00203 
00204         parent::assign( $dbRecord );
00205         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00206 
00207         if ( $this->oxcontents__oxcontent ) {
00208             $this->oxcontents__oxcontent->setValue( str_replace( '&lang=', '&amp;lang=', $this->oxcontents__oxcontent->value ), oxField::T_RAW );
00209         }
00210     }
00211 
00219     public function getBaseSeoLink( $iLang )
00220     {
00221         return oxRegistry::get( "oxSeoEncoderContent" )->getContentUrl( $this, $iLang );
00222     }
00223 
00231     public function getLink( $iLang = null )
00232     {
00233         if ( !oxRegistry::getUtils()->seoIsActive() ) {
00234             return $this->getStdLink( $iLang );
00235         }
00236 
00237         if ( $iLang === null ) {
00238             $iLang = $this->getLanguage();
00239         }
00240 
00241         if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
00242             $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
00243         }
00244 
00245         return $this->_aSeoUrls[$iLang];
00246     }
00247 
00257     public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
00258     {
00259         $sUrl = '';
00260         if ( $blFull ) {
00261             //always returns shop url, not admin
00262             $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
00263         }
00264 
00265         if ( $this->oxcontents__oxloadid->value === 'oxcredits' ) {
00266             $sUrl .= "index.php?cl=credits";
00267         } else {
00268             $sUrl .= "index.php?cl=content";
00269         }
00270         $sUrl .= '&amp;oxloadid=' . $this->getLoadId();
00271 
00272         if ( $blAddId ) {
00273             $sUrl .= "&amp;oxcid=" . $this->getId();
00274             // adding parent category if if available
00275             if ( $this->_sParentCatId !== false && $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid' ) {
00276 
00277                 if ( $this->_sParentCatId === null ) {
00278                     $this->_sParentCatId = false;
00279                     $oDb = oxDb::getDb();
00280                     $sParentId = $oDb->getOne( "select oxparentid from oxcategories where oxid = " . $oDb->quote( $this->oxcontents__oxcatid->value ) );
00281                     if ( $sParentId && 'oxrootid' != $sParentId ) {
00282                         $this->_sParentCatId = $sParentId;
00283                     }
00284                 }
00285 
00286                 if ( $this->_sParentCatId ) {
00287                     $sUrl .= "&amp;cnid=" . $this->_sParentCatId;
00288                 }
00289             }
00290         }
00291 
00292         //always returns shop url, not admin
00293         return $sUrl;
00294     }
00295 
00304     public function getStdLink( $iLang = null, $aParams = array() )
00305     {
00306         if ( $iLang === null ) {
00307             $iLang = $this->getLanguage();
00308         }
00309 
00310         return oxRegistry::get( "oxUtilsUrl" )->processUrl( $this->getBaseStdLink( $iLang ), true, $aParams, $iLang );
00311     }
00312 
00322     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT )
00323     {
00324         if ( 'oxcontent' === strtolower( $sFieldName ) || 'oxcontents__oxcontent' === strtolower( $sFieldName ) ) {
00325             $iDataType = oxField::T_RAW;
00326         }
00327 
00328         return parent::_setFieldData( $sFieldName, $sValue, $iDataType );
00329     }
00330 
00338     public function delete( $sOXID = null )
00339     {
00340         if ( !$sOXID ) {
00341             $sOXID = $this->getId();
00342         }
00343 
00344         if ( parent::delete( $sOXID ) ) {
00345             oxRegistry::get( "oxSeoEncoderContent" )->onDeleteContent( $sOXID );
00346             return true;
00347         }
00348         return false;
00349     }
00350 
00356     public function save()
00357     {
00358         $blSaved = parent::save();
00359         if ( $blSaved && $this->oxcontents__oxloadid->value === 'oxagb' ) {
00360             $sShopId = $this->getConfig()->getShopId();
00361             $sVersion = $this->oxcontents__oxtermversion->value;
00362 
00363             $oDb = oxDb::getDb();
00364             // dropping expired..
00365             $oDb->execute( "delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != " . $oDb->quote( $sVersion ) );
00366         }
00367         return $blSaved;
00368     }
00369 
00375     public function getTermsVersion()
00376     {
00377         if ( $this->loadByIdent( 'oxagb' ) ) {
00378             return $this->oxcontents__oxtermversion->value;
00379         }
00380     }
00381 
00387     public function getType()
00388     {
00389         return $this->oxcontents__oxtype->value;
00390     }
00391 
00392 }