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         $oConfig = $this->getConfig();
00037         $sId = $oConfig->getRequestParameter( 'oxid' );
00038         $sSynchId = $oConfig->getRequestParameter( 'synchoxid' );
00039 
00040         $sCategoryTable = $this->_getViewName('oxcategories');
00041 
00042         // category selected or not ?
00043         if ( !$sId) {
00044             $sQAdd  = " from $sCategoryTable";
00045         } else {
00046             $sQAdd  = " from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
00047             $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcategories' ";
00048         }
00049 
00050         if ( $sSynchId && $sSynchId != $sId) {
00051             // dodger performance
00052             $sSubSelect  = " select $sCategoryTable.oxid from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
00053             $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcategories' ";
00054             if ( stristr( $sQAdd, 'where' ) === false )
00055                 $sQAdd .= ' where ';
00056             else
00057                 $sQAdd .= ' and ';
00058             $sQAdd .= " $sCategoryTable.oxid not in ( $sSubSelect ) ";
00059         }
00060 
00061         return $sQAdd;
00062     }
00063 
00069     public function removeDiscCat()
00070     {
00071         $oConfig = $this->getConfig();
00072         $aChosenCat = $this->_getActionIds( 'oxobject2discount.oxid' );
00073 
00074 
00075         if ( $oConfig->getRequestParameter( 'all' ) ) {
00076 
00077             $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
00078             oxDb::getDb()->Execute( $sQ );
00079 
00080         } elseif ( is_array( $aChosenCat ) ) {
00081             $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00082             oxDb::getDb()->Execute( $sQ );
00083         }
00084     }
00085 
00091     public function addDiscCat()
00092     {
00093         $oConfig = $this->getConfig();
00094         $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
00095         $soxId      = $oConfig->getRequestParameter( 'synchoxid');
00096 
00097 
00098         if ( $oConfig->getRequestParameter( 'all' ) ) {
00099             $sCategoryTable = $this->_getViewName('oxcategories');
00100             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCategoryTable.oxid ".$this->_getQuery() ) );
00101         }
00102         if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
00103             foreach ( $aChosenCat as $sChosenCat) {
00104                 $oObject2Discount = oxNew( "oxbase" );
00105                 $oObject2Discount->init( 'oxobject2discount' );
00106                 $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
00107                 $oObject2Discount->oxobject2discount__oxobjectid   = new oxField($sChosenCat);
00108                 $oObject2Discount->oxobject2discount__oxtype       = new oxField("oxcategories");
00109                 $oObject2Discount->save();
00110             }
00111         }
00112 
00113     }
00114 }