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         $oDb = oxDb::getDb();
00034         $sQ = "select max(oxsort) from oxactions2article where oxactionid = ".$oDb->quote( $this->getId() )." and oxshopid = '".$this->getShopId()."'";
00035         $iSort = ( (int) $oDb->getOne( $sQ ) ) + 1;
00036 
00037         $oNewGroup = oxNew( 'oxbase' );
00038         $oNewGroup->init( 'oxactions2article' );
00039         $oNewGroup->oxactions2article__oxshopid   = new oxField( $this->getShopId() );
00040         $oNewGroup->oxactions2article__oxactionid = new oxField( $this->getId() );
00041         $oNewGroup->oxactions2article__oxartid = new oxField( $sOxId );
00042         $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort );
00043         $oNewGroup->save();
00044     }
00045 
00053     public function removeArticle( $sOxId )
00054     {
00055         // remove actions from articles also
00056         $oDb = oxDb::getDb(true);
00057         $sDelete = "delete from oxactions2article where oxactionid = ".$oDb->quote( $this->getId() )." and oxartid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
00058         $oDb->execute( $sDelete );
00059 
00060         return ( bool ) $oDb->affected_Rows();
00061     }
00062 
00072     public function delete( $sOxId = null )
00073     {
00074         if ( !$sOxId ) {
00075             $sOxId = $this->getId();
00076         }
00077         if ( !$sOxId ) {
00078             return false;
00079         }
00080 
00081 
00082         // remove actionss from articles also
00083         $oDb = oxDb::getDb(true);
00084         $sDelete = "delete from oxactions2article where oxactionid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
00085         $oDb->execute( $sDelete );
00086 
00087         return parent::delete( $sOxId );
00088     }
00089 
00095     public function getTimeLeft()
00096     {
00097         $iNow  = oxUtilsDate::getInstance()->getTime();
00098         $iFrom = strtotime($this->oxactions__oxactiveto->value);
00099         return $iFrom-$iNow;
00100     }
00101 
00107     public function getTimeUntilStart()
00108     {
00109         $iNow  = oxUtilsDate::getInstance()->getTime();
00110         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00111         return $iFrom-$iNow;
00112     }
00113 
00119     public function start()
00120     {
00121         $this->oxactions__oxactivefrom = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00122         if ($this->oxactions__oxactiveto->value && ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00')) {
00123             $iNow = oxUtilsDate::getInstance()->getTime();
00124             $iTo  = strtotime($this->oxactions__oxactiveto->value);
00125             if ($iNow > $iTo) {
00126                 $this->oxactions__oxactiveto = new oxField('0000-00-00 00:00:00');
00127             }
00128         }
00129         $this->save();
00130     }
00131 
00137     public function stop()
00138     {
00139         $this->oxactions__oxactiveto = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00140         $this->save();
00141     }
00142 
00148     public function isRunning()
00149     {
00150         if (!($this->oxactions__oxactive->value
00151                 && $this->oxactions__oxtype->value == 2
00152                 && $this->oxactions__oxactivefrom->value != '0000-00-00 00:00:00'
00153             )) {
00154             return false;
00155         }
00156         $iNow = oxUtilsDate::getInstance()->getTime();
00157         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00158         if ($iNow < $iFrom) {
00159             return false;
00160         }
00161 
00162         if ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00') {
00163             $iTo = strtotime($this->oxactions__oxactiveto->value);
00164             if ($iNow > $iTo) {
00165                 return false;
00166             }
00167         }
00168 
00169         return true;
00170     }
00171 
00177     public function getLongDesc()
00178     {
00179         return oxUtilsView::getInstance()->parseThroughSmarty( $this->oxactions__oxlongdesc->getRawValue(), $this->getId().$this->getLanguage() );
00180     }
00181 
00187     public function getBannerArticle()
00188     {
00189         $oDb = oxDb::getDb();
00190         $sArtId = $oDb->getOne(
00191             'select oxobjectid from oxobject2action '
00192           . 'where oxactionid='.$oDb->quote($this->getId())
00193           . ' and oxclass="oxarticle"'
00194         );
00195 
00196         if ( $sArtId ) {
00197             $oArticle = oxNew( 'oxarticle' );
00198 
00199             if ( $this->isAdmin() ) {
00200                 $oArticle->setLanguage( oxLang::getInstance()->getEditLanguage() );
00201             }
00202 
00203             if ( $oArticle->load($sArtId) ) {
00204                 return $oArticle;
00205             }
00206         }
00207         return null;
00208     }
00209 
00210 
00216     public function getBannerPictureUrl()
00217     {
00218         if ( isset( $this->oxactions__oxpic ) && $this->oxactions__oxpic->value ) {
00219             $sPromoDir = oxUtilsFile::getInstance()->normalizeDir( oxUtilsFile::PROMO_PICTURE_DIR );
00220             return $this->getConfig()->getPictureUrl( $sPromoDir.$this->oxactions__oxpic->value, false );
00221         }
00222     }
00223 
00230     public function getBannerLink()
00231     {
00232         if ( isset( $this->oxactions__oxlink ) && $this->oxactions__oxlink->value ) {
00233             return  oxUtilsUrl::getInstance()->processUrl( $this->oxactions__oxlink->value );
00234         } else {
00235             // if article is assinged to banner, getting article link
00236             if ( $oArticle = $this->getBannerArticle() ) {
00237                 return $oArticle->getLink();
00238             }
00239         }
00240     }
00241 }