delivery_groups_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class delivery_groups_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,  visible, multilanguage, ident
00014                                         array( 'oxtitle',  'oxgroups', 1, 0, 0 ),
00015                                         array( 'oxid',     'oxgroups', 0, 0, 0 ),
00016                                         array( 'oxid',     'oxgroups', 0, 0, 1 ),
00017                                         ),
00018                                     'container2' => array(
00019                                         array( 'oxtitle',  'oxgroups', 1, 0, 0 ),
00020                                         array( 'oxid',     'oxgroups', 0, 0, 0 ),
00021                                         array( 'oxid',     'oxobject2delivery', 0, 0, 1 ),
00022                                         )
00023                                 );
00024 
00030     protected function _getQuery()
00031     {
00032         $myConfig = $this->getConfig();
00033         $oDb = oxDb::getDb();
00034 
00035         // active AJAX component
00036         $sGroupTable = $this->_getViewName('oxgroups');
00037 
00038         $sId      = $myConfig->getRequestParameter( 'oxid' );
00039         $sSynchId = $myConfig->getRequestParameter( 'synchoxid' );
00040 
00041         // category selected or not ?
00042         if ( !$sId ) {
00043             $sQAdd  = " from $sGroupTable where 1 ";
00044         } else {
00045             $sQAdd  = " from oxobject2delivery left join $sGroupTable on $sGroupTable.oxid=oxobject2delivery.oxobjectid ";
00046             $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sId )." and oxobject2delivery.oxtype = 'oxgroups' ";
00047         }
00048 
00049         if ( $sSynchId && $sSynchId != $sId ) {
00050             $sQAdd .= " and $sGroupTable.oxid not in ( select $sGroupTable.oxid from oxobject2delivery left join $sGroupTable on $sGroupTable.oxid=oxobject2delivery.oxobjectid ";
00051             $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sSynchId )." and oxobject2delivery.oxtype = 'oxgroups' ) ";
00052         }
00053 
00054         return $sQAdd;
00055     }
00056 
00062     public function removeGroupFromDel()
00063     {
00064         $aRemoveGroups = $this->_getActionIds( 'oxobject2delivery.oxid' );
00065         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00066 
00067             $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
00068             oxDb::getDb()->Execute( $sQ );
00069 
00070         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00071             $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00072             oxDb::getDb()->Execute( $sQ );
00073         }
00074     }
00075 
00081     public function addGroupToDel()
00082     {
00083         $aChosenCat = $this->_getActionIds( 'oxgroups.oxid' );
00084         $soxId      = $this->getConfig()->getRequestParameter( 'synchoxid' );
00085 
00086         // adding
00087         if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00088             $sGroupTable = $this->_getViewName('oxgroups');
00089             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sGroupTable.oxid ".$this->_getQuery() ) );
00090         }
00091 
00092         if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
00093             foreach ( $aChosenCat as $sChosenCat) {
00094                 $oObject2Delivery = oxNew( 'oxbase' );
00095                 $oObject2Delivery->init( 'oxobject2delivery' );
00096                 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00097                 $oObject2Delivery->oxobject2delivery__oxobjectid   = new oxField($sChosenCat);
00098                 $oObject2Delivery->oxobject2delivery__oxtype       = new oxField('oxgroups');
00099                 $oObject2Delivery->save();
00100             }
00101         }
00102     }
00103 }