discount_categories_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class discount_categories_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00014                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00015                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00016                                         array( 'oxid',    'oxcategories', 0, 0, 0 ),
00017                                         array( 'oxid',    'oxcategories', 0, 0, 1 )
00018                                         ),
00019                                     'container2' => array(
00020                                         array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
00021                                         array( 'oxdesc',  'oxcategories', 1, 1, 0 ),
00022                                         array( 'oxid',    'oxcategories', 0, 0, 0 ),
00023                                         array( 'oxid',    'oxobject2discount', 0, 0, 1 ),
00024                                         array( 'oxid',    'oxcategories',      0, 0, 1 )
00025                                         ),
00026                                 );
00027 
00033     protected function _getQuery()
00034     {
00035         $oDb = oxDb::getDb();
00036         $sId = oxConfig::getParameter( 'oxid' );
00037         $sSynchId = oxConfig::getParameter( 'synchoxid' );
00038 
00039         $sCategoryTable = $this->_getViewName('oxcategories');
00040 
00041         // category selected or not ?
00042         if ( !$sId) {
00043             $sQAdd  = " from $sCategoryTable";
00044         } else {
00045             $sQAdd  = " from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
00046             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcategories' ";
00047         }
00048 
00049         if ( $sSynchId && $sSynchId != $sId) {
00050             // dodger performance
00051             $sSubSelect  = " select $sCategoryTable.oxid from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
00052             $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcategories' ";
00053             if ( stristr( $sQAdd, 'where' ) === false )
00054                 $sQAdd .= ' where ';
00055             else
00056                 $sQAdd .= ' and ';
00057             $sQAdd .= " $sCategoryTable.oxid not in ( $sSubSelect ) ";
00058         }
00059 
00060         return $sQAdd;
00061     }
00062 
00068     public function removeDiscCat()
00069     {
00070         $aChosenCat = $this->_getActionIds( 'oxobject2discount.oxid' );
00071         if ( oxConfig::getParameter( 'all' ) ) {
00072 
00073             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00074             oxDb::getDb()->Execute( $sQ );
00075 
00076         } elseif ( is_array( $aChosenCat ) ) {
00077             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00078             oxDb::getDb()->Execute( $sQ );
00079         }
00080     }
00081 
00087     public function addDiscCat()
00088     {
00089         $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
00090         $soxId      = oxConfig::getParameter( 'synchoxid');
00091 
00092         if ( oxConfig::getParameter( 'all' ) ) {
00093             $sCategoryTable = $this->_getViewName('oxcategories');
00094             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCategoryTable.oxid ".$this->_getQuery() ) );
00095         }
00096         if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
00097             foreach ( $aChosenCat as $sChosenCat) {
00098                 $oObject2Discount = oxNew( "oxbase" );
00099                 $oObject2Discount->init( 'oxobject2discount' );
00100                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00101                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCat);
00102                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcategories");
00103                 $oObject2Discount->save();
00104             }
00105         }
00106     }
00107 }