OXID eShop CE  4.9.5
 All Classes Files Functions Variables Pages
oxactionlist.php
Go to the documentation of this file.
1 <?php
2 
7 class oxActionList extends oxList
8 {
9 
15  protected $_sObjectsInListName = 'oxactions';
16 
22  public function loadFinishedByCount($iCount)
23  {
24  $sViewName = $this->getBaseObject()->getViewName();
25  $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
26 
27  $oDb = oxDb::getDb();
28  $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='" . $this->getConfig()->getShopId() . "' and oxactiveto>0 and oxactiveto < " . $oDb->quote($sDate) . "
29  " . $this->_getUserGroupFilter() . "
30  order by oxactiveto desc, oxactivefrom desc limit " . (int) $iCount;
31  $this->selectString($sQ);
32  $this->_aArray = array_reverse($this->_aArray, true);
33  }
34 
40  public function loadFinishedByTimespan($iTimespan)
41  {
42  $sViewName = $this->getBaseObject()->getViewName();
43  $sDateTo = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
44  $sDateFrom = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() - $iTimespan);
45  $oDb = oxDb::getDb();
46  $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='" . $this->getConfig()->getShopId() . "' and oxactiveto < " . $oDb->quote($sDateTo) . " and oxactiveto > " . $oDb->quote($sDateFrom) . "
47  " . $this->_getUserGroupFilter() . "
48  order by oxactiveto, oxactivefrom";
49  $this->selectString($sQ);
50  }
51 
55  public function loadCurrent()
56  {
57  $sViewName = $this->getBaseObject()->getViewName();
58  $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
59  $oDb = oxDb::getDb();
60  $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='" . $this->getConfig()->getShopId() . "' and (oxactiveto > " . $oDb->quote($sDate) . " or oxactiveto=0) and oxactivefrom != 0 and oxactivefrom < " . $oDb->quote($sDate) . "
61  " . $this->_getUserGroupFilter() . "
62  order by oxactiveto, oxactivefrom";
63  $this->selectString($sQ);
64  }
65 
71  public function loadFutureByCount($iCount)
72  {
73  $sViewName = $this->getBaseObject()->getViewName();
74  $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
75  $oDb = oxDb::getDb();
76  $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='" . $this->getConfig()->getShopId() . "' and (oxactiveto > " . $oDb->quote($sDate) . " or oxactiveto=0) and oxactivefrom > " . $oDb->quote($sDate) . "
77  " . $this->_getUserGroupFilter() . "
78  order by oxactiveto, oxactivefrom limit " . (int) $iCount;
79  $this->selectString($sQ);
80  }
81 
87  public function loadFutureByTimespan($iTimespan)
88  {
89  $sViewName = $this->getBaseObject()->getViewName();
90  $sDate = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime());
91  $sDateTo = date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() + $iTimespan);
92  $oDb = oxDb::getDb();
93  $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='" . $this->getConfig()->getShopId() . "' and (oxactiveto > " . $oDb->quote($sDate) . " or oxactiveto=0) and oxactivefrom > " . $oDb->quote($sDate) . " and oxactivefrom < " . $oDb->quote($sDateTo) . "
94  " . $this->_getUserGroupFilter() . "
95  order by oxactiveto, oxactivefrom";
96  $this->selectString($sQ);
97  }
98 
106  protected function _getUserGroupFilter($oUser = null)
107  {
108  $oUser = ($oUser == null) ? $this->getUser() : $oUser;
109  $sTable = getViewName('oxactions');
110  $sGroupTable = getViewName('oxgroups');
111 
112  $aIds = array();
113  // checking for current session user which gives additional restrictions for user itself, users group and country
114  if ($oUser && count($aGroupIds = $oUser->getUserGroups())) {
115  foreach ($aGroupIds as $oGroup) {
116  $aIds[] = $oGroup->getId();
117  }
118  }
119 
120  $sGroupSql = count($aIds) ? "EXISTS(select oxobject2action.oxid from oxobject2action where oxobject2action.oxactionid=$sTable.OXID and oxobject2action.oxclass='oxgroups' and oxobject2action.OXOBJECTID in (" . implode(', ', oxDb::getInstance()->quoteArray($aIds)) . ") )" : '0';
121  $sQ = " and (
122  select
123  if(EXISTS(select 1 from oxobject2action, $sGroupTable where $sGroupTable.oxid=oxobject2action.oxobjectid and oxobject2action.oxactionid=$sTable.OXID and oxobject2action.oxclass='oxgroups' LIMIT 1),
124  $sGroupSql,
125  1)
126  ) ";
127 
128  return $sQ;
129  }
130 
136  public function areAnyActivePromotions()
137  {
138  return (bool) oxDb::getDb()->getOne("select 1 from " . getViewName('oxactions') . " where oxtype=2 and oxactive=1 and oxshopid='" . $this->getConfig()->getShopId() . "' limit 1");
139  }
140 
141 
145  public function loadBanners()
146  {
147  $oBaseObject = $this->getBaseObject();
148  $oViewName = $oBaseObject->getViewName();
149  $sQ = "select * from {$oViewName} where oxtype=3 and " . $oBaseObject->getSqlActiveSnippet()
150  . " and oxshopid='" . $this->getConfig()->getShopId() . "' " . $this->_getUserGroupFilter()
151  . " order by oxsort";
152  $this->selectString($sQ);
153  }
154 }