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