OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxcontent.php
Go to the documentation of this file.
1 <?php
2 
8 class oxContent extends oxI18n implements oxIUrl
9 {
15  protected $_sClassName = 'oxcontent';
16 
22  protected $_aSeoUrls = array();
23 
29  protected $_sParentCatId = null;
30 
36  protected $_blExpanded = null;
37 
43  protected $_blIsSeoObject = true;
44 
50  protected $_sCategoryId;
51 
59  public function __get( $sName )
60  {
61  switch ( $sName ) {
62  case 'expanded':
63  return $this->getExpanded();
64  break;
65  }
66  return parent::__get( $sName );
67  }
68 
72  public function __construct()
73  {
75  $this->init( 'oxcontents' );
76  }
77 
83  public function getExpanded()
84  {
85  if ( !isset( $this->_blExpanded ) ) {
86  $this->_blExpanded = ( $this->getId() == oxConfig::getParameter( 'oxcid' ) );
87  }
88  return $this->_blExpanded;
89  }
90 
96  public function setCategoryId( $sCategoryId )
97  {
98  $this->oxcontents__oxcatid = new oxField( $sCategoryId );
99  }
100 
106  public function getCategoryId()
107  {
108  return $this->oxcontents__oxcatid->value;
109  }
110 
111 
119  protected function _loadFromDb( $sLoadId )
120  {
121  $sTable = $this->getViewName();
122  $sShopId = $this->getShopId();
123  $aParams = array( $sTable . '.oxloadid' => $sLoadId, $sTable . '.oxshopid' => $sShopId );
124 
125  $sSelect = $this->buildSelectString( $aParams );
126 
127  //Loads "credits" content object and its text (first available)
128  if ( $sLoadId == 'oxcredits' ) {
129 
130  // fetching column names
131  $sColQ = "SHOW COLUMNS FROM oxcontents WHERE field LIKE 'oxcontent%'";
132  $aCols = oxDb::getDb()->getAll( $sColQ );
133 
134  // building subquery
135  $sPattern = "IF ( %s != '', %s, %s ) ";
136  $iCount = count( $aCols ) - 1;
137 
138  $sContQ = "SELECT {$sPattern}";
139  foreach ( $aCols as $iKey => $aCol ) {
140  $sContQ = sprintf( $sContQ, $aCol[0], $aCol[0], $iCount != $iKey ? $sPattern : "''" );
141  }
142  $sContQ .= " FROM oxcontents WHERE oxloadid = '{$sLoadId}' AND oxshopid = '{$sShopId}'";
143 
144  $sSelect = $this->buildSelectString( $aParams );
145  $sSelect = str_replace( "`{$sTable}`.`oxcontent`", "( $sContQ ) as oxcontent", $sSelect );
146  }
147 
148  $aData = oxDb::getDb( oxDb::FETCH_MODE_ASSOC )->getRow( $sSelect );
149 
150  return $aData;
151  }
152 
160  public function loadByIdent( $sLoadId )
161  {
162 
163  $aData = $this->_loadFromDb( $sLoadId );
164 
165  if ( $aData ) {
166  $this->assign( $aData );
167  return true;
168  }
169 
170  return false;
171  }
172 
173 
179  public function getLoadId()
180  {
181  return $this->oxcontents__oxloadid->value;
182  }
183 
189  public function isActive()
190  {
191  return $this->oxcontents__oxactive->value;
192  }
193 
201  public function assign( $dbRecord )
202  {
203 
204  parent::assign( $dbRecord );
205  // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
206 
207  if ( $this->oxcontents__oxcontent ) {
208  $this->oxcontents__oxcontent->setValue( str_replace( '&lang=', '&amp;lang=', $this->oxcontents__oxcontent->value ), oxField::T_RAW );
209  }
210  }
211 
219  public function getBaseSeoLink( $iLang )
220  {
221  return oxRegistry::get( "oxSeoEncoderContent" )->getContentUrl( $this, $iLang );
222  }
223 
231  public function getLink( $iLang = null )
232  {
233  if ( !oxRegistry::getUtils()->seoIsActive() ) {
234  return $this->getStdLink( $iLang );
235  }
236 
237  if ( $iLang === null ) {
238  $iLang = $this->getLanguage();
239  }
240 
241  if ( !isset( $this->_aSeoUrls[$iLang] ) ) {
242  $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink( $iLang );
243  }
244 
245  return $this->_aSeoUrls[$iLang];
246  }
247 
257  public function getBaseStdLink( $iLang, $blAddId = true, $blFull = true )
258  {
259  $sUrl = '';
260  if ( $blFull ) {
261  //always returns shop url, not admin
262  $sUrl = $this->getConfig()->getShopUrl( $iLang, false );
263  }
264 
265  if ( $this->oxcontents__oxloadid->value === 'oxcredits' ) {
266  $sUrl .= "index.php?cl=credits";
267  } else {
268  $sUrl .= "index.php?cl=content";
269  }
270  $sUrl .= '&amp;oxloadid=' . $this->getLoadId();
271 
272  if ( $blAddId ) {
273  $sUrl .= "&amp;oxcid=" . $this->getId();
274  // adding parent category if if available
275  if ( $this->_sParentCatId !== false && $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid' ) {
276 
277  if ( $this->_sParentCatId === null ) {
278  $this->_sParentCatId = false;
279  $oDb = oxDb::getDb();
280  $sParentId = $oDb->getOne( "select oxparentid from oxcategories where oxid = " . $oDb->quote( $this->oxcontents__oxcatid->value ) );
281  if ( $sParentId && 'oxrootid' != $sParentId ) {
282  $this->_sParentCatId = $sParentId;
283  }
284  }
285 
286  if ( $this->_sParentCatId ) {
287  $sUrl .= "&amp;cnid=" . $this->_sParentCatId;
288  }
289  }
290  }
291 
292  //always returns shop url, not admin
293  return $sUrl;
294  }
295 
304  public function getStdLink( $iLang = null, $aParams = array() )
305  {
306  if ( $iLang === null ) {
307  $iLang = $this->getLanguage();
308  }
309 
310  return oxRegistry::get( "oxUtilsUrl" )->processUrl( $this->getBaseStdLink( $iLang ), true, $aParams, $iLang );
311  }
312 
322  protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT )
323  {
324  if ( 'oxcontent' === strtolower( $sFieldName ) || 'oxcontents__oxcontent' === strtolower( $sFieldName ) ) {
325  $iDataType = oxField::T_RAW;
326  }
327 
328  return parent::_setFieldData( $sFieldName, $sValue, $iDataType );
329  }
330 
338  public function delete( $sOXID = null )
339  {
340  if ( !$sOXID ) {
341  $sOXID = $this->getId();
342  }
343 
344  if ( parent::delete( $sOXID ) ) {
345  oxRegistry::get( "oxSeoEncoderContent" )->onDeleteContent( $sOXID );
346  return true;
347  }
348  return false;
349  }
350 
356  public function save()
357  {
358  $blSaved = parent::save();
359  if ( $blSaved && $this->oxcontents__oxloadid->value === 'oxagb' ) {
360  $sShopId = $this->getConfig()->getShopId();
361  $sVersion = $this->oxcontents__oxtermversion->value;
362 
363  $oDb = oxDb::getDb();
364  // dropping expired..
365  $oDb->execute( "delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != " . $oDb->quote( $sVersion ) );
366  }
367  return $blSaved;
368  }
369 
375  public function getTermsVersion()
376  {
377  if ( $this->loadByIdent( 'oxagb' ) ) {
378  return $this->oxcontents__oxtermversion->value;
379  }
380  }
381 
387  public function getType()
388  {
389  return $this->oxcontents__oxtype->value;
390  }
391 
392 }