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 
00072 
00073         if ( oxConfig::getParameter( 'all' ) ) {
00074 
00075             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00076             oxDb::getDb()->Execute( $sQ );
00077 
00078         } elseif ( is_array( $aChosenCat ) ) {
00079             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00080             oxDb::getDb()->Execute( $sQ );
00081         }
00082     }
00083 
00089     public function addDiscCat()
00090     {
00091         $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
00092         $soxId      = oxConfig::getParameter( 'synchoxid');
00093 
00094 
00095         if ( oxConfig::getParameter( 'all' ) ) {
00096             $sCategoryTable = $this->_getViewName('oxcategories');
00097             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCategoryTable.oxid ".$this->_getQuery() ) );
00098         }
00099         if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
00100             foreach ( $aChosenCat as $sChosenCat) {
00101                 $oObject2Discount = oxNew( "oxbase" );
00102                 $oObject2Discount->init( 'oxobject2discount' );
00103                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00104                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCat);
00105                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcategories");
00106                 $oObject2Discount->save();
00107             }
00108         }
00109 
00110         $oCategory = oxNew( 'oxCategory' );
00111         $oCategory->executeDependencyEvent( $aChosenCat );
00112 
00113     }
00114 }