oxactions.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxActions extends oxI18n
00008 {
00014     protected $_sClassName = "oxactions";
00015 
00019     public function __construct()
00020     {
00021         parent::__construct();
00022         $this->init( "oxactions" );
00023     }
00024 
00032     public function addArticle( $sOxId )
00033     {
00034         $oDb = oxDb::getDb();
00035         $sQ = "select max(oxsort) from oxactions2article where oxactionid = ".$oDb->quote( $this->getId() )." and oxshopid = '".$this->getShopId()."'";
00036         $iSort = ( (int) $oDb->getOne( $sQ ) ) + 1;
00037 
00038         $oNewGroup = oxNew( 'oxbase' );
00039         $oNewGroup->init( 'oxactions2article' );
00040         $oNewGroup->oxactions2article__oxshopid   = new oxField( $this->getShopId() );
00041         $oNewGroup->oxactions2article__oxactionid = new oxField( $this->getId() );
00042         $oNewGroup->oxactions2article__oxartid = new oxField( $sOxId );
00043         $oNewGroup->oxactions2article__oxsort  = new oxField( $iSort );
00044         $oNewGroup->save();
00045 
00046 
00047     }
00048 
00056     public function removeArticle( $sOxId )
00057     {
00058         // remove actions from articles also
00059         $oDb = oxDb::getDb();
00060         $sDelete = "delete from oxactions2article where oxactionid = ".$oDb->quote( $this->getId() )." and oxartid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
00061         $oDb->execute( $sDelete );
00062 
00063 
00064         return ( bool ) $oDb->affected_Rows();
00065     }
00066 
00076     public function delete( $sOxId = null )
00077     {
00078         if ( !$sOxId ) {
00079             $sOxId = $this->getId();
00080         }
00081         if ( !$sOxId ) {
00082             return false;
00083         }
00084 
00085 
00086         // remove actions from articles also
00087         $oDb = oxDb::getDb();
00088         $sDelete = "delete from oxactions2article where oxactionid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
00089         $oDb->execute( $sDelete );
00090 
00091         return parent::delete( $sOxId );
00092     }
00093 
00099     public function getTimeLeft()
00100     {
00101         $iNow  = oxRegistry::get("oxUtilsDate")->getTime();
00102         $iFrom = strtotime($this->oxactions__oxactiveto->value);
00103         return $iFrom-$iNow;
00104     }
00105 
00111     public function getTimeUntilStart()
00112     {
00113         $iNow  = oxRegistry::get("oxUtilsDate")->getTime();
00114         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00115         return $iFrom-$iNow;
00116     }
00117 
00123     public function start()
00124     {
00125         $this->oxactions__oxactivefrom = new oxField(date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() ));
00126         if ($this->oxactions__oxactiveto->value && ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00')) {
00127             $iNow = oxRegistry::get("oxUtilsDate")->getTime();
00128             $iTo  = strtotime($this->oxactions__oxactiveto->value);
00129             if ($iNow > $iTo) {
00130                 $this->oxactions__oxactiveto = new oxField('0000-00-00 00:00:00');
00131             }
00132         }
00133         $this->save();
00134 
00135     }
00136 
00142     public function stop()
00143     {
00144         $this->oxactions__oxactiveto = new oxField(date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->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 = oxRegistry::get("oxUtilsDate")->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 
00182     public function getLongDesc()
00183     {
00184         return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->oxactions__oxlongdesc->getRawValue(), $this->getId().$this->getLanguage() );
00185     }
00186 
00192     public function getBannerArticle()
00193     {
00194         $oDb = oxDb::getDb();
00195         $sArtId = $oDb->getOne(
00196             'select oxobjectid from oxobject2action '
00197           . 'where oxactionid='.$oDb->quote($this->getId())
00198           . ' and oxclass="oxarticle"'
00199         );
00200 
00201         if ( $sArtId ) {
00202             $oArticle = oxNew( 'oxarticle' );
00203 
00204             if ( $this->isAdmin() ) {
00205                 $oArticle->setLanguage( oxRegistry::getLang()->getEditLanguage() );
00206             }
00207 
00208             if ( $oArticle->load($sArtId) ) {
00209                 return $oArticle;
00210             }
00211         }
00212         return null;
00213     }
00214 
00215 
00221     public function getBannerPictureUrl()
00222     {
00223         if ( isset( $this->oxactions__oxpic ) && $this->oxactions__oxpic->value ) {
00224             $sPromoDir = oxRegistry::get("oxUtilsFile")->normalizeDir( oxUtilsFile::PROMO_PICTURE_DIR );
00225             return $this->getConfig()->getPictureUrl( $sPromoDir.$this->oxactions__oxpic->value, false );
00226         }
00227     }
00228 
00235     public function getBannerLink()
00236     {
00237         if ( isset( $this->oxactions__oxlink ) && $this->oxactions__oxlink->value ) {
00238            $sUrl = $this->oxactions__oxlink->value ;
00239             if ( !preg_match( "#^https?://#i", $sUrl) ) {
00240                  $sUrl =  $this->getConfig()->getShopUrl() . $sUrl ;
00241             }
00242             return  oxRegistry::get("oxUtilsUrl")->processUrl( $sUrl );
00243         } else {
00244             // if article is assigned to banner, getting article link
00245             if ( $oArticle = $this->getBannerArticle() ) {
00246                 return $oArticle->getLink();
00247             }
00248         }
00249     }
00250 
00251 
00252 }