discount_groups_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_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',     'oxobject2discount', 0, 0, 1 ),
00022                                         )
00023                                 );
00024 
00030     protected function _getQuery()
00031     {
00032         // active AJAX component
00033         $sGroupTable = $this->_getViewName('oxgroups');
00034         $oDb = oxDb::getDb();
00035         $sId = oxConfig::getParameter( 'oxid' );
00036         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00037 
00038         // category selected or not ?
00039         if ( !$sId) {
00040             $sQAdd  = " from $sGroupTable where 1 ";
00041         } else {
00042             $sQAdd .= " from oxobject2discount, $sGroupTable where $sGroupTable.oxid=oxobject2discount.oxobjectid ";
00043             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxgroups' ";
00044         }
00045 
00046         if ( $sSynchId && $sSynchId != $sId) {
00047             $sQAdd .= " and $sGroupTable.oxid not in ( select $sGroupTable.oxid from oxobject2discount, $sGroupTable where $sGroupTable.oxid=oxobject2discount.oxobjectid ";
00048             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxgroups' ) ";
00049         }
00050 
00051         return $sQAdd;
00052     }
00053 
00059     public function removeDiscGroup()
00060     {
00061 
00062         $aRemoveGroups = $this->_getActionIds( 'oxobject2discount.oxid' );
00063         if ( oxConfig::getParameter( 'all' ) ) {
00064 
00065             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00066             oxDb::getDb()->Execute( $sQ );
00067 
00068         } elseif ( $aRemoveGroups && is_array( $aRemoveGroups ) ) {
00069             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aRemoveGroups ) ) . ") ";
00070             oxDb::getDb()->Execute( $sQ );
00071         }
00072     }
00073 
00079     public function addDiscGroup()
00080     {
00081         $aChosenCat = $this->_getActionIds( 'oxgroups.oxid' );
00082         $soxId      = oxConfig::getParameter( 'synchoxid' );
00083 
00084 
00085         if ( oxConfig::getParameter( 'all' ) ) {
00086             $sGroupTable = $this->_getViewName('oxgroups');
00087             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sGroupTable.oxid ".$this->_getQuery() ) );
00088         }
00089         if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
00090             foreach ( $aChosenCat as $sChosenCat) {
00091                 $oObject2Discount = oxNew( "oxbase" );
00092                 $oObject2Discount->init( 'oxobject2discount' );
00093                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00094                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCat);
00095                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxgroups");
00096                 $oObject2Discount->save();
00097             }
00098         }
00099     }
00100 }