delivery_articles_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class delivery_articles_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('oxean', 'oxarticles', 1, 0, 0),
00018         array('oxmpn', 'oxarticles', 0, 0, 0),
00019         array('oxprice', 'oxarticles', 0, 0, 0),
00020         array('oxstock', 'oxarticles', 0, 0, 0),
00021         array('oxid', 'oxarticles', 0, 0, 1)
00022     ),
00023                                  'container2' => array(
00024                                      array('oxartnum', 'oxarticles', 1, 0, 0),
00025                                      array('oxtitle', 'oxarticles', 1, 1, 0),
00026                                      array('oxean', 'oxarticles', 1, 0, 0),
00027                                      array('oxmpn', 'oxarticles', 0, 0, 0),
00028                                      array('oxprice', 'oxarticles', 0, 0, 0),
00029                                      array('oxstock', 'oxarticles', 0, 0, 0),
00030                                      array('oxid', 'oxobject2delivery', 0, 0, 1)
00031                                  )
00032     );
00033 
00039     protected $_blAllowExtColumns = true;
00040 
00046     protected function _getQuery()
00047     {
00048         $myConfig = $this->getConfig();
00049         $oDb = oxDb::getDb();
00050 
00051         // looking for table/view
00052         $sArtTable = $this->_getViewName('oxarticles');
00053         $sCatTable = $this->_getViewName('oxcategories');
00054         $sO2CView = $this->_getViewName('oxobject2category');
00055 
00056         $sDelId = $this->getConfig()->getRequestParameter('oxid');
00057         $sSynchDelId = $this->getConfig()->getRequestParameter('synchoxid');
00058 
00059         // category selected or not ?
00060         if (!$sDelId) {
00061             // performance
00062             $sQAdd = " from $sArtTable where 1 ";
00063             $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : "and $sArtTable.oxparentid = '' ";
00064         } else {
00065             // selected category ?
00066             if ($sSynchDelId && $sDelId != $sSynchDelId) {
00067                 $sQAdd = " from $sO2CView left join $sArtTable on ";
00068                 $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid)" : " $sArtTable.oxid=$sO2CView.oxobjectid ";
00069                 $sQAdd .= "where $sO2CView.oxcatnid = " . $oDb->quote($sDelId);
00070             } else {
00071                 $sQAdd = ' from oxobject2delivery left join ' . $sArtTable . ' on ' . $sArtTable . '.oxid=oxobject2delivery.oxobjectid ';
00072                 $sQAdd .= 'where oxobject2delivery.oxdeliveryid = ' . $oDb->quote($sDelId) . ' and oxobject2delivery.oxtype = "oxarticles" ';
00073             }
00074         }
00075 
00076         if ($sSynchDelId && $sSynchDelId != $sDelId) {
00077             $sQAdd .= 'and ' . $sArtTable . '.oxid not in ( ';
00078             $sQAdd .= 'select oxobject2delivery.oxobjectid from oxobject2delivery ';
00079             $sQAdd .= 'where oxobject2delivery.oxdeliveryid = ' . $oDb->quote($sSynchDelId) . ' and oxobject2delivery.oxtype = "oxarticles" ) ';
00080         }
00081 
00082         return $sQAdd;
00083     }
00084 
00092     /*protected function _addFilter( $sQ )
00093     {
00094         $sArtTable = $this->_getViewName('oxarticles');
00095         $sQ = parent::_addFilter( $sQ );
00096 
00097         // display variants or not ?
00098         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00099         return $sQ;
00100     }*/
00101 
00105     public function removeArtFromDel()
00106     {
00107         $aChosenArt = $this->_getActionIds('oxobject2delivery.oxid');
00108         // removing all
00109         if ($this->getConfig()->getRequestParameter('all')) {
00110 
00111             $sQ = parent::_addFilter("delete oxobject2delivery.* " . $this->_getQuery());
00112             oxDb::getDb()->Execute($sQ);
00113 
00114         } elseif (is_array($aChosenArt)) {
00115             $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenArt)) . ") ";
00116             oxDb::getDb()->Execute($sQ);
00117         }
00118     }
00119 
00123     public function addArtToDel()
00124     {
00125         $aChosenArt = $this->_getActionIds('oxarticles.oxid');
00126         $soxId = $this->getConfig()->getRequestParameter('synchoxid');
00127 
00128         // adding
00129         if ($this->getConfig()->getRequestParameter('all')) {
00130             $sArtTable = $this->_getViewName('oxarticles');
00131             $aChosenArt = $this->_getAll($this->_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00132         }
00133 
00134         if ($soxId && $soxId != "-1" && is_array($aChosenArt)) {
00135             foreach ($aChosenArt as $sChosenArt) {
00136                 $oObject2Delivery = oxNew('oxbase');
00137                 $oObject2Delivery->init('oxobject2delivery');
00138                 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00139                 $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenArt);
00140                 $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxarticles");
00141                 $oObject2Delivery->save();
00142             }
00143         }
00144     }
00145 }