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