OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
oxnews.php
Go to the documentation of this file.
1 <?php
2 
9 class oxNews extends oxI18n
10 {
11 
17  protected $_oGroups = null;
18 
24  protected $_sClassName = 'oxnews';
25 
31  public function __construct()
32  {
34  $this->init('oxnews');
35  }
36 
44  public function assign($dbRecord)
45  {
46 
47  parent::assign($dbRecord);
48 
49  // convert date's to international format
50  if ($this->oxnews__oxdate) {
51  $this->oxnews__oxdate->setValue(oxRegistry::get("oxUtilsDate")->formatDBDate($this->oxnews__oxdate->value));
52  }
53  }
54 
60  public function getGroups()
61  {
62  if ($this->_oGroups == null && $sOxid = $this->getId()) {
63  // usergroups
64  $this->_oGroups = oxNew('oxlist', 'oxgroups');
65  $sViewName = getViewName("oxgroups", $this->getLanguage());
66  $sSelect = "select {$sViewName}.* from {$sViewName}, oxobject2group ";
67  $sSelect .= "where oxobject2group.oxobjectid='$sOxid' ";
68  $sSelect .= "and oxobject2group.oxgroupsid={$sViewName}.oxid ";
69  $this->_oGroups->selectString($sSelect);
70  }
71 
72  return $this->_oGroups;
73  }
74 
82  public function inGroup($sGroupID)
83  {
84  $blResult = false;
85  $aGroups = $this->getGroups();
86  foreach ($aGroups as $oObject) {
87  if ($oObject->_sOXID == $sGroupID) {
88  $blResult = true;
89  break;
90  }
91  }
92 
93  return $blResult;
94  }
95 
103  public function delete($sOxid = null)
104  {
105  if (!$sOxid) {
106  $sOxid = $this->getId();
107  }
108  if (!$sOxid) {
109  return false;
110  }
111 
112  if ($blDelete = parent::delete($sOxid)) {
113  $oDb = oxDb::getDb();
114  $oDb->execute("delete from oxobject2group where oxobject2group.oxobjectid = " . $oDb->quote($sOxid));
115  }
116 
117 
118  return $blDelete;
119  }
120 
124  protected function _update()
125  {
126  $this->oxnews__oxdate->setValue(oxRegistry::get("oxUtilsDate")->formatDBDate($this->oxnews__oxdate->value, true));
127 
128 
129  parent::_update();
130  }
131 
137  protected function _insert()
138  {
139  if (!$this->oxnews__oxdate || oxRegistry::get("oxUtilsDate")->isEmptyDate($this->oxnews__oxdate->value)) {
140  // if date field is empty, assigning current date
141  $this->oxnews__oxdate = new oxField(date('Y-m-d'));
142  } else {
143  $this->oxnews__oxdate = new oxField(oxRegistry::get("oxUtilsDate")->formatDBDate($this->oxnews__oxdate->value, true));
144  }
145 
146 
147  return parent::_insert();
148  }
149 
159  protected function _setFieldData($sFieldName, $sValue, $iDataType = oxField::T_TEXT)
160  {
161  switch (strtolower($sFieldName)) {
162  case 'oxlongdesc':
163  case 'oxnews__oxlongdesc':
164  $iDataType = oxField::T_RAW;
165  break;
166  }
167  return parent::_setFieldData($sFieldName, $sValue, $iDataType);
168  }
169 
175  public function getLongDesc()
176  {
178  $oUtilsView = oxRegistry::get("oxUtilsView");
179  return $oUtilsView->parseThroughSmarty($this->oxnews__oxlongdesc->getRawValue(), $this->getId() . $this->getLanguage(), null, true);
180  }
181 
182 }