OXID eShop CE  4.10.2
 All Classes Namespaces Files Functions Variables Pages
oxnewslist.php
Go to the documentation of this file.
1 <?php
2 
9 class oxNewslist extends oxList
10 {
11 
17  protected $_sObjectsInListName = 'oxnews';
18 
22  protected $_oUser = null;
23 
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 
97  public function setUser($oUser)
98  {
99  $this->_oUser = $oUser;
100  }
101 
107  public function getUser()
108  {
109  if ($this->_oUser == null) {
110  $this->_oUser = parent::getUser();
111  }
112 
113  return $this->_oUser;
114  }
115 }