OXID eShop CE  4.9.9
 All Classes Files Functions Variables Pages
actions_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_blAllowExtColumns = true;
15 
21  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
22  array('oxartnum', 'oxarticles', 1, 0, 0),
23  array('oxtitle', 'oxarticles', 1, 1, 0),
24  array('oxean', 'oxarticles', 1, 0, 0),
25  array('oxmpn', 'oxarticles', 0, 0, 0),
26  array('oxprice', 'oxarticles', 0, 0, 0),
27  array('oxstock', 'oxarticles', 0, 0, 0),
28  array('oxid', 'oxarticles', 0, 0, 1)
29  ),
30  'container2' => array(
31  array('oxartnum', 'oxarticles', 1, 0, 0),
32  array('oxsort', 'oxactions2article', 1, 0, 0),
33  array('oxtitle', 'oxarticles', 1, 1, 0),
34  array('oxean', 'oxarticles', 1, 0, 0),
35  array('oxmpn', 'oxarticles', 0, 0, 0),
36  array('oxprice', 'oxarticles', 0, 0, 0),
37  array('oxstock', 'oxarticles', 0, 0, 0),
38  array('oxid', 'oxactions2article', 0, 0, 1)
39  )
40  );
41 
47  protected function _getQuery()
48  {
49  $myConfig = $this->getConfig();
50  $oDb = oxDb::getDb();
51  // looking for table/view
52  $sArtTable = $this->_getViewName('oxarticles');
53  $sView = $this->_getViewName('oxobject2category');
54 
55  $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
56  $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
57 
58  // category selected or not ?
59  if (!$sSelId) {
60  //performance
61  $sQAdd = " from $sArtTable where 1 ";
62  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
63  } else {
64  // selected category ?
65  if ($sSynchSelId && $sSelId != $sSynchSelId) {
66 
67  $sQAdd = " from {$sView} left join $sArtTable on ";
68  $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
69  $sSqlIfTrue = " ( $sArtTable.oxid={$sView}.oxobjectid or $sArtTable.oxparentid={$sView}.oxobjectid) ";
70  $sSqlIfFalse = " $sArtTable.oxid={$sView}.oxobjectid ";
71  $sQAdd .= $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
72  $sQAdd .= " where {$sView}.oxcatnid = " . $oDb->quote($sSelId);
73  } else {
74 
75  $sQAdd = " from {$sArtTable} left join oxactions2article " .
76  "on {$sArtTable}.oxid=oxactions2article.oxartid " .
77  " where oxactions2article.oxactionid = " . $oDb->quote($sSelId) .
78  " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' ";
79  }
80  }
81 
82  if ($sSynchSelId && $sSynchSelId != $sSelId) {
83  $sQAdd .= " and {$sArtTable}.oxid not in ( select oxactions2article.oxartid from oxactions2article " .
84  " where oxactions2article.oxactionid = " . $oDb->quote($sSynchSelId) .
85  " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' ) ";
86  }
87 
88  return $sQAdd;
89  }
90 
98  protected function _addFilter($sQ)
99  {
100  $sQ = parent::_addFilter($sQ);
101 
102  // display variants or not ?
103  if ($this->getConfig()->getConfigParam('blVariantsSelection')) {
104  $sQ .= ' group by ' . $this->_getViewName('oxarticles') . '.oxid ';
105 
106  $oStr = getStr();
107  if ($oStr->strpos($sQ, "select count( * ) ") === 0) {
108  $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
109  }
110  }
111 
112  //echo $sQ;
113  return $sQ;
114  }
115 
121  protected function _getSorting()
122  {
123  $sOxIdParameter = oxRegistry::getConfig()->getRequestParameter('oxid');
124  $sSynchOxidParameter = oxRegistry::getConfig()->getRequestParameter('synchoxid');
125  if ($sOxIdParameter && !$sSynchOxidParameter) {
126  return 'order by oxactions2article.oxsort ';
127  }
128 
129  return parent::_getSorting();
130  }
131 
135  public function removeArtFromAct()
136  {
137  $aChosenArt = $this->_getActionIds('oxactions2article.oxid');
138  $sOxid = oxRegistry::getConfig()->getRequestParameter('oxid');
139 
140  $this->_getOxRssFeed()->removeCacheFile($sOxid);
141 
142  if (oxRegistry::getConfig()->getRequestParameter('all')) {
143  $sQ = parent::_addFilter("delete oxactions2article.* " . $this->_getQuery());
144  oxDb::getDb()->Execute($sQ);
145  } elseif (is_array($aChosenArt)) {
146  $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
147  $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . $sChosenArticles . ") ";
148  oxDb::getDb()->Execute($sQ);
149  }
150  }
151 
155  public function addArtToAct()
156  {
157  $myConfig = $this->getConfig();
158  $aArticles = $this->_getActionIds('oxarticles.oxid');
159  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
160 
161  $this->_getOxRssFeed()->removeCacheFile($soxId);
162 
163  if (oxRegistry::getConfig()->getRequestParameter('all')) {
164  $sArtTable = $this->_getViewName('oxarticles');
165  $aArticles = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
166  }
167 
168  $oDb = oxDb::getDb();
169  $sArtTable = $this->_getViewName('oxarticles');
170  $sQ = "select max(oxactions2article.oxsort) from oxactions2article join {$sArtTable} " .
171  "on {$sArtTable}.oxid=oxactions2article.oxartid " .
172  "where oxactions2article.oxactionid = " . $oDb->quote($soxId) .
173  " and oxactions2article.oxshopid = '" . $myConfig->getShopId() .
174  "'and $sArtTable.oxid is not null";
175  $iSort = ((int) $oDb->getOne($sQ, false, false)) + 1;
176 
177  if ($soxId && $soxId != "-1" && is_array($aArticles)) {
178  $sShopId = $myConfig->getShopId();
179  foreach ($aArticles as $sAdd) {
180  $oNewGroup = oxNew('oxbase');
181  $oNewGroup->init('oxactions2article');
182  $oNewGroup->oxactions2article__oxshopid = new oxField($sShopId);
183  $oNewGroup->oxactions2article__oxactionid = new oxField($soxId);
184  $oNewGroup->oxactions2article__oxartid = new oxField($sAdd);
185  $oNewGroup->oxactions2article__oxsort = new oxField($iSort++);
186  $oNewGroup->save();
187  }
188  }
189  }
190 
194  public function setSorting()
195  {
196  $myConfig = $this->getConfig();
197  $sArtTable = $this->_getViewName('oxarticles');
198  $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
199  $sSelect = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
200  $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote($sSelId) .
201  " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' " . $this->_getSorting();
202 
203  $oList = oxNew("oxlist");
204  $oList->init("oxbase", "oxactions2article");
205  $oList->selectString($sSelect);
206 
207  // fixing indexes
208  $iSelCnt = 0;
209  $aIdx2Id = array();
210  foreach ($oList as $sKey => $oSel) {
211  if ($oSel->oxactions2article__oxsort->value != $iSelCnt) {
212  $oSel->oxactions2article__oxsort->setValue($iSelCnt);
213 
214  // saving new index
215  $oSel->save();
216  }
217  $aIdx2Id[$iSelCnt] = $sKey;
218  $iSelCnt++;
219  }
220 
221  //
222  if (($iKey = array_search(oxRegistry::getConfig()->getRequestParameter('sortoxid'), $aIdx2Id)) !== false) {
223  $iDir = (oxRegistry::getConfig()->getRequestParameter('direction') == 'up') ? ($iKey - 1) : ($iKey + 1);
224  if (isset($aIdx2Id[$iDir])) {
225 
226  // exchanging indexes
227  $oDir1 = $oList->offsetGet($aIdx2Id[$iDir]);
228  $oDir2 = $oList->offsetGet($aIdx2Id[$iKey]);
229 
230  $iCopy = $oDir1->oxactions2article__oxsort->value;
231  $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
232  $oDir2->oxactions2article__oxsort->setValue($iCopy);
233 
234  $oDir1->save();
235  $oDir2->save();
236  }
237  }
238 
239  $sQAdd = $this->_getQuery();
240 
241  $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
242  $sCountQ = 'select count( * ) ' . $sQAdd;
243 
244  $this->_outputResponse($this->_getData($sCountQ, $sQ));
245 
246  }
247 
253  protected function _getOxRssFeed()
254  {
255  return oxNew('oxRssFeed');
256  }
257 
258 }