category_order_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class category_order_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxartnum', 'oxarticles', 1, 0, 0),
00016         array('oxtitle', 'oxarticles', 1, 1, 0),
00017         array('oxpos', 'oxobject2category', 1, 0, 0),
00018         array('oxean', 'oxarticles', 0, 0, 0),
00019         array('oxmpn', 'oxarticles', 0, 0, 0),
00020         array('oxprice', 'oxarticles', 0, 0, 0),
00021         array('oxstock', 'oxarticles', 0, 0, 0),
00022         array('oxid', 'oxarticles', 0, 0, 1)
00023     ),
00024                                  'container2' => array(
00025                                      array('oxartnum', 'oxarticles', 1, 0, 0),
00026                                      array('oxtitle', 'oxarticles', 1, 1, 0),
00027                                      array('oxean', 'oxarticles', 0, 0, 0),
00028                                      array('oxmpn', 'oxarticles', 0, 0, 0),
00029                                      array('oxprice', 'oxarticles', 0, 0, 0),
00030                                      array('oxstock', 'oxarticles', 0, 0, 0),
00031                                      array('oxid', 'oxarticles', 0, 0, 1)
00032                                  )
00033     );
00034 
00040     protected function _getQuery()
00041     {
00042         // looking for table/view
00043         $sArtTable = $this->_getViewName('oxarticles');
00044         $sO2CView = $this->_getViewName('oxobject2category');
00045         $oDb = oxDb::getDb();
00046 
00047         // category selected or not ?
00048         if ($sSynchOxid = oxRegistry::getConfig()->getRequestParameter('synchoxid')) {
00049             $sQAdd = " from $sArtTable left join $sO2CView on $sArtTable.oxid=$sO2CView.oxobjectid where $sO2CView.oxcatnid = " . $oDb->quote($sSynchOxid);
00050             if ($aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess')) {
00051                 $sQAdd .= " and $sArtTable.oxid not in ( " . implode(", ", oxDb::getInstance()->quoteArray($aSkipArt)) . " ) ";
00052             }
00053         } else {
00054             // which fields to load ?
00055             $sQAdd = " from $sArtTable where ";
00056             if ($aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess')) {
00057                 $sQAdd .= " $sArtTable.oxid in ( " . implode(", ", oxDb::getInstance()->quoteArray($aSkipArt)) . " ) ";
00058             } else {
00059                 $sQAdd .= " 1 = 0 ";
00060             }
00061         }
00062 
00063         return $sQAdd;
00064     }
00065 
00071     protected function _getSorting()
00072     {
00073         $sOrder = '';
00074         if (oxRegistry::getConfig()->getRequestParameter('synchoxid')) {
00075             $sOrder = parent::_getSorting();
00076         } elseif (($aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess'))) {
00077             $sOrderBy = '';
00078             $sArtTable = $this->_getViewName('oxarticles');
00079             $sSep = '';
00080             foreach ($aSkipArt as $sId) {
00081                 $sOrderBy = " $sArtTable.oxid=" . oxDb::getDb()->quote($sId) . " " . $sSep . $sOrderBy;
00082                 $sSep = ", ";
00083             }
00084             $sOrder = "order by " . $sOrderBy;
00085         }
00086 
00087         return $sOrder;
00088     }
00089 
00093     public function removeCatOrderArticle()
00094     {
00095         $aRemoveArt = $this->_getActionIds('oxarticles.oxid');
00096         $soxId = oxRegistry::getConfig()->getRequestParameter('oxid');
00097         $aSkipArt = oxRegistry::getSession()->getVariable('neworder_sess');
00098 
00099         if (is_array($aRemoveArt) && is_array($aSkipArt)) {
00100             foreach ($aRemoveArt as $sRem) {
00101                 if (($iKey = array_search($sRem, $aSkipArt)) !== false) {
00102                     unset($aSkipArt[$iKey]);
00103                 }
00104             }
00105             oxRegistry::getSession()->setVariable('neworder_sess', $aSkipArt);
00106 
00107             $sArticleTable = $this->_getViewName('oxarticles');
00108             $sO2CView = $this->_getViewName('oxobject2category');
00109 
00110             // checking if all articles were moved from one
00111             $sSelect = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
00112             $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
00113             $sSelect .= "not in ( " . implode(", ", oxDb::getInstance()->quoteArray($aSkipArt)) . " ) ";
00114 
00115             // simply echoing "1" if some items found, and 0 if nothing was found
00116             echo (int) oxDb::getDb()->getOne($sSelect, false, false);
00117         }
00118     }
00119 
00123     public function addCatOrderArticle()
00124     {
00125         $aAddArticle = $this->_getActionIds('oxarticles.oxid');
00126         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00127 
00128         $aOrdArt = oxRegistry::getSession()->getVariable('neworder_sess');
00129         if (!is_array($aOrdArt)) {
00130             $aOrdArt = array();
00131         }
00132 
00133         $blEnable = false;
00134 
00135         if (is_array($aAddArticle)) {
00136             // storing newly ordered article seq.
00137             foreach ($aAddArticle as $sAdd) {
00138                 if (array_search($sAdd, $aOrdArt) === false) {
00139                     $aOrdArt[] = $sAdd;
00140                 }
00141             }
00142             oxRegistry::getSession()->setVariable('neworder_sess', $aOrdArt);
00143 
00144             $sArticleTable = $this->_getViewName('oxarticles');
00145             $sO2CView = $this->_getViewName('oxobject2category');
00146 
00147             // checking if all articles were moved from one
00148             $sSelect = "select 1 from $sArticleTable left join $sO2CView on $sArticleTable.oxid=$sO2CView.oxobjectid ";
00149             $sSelect .= "where $sO2CView.oxcatnid = '$soxId' and $sArticleTable.oxparentid = '' and $sArticleTable.oxid ";
00150             $sSelect .= "not in ( " . implode(", ", oxDb::getInstance()->quoteArray($aOrdArt)) . " ) ";
00151 
00152             // simply echoing "1" if some items found, and 0 if nothing was found
00153             echo (int) oxDb::getDb()->getOne($sSelect, false, false);
00154         }
00155     }
00156 
00162     public function saveNewOrder()
00163     {
00164         $oCategory = oxNew("oxcategory");
00165         $sId = oxRegistry::getConfig()->getRequestParameter("oxid");
00166         if ($oCategory->load($sId)) {
00167 
00168 
00169             $aNewOrder = oxRegistry::getSession()->getVariable("neworder_sess");
00170             if (is_array($aNewOrder) && count($aNewOrder)) {
00171                 $sO2CView = $this->_getViewName('oxobject2category');
00172                 $sSelect = "select * from $sO2CView where $sO2CView.oxcatnid='" . $oCategory->getId() . "' and $sO2CView.oxobjectid in (" . implode(", ", oxDb::getInstance()->quoteArray($aNewOrder)) . " )";
00173                 $oList = oxNew("oxlist");
00174                 $oList->init("oxbase", "oxobject2category");
00175                 $oList->selectString($sSelect);
00176 
00177                 // setting new position
00178                 foreach ($oList as $oObj) {
00179                     if (($iNewPos = array_search($oObj->oxobject2category__oxobjectid->value, $aNewOrder)) !== false) {
00180                         $oObj->oxobject2category__oxpos->setValue($iNewPos);
00181                         $oObj->save();
00182                     }
00183                 }
00184 
00185                 oxRegistry::getSession()->setVariable('neworder_sess', null);
00186             }
00187 
00188 
00189         }
00190     }
00191 
00197     public function remNewOrder()
00198     {
00199         $oCategory = oxNew("oxcategory");
00200         $sId = oxRegistry::getConfig()->getRequestParameter("oxid");
00201         if ($oCategory->load($sId)) {
00202 
00203 
00204             $oDb = oxDb::getDb();
00205 
00206             $sQuotedCategoryId = $oDb->quote($oCategory->getId());
00207 
00208             $sSqlShopFilter = "";
00209             $sSelect = "update oxobject2category set oxpos = '0' where oxobject2category.oxcatnid = {$sQuotedCategoryId} {$sSqlShopFilter}";
00210             $oDb->execute($sSelect);
00211 
00212             oxRegistry::getSession()->setVariable('neworder_sess', null);
00213 
00214         }
00215     }
00216 }