OXID eShop CE  4.9.6
 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  if (oxRegistry::getConfig()->getRequestParameter('all')) {
140  $sQ = parent::_addFilter("delete oxactions2article.* " . $this->_getQuery());
141  oxDb::getDb()->Execute($sQ);
142  } elseif (is_array($aChosenArt)) {
143  $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
144  $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . $sChosenArticles . ") ";
145  oxDb::getDb()->Execute($sQ);
146  }
147  }
148 
152  public function addArtToAct()
153  {
154  $myConfig = $this->getConfig();
155  $aArticles = $this->_getActionIds('oxarticles.oxid');
156  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
157 
158  if (oxRegistry::getConfig()->getRequestParameter('all')) {
159  $sArtTable = $this->_getViewName('oxarticles');
160  $aArticles = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
161  }
162 
163  $oDb = oxDb::getDb();
164  $sArtTable = $this->_getViewName('oxarticles');
165  $sQ = "select max(oxactions2article.oxsort) from oxactions2article join {$sArtTable} " .
166  "on {$sArtTable}.oxid=oxactions2article.oxartid " .
167  "where oxactions2article.oxactionid = " . $oDb->quote($soxId) .
168  " and oxactions2article.oxshopid = '" . $myConfig->getShopId() .
169  "'and $sArtTable.oxid is not null";
170  $iSort = ((int) $oDb->getOne($sQ, false, false)) + 1;
171 
172  if ($soxId && $soxId != "-1" && is_array($aArticles)) {
173  $sShopId = $myConfig->getShopId();
174  foreach ($aArticles as $sAdd) {
175  $oNewGroup = oxNew('oxbase');
176  $oNewGroup->init('oxactions2article');
177  $oNewGroup->oxactions2article__oxshopid = new oxField($sShopId);
178  $oNewGroup->oxactions2article__oxactionid = new oxField($soxId);
179  $oNewGroup->oxactions2article__oxartid = new oxField($sAdd);
180  $oNewGroup->oxactions2article__oxsort = new oxField($iSort++);
181  $oNewGroup->save();
182  }
183  }
184  }
185 
189  public function setSorting()
190  {
191  $myConfig = $this->getConfig();
192  $sArtTable = $this->_getViewName('oxarticles');
193  $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
194  $sSelect = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
195  $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote($sSelId) .
196  " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' " . $this->_getSorting();
197 
198  $oList = oxNew("oxlist");
199  $oList->init("oxbase", "oxactions2article");
200  $oList->selectString($sSelect);
201 
202  // fixing indexes
203  $iSelCnt = 0;
204  $aIdx2Id = array();
205  foreach ($oList as $sKey => $oSel) {
206  if ($oSel->oxactions2article__oxsort->value != $iSelCnt) {
207  $oSel->oxactions2article__oxsort->setValue($iSelCnt);
208 
209  // saving new index
210  $oSel->save();
211  }
212  $aIdx2Id[$iSelCnt] = $sKey;
213  $iSelCnt++;
214  }
215 
216  //
217  if (($iKey = array_search(oxRegistry::getConfig()->getRequestParameter('sortoxid'), $aIdx2Id)) !== false) {
218  $iDir = (oxRegistry::getConfig()->getRequestParameter('direction') == 'up') ? ($iKey - 1) : ($iKey + 1);
219  if (isset($aIdx2Id[$iDir])) {
220 
221  // exchanging indexes
222  $oDir1 = $oList->offsetGet($aIdx2Id[$iDir]);
223  $oDir2 = $oList->offsetGet($aIdx2Id[$iKey]);
224 
225  $iCopy = $oDir1->oxactions2article__oxsort->value;
226  $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
227  $oDir2->oxactions2article__oxsort->setValue($iCopy);
228 
229  $oDir1->save();
230  $oDir2->save();
231  }
232  }
233 
234  $sQAdd = $this->_getQuery();
235 
236  $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
237  $sCountQ = 'select count( * ) ' . $sQAdd;
238 
239  $this->_outputResponse($this->_getData($sCountQ, $sQ));
240 
241  }
242 }