actions_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class actions_main_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_blAllowExtColumns = true;
00015 
00021     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00022         array('oxartnum', 'oxarticles', 1, 0, 0),
00023         array('oxtitle', 'oxarticles', 1, 1, 0),
00024         array('oxean', 'oxarticles', 1, 0, 0),
00025         array('oxmpn', 'oxarticles', 0, 0, 0),
00026         array('oxprice', 'oxarticles', 0, 0, 0),
00027         array('oxstock', 'oxarticles', 0, 0, 0),
00028         array('oxid', 'oxarticles', 0, 0, 1)
00029     ),
00030                                  'container2' => array(
00031                                      array('oxartnum', 'oxarticles', 1, 0, 0),
00032                                      array('oxsort', 'oxactions2article', 1, 0, 0),
00033                                      array('oxtitle', 'oxarticles', 1, 1, 0),
00034                                      array('oxean', 'oxarticles', 1, 0, 0),
00035                                      array('oxmpn', 'oxarticles', 0, 0, 0),
00036                                      array('oxprice', 'oxarticles', 0, 0, 0),
00037                                      array('oxstock', 'oxarticles', 0, 0, 0),
00038                                      array('oxid', 'oxactions2article', 0, 0, 1)
00039                                  )
00040     );
00041 
00047     protected function _getQuery()
00048     {
00049         $myConfig = $this->getConfig();
00050         $oDb = oxDb::getDb();
00051         // looking for table/view
00052         $sArtTable = $this->_getViewName('oxarticles');
00053         $sView = $this->_getViewName('oxobject2category');
00054 
00055         $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00056         $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00057 
00058         // category selected or not ?
00059         if (!$sSelId) {
00060             //performance
00061             $sQAdd = " from $sArtTable where 1 ";
00062             $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
00063         } else {
00064             // selected category ?
00065             if ($sSynchSelId && $sSelId != $sSynchSelId) {
00066 
00067                 $sQAdd = " from {$sView} left join $sArtTable on ";
00068                 $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
00069                 $sSqlIfTrue = " ( $sArtTable.oxid={$sView}.oxobjectid or $sArtTable.oxparentid={$sView}.oxobjectid) ";
00070                 $sSqlIfFalse = " $sArtTable.oxid={$sView}.oxobjectid ";
00071                 $sQAdd .= $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
00072                 $sQAdd .= " where {$sView}.oxcatnid = " . $oDb->quote($sSelId);
00073             } else {
00074 
00075                 $sQAdd = " from {$sArtTable} left join oxactions2article " .
00076                          "on {$sArtTable}.oxid=oxactions2article.oxartid " .
00077                          " where oxactions2article.oxactionid = " . $oDb->quote($sSelId) .
00078                          " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' ";
00079             }
00080         }
00081 
00082         if ($sSynchSelId && $sSynchSelId != $sSelId) {
00083             $sQAdd .= " and {$sArtTable}.oxid not in ( select oxactions2article.oxartid from oxactions2article " .
00084                       " where oxactions2article.oxactionid = " . $oDb->quote($sSynchSelId) .
00085                       " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' ) ";
00086         }
00087 
00088         return $sQAdd;
00089     }
00090 
00098     protected function _addFilter($sQ)
00099     {
00100         $sQ = parent::_addFilter($sQ);
00101 
00102         // display variants or not ?
00103         if ($this->getConfig()->getConfigParam('blVariantsSelection')) {
00104             $sQ .= ' group by ' . $this->_getViewName('oxarticles') . '.oxid ';
00105 
00106             $oStr = getStr();
00107             if ($oStr->strpos($sQ, "select count( * ) ") === 0) {
00108                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00109             }
00110         }
00111 
00112         //echo $sQ;
00113         return $sQ;
00114     }
00115 
00121     protected function _getSorting()
00122     {
00123         $sOxIdParameter = oxRegistry::getConfig()->getRequestParameter('oxid');
00124         $sSynchOxidParameter = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00125         if ($sOxIdParameter && !$sSynchOxidParameter) {
00126             return 'order by oxactions2article.oxsort ';
00127         }
00128 
00129         return parent::_getSorting();
00130     }
00131 
00135     public function removeArtFromAct()
00136     {
00137         $aChosenArt = $this->_getActionIds('oxactions2article.oxid');
00138         $sOxid = oxRegistry::getConfig()->getRequestParameter('oxid');
00139         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00140             $sQ = parent::_addFilter("delete oxactions2article.* " . $this->_getQuery());
00141             oxDb::getDb()->Execute($sQ);
00142         } elseif (is_array($aChosenArt)) {
00143             $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
00144             $sQ = "delete from oxactions2article where oxactions2article.oxid in (" . $sChosenArticles . ") ";
00145             oxDb::getDb()->Execute($sQ);
00146         }
00147     }
00148 
00152     public function addArtToAct()
00153     {
00154         $myConfig = $this->getConfig();
00155         $aArticles = $this->_getActionIds('oxarticles.oxid');
00156         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00157 
00158         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00159             $sArtTable = $this->_getViewName('oxarticles');
00160             $aArticles = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00161         }
00162 
00163         $oDb = oxDb::getDb();
00164         $sArtTable = $this->_getViewName('oxarticles');
00165         $sQ = "select max(oxactions2article.oxsort) from oxactions2article join {$sArtTable} " .
00166               "on {$sArtTable}.oxid=oxactions2article.oxartid " .
00167               "where oxactions2article.oxactionid = " . $oDb->quote($soxId) .
00168               " and oxactions2article.oxshopid = '" . $myConfig->getShopId() .
00169               "'and $sArtTable.oxid is not null";
00170         $iSort = ((int) $oDb->getOne($sQ, false, false)) + 1;
00171 
00172         if ($soxId && $soxId != "-1" && is_array($aArticles)) {
00173             $sShopId = $myConfig->getShopId();
00174             foreach ($aArticles as $sAdd) {
00175                 $oNewGroup = oxNew('oxbase');
00176                 $oNewGroup->init('oxactions2article');
00177                 $oNewGroup->oxactions2article__oxshopid = new oxField($sShopId);
00178                 $oNewGroup->oxactions2article__oxactionid = new oxField($soxId);
00179                 $oNewGroup->oxactions2article__oxartid = new oxField($sAdd);
00180                 $oNewGroup->oxactions2article__oxsort = new oxField($iSort++);
00181                 $oNewGroup->save();
00182             }
00183         }
00184     }
00185 
00189     public function setSorting()
00190     {
00191         $myConfig = $this->getConfig();
00192         $sArtTable = $this->_getViewName('oxarticles');
00193         $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00194         $sSelect = "select * from $sArtTable left join oxactions2article on $sArtTable.oxid=oxactions2article.oxartid ";
00195         $sSelect .= "where oxactions2article.oxactionid = " . oxDb::getDb()->quote($sSelId) .
00196                     " and oxactions2article.oxshopid = '" . $myConfig->getShopID() . "' " . $this->_getSorting();
00197 
00198         $oList = oxNew("oxlist");
00199         $oList->init("oxbase", "oxactions2article");
00200         $oList->selectString($sSelect);
00201 
00202         // fixing indexes
00203         $iSelCnt = 0;
00204         $aIdx2Id = array();
00205         foreach ($oList as $sKey => $oSel) {
00206             if ($oSel->oxactions2article__oxsort->value != $iSelCnt) {
00207                 $oSel->oxactions2article__oxsort->setValue($iSelCnt);
00208 
00209                 // saving new index
00210                 $oSel->save();
00211             }
00212             $aIdx2Id[$iSelCnt] = $sKey;
00213             $iSelCnt++;
00214         }
00215 
00216         //
00217         if (($iKey = array_search(oxRegistry::getConfig()->getRequestParameter('sortoxid'), $aIdx2Id)) !== false) {
00218             $iDir = (oxRegistry::getConfig()->getRequestParameter('direction') == 'up') ? ($iKey - 1) : ($iKey + 1);
00219             if (isset($aIdx2Id[$iDir])) {
00220 
00221                 // exchanging indexes
00222                 $oDir1 = $oList->offsetGet($aIdx2Id[$iDir]);
00223                 $oDir2 = $oList->offsetGet($aIdx2Id[$iKey]);
00224 
00225                 $iCopy = $oDir1->oxactions2article__oxsort->value;
00226                 $oDir1->oxactions2article__oxsort->setValue($oDir2->oxactions2article__oxsort->value);
00227                 $oDir2->oxactions2article__oxsort->setValue($iCopy);
00228 
00229                 $oDir1->save();
00230                 $oDir2->save();
00231             }
00232         }
00233 
00234         $sQAdd = $this->_getQuery();
00235 
00236         $sQ = 'select ' . $this->_getQueryCols() . $sQAdd;
00237         $sCountQ = 'select count( * ) ' . $sQAdd;
00238 
00239         $this->_outputResponse($this->_getData($sCountQ, $sQ));
00240 
00241     }
00242 }