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