discount_categories.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00005                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00006                                         array( 'oxid',    'oxcategories', 0, 0, 0 ),
00007                                         array( 'oxid',    'oxcategories', 0, 0, 1 )
00008                                         ),
00009                      'container2' => array(
00010                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00011                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00012                                         array( 'oxid',    'oxcategories', 0, 0, 0 ),
00013                                         array( 'oxid',    'oxobject2discount', 0, 0, 1 ),
00014                                         array( 'oxid',    'oxcategories',      0, 0, 1 )
00015                                         ),
00016                    );
00020 class ajaxComponent extends ajaxListComponent
00021 {
00027     protected function _getQuery()
00028     {
00029         $oDb = oxDb::getDb();
00030         $sId = oxConfig::getParameter( 'oxid' );
00031         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00032 
00033         $sCategoryTable = $this->_getViewName('oxcategories');
00034 
00035         // category selected or not ?
00036         if ( !$sId) {
00037             $sQAdd  = " from $sCategoryTable";
00038         } else {
00039             $sQAdd  = " from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
00040             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcategories' ";
00041         }
00042 
00043         if ( $sSynchId && $sSynchId != $sId) {
00044             // dodger performance
00045             $sSubSelect  = " select $sCategoryTable.oxid from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
00046             $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcategories' ";
00047             if ( stristr( $sQAdd, 'where' ) === false )
00048                 $sQAdd .= ' where ';
00049             else
00050                 $sQAdd .= ' and ';
00051             $sQAdd .= " $sCategoryTable.oxid not in ( $sSubSelect ) ";
00052         }
00053 
00054         return $sQAdd;
00055     }
00056 
00062     public function removedisccat()
00063     {
00064         $aChosenCat = $this->_getActionIds( 'oxobject2discount.oxid' );
00065         if ( oxConfig::getParameter( 'all' ) ) {
00066 
00067             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00068             oxDb::getDb()->Execute( $sQ );
00069 
00070         } elseif ( is_array( $aChosenCat ) ) {
00071             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00072             oxDb::getDb()->Execute( $sQ );
00073         }
00074     }
00075 
00081     public function adddisccat()
00082     {
00083         $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
00084         $soxId      = oxConfig::getParameter( 'synchoxid');
00085 
00086         if ( oxConfig::getParameter( 'all' ) ) {
00087             $sCategoryTable = $this->_getViewName('oxcategories');
00088             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCategoryTable.oxid ".$this->_getQuery() ) );
00089         }
00090         if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
00091             foreach ( $aChosenCat as $sChosenCat) {
00092                 $oObject2Discount = oxNew( "oxbase" );
00093                 $oObject2Discount->init( 'oxobject2discount' );
00094                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00095                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCat);
00096                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcategories");
00097                 $oObject2Discount->save();
00098             }
00099         }
00100     }
00101 }