deliveryset_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class deliveryset_main_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00014                                         array( 'oxtitle',      'oxdelivery', 1, 1, 0 ),
00015                                         array( 'oxaddsum',     'oxdelivery', 1, 0, 0 ),
00016                                         array( 'oxaddsumtype', 'oxdelivery', 1, 0, 0 ),
00017                                         array( 'oxid',         'oxdelivery', 0, 0, 1 )
00018                                         ),
00019                                     'container2' => array(
00020                                         array( 'oxtitle',      'oxdelivery', 1, 1, 0 ),
00021                                         array( 'oxaddsum',     'oxdelivery', 1, 0, 0 ),
00022                                         array( 'oxaddsumtype', 'oxdelivery', 1, 0, 0 ),
00023                                         array( 'oxid',  'oxdel2delset', 0, 0, 1 )
00024                                         )
00025                                 );
00026 
00032     protected function _getQuery()
00033     {
00034         $sId = $this->getConfig()->getRequestParameter( 'oxid' );
00035         $sSynchId = $this->getConfig()->getRequestParameter( 'synchoxid' );
00036         $oDb = oxDb::getDb();
00037 
00038         $sDeliveryViewName = $this->_getViewName('oxdelivery');
00039 
00040         // category selected or not ?
00041         if ( !$sId) {
00042             $sQAdd  = " from $sDeliveryViewName where 1 ";
00043         } else {
00044             $sQAdd  = " from $sDeliveryViewName left join oxdel2delset on oxdel2delset.oxdelid=$sDeliveryViewName.oxid ";
00045             $sQAdd .= "where oxdel2delset.oxdelsetid = ".$oDb->quote( $sId );
00046         }
00047 
00048         if ( $sSynchId && $sSynchId != $sId ) {
00049             $sQAdd .= "and $sDeliveryViewName.oxid not in ( select $sDeliveryViewName.oxid from $sDeliveryViewName left join oxdel2delset on oxdel2delset.oxdelid=$sDeliveryViewName.oxid ";
00050             $sQAdd .= "where oxdel2delset.oxdelsetid = ".$oDb->quote( $sSynchId ) ." ) ";
00051         }
00052 
00053         return $sQAdd;
00054     }
00055 
00061     public function removeFromSet()
00062     {
00063         $aRemoveGroups = $this->_getActionIds( 'oxdel2delset.oxid' );
00064         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00065 
00066             $sQ = $this->_addFilter( "delete oxdel2delset.* ".$this->_getQuery() );
00067             oxDb::getDb()->Execute( $sQ );
00068 
00069         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00070             $sQ = "delete from oxdel2delset where oxdel2delset.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00071             oxDb::getDb()->Execute( $sQ );
00072         }
00073     }
00074 
00080     public function addToSet()
00081     {
00082         $aChosenSets = $this->_getActionIds( 'oxdelivery.oxid' );
00083         $soxId       = oxConfig::getParameter( 'synchoxid');
00084 
00085         // adding
00086         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00087             $sDeliveryViewName = $this->_getViewName('oxdelivery');
00088             $aChosenSets = $this->_getAll( $this->_addFilter( "select $sDeliveryViewName.oxid ".$this->_getQuery() ) );
00089         }
00090         if ( $soxId && $soxId != "-1" && is_array( $aChosenSets ) ) {
00091             $oDb = oxDb::getDb();
00092             foreach ( $aChosenSets as $sChosenSet) {
00093                 // check if we have this entry already in
00094                 $sID = $oDb->getOne("select oxid from oxdel2delset where oxdelid =  " . $oDb->quote( $sChosenSet ) . " and oxdelsetid = ".$oDb->quote( $soxId ), false, false );
00095                 if ( !isset( $sID) || !$sID) {
00096                     $oDel2delset = oxNew( 'oxbase' );
00097                     $oDel2delset->init( 'oxdel2delset' );
00098                     $oDel2delset->oxdel2delset__oxdelid    = new oxField($sChosenSet);
00099                     $oDel2delset->oxdel2delset__oxdelsetid = new oxField($soxId);
00100                     $oDel2delset->save();
00101                 }
00102             }
00103         }
00104     }
00105 }