oxactions.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxActions extends oxI18n
00008 {
00009 
00015     protected $_sClassName = "oxactions";
00016 
00020     public function __construct()
00021     {
00022         parent::__construct();
00023         $this->init("oxactions");
00024     }
00025 
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 
00046     }
00047 
00055     public function removeArticle($sOxId)
00056     {
00057         // remove actions from articles also
00058         $oDb = oxDb::getDb();
00059         $sDelete = "delete from oxactions2article where oxactionid = " . $oDb->quote($this->getId()) . " and oxartid = " . $oDb->quote($sOxId) . " and oxshopid = '" . $this->getShopId() . "'";
00060         $oDb->execute($sDelete);
00061         $iRemovedArticles = $oDb->affected_Rows();
00062 
00063 
00064         return (bool) $iRemovedArticles;
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 
00104         return $iFrom - $iNow;
00105     }
00106 
00112     public function getTimeUntilStart()
00113     {
00114         $iNow = oxRegistry::get("oxUtilsDate")->getTime();
00115         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00116 
00117         return $iFrom - $iNow;
00118     }
00119 
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 
00140     public function stop()
00141     {
00142         $this->oxactions__oxactiveto = new oxField(date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()));
00143         $this->save();
00144     }
00145 
00151     public function isRunning()
00152     {
00153         if (!($this->oxactions__oxactive->value
00154               && $this->oxactions__oxtype->value == 2
00155               && $this->oxactions__oxactivefrom->value != '0000-00-00 00:00:00'
00156         )
00157         ) {
00158             return false;
00159         }
00160         $iNow = oxRegistry::get("oxUtilsDate")->getTime();
00161         $iFrom = strtotime($this->oxactions__oxactivefrom->value);
00162         if ($iNow < $iFrom) {
00163             return false;
00164         }
00165 
00166         if ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00') {
00167             $iTo = strtotime($this->oxactions__oxactiveto->value);
00168             if ($iNow > $iTo) {
00169                 return false;
00170             }
00171         }
00172 
00173         return true;
00174     }
00175 
00181     public function getLongDesc()
00182     {
00183         return oxRegistry::get("oxUtilsView")->parseThroughSmarty($this->oxactions__oxlongdesc->getRawValue(), $this->getId() . $this->getLanguage());
00184     }
00185 
00191     public function getBannerArticle()
00192     {
00193         $oDb = oxDb::getDb();
00194         $sArtId = $oDb->getOne(
00195             'select oxobjectid from oxobject2action '
00196             . 'where oxactionid=' . $oDb->quote($this->getId())
00197             . ' and oxclass="oxarticle"'
00198         );
00199 
00200         if ($sArtId) {
00201             $oArticle = oxNew('oxarticle');
00202 
00203             if ($this->isAdmin()) {
00204                 $oArticle->setLanguage(oxRegistry::getLang()->getEditLanguage());
00205             }
00206 
00207             if ($oArticle->load($sArtId)) {
00208                 return $oArticle;
00209             }
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 
00226             return $this->getConfig()->getPictureUrl($sPromoDir . $this->oxactions__oxpic->value, false);
00227         }
00228     }
00229 
00236     public function getBannerLink()
00237     {
00238         $sUrl = null;
00239 
00240         if (isset($this->oxactions__oxlink) && $this->oxactions__oxlink->value) {
00242             $oUtilsUlr = oxRegistry::get("oxUtilsUrl");
00243             $sUrl = $oUtilsUlr->addShopHost($this->oxactions__oxlink->value);
00244             $sUrl = $oUtilsUlr->processUrl($sUrl);
00245         } else {
00246             if ($oArticle = $this->getBannerArticle()) {
00247                 // if article is assigned to banner, getting article link
00248                 $sUrl = $oArticle->getLink();
00249             }
00250         }
00251 
00252         return $sUrl;
00253     }
00254 
00255 }