oxactionlist.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxActionList extends oxList
00008 {
00014     protected $_sObjectsInListName = 'oxactions';
00015 
00023     public function loadFinishedByCount($iCount)
00024     {
00025         $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00026         $sQ = "select * from oxactions where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and oxactiveto>0 and oxactiveto < ".oxDb::getDb()->quote($sDate)."
00027                ".$this->_getUserGroupFilter()."
00028                order by oxactiveto desc, oxactivefrom desc limit ".(int)$iCount;
00029         $this->selectString( $sQ );
00030         $this->_aArray = array_reverse( $this->_aArray, true );
00031     }
00032 
00040     public function loadFinishedByTimespan($iTimespan)
00041     {
00042         $sDateTo   = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00043         $sDateFrom = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime()-$iTimespan );
00044         $sQ = "select * from oxactions where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and oxactiveto < ".oxDb::getDb()->quote($sDateTo)." and oxactiveto > ".oxDb::getDb()->quote($sDateFrom)."
00045                ".$this->_getUserGroupFilter()."
00046                order by oxactiveto, oxactivefrom";
00047         $this->selectString( $sQ );
00048     }
00049 
00055     public function loadCurrent()
00056     {
00057         $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00058         $sQ = "select * from oxactions where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and (oxactiveto > ".oxDb::getDb()->quote($sDate)." or oxactiveto=0) and oxactivefrom != 0 and oxactivefrom < ".oxDb::getDb()->quote($sDate)."
00059                ".$this->_getUserGroupFilter()."
00060                order by oxactiveto, oxactivefrom";
00061         $this->selectString( $sQ );
00062     }
00063 
00071     public function loadFutureByCount($iCount)
00072     {
00073         $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00074         $sQ = "select * from oxactions where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and (oxactiveto > ".oxDb::getDb()->quote($sDate)." or oxactiveto=0) and oxactivefrom > ".oxDb::getDb()->quote($sDate)."
00075                ".$this->_getUserGroupFilter()."
00076                order by oxactiveto, oxactivefrom limit ".(int)$iCount;
00077         $this->selectString( $sQ );
00078     }
00079 
00087     public function loadFutureByTimespan($iTimespan)
00088     {
00089         $sDate = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() );
00090         $sDateTo = date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime()+$iTimespan );
00091         $sQ = "select * from oxactions where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and (oxactiveto > ".oxDb::getDb()->quote($sDate)." or oxactiveto=0) and oxactivefrom > ".oxDb::getDb()->quote($sDate)." and oxactivefrom < ".oxDb::getDb()->quote($sDateTo)."
00092                ".$this->_getUserGroupFilter()."
00093                order by oxactiveto, oxactivefrom";
00094         $this->selectString( $sQ );
00095     }
00096 
00104     protected function _getUserGroupFilter( $oUser = null )
00105     {
00106         $oUser = ( $oUser == null ) ? $this->getUser() : $oUser;
00107         $sTable      = getViewName( 'oxactions' );
00108         $sGroupTable = getViewName( 'oxgroups' );
00109 
00110         $aIds = array();
00111         // checking for current session user which gives additional restrictions for user itself, users group and country
00112         if ( $oUser && count( $aGroupIds = $oUser->getUserGroups() ) ) {
00113             foreach ( $aGroupIds as $oGroup ) {
00114                 $aIds[] = $oGroup->getId();
00115             }
00116         }
00117 
00118         $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';
00119         $sQ = " and (
00120             select
00121                 if(EXISTS(select 1 from oxobject2action, $sGroupTable where $sGroupTable.oxid=oxobject2action.oxobjectid and oxobject2action.oxactionid=$sTable.OXID and oxobject2action.oxclass='oxgroups' LIMIT 1),
00122                     $sGroupSql,
00123                     1)
00124             ) ";
00125 
00126         return $sQ;
00127     }
00128 
00134     public function areAnyActivePromotions()
00135     {
00136         return (bool) oxDb::getDb()->getOne("select 1 from ".getViewName( 'oxactions' )." where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' limit 1");
00137     }
00138 }