oxnews.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class oxNews extends oxI18n
00011 {
00017     protected $_oGroups  = null;
00018 
00024     protected $_sClassName = 'oxnews';
00025 
00031     public function __construct()
00032     {
00033         parent::__construct();
00034         $this->init('oxnews');
00035     }
00036 
00044     public function assign( $dbRecord )
00045     {
00046 
00047         parent::assign( $dbRecord );
00048 
00049         // convert date's to international format
00050         $this->oxnews__oxdate->setValue( oxUtilsDate::getInstance()->formatDBDate( $this->oxnews__oxdate->value ) );
00051     }
00052 
00058     public function getGroups()
00059     {
00060         if ( $this->_oGroups == null && $sOxid = $this->getId() ) {
00061             // usergroups
00062             $this->_oGroups = oxNew( 'oxlist', 'oxgroups' );
00063             $sViewName = getViewName( "oxgroups", $this->getLanguage() );
00064             $sSelect  = "select {$sViewName}.* from {$sViewName}, oxobject2group ";
00065             $sSelect .= "where oxobject2group.oxobjectid='$sOxid' ";
00066             $sSelect .= "and oxobject2group.oxgroupsid={$sViewName}.oxid ";
00067             $this->_oGroups->selectString( $sSelect );
00068         }
00069 
00070         return $this->_oGroups;
00071     }
00072 
00080     public function inGroup( $sGroupID )
00081     {
00082         $blResult = false;
00083         $aGroups  = &$this->getGroups();
00084         foreach ( $aGroups as $oObject ) {
00085             if ( $oObject->_sOXID == $sGroupID ) {
00086                 $blResult = true;
00087                 break;
00088             }
00089         }
00090         return $blResult;
00091     }
00092 
00100     public function delete( $sOxid = null )
00101     {
00102         if ( !$sOxid ) {
00103             $sOxid = $this->getId();
00104         }
00105         if ( !$sOxid ) {
00106             return false;
00107         }
00108 
00109         if ( $blDelete = parent::delete( $sOxid ) ) {
00110             $oDb = oxDb::getDb();
00111             $oDb->execute( "delete from oxobject2group where oxobject2group.oxobjectid = ".$oDb->quote( $sOxid ) );
00112         }
00113         return $blDelete;
00114     }
00115 
00121     protected function _update()
00122     {
00123         $this->oxnews__oxdate->setValue( oxUtilsDate::getInstance()->formatDBDate( $this->oxnews__oxdate->value, true ) );
00124 
00125         parent::_update();
00126     }
00127 
00133     protected function _insert()
00134     {
00135         if ( !$this->oxnews__oxdate || oxUtilsDate::getInstance()->isEmptyDate( $this->oxnews__oxdate->value ) ) {
00136             // if date field is empty, assigning current date
00137             $this->oxnews__oxdate = new oxField( date( 'Y-m-d' ) );
00138         } else {
00139             $this->oxnews__oxdate = new oxField( oxUtilsDate::getInstance()->formatDBDate( $this->oxnews__oxdate->value, true ) );
00140         }
00141 
00142         return parent::_insert();
00143     }
00144 
00154     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00155     {
00156         switch (strtolower($sFieldName)) {
00157             case 'oxshortdesc':
00158             case 'oxlongdesc':
00159             case 'oxnews__oxlongdesc':
00160             case 'oxnews__oxshortdesc':
00161                 $iDataType = oxField::T_RAW;
00162                 break;
00163         }
00164         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00165     }
00166 
00172     public function getLongDesc()
00173     {
00174         return oxUtilsView::getInstance()->parseThroughSmarty( $this->oxnews__oxlongdesc->getRawValue(), $this->getId().$this->getLanguage() );
00175     }
00176 }