OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxactionlist.php
Go to the documentation of this file.
1 <?php
2 
7 class oxActionList extends oxList
8 {
14  protected $_sObjectsInListName = 'oxactions';
15 
23  public function loadFinishedByCount($iCount)
24  {
25  $sViewName = $this->getBaseObject()->getViewName();
26  $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
27 
28  $oDb = oxDb::getDb();
29  $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and oxactiveto>0 and oxactiveto < ".$oDb->quote($sDate)."
30  ".$this->_getUserGroupFilter()."
31  order by oxactiveto desc, oxactivefrom desc limit ".(int)$iCount;
32  $this->selectString( $sQ );
33  $this->_aArray = array_reverse( $this->_aArray, true );
34  }
35 
43  public function loadFinishedByTimespan($iTimespan)
44  {
45  $sViewName = $this->getBaseObject()->getViewName();
46  $sDateTo = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
47  $sDateFrom = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()-$iTimespan );
48  $oDb = oxDb::getDb();
49  $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)."
50  ".$this->_getUserGroupFilter()."
51  order by oxactiveto, oxactivefrom";
52  $this->selectString( $sQ );
53  }
54 
60  public function loadCurrent()
61  {
62  $sViewName = $this->getBaseObject()->getViewName();
63  $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
64  $oDb = oxDb::getDb();
65  $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)."
66  ".$this->_getUserGroupFilter()."
67  order by oxactiveto, oxactivefrom";
68  $this->selectString( $sQ );
69  }
70 
78  public function loadFutureByCount($iCount)
79  {
80  $sViewName = $this->getBaseObject()->getViewName();
81  $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
82  $oDb = oxDb::getDb();
83  $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)."
84  ".$this->_getUserGroupFilter()."
85  order by oxactiveto, oxactivefrom limit ".(int)$iCount;
86  $this->selectString( $sQ );
87  }
88 
96  public function loadFutureByTimespan($iTimespan)
97  {
98  $sViewName = $this->getBaseObject()->getViewName();
99  $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
100  $sDateTo = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()+$iTimespan );
101  $oDb = oxDb::getDb();
102  $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)."
103  ".$this->_getUserGroupFilter()."
104  order by oxactiveto, oxactivefrom";
105  $this->selectString( $sQ );
106  }
107 
115  protected function _getUserGroupFilter( $oUser = null )
116  {
117  $oUser = ( $oUser == null ) ? $this->getUser() : $oUser;
118  $sTable = getViewName( 'oxactions' );
119  $sGroupTable = getViewName( 'oxgroups' );
120 
121  $aIds = array();
122  // checking for current session user which gives additional restrictions for user itself, users group and country
123  if ( $oUser && count( $aGroupIds = $oUser->getUserGroups() ) ) {
124  foreach ( $aGroupIds as $oGroup ) {
125  $aIds[] = $oGroup->getId();
126  }
127  }
128 
129  $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';
130  $sQ = " and (
131  select
132  if(EXISTS(select 1 from oxobject2action, $sGroupTable where $sGroupTable.oxid=oxobject2action.oxobjectid and oxobject2action.oxactionid=$sTable.OXID and oxobject2action.oxclass='oxgroups' LIMIT 1),
133  $sGroupSql,
134  1)
135  ) ";
136 
137  return $sQ;
138  }
139 
145  public function areAnyActivePromotions()
146  {
147  return (bool) oxDb::getDb()->getOne("select 1 from ".getViewName( 'oxactions' )." where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' limit 1");
148  }
149 
150 
151 
152 
158  public function loadBanners()
159  {
160  $oBaseObject = $this->getBaseObject();
161  $oViewName = $oBaseObject->getViewName();
162  $sQ = "select * from {$oViewName} where oxtype=3 and " . $oBaseObject->getSqlActiveSnippet()
163  . " and oxshopid='" . $this->getConfig()->getShopId() . "' " . $this->_getUserGroupFilter()
164  . " order by oxsort";
165  $this->selectString( $sQ );
166  }
167 }