OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
oxcontent.php
Go to the documentation of this file.
1 <?php
2 
8 class oxContent extends oxI18n implements oxIUrl
9 {
10 
16  protected $_sClassName = 'oxcontent';
17 
23  protected $_aSeoUrls = array();
24 
30  protected $_sParentCatId = null;
31 
37  protected $_blExpanded = null;
38 
44  protected $_blIsSeoObject = true;
45 
51  protected $_sCategoryId;
52 
60  public function __get($sName)
61  {
62  switch ($sName) {
63  case 'expanded':
64  return $this->getExpanded();
65  break;
66  }
67  return parent::__get($sName);
68  }
69 
73  public function __construct()
74  {
76  $this->init('oxcontents');
77  }
78 
84  public function getExpanded()
85  {
86  if (!isset($this->_blExpanded)) {
87  $this->_blExpanded = ($this->getId() == oxRegistry::getConfig()->getRequestParameter('oxcid'));
88  }
89 
90  return $this->_blExpanded;
91  }
92 
98  public function setCategoryId($sCategoryId)
99  {
100  $this->oxcontents__oxcatid = new oxField($sCategoryId);
101  }
102 
108  public function getCategoryId()
109  {
110  return $this->oxcontents__oxcatid->value;
111  }
112 
113 
121  protected function _loadFromDb($sLoadId)
122  {
123  $sTable = $this->getViewName();
124  $sShopId = $this->getShopId();
125  $aParams = array($sTable . '.oxloadid' => $sLoadId, $sTable . '.oxshopid' => $sShopId);
126 
127  $sSelect = $this->buildSelectString($aParams);
128 
129  //Loads "credits" content object and its text (first available)
130  if ($sLoadId == 'oxcredits') {
131 
132  // fetching column names
133  $sColQ = "SHOW COLUMNS FROM oxcontents WHERE field LIKE 'oxcontent%'";
134  $aCols = oxDb::getDb()->getAll($sColQ);
135 
136  // building subquery
137  $sPattern = "IF ( %s != '', %s, %s ) ";
138  $iCount = count($aCols) - 1;
139 
140  $sContQ = "SELECT {$sPattern}";
141  foreach ($aCols as $iKey => $aCol) {
142  $sContQ = sprintf($sContQ, $aCol[0], $aCol[0], $iCount != $iKey ? $sPattern : "''");
143  }
144  $sContQ .= " FROM oxcontents WHERE oxloadid = '{$sLoadId}' AND oxshopid = '{$sShopId}'";
145 
146  $sSelect = $this->buildSelectString($aParams);
147  $sSelect = str_replace("`{$sTable}`.`oxcontent`", "( $sContQ ) as oxcontent", $sSelect);
148  }
149 
150  $aData = oxDb::getDb(oxDb::FETCH_MODE_ASSOC)->getRow($sSelect);
151 
152  return $aData;
153  }
154 
162  public function loadByIdent($sLoadId)
163  {
164 
165  $aData = $this->_loadFromDb($sLoadId);
166 
167  if ($aData) {
168  $this->assign($aData);
169 
170  return true;
171  }
172 
173  return false;
174  }
175 
176 
182  public function getLoadId()
183  {
184  return $this->oxcontents__oxloadid->value;
185  }
186 
192  public function isActive()
193  {
194  return $this->oxcontents__oxactive->value;
195  }
196 
204  public function assign($dbRecord)
205  {
206 
207  parent::assign($dbRecord);
208  // workaround for firefox showing &lang= as &9001;= entity, mantis#0001272
209 
210  if ($this->oxcontents__oxcontent) {
211  $this->oxcontents__oxcontent->setValue(str_replace('&lang=', '&amp;lang=', $this->oxcontents__oxcontent->value), oxField::T_RAW);
212  }
213  }
214 
222  public function getBaseSeoLink($iLang)
223  {
224  return oxRegistry::get("oxSeoEncoderContent")->getContentUrl($this, $iLang);
225  }
226 
234  public function getLink($iLang = null)
235  {
236  if (!oxRegistry::getUtils()->seoIsActive()) {
237  return $this->getStdLink($iLang);
238  }
239 
240  if ($iLang === null) {
241  $iLang = $this->getLanguage();
242  }
243 
244  if (!isset($this->_aSeoUrls[$iLang])) {
245  $this->_aSeoUrls[$iLang] = $this->getBaseSeoLink($iLang);
246  }
247 
248  return $this->_aSeoUrls[$iLang];
249  }
250 
260  public function getBaseStdLink($iLang, $blAddId = true, $blFull = true)
261  {
262  $sUrl = '';
263  if ($blFull) {
264  //always returns shop url, not admin
265  $sUrl = $this->getConfig()->getShopUrl($iLang, false);
266  }
267 
268  if ($this->oxcontents__oxloadid->value === 'oxcredits') {
269  $sUrl .= "index.php?cl=credits";
270  } else {
271  $sUrl .= "index.php?cl=content";
272  }
273  $sUrl .= '&amp;oxloadid=' . $this->getLoadId();
274 
275  if ($blAddId) {
276  $sUrl .= "&amp;oxcid=" . $this->getId();
277  // adding parent category if if available
278  if ($this->_sParentCatId !== false && $this->oxcontents__oxcatid->value && $this->oxcontents__oxcatid->value != 'oxrootid') {
279 
280  if ($this->_sParentCatId === null) {
281  $this->_sParentCatId = false;
282  $oDb = oxDb::getDb();
283  $sParentId = $oDb->getOne("select oxparentid from oxcategories where oxid = " . $oDb->quote($this->oxcontents__oxcatid->value));
284  if ($sParentId && 'oxrootid' != $sParentId) {
285  $this->_sParentCatId = $sParentId;
286  }
287  }
288 
289  if ($this->_sParentCatId) {
290  $sUrl .= "&amp;cnid=" . $this->_sParentCatId;
291  }
292  }
293  }
294 
295  //always returns shop url, not admin
296  return $sUrl;
297  }
298 
307  public function getStdLink($iLang = null, $aParams = array())
308  {
309  if ($iLang === null) {
310  $iLang = $this->getLanguage();
311  }
312 
313  return oxRegistry::get("oxUtilsUrl")->processUrl($this->getBaseStdLink($iLang), true, $aParams, $iLang);
314  }
315 
325  protected function _setFieldData($sFieldName, $sValue, $iDataType = oxField::T_TEXT)
326  {
327  if ('oxcontent' === strtolower($sFieldName) || 'oxcontents__oxcontent' === strtolower($sFieldName)) {
328  $iDataType = oxField::T_RAW;
329  }
330 
331  return parent::_setFieldData($sFieldName, $sValue, $iDataType);
332  }
333 
341  protected function _getFieldData($sFieldName)
342  {
343  return $this->{$sFieldName}->value;
344  }
345 
353  public function delete($sOXID = null)
354  {
355  if (!$sOXID) {
356  $sOXID = $this->getId();
357  }
358 
359  if (parent::delete($sOXID)) {
360  oxRegistry::get("oxSeoEncoderContent")->onDeleteContent($sOXID);
361 
362  return true;
363  }
364 
365  return false;
366  }
367 
373  public function save()
374  {
375  $blSaved = parent::save();
376  if ($blSaved && $this->oxcontents__oxloadid->value === 'oxagb') {
377  $sShopId = $this->getConfig()->getShopId();
378  $sVersion = $this->oxcontents__oxtermversion->value;
379 
380  $oDb = oxDb::getDb();
381  // dropping expired..
382  $oDb->execute("delete from oxacceptedterms where oxshopid='{$sShopId}' and oxtermversion != " . $oDb->quote($sVersion));
383  }
384 
385  return $blSaved;
386  }
387 
393  public function getTermsVersion()
394  {
395  if ($this->loadByIdent('oxagb')) {
396  return $this->oxcontents__oxtermversion->value;
397  }
398  }
399 
405  public function setType($sValue)
406  {
407  $this->_setFieldData('oxcontents__oxtype', $sValue);
408  }
409 
415  public function getType()
416  {
417  return (int) $this->_getFieldData('oxcontents__oxtype');
418  }
419 
425  public function setTitle($sValue)
426  {
427  $this->_setFieldData('oxcontents__oxtitle', $sValue);
428  }
429 
435  public function getTitle()
436  {
437  return (string) $this->_getFieldData('oxcontents__oxtitle');
438  }
439 }