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 
00091     public function getTimeLeft()
00092     {
00093         $iNow  = oxUtilsDate::getInstance()->getTime();
00094         $iFrom = strtotime($this->oxactions__oxactiveto->value);
00095         return $iFrom-$iNow;
00096     }
00097 
00103     public function getTimeUntilStart()
00104     {
00105         $iNow  = oxUtilsDate::getInstance()->getTime();
00106         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00107         return $iFrom-$iNow;
00108     }
00109 
00115     public function start()
00116     {
00117         $this->oxactions__oxactivefrom = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00118         if ($this->oxactions__oxactiveto->value && ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00')) {
00119             $iNow = oxUtilsDate::getInstance()->getTime();
00120             $iTo  = strtotime($this->oxactions__oxactiveto->value);
00121             if ($iNow > $iTo) {
00122                 $this->oxactions__oxactiveto = new oxField('0000-00-00 00:00:00');
00123             }
00124         }
00125         $this->save();
00126     }
00127 
00133     public function stop()
00134     {
00135         $this->oxactions__oxactiveto = new oxField(date( 'Y-m-d H:i:s', oxUtilsDate::getInstance()->getTime() ));
00136         $this->save();
00137     }
00138 
00144     public function isRunning()
00145     {
00146         if (!($this->oxactions__oxactive->value
00147                 && $this->oxactions__oxtype->value == 2
00148                 && $this->oxactions__oxactivefrom->value != '0000-00-00 00:00:00'
00149             )) {
00150             return false;
00151         }
00152         $iNow = oxUtilsDate::getInstance()->getTime();
00153         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00154         if ($iNow < $iFrom) {
00155             return false;
00156         }
00157 
00158         if ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00') {
00159             $iTo = strtotime($this->oxactions__oxactiveto->value);
00160             if ($iNow > $iTo) {
00161                 return false;
00162             }
00163         }
00164 
00165         return true;
00166     }
00167 
00173     public function getLongDesc()
00174     {
00175         return oxUtilsView::getInstance()->parseThroughSmarty( $this->oxactions__oxlongdesc->getRawValue(), $this->getId().$this->getLanguage() );
00176     }
00177 
00183     public function getBannerArticle()
00184     {
00185         $oDb = oxDb::getDb();
00186         $sArtId = $oDb->getOne(
00187             'select oxobjectid from oxobject2action '
00188           . 'where oxactionid='.$oDb->quote($this->getId())
00189           . ' and oxclass="oxarticle"'
00190         );
00191 
00192         if ( $sArtId ) {
00193             $oArticle = oxNew( 'oxarticle' );
00194 
00195             if ( $this->isAdmin() ) {
00196                 $oArticle->setLanguage( oxLang::getInstance()->getEditLanguage() );
00197             }
00198 
00199             if ( $oArticle->load($sArtId) ) {
00200                 return $oArticle;
00201             }
00202         }
00203         return null;
00204     }
00205 
00206 
00212     public function getBannerPictureUrl()
00213     {
00214         if ( isset( $this->oxactions__oxpic ) && $this->oxactions__oxpic->value ) {
00215             $sPromoDir = oxUtilsFile::getInstance()->normalizeDir( oxUtilsFile::PROMO_PICTURE_DIR );
00216             return $this->getConfig()->getPictureUrl( $sPromoDir.$this->oxactions__oxpic->value, false );
00217         }
00218     }
00219 
00226     public function getBannerLink()
00227     {
00228         if ( isset( $this->oxactions__oxlink ) && $this->oxactions__oxlink->value ) {
00229             return  oxUtilsUrl::getInstance()->processUrl( $this->oxactions__oxlink->value );
00230         } else {
00231             // if article is assinged to banner, getting article link
00232             if ( $oArticle = $this->getBannerArticle() ) {
00233                 return $oArticle->getLink();
00234             }
00235         }
00236     }
00237 }