OXID eShop CE  4.10.4
 All Classes Namespaces Files Functions Variables Pages
category_order_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
15  array('oxartnum', 'oxarticles', 1, 0, 0),
16  array('oxtitle', 'oxarticles', 1, 1, 0),
17  array('oxpos', 'oxobject2category', 1, 0, 0),
18  array('oxean', 'oxarticles', 0, 0, 0),
19  array('oxmpn', 'oxarticles', 0, 0, 0),
20  array('oxprice', 'oxarticles', 0, 0, 0),
21  array('oxstock', 'oxarticles', 0, 0, 0),
22  array('oxid', 'oxarticles', 0, 0, 1)
23  ),
24  'container2' => array(
25  array('oxartnum', 'oxarticles', 1, 0, 0),
26  array('oxtitle', 'oxarticles', 1, 1, 0),
27  array('oxean', 'oxarticles', 0, 0, 0),
28  array('oxmpn', 'oxarticles', 0, 0, 0),
29  array('oxprice', 'oxarticles', 0, 0, 0),
30  array('oxstock', 'oxarticles', 0, 0, 0),
31  array('oxid', 'oxarticles', 0, 0, 1)
32  )
33  );
34 
40  protected function _getQuery()
41  {
42  // looking for table/view
43  $sArtTable = $this->_getViewName('oxarticles');
44  $sO2CView = $this->_getViewName('oxobject2category');
45  $oDb = oxDb::getDb();
46 
47  // category selected or not ?
48  if ($sSynchOxid = oxRegistry::getConfig()->getRequestParameter('synchoxid')) {
49  $sQAdd = " from $sArtTable left join $sO2CView on $sArtTable.oxid=$sO2CView.oxobjectid where $sO2CView.oxcatnid = " . $oDb->quote($sSynchOxid);
50  if ($aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess')) {
51  $sQAdd .= " and $sArtTable.oxid not in ( " . implode(", ", oxDb::getInstance()->quoteArray($aSkipArt)) . " ) ";
52  }
53  } else {
54  // which fields to load ?
55  $sQAdd = " from $sArtTable where ";
56  if ($aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess')) {
57  $sQAdd .= " $sArtTable.oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aSkipArt)) . " ) ";
58  } else {
59  $sQAdd .= " 1 = 0 ";
60  }
61  }
62 
63  return $sQAdd;
64  }
65 
71  protected function _getSorting()
72  {
73  $sOrder = '';
74  if (oxRegistry::getConfig()->getRequestParameter('synchoxid')) {
75  $sOrder = parent::_getSorting();
76  } elseif (($aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess'))) {
77  $sOrderBy = '';
78  $sArtTable = $this->_getViewName('oxarticles');
79  $sSep = '';
80  foreach ($aSkipArt as $sId) {
81  $sOrderBy = " $sArtTable.oxid=" . oxDb::getDb()->quote($sId) . " " . $sSep . $sOrderBy;
82  $sSep = ", ";
83  }
84  $sOrder = "order by " . $sOrderBy;
85  }
86 
87  return $sOrder;
88  }
89 
93  public function removeCatOrderArticle()
94  {
95  $aRemoveArt = $this->_getActionIds('oxarticles.oxid');
96  $soxId = oxRegistry::getConfig()->getRequestParameter('oxid');
97  $aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess');
98 
99  if (is_array($aRemoveArt) && is_array($aSkipArt)) {
100  foreach ($aRemoveArt as $sRem) {
101  if (($iKey = array_search($sRem, $aSkipArt)) !== false) {
102  unset($aSkipArt[$iKey]);
103  }
104  }
105  oxRegistry::getSession()->setVariable('neworder_sess', $aSkipArt);
106 
107  $sArticleTable = $this->_getViewName('oxarticles');
108  $sO2CView = $this->_getViewName('oxobject2category');
109 
110  // checking if all articles were moved from one
111  $sSelect = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
112  $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
113  $sSelect .= "not in ( " . implode(", ", oxDb::getInstance()->quoteArray($aSkipArt)) . " ) ";
114 
115  // simply echoing "1" if some items found, and 0 if nothing was found
116  echo (int) oxDb::getDb()->getOne($sSelect, false, false);
117  }
118  }
119 
123  public function addCatOrderArticle()
124  {
125  $aAddArticle = $this->_getActionIds('oxarticles.oxid');
126  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
127 
128  $aOrdArt = oxRegistry::getSession()->getVariable('neworder_sess');
129  if (!is_array($aOrdArt)) {
130  $aOrdArt = array();
131  }
132 
133  $blEnable = false;
134 
135  if (is_array($aAddArticle)) {
136  // storing newly ordered article seq.
137  foreach ($aAddArticle as $sAdd) {
138  if (array_search($sAdd, $aOrdArt) === false) {
139  $aOrdArt[] = $sAdd;
140  }
141  }
142  oxRegistry::getSession()->setVariable('neworder_sess', $aOrdArt);
143 
144  $sArticleTable = $this->_getViewName('oxarticles');
145  $sO2CView = $this->_getViewName('oxobject2category');
146 
147  // checking if all articles were moved from one
148  $sSelect = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
149  $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
150  $sSelect .= "not in ( " . implode(", ", oxDb::getInstance()->quoteArray($aOrdArt)) . " ) ";
151 
152  // simply echoing "1" if some items found, and 0 if nothing was found
153  echo (int) oxDb::getDb()->getOne($sSelect, false, false);
154  }
155  }
156 
162  public function saveNewOrder()
163  {
164  $oCategory = oxNew("oxcategory");
165  $sId = oxRegistry::getConfig()->getRequestParameter("oxid");
166  if ($oCategory->load($sId)) {
167 
168  $this->resetContentCache();
169 
170  $aNewOrder = oxRegistry::getSession()->getVariable("neworder_sess");
171  if (is_array($aNewOrder) && count($aNewOrder)) {
172  $sO2CView = $this->_getViewName('oxobject2category');
173  $sSelect = "select * from $sO2CView where $sO2CView.oxcatnid='" . $oCategory->getId() . "' and $sO2CView.oxobjectid in (" . implode(", ", oxDb::getInstance()->quoteArray($aNewOrder)) . " )";
174  $oList = oxNew("oxlist");
175  $oList->init("oxbase", "oxobject2category");
176  $oList->selectString($sSelect);
177 
178  // setting new position
179  foreach ($oList as $oObj) {
180  if (($iNewPos = array_search($oObj->oxobject2category__oxobjectid->value, $aNewOrder)) !== false) {
181  $oObj->oxobject2category__oxpos->setValue($iNewPos);
182  $oObj->save();
183  }
184  }
185 
186  oxRegistry::getSession()->setVariable('neworder_sess', null);
187  }
188 
189 
190  }
191  }
192 
198  public function remNewOrder()
199  {
200  $oCategory = oxNew("oxcategory");
201  $sId = oxRegistry::getConfig()->getRequestParameter("oxid");
202  if ($oCategory->load($sId)) {
203 
204 
205  $oDb = oxDb::getDb();
206 
207  $sQuotedCategoryId = $oDb->quote($oCategory->getId());
208 
209  $sSqlShopFilter = "";
210  $sSelect = "update oxobject2category set oxpos = '0' where oxobject2category.oxcatnid = {$sQuotedCategoryId} {$sSqlShopFilter}";
211  $oDb->execute($sSelect);
212 
213  oxRegistry::getSession()->setVariable('neworder_sess', null);
214 
215  }
216  }
217 }