oxcontent.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxContent extends oxI18n implements oxIUrl
00009 {
00010 
00016     protected $_sClassName = 'oxcontent';
00017 
00023     protected $_aSeoUrls = array();
00024 
00030     protected $_sParentCatId = null;
00031 
00037     protected $_blExpanded = null;
00038 
00044     protected $_blIsSeoObject = true;
00045 
00051     protected $_sCategoryId;
00052 
00060     public function __get($sName)
00061     {
00062         switch ($sName) {
00063             case 'expanded':
00064                 return $this->getExpanded();
00065                 break;
00066         }
00067         return parent::__get($sName);
00068     }
00069 
00073     public function __construct()
00074     {
00075         parent::__construct();
00076         $this->init('oxcontents');
00077     }
00078 
00084     public function getExpanded()
00085     {
00086         if (!isset($this->_blExpanded)) {
00087             $this->_blExpanded = ($this->getId() == oxRegistry::getConfig()->getRequestParameter('oxcid'));
00088         }
00089 
00090         return $this->_blExpanded;
00091     }
00092 
00098     public function setCategoryId($sCategoryId)
00099     {
00100         $this->oxcontents__oxcatid = new oxField($sCategoryId);
00101     }
00102 
00108     public function getCategoryId()
00109     {
00110         return $this->oxcontents__oxcatid->value;
00111     }
00112 
00113 
00121     protected function _loadFromDb($sLoadId)
00122     {
00123         $sTable = $this->getViewName();
00124         $sShopId = $this->getShopId();
00125         $aParams = array($sTable . '.oxloadid' => $sLoadId, $sTable . '.oxshopid' => $sShopId);
00126 
00127         $sSelect = $this->buildSelectString($aParams);
00128 
00129         //Loads "credits" content object and its text (first available)
00130         if ($sLoadId == 'oxcredits') {
00131 
00132             // fetching column names
00133             $sColQ = "SHOW COLUMNS FROM oxcontents WHERE field LIKE  'oxcontent%'";
00134             $aCols = oxDb::getDb()->getAll($sColQ);
00135 
00136             // building subquery
00137             $sPattern = "IF ( %s != '', %s, %s ) ";
00138             $iCount = count($aCols) - 1;
00139 
00140             $sContQ = "SELECT {$sPattern}";
00141             foreach ($aCols as $iKey => $aCol) {
00142                 $sContQ = sprintf($sContQ, $aCol[0], $aCol[0], $iCount != $iKey ? $sPattern : "''");
00143             }
00144             $sContQ .= " FROM oxcontents WHERE oxloadid = '{$sLoadId}' AND oxshopid = '{$sShopId}'";
00145 
00146             $sSelect = $this->buildSelectString($aParams);
00147             $sSelect = str_replace("`{$sTable}`.`oxcontent`", "( $sContQ ) as oxcontent", $sSelect);
00148         }
00149 
00150         $aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow($sSelect);
00151 
00152         return $aData;
00153     }
00154 
00162     public function loadByIdent($sLoadId)
00163     {
00164 
00165         $aData = $this->_loadFromDb($sLoadId);
00166 
00167         if ($aData) {
00168             $this->assign($aData);
00169 
00170             return true;
00171         }
00172 
00173         return false;
00174     }
00175 
00176 
00182     public function getLoadId()
00183     {
00184         return $this->oxcontents__oxloadid->value;
00185     }
00186 
00192     public function isActive()
00193     {
00194         return $this->oxcontents__oxactive->value;
00195     }
00196 
00204     public function assign($dbRecord)
00205     {
00206 
00207         parent::assign($dbRecord);
00208         // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
00209 
00210         if ($this->oxcontents__oxcontent) {
00211             $this->oxcontents__oxcontent->setValue(str_replace('&lang=', '&amp;lang=', $this->oxcontents__oxcontent->value), oxField::T_RAW);
00212         }
00213     }
00214 
00222     public function getBaseSeoLink($iLang)
00223     {
00224         return oxRegistry::get("oxSeoEncoderContent")->getContentUrl($this, $iLang);
00225     }
00226 
00234     public function getLink($iLang = null)
00235     {
00236         if (!oxRegistry::getUtils()->seoIsActive()) {
00237             return $this->getStdLink($iLang);
00238         }
00239 
00240         if ($iLang === null) {
00241             $iLang = $this->getLanguage();
00242         }
00243 
00244         if (!isset($this->_aSeoUrls[$iLang])) {
00245             $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink($iLang);
00246         }
00247 
00248         return $this->_aSeoUrls[$iLang];
00249     }
00250 
00260     public function getBaseStdLink($iLang, $blAddId = true, $blFull = true)
00261     {
00262         $sUrl = '';
00263         if ($blFull) {
00264             //always returns shop url, not admin
00265             $sUrl = $this->getConfig()->getShopUrl($iLang, false);
00266         }
00267 
00268         if ($this->oxcontents__oxloadid->value === 'oxcredits') {
00269             $sUrl .= "index.php?cl=credits";
00270         } else {
00271             $sUrl .= "index.php?cl=content";
00272         }
00273         $sUrl .= '&amp;oxloadid=' . $this->getLoadId();
00274 
00275         if ($blAddId) {
00276             $sUrl .= "&amp;oxcid=" . $this->getId();
00277             // adding parent category if if available
00278             if ($this->_sParentCatId !== false && $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid') {
00279 
00280                 if ($this->_sParentCatId === null) {
00281                     $this->_sParentCatId = false;
00282                     $oDb = oxDb::getDb();
00283                     $sParentId = $oDb->getOne("select oxparentid from oxcategories where oxid = " . $oDb->quote($this->oxcontents__oxcatid->value));
00284                     if ($sParentId && 'oxrootid' != $sParentId) {
00285                         $this->_sParentCatId = $sParentId;
00286                     }
00287                 }
00288 
00289                 if ($this->_sParentCatId) {
00290                     $sUrl .= "&amp;cnid=" . $this->_sParentCatId;
00291                 }
00292             }
00293         }
00294 
00295         //always returns shop url, not admin
00296         return $sUrl;
00297     }
00298 
00307     public function getStdLink($iLang = null, $aParams = array())
00308     {
00309         if ($iLang === null) {
00310             $iLang = $this->getLanguage();
00311         }
00312 
00313         return oxRegistry::get("oxUtilsUrl")->processUrl($this->getBaseStdLink($iLang), true, $aParams, $iLang);
00314     }
00315 
00325     protected function _setFieldData($sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00326     {
00327         if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
00328             $iDataType = oxField::T_RAW;
00329         }
00330 
00331         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00332     }
00333 
00341     protected function _getFieldData($sFieldName)
00342     {
00343         return $this->{$sFieldName}->value;
00344     }
00345 
00353     public function delete($sOXID = null)
00354     {
00355         if (!$sOXID) {
00356             $sOXID = $this->getId();
00357         }
00358 
00359         if (parent::delete($sOXID)) {
00360             oxRegistry::get("oxSeoEncoderContent")->onDeleteContent($sOXID);
00361 
00362             return true;
00363         }
00364 
00365         return false;
00366     }
00367 
00373     public function save()
00374     {
00375         $blSaved = parent::save();
00376         if ($blSaved && $this->oxcontents__oxloadid->value === 'oxagb') {
00377             $sShopId = $this->getConfig()->getShopId();
00378             $sVersion = $this->oxcontents__oxtermversion->value;
00379 
00380             $oDb = oxDb::getDb();
00381             // dropping expired..
00382             $oDb->execute("delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != " . $oDb->quote($sVersion));
00383         }
00384 
00385         return $blSaved;
00386     }
00387 
00393     public function getTermsVersion()
00394     {
00395         if ($this->loadByIdent('oxagb')) {
00396             return $this->oxcontents__oxtermversion->value;
00397         }
00398     }
00399 
00405     public function setType($sValue)
00406     {
00407         $this->_setFieldData('oxcontents__oxtype', $sValue);
00408     }
00409 
00415     public function getType()
00416     {
00417         return (int) $this->_getFieldData('oxcontents__oxtype');
00418     }
00419 
00425     public function setTitle($sValue)
00426     {
00427         $this->_setFieldData('oxcontents__oxtitle', $sValue);
00428     }
00429 
00435     public function getTitle()
00436     {
00437         return (string) $this->_getFieldData('oxcontents__oxtitle');
00438     }
00439 }