OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxnews.php
Go to the documentation of this file.
1 <?php
2 
9 class oxNews extends oxI18n
10 {
16  protected $_oGroups = null;
17 
23  protected $_sClassName = 'oxnews';
24 
30  public function __construct()
31  {
33  $this->init('oxnews');
34  }
35 
43  public function assign( $dbRecord )
44  {
45 
46  parent::assign( $dbRecord );
47 
48  // convert date's to international format
49  if ($this->oxnews__oxdate) {
50  $this->oxnews__oxdate->setValue( oxRegistry::get("oxUtilsDate")->formatDBDate( $this->oxnews__oxdate->value ) );
51  }
52  }
53 
59  public function getGroups()
60  {
61  if ( $this->_oGroups == null && $sOxid = $this->getId() ) {
62  // usergroups
63  $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
64  $sViewName = getViewName( "oxgroups", $this->getLanguage() );
65  $sSelect = "select {$sViewName}.* from {$sViewName}, oxobject2group ";
66  $sSelect .= "where oxobject2group.oxobjectid='$sOxid' ";
67  $sSelect .= "and oxobject2group.oxgroupsid={$sViewName}.oxid ";
68  $this->_oGroups->selectString( $sSelect );
69  }
70 
71  return $this->_oGroups;
72  }
73 
81  public function inGroup( $sGroupID )
82  {
83  $blResult = false;
84  $aGroups = $this->getGroups();
85  foreach ( $aGroups as $oObject ) {
86  if ( $oObject->_sOXID == $sGroupID ) {
87  $blResult = true;
88  break;
89  }
90  }
91  return $blResult;
92  }
93 
101  public function delete( $sOxid = null )
102  {
103  if ( !$sOxid ) {
104  $sOxid = $this->getId();
105  }
106  if ( !$sOxid ) {
107  return false;
108  }
109 
110  if ( $blDelete = parent::delete( $sOxid ) ) {
111  $oDb = oxDb::getDb();
112  $oDb->execute( "delete from oxobject2group where oxobject2group.oxobjectid = ".$oDb->quote( $sOxid ) );
113  }
114 
115 
116  return $blDelete;
117  }
118 
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 }