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
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
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 {
00184 $oUtilsView = oxRegistry::get("oxUtilsView");
00185 return $oUtilsView->parseThroughSmarty($this->oxactions__oxlongdesc->getRawValue(), $this->getId() . $this->getLanguage(), null, true);
00186 }
00187
00193 public function getBannerArticle()
00194 {
00195 $oDb = oxDb::getDb();
00196 $sArtId = $oDb->getOne(
00197 'select oxobjectid from oxobject2action '
00198 . 'where oxactionid=' . $oDb->quote($this->getId())
00199 . ' and oxclass="oxarticle"'
00200 );
00201
00202 if ($sArtId) {
00203 $oArticle = oxNew('oxarticle');
00204
00205 if ($this->isAdmin()) {
00206 $oArticle->setLanguage(oxRegistry::getLang()->getEditLanguage());
00207 }
00208
00209 if ($oArticle->load($sArtId)) {
00210 return $oArticle;
00211 }
00212 }
00213
00214 return null;
00215 }
00216
00217
00223 public function getBannerPictureUrl()
00224 {
00225 if (isset($this->oxactions__oxpic) && $this->oxactions__oxpic->value) {
00226 $sPromoDir = oxRegistry::get("oxUtilsFile")->normalizeDir(oxUtilsFile::PROMO_PICTURE_DIR);
00227
00228 return $this->getConfig()->getPictureUrl($sPromoDir . $this->oxactions__oxpic->value, false);
00229 }
00230 }
00231
00238 public function getBannerLink()
00239 {
00240 $sUrl = null;
00241
00242 if (isset($this->oxactions__oxlink) && $this->oxactions__oxlink->value) {
00244 $oUtilsUlr = oxRegistry::get("oxUtilsUrl");
00245 $sUrl = $oUtilsUlr->addShopHost($this->oxactions__oxlink->value);
00246 $sUrl = $oUtilsUlr->processUrl($sUrl);
00247 } else {
00248 if ($oArticle = $this->getBannerArticle()) {
00249
00250 $sUrl = $oArticle->getLink();
00251 }
00252 }
00253
00254 return $sUrl;
00255 }
00256
00257 }