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         $sViewName = $this->getBaseObject()->getViewName();
00026         $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00027 
00028         $oDb = oxDb::getDb();
00029         $sQ = "select * from {$sViewName} where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' and oxactiveto>0 and oxactiveto < ".$oDb->quote($sDate)."
00030                ".$this->_getUserGroupFilter()."
00031                order by oxactiveto desc, oxactivefrom desc limit ".(int)$iCount;
00032         $this->selectString( $sQ );
00033         $this->_aArray = array_reverse( $this->_aArray, true );
00034     }
00035 
00043     public function loadFinishedByTimespan($iTimespan)
00044     {
00045         $sViewName = $this->getBaseObject()->getViewName();
00046         $sDateTo   = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00047         $sDateFrom = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()-$iTimespan );
00048         $oDb = oxDb::getDb();
00049         $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)."
00050                ".$this->_getUserGroupFilter()."
00051                order by oxactiveto, oxactivefrom";
00052         $this->selectString( $sQ );
00053     }
00054 
00060     public function loadCurrent()
00061     {
00062         $sViewName = $this->getBaseObject()->getViewName();
00063         $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00064         $oDb = oxDb::getDb();
00065         $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)."
00066                ".$this->_getUserGroupFilter()."
00067                order by oxactiveto, oxactivefrom";
00068         $this->selectString( $sQ );
00069     }
00070 
00078     public function loadFutureByCount($iCount)
00079     {
00080         $sViewName = $this->getBaseObject()->getViewName();
00081         $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00082         $oDb = oxDb::getDb();
00083         $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)."
00084                ".$this->_getUserGroupFilter()."
00085                order by oxactiveto, oxactivefrom limit ".(int)$iCount;
00086         $this->selectString( $sQ );
00087     }
00088 
00096     public function loadFutureByTimespan($iTimespan)
00097     {
00098         $sViewName = $this->getBaseObject()->getViewName();
00099         $sDate = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() );
00100         $sDateTo = date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()+$iTimespan );
00101         $oDb = oxDb::getDb();
00102         $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)."
00103                ".$this->_getUserGroupFilter()."
00104                order by oxactiveto, oxactivefrom";
00105         $this->selectString( $sQ );
00106     }
00107 
00115     protected function _getUserGroupFilter( $oUser = null )
00116     {
00117         $oUser = ( $oUser == null ) ? $this->getUser() : $oUser;
00118         $sTable      = getViewName( 'oxactions' );
00119         $sGroupTable = getViewName( 'oxgroups' );
00120 
00121         $aIds = array();
00122         // checking for current session user which gives additional restrictions for user itself, users group and country
00123         if ( $oUser && count( $aGroupIds = $oUser->getUserGroups() ) ) {
00124             foreach ( $aGroupIds as $oGroup ) {
00125                 $aIds[] = $oGroup->getId();
00126             }
00127         }
00128 
00129         $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';
00130         $sQ = " and (
00131             select
00132                 if(EXISTS(select 1 from oxobject2action, $sGroupTable where $sGroupTable.oxid=oxobject2action.oxobjectid and oxobject2action.oxactionid=$sTable.OXID and oxobject2action.oxclass='oxgroups' LIMIT 1),
00133                     $sGroupSql,
00134                     1)
00135             ) ";
00136 
00137         return $sQ;
00138     }
00139 
00145     public function areAnyActivePromotions()
00146     {
00147         return (bool) oxDb::getDb()->getOne("select 1 from ".getViewName( 'oxactions' )." where oxtype=2 and oxactive=1 and oxshopid='".$this->getConfig()->getShopId()."' limit 1");
00148     }
00149 
00150 
00151 
00152 
00158     public function loadBanners()
00159     {
00160         $oBaseObject = $this->getBaseObject();
00161         $oViewName = $oBaseObject->getViewName();
00162         $sQ = "select * from {$oViewName} where oxtype=3 and " . $oBaseObject->getSqlActiveSnippet()
00163             . " and oxshopid='" . $this->getConfig()->getShopId() . "' " . $this->_getUserGroupFilter()
00164             . " order by oxsort";
00165         $this->selectString( $sQ );
00166     }
00167 }