oxnewslist.php

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