OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
oxnewslist.php
Go to the documentation of this file.
1 <?php
2 
8 class oxNewslist extends oxList
9 {
15  protected $_sObjectsInListName = 'oxnews';
16 
20  protected $_oUser = null;
21 
31  public function loadNews( $iFrom = 0, $iLimit = 10 )
32  {
33  if ( $iLimit ) {
34  $this->setSqlLimit( $iFrom, $iLimit );
35  }
36 
37  $sNewsViewName = getViewName( 'oxnews' );
38  $oBaseObject = $this->getBaseObject();
39  $sSelectFields = $oBaseObject->getSelectFields();
40 
41  if ( $oUser = $this->getUser() ) {
42  // performance - only join if user is logged in
43  $sSelect = "select $sSelectFields from $sNewsViewName ";
44  $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where ";
45  $sSelect .= "oxobject2group.oxgroupsid in ( select oxgroupsid from oxobject2group where oxobjectid='".$oUser->getId()."' ) or ";
46  $sSelect .= "( oxobject2group.oxgroupsid is null ) ";
47  } else {
48  $sSelect = "select $sSelectFields, oxobject2group.oxgroupsid from $sNewsViewName ";
49  $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where oxobject2group.oxgroupsid is null ";
50  }
51 
52  $sSelect .= " and ".$oBaseObject->getSqlActiveSnippet();
53  $sSelect .= " and $sNewsViewName.oxshortdesc <> '' ";
54  $sSelect .= " group by $sNewsViewName.oxid order by $sNewsViewName.oxdate desc ";
55 
56  $this->selectString( $sSelect );
57  }
58 
64  public function getCount()
65  {
66  $myConfig = $this->getConfig();
67  $oDb = oxDb::getDb();
68 
69  $sNewsViewName = getViewName( 'oxnews' );
70  $oBaseObject = $this->getBaseObject();
71  //$sSelectFields = $oBaseObject->getSelectFields();
72 
73  if ( $oUser = $this->getUser() ) {
74  // performance - only join if user is logged in
75  $sSelect = "select COUNT($sNewsViewName.`oxid`) from $sNewsViewName ";
76  $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where ";
77  $sSelect .= "oxobject2group.oxgroupsid in ( select oxgroupsid from oxobject2group where oxobjectid='".$oUser->getId()."' ) or ";
78  $sSelect .= "( oxobject2group.oxgroupsid is null ) ";
79  } else {
80  $sSelect = "select COUNT($sNewsViewName.`oxid`) from $sNewsViewName ";
81  $sSelect .= "left join oxobject2group on oxobject2group.oxobjectid=$sNewsViewName.oxid where oxobject2group.oxgroupsid is null ";
82  }
83 
84  $sSelect .= " and ".$oBaseObject->getSqlActiveSnippet();
85 
86  // loading only if there is some data
87  $iRecCnt = (int) $oDb->getOne( $sSelect );
88 
89  return $iRecCnt;
90  }
91 
99  public function setUser( $oUser )
100  {
101  $this->_oUser = $oUser;
102  }
103 
109  public function getUser()
110  {
111  if ( $this->_oUser == null ) {
112  $this->_oUser = parent::getUser();
113  }
114 
115  return $this->_oUser;
116  }
117 }