oxnewslist.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxNewslist extends oxList
00008 {
00014     protected $_sObjectsInListName = 'oxnews';
00015 
00019     protected $_oUser = null;
00020 
00030     public function loadNews( $iFrom = 0, $iLimit = 10 )
00031     {
00032         if ( $iLimit ) {
00033             $this->setSqlLimit( $iFrom, $iLimit );
00034         }
00035 
00036         $sNewsViewName = getViewName( 'oxnews' );
00037         $oBaseObject   = $this->getBaseObject();
00038         $sSelectFields = $oBaseObject->getSelectFields();
00039 
00040         if ( $oUser = $this->getUser() ) {
00041             // performance - only join if user is logged in
00042             $sSelect  = "select $sSelectFields from $sNewsViewName ";
00043             $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where ";
00044             $sSelect .= "oxobject2group.oxgroupsid in ( select oxgroupsid from oxobject2group where oxobjectid='".$oUser->getId()."' ) or ";
00045             $sSelect .= "( oxobject2group.oxgroupsid is null ) ";
00046         } else {
00047             $sSelect  = "select $sSelectFields, oxobject2group.oxgroupsid from $sNewsViewName ";
00048             $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where oxobject2group.oxgroupsid is null ";
00049         }
00050 
00051         $sSelect .= " and ".$oBaseObject->getSqlActiveSnippet();
00052         $sSelect .= " group by $sNewsViewName.oxid order by $sNewsViewName.oxdate desc ";
00053 
00054 
00055         $this->selectString( $sSelect );
00056     }
00057 
00063     public function getCount()
00064     {
00065         $myConfig = $this->getConfig();
00066         $oDb = oxDb::getDb();
00067 
00068         $sNewsViewName = getViewName( 'oxnews' );
00069         $oBaseObject   = $this->getBaseObject();
00070         //$sSelectFields = $oBaseObject->getSelectFields();
00071 
00072         if ( $oUser = $this->getUser() ) {
00073             // performance - only join if user is logged in
00074             $sSelect  = "select COUNT($sNewsViewName.`oxid`) from $sNewsViewName ";
00075             $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where ";
00076             $sSelect .= "oxobject2group.oxgroupsid in ( select oxgroupsid from oxobject2group where oxobjectid='".$oUser->getId()."' ) or ";
00077             $sSelect .= "( oxobject2group.oxgroupsid is null ) ";
00078         } else {
00079             $sSelect  = "select COUNT($sNewsViewName.`oxid`) from $sNewsViewName ";
00080             $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where oxobject2group.oxgroupsid is null ";
00081         }
00082 
00083         $sSelect .= " and ".$oBaseObject->getSqlActiveSnippet();
00084 
00085         // loading only if there is some data
00086         $iRecCnt = (int) $oDb->getOne( $sSelect );
00087 
00088         return $iRecCnt;
00089     }
00090 
00098     public function setUser( $oUser )
00099     {
00100         $this->_oUser = $oUser;
00101     }
00102 
00108     public function getUser()
00109     {
00110         if ( $this->_oUser == null ) {
00111             $this->_oUser = parent::getUser();
00112         }
00113 
00114         return $this->_oUser;
00115     }
00116 }