OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxactions.php
Go to the documentation of this file.
1 <?php
2 
7 class oxActions extends oxI18n
8 {
14  protected $_sClassName = "oxactions";
15 
19  public function __construct()
20  {
22  $this->init( "oxactions" );
23  }
24 
32  public function addArticle( $sOxId )
33  {
34  $oDb = oxDb::getDb();
35  $sQ = "select max(oxsort) from oxactions2article where oxactionid = ".$oDb->quote( $this->getId() )." and oxshopid = '".$this->getShopId()."'";
36  $iSort = ( (int) $oDb->getOne( $sQ ) ) + 1;
37 
38  $oNewGroup = oxNew( 'oxbase' );
39  $oNewGroup->init( 'oxactions2article' );
40  $oNewGroup->oxactions2article__oxshopid = new oxField( $this->getShopId() );
41  $oNewGroup->oxactions2article__oxactionid = new oxField( $this->getId() );
42  $oNewGroup->oxactions2article__oxartid = new oxField( $sOxId );
43  $oNewGroup->oxactions2article__oxsort = new oxField( $iSort );
44  $oNewGroup->save();
45 
46 
47  }
48 
56  public function removeArticle( $sOxId )
57  {
58  // remove actions from articles also
59  $oDb = oxDb::getDb();
60  $sDelete = "delete from oxactions2article where oxactionid = ".$oDb->quote( $this->getId() )." and oxartid = ".$oDb->quote($sOxId)." and oxshopid = '" . $this->getShopId() . "'";
61  $oDb->execute( $sDelete );
62 
63 
64  return ( bool ) $oDb->affected_Rows();
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  return $iFrom-$iNow;
104  }
105 
111  public function getTimeUntilStart()
112  {
113  $iNow = oxRegistry::get("oxUtilsDate")->getTime();
114  $iFrom = strtotime($this->oxactions__oxactivefrom->value);
115  return $iFrom-$iNow;
116  }
117 
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 
142  public function stop()
143  {
144  $this->oxactions__oxactiveto = new oxField(date( 'Y-m-d H:i:s', oxRegistry::get("oxUtilsDate")->getTime() ));
145  $this->save();
146  }
147 
153  public function isRunning()
154  {
155  if (!($this->oxactions__oxactive->value
156  && $this->oxactions__oxtype->value == 2
157  && $this->oxactions__oxactivefrom->value != '0000-00-00 00:00:00'
158  )) {
159  return false;
160  }
161  $iNow = oxRegistry::get("oxUtilsDate")->getTime();
162  $iFrom = strtotime($this->oxactions__oxactivefrom->value);
163  if ($iNow < $iFrom) {
164  return false;
165  }
166 
167  if ($this->oxactions__oxactiveto->value != '0000-00-00 00:00:00') {
168  $iTo = strtotime($this->oxactions__oxactiveto->value);
169  if ($iNow > $iTo) {
170  return false;
171  }
172  }
173 
174  return true;
175  }
176 
182  public function getLongDesc()
183  {
184  return oxRegistry::get("oxUtilsView")->parseThroughSmarty( $this->oxactions__oxlongdesc->getRawValue(), $this->getId().$this->getLanguage(), null, true );
185  }
186 
192  public function getBannerArticle()
193  {
194  $oDb = oxDb::getDb();
195  $sArtId = $oDb->getOne(
196  'select oxobjectid from oxobject2action '
197  . 'where oxactionid='.$oDb->quote($this->getId())
198  . ' and oxclass="oxarticle"'
199  );
200 
201  if ( $sArtId ) {
202  $oArticle = oxNew( 'oxarticle' );
203 
204  if ( $this->isAdmin() ) {
205  $oArticle->setLanguage( oxRegistry::getLang()->getEditLanguage() );
206  }
207 
208  if ( $oArticle->load($sArtId) ) {
209  return $oArticle;
210  }
211  }
212  return null;
213  }
214 
215 
221  public function getBannerPictureUrl()
222  {
223  if ( isset( $this->oxactions__oxpic ) && $this->oxactions__oxpic->value ) {
224  $sPromoDir = oxRegistry::get("oxUtilsFile")->normalizeDir( oxUtilsFile::PROMO_PICTURE_DIR );
225  return $this->getConfig()->getPictureUrl( $sPromoDir.$this->oxactions__oxpic->value, false );
226  }
227  }
228 
235  public function getBannerLink()
236  {
237  if ( isset( $this->oxactions__oxlink ) && $this->oxactions__oxlink->value ) {
238  $sUrl = $this->oxactions__oxlink->value ;
239  if ( !preg_match( "#^https?://#i", $sUrl) ) {
240  $sUrl = $this->getConfig()->getShopUrl() . $sUrl ;
241  }
242  return oxRegistry::get("oxUtilsUrl")->processUrl( $sUrl );
243  } else {
244  // if article is assigned to banner, getting article link
245  if ( $oArticle = $this->getBannerArticle() ) {
246  return $oArticle->getLink();
247  }
248  }
249  }
250 
251 
252 }