oxactions.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class oxActions extends oxI18n
00007 {
00013     protected $_sClassName = "oxactions";
00014 
00018     public function __construct()
00019     {
00020         parent::__construct();
00021         $this->init( "oxactions" );
00022     }
00023 
00031     public function addArticle( $sOxId )
00032     {
00033         $oNewGroup = oxNew( 'oxbase' );
00034         $oNewGroup->init( 'oxactions2article' );
00035         $oNewGroup->oxactions2article__oxshopid = new oxField($this->getShopId());
00036         $oNewGroup->oxactions2article__oxactionid = new oxField($this->getId());
00037         $oNewGroup->oxactions2article__oxartid = new oxField($sOxId);
00038         $oNewGroup->oxactions2article__oxsort = new oxField(((int) oxDb::getDb(true)->getOne("select max(oxsort) from oxactions2article where oxactionid = '".$this->getId()."' and oxshopid = '".$this->getShopId()."'") + 1 ));
00039         $oNewGroup->save();
00040     }
00041 
00049     public function removeArticle( $sOxId )
00050     {
00051         // remove actions from articles also
00052         $oDb = oxDb::getDb(true);
00053         $sDelete = "delete from oxactions2article where oxactionid = '".$this->getId()."' and oxartid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
00054         $oDb->execute( $sDelete );
00055 
00056         return ( bool ) $oDb->affected_Rows();
00057     }
00058 
00068     public function delete( $sOxId = null )
00069     {
00070         if ( !$sOxId ) {
00071             $sOxId = $this->getId();
00072         }
00073         if ( !$sOxId ) {
00074             return false;
00075         }
00076 
00077 
00078         // remove actionss from articles also
00079         $oDb = oxDb::getDb(true);
00080         $sDelete = "delete from oxactions2article where oxactionid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
00081         $oDb->execute( $sDelete );
00082 
00083         return parent::delete( $sOxId );
00084     }
00085     
00086     
00087 
00088 
00089 
00090 
00091 
00092 
00093 
00094 
00100     public function getTimeLeft()
00101     {
00102         $iNow  = oxUtilsDate::getInstance()->getTime();
00103         $iFrom = strtotime($this->oxactions__oxactiveto->value);
00104         return $iFrom-$iNow;
00105     }
00106 
00112     public function getTimeUntilStart()
00113     {
00114         $iNow  = oxUtilsDate::getInstance()->getTime();
00115         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00116         return $iFrom-$iNow;
00117     }
00118 
00124     public function start()
00125     {
00126         $this->oxactions__oxactivefrom = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00127         if ($this->oxactions__oxactiveto->value && ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00')) {
00128             $iNow = oxUtilsDate::getInstance()->getTime();
00129             $iTo  = strtotime($this->oxactions__oxactiveto->value);
00130             if ($iNow > $iTo) {
00131                 $this->oxactions__oxactiveto = new oxField('0000-00-00 00:00:00');
00132             }
00133         }
00134         $this->save();
00135     }
00136 
00142     public function stop()
00143     {
00144         $this->oxactions__oxactiveto = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00145         $this->save();
00146     }
00147 
00153     public function isRunning()
00154     {
00155         if (!($this->oxactions__oxactive->value
00156                 && $this->oxactions__oxtype->value == 2
00157                 && $this->oxactions__oxactivefrom->value != '0000-00-00 00:00:00'
00158             )) {
00159             return false;
00160         }
00161         $iNow = oxUtilsDate::getInstance()->getTime();
00162         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00163         if ($iNow < $iFrom) {
00164             return false;
00165         }
00166 
00167         if ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00') {
00168             $iTo = strtotime($this->oxactions__oxactiveto->value);
00169             if ($iNow > $iTo) {
00170                 return false;
00171             }
00172         }
00173 
00174         return true;
00175     }
00176 
00177 
00183     public function getLongDesc()
00184     {
00185         $sDbValue = $this->oxactions__oxlongdesc->getRawValue();
00186         $oStr = getStr();
00187         $blHasSmarty = $oStr->strstr( $sDbValue, '[{' );
00188         $blHasPhp = $oStr->strstr( $sDbValue, '<?' );
00189         if ( $blHasSmarty || $blHasPhp) {
00190             $sDbValue = oxUtilsView::getInstance()->parseThroughSmarty( $sDbValue, "promotion_".$this->getId() );
00191         }
00192         return $sDbValue;
00193     }
00194     
00195 }