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