OXID eShop CE  4.10.6
 All Classes Namespaces Files Functions Variables Pages
oxactions.php
Go to the documentation of this file.
1 <?php
2 
7 class oxActions extends oxI18n
8 {
9 
15  protected $_sClassName = "oxactions";
16 
20  public function __construct()
21  {
23  $this->init("oxactions");
24  }
25 
31  public function addArticle($sOxId)
32  {
33  $oDb = oxDb::getDb();
34  $sQ = "select max(oxsort) from oxactions2article where oxactionid = " . $oDb->quote($this->getId()) . " and oxshopid = '" . $this->getShopId() . "'";
35  $iSort = ((int) $oDb->getOne($sQ)) + 1;
36 
37  $oNewGroup = oxNew('oxbase');
38  $oNewGroup->init('oxactions2article');
39  $oNewGroup->oxactions2article__oxshopid = new oxField($this->getShopId());
40  $oNewGroup->oxactions2article__oxactionid = new oxField($this->getId());
41  $oNewGroup->oxactions2article__oxartid = new oxField($sOxId);
42  $oNewGroup->oxactions2article__oxsort = new oxField($iSort);
43  $oNewGroup->save();
44 
45 
46  }
47 
55  public function removeArticle($sOxId)
56  {
57  // remove actions from articles also
58  $oDb = oxDb::getDb();
59  $sDelete = "delete from oxactions2article where oxactionid = " . $oDb->quote($this->getId()) . " and oxartid = " . $oDb->quote($sOxId) . " and oxshopid = '" . $this->getShopId() . "'";
60  $oDb->execute($sDelete);
61  $iRemovedArticles = $oDb->affected_Rows();
62 
63 
64  return (bool) $iRemovedArticles;
65  }
66 
76  public function delete($sOxId = null)
77  {
78  if (!$sOxId) {
79  $sOxId = $this->getId();
80  }
81  if (!$sOxId) {
82  return false;
83  }
84 
85 
86  // remove actions from articles also
87  $oDb = oxDb::getDb();
88  $sDelete = "delete from oxactions2article where oxactionid = " . $oDb->quote($sOxId) . " and oxshopid = '" . $this->getShopId() . "'";
89  $oDb->execute($sDelete);
90 
91  return parent::delete($sOxId);
92  }
93 
99  public function getTimeLeft()
100  {
101  $iNow = oxRegistry::get("oxUtilsDate")->getTime();
102  $iFrom = strtotime($this->oxactions__oxactiveto->value);
103 
104  return $iFrom - $iNow;
105  }
106 
112  public function getTimeUntilStart()
113  {
114  $iNow = oxRegistry::get("oxUtilsDate")->getTime();
115  $iFrom = strtotime($this->oxactions__oxactivefrom->value);
116 
117  return $iFrom - $iNow;
118  }
119 
123  public function start()
124  {
125  $this->oxactions__oxactivefrom = new oxField(date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()));
126  if ($this->oxactions__oxactiveto->value && ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00')) {
127  $iNow = oxRegistry::get("oxUtilsDate")->getTime();
128  $iTo = strtotime($this->oxactions__oxactiveto->value);
129  if ($iNow > $iTo) {
130  $this->oxactions__oxactiveto = new oxField('0000-00-00 00:00:00');
131  }
132  }
133  $this->save();
134 
135  }
136 
140  public function stop()
141  {
142  $this->oxactions__oxactiveto = new oxField(date('Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime()));
143  $this->save();
144  }
145 
151  public function isRunning()
152  {
153  if (!($this->oxactions__oxactive->value
154  && $this->oxactions__oxtype->value == 2
155  && $this->oxactions__oxactivefrom->value != '0000-00-00 00:00:00'
156  )
157  ) {
158  return false;
159  }
160  $iNow = oxRegistry::get("oxUtilsDate")->getTime();
161  $iFrom = strtotime($this->oxactions__oxactivefrom->value);
162  if ($iNow < $iFrom) {
163  return false;
164  }
165 
166  if ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00') {
167  $iTo = strtotime($this->oxactions__oxactiveto->value);
168  if ($iNow > $iTo) {
169  return false;
170  }
171  }
172 
173  return true;
174  }
175 
181  public function getLongDesc()
182  {
184  $oUtilsView = oxRegistry::get("oxUtilsView");
185  return $oUtilsView->parseThroughSmarty($this->oxactions__oxlongdesc->getRawValue(), $this->getId() . $this->getLanguage(), null, true);
186  }
187 
193  public function getBannerArticle()
194  {
195  $oDb = oxDb::getDb();
196  $sArtId = $oDb->getOne(
197  'select oxobjectid from oxobject2action '
198  . 'where oxactionid=' . $oDb->quote($this->getId())
199  . ' and oxclass="oxarticle"'
200  );
201 
202  if ($sArtId) {
203  $oArticle = oxNew('oxarticle');
204 
205  if ($this->isAdmin()) {
206  $oArticle->setLanguage(oxRegistry::getLang()->getEditLanguage());
207  }
208 
209  if ($oArticle->load($sArtId)) {
210  return $oArticle;
211  }
212  }
213 
214  return null;
215  }
216 
217 
223  public function getBannerPictureUrl()
224  {
225  if (isset($this->oxactions__oxpic) && $this->oxactions__oxpic->value) {
226  $sPromoDir = oxRegistry::get("oxUtilsFile")->normalizeDir(oxUtilsFile::PROMO_PICTURE_DIR);
227 
228  return $this->getConfig()->getPictureUrl($sPromoDir . $this->oxactions__oxpic->value, false);
229  }
230  }
231 
238  public function getBannerLink()
239  {
240  $sUrl = null;
241 
242  if (isset($this->oxactions__oxlink) && $this->oxactions__oxlink->value) {
244  $oUtilsUlr = oxRegistry::get("oxUtilsUrl");
245  $sUrl = $oUtilsUlr->addShopHost($this->oxactions__oxlink->value);
246  $sUrl = $oUtilsUlr->processUrl($sUrl);
247  } else {
248  if ($oArticle = $this->getBannerArticle()) {
249  // if article is assigned to banner, getting article link
250  $sUrl = $oArticle->getLink();
251  }
252  }
253 
254  return $sUrl;
255  }
256 
257 }