delivery_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',    'oxobject2delivery', 0, 0, 1 ),
00014                                         array( 'oxid',    'oxcategories',      0, 0, 1 )
00015                                         ),
00016                    );
00020 class ajaxComponent extends ajaxListComponent
00021 {
00027     protected function _getQuery()
00028     {
00029         // looking for table/view
00030         $sCatTable = $this->_getViewName('oxcategories');
00031         $oDb = oxDb::getDb();
00032         $sDelId      = oxConfig::getParameter( 'oxid' );
00033         $sSynchDelId = oxConfig::getParameter( 'synchoxid' );
00034 
00035         // category selected or not ?
00036         if ( !$sDelId) {
00037             $sQAdd  = " from $sCatTable ";
00038         } else {
00039             $sQAdd  = " from oxobject2delivery left join $sCatTable on $sCatTable.oxid=oxobject2delivery.oxobjectid ";
00040             $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sDelId )." and oxobject2delivery.oxtype = 'oxcategories' ";
00041         }
00042 
00043         if ( $sSynchDelId && $sSynchDelId != $sDelId) {
00044             // dodger performance
00045             $sSubSelect  = " select $sCatTable.oxid from oxobject2delivery left join $sCatTable on $sCatTable.oxid=oxobject2delivery.oxobjectid ";
00046             $sSubSelect .= " where oxobject2delivery.oxdeliveryid = ".oxDb::getDb()->quote( $sSynchDelId )." and oxobject2delivery.oxtype = 'oxcategories' ";
00047             if ( stristr( $sQAdd, 'where' ) === false )
00048                 $sQAdd .= ' where ';
00049             else
00050                 $sQAdd .= ' and ';
00051             $sQAdd .= " $sCatTable.oxid not in ( $sSubSelect ) ";
00052         }
00053 
00054         return $sQAdd;
00055     }
00056 
00062     public function removecatfromdel()
00063     {
00064         $aChosenCat = $this->_getActionIds( 'oxobject2delivery.oxid' );
00065 
00066         // removing all
00067         if ( oxConfig::getParameter( 'all' ) ) {
00068 
00069             $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
00070             oxDb::getDb()->Execute( $sQ );
00071 
00072         } elseif ( is_array( $aChosenCat ) ) {
00073             $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00074             oxDb::getDb()->Execute( $sQ );
00075         }
00076     }
00077 
00083     public function addcattodel()
00084     {
00085         $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
00086         $soxId      = oxConfig::getParameter( 'synchoxid');
00087 
00088         // adding
00089         if ( oxConfig::getParameter( 'all' ) ) {
00090             $sCatTable = $this->_getViewName('oxcategories');
00091             $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
00092         }
00093 
00094         if ( isset( $soxId) && $soxId != "-1" && isset( $aChosenCat) && $aChosenCat) {
00095             foreach ( $aChosenCat as $sChosenCat) {
00096                 $oObject2Delivery = oxNew( 'oxbase' );
00097                 $oObject2Delivery->init( 'oxobject2delivery' );
00098                 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00099                 $oObject2Delivery->oxobject2delivery__oxobjectid   = new oxField($sChosenCat);
00100                 $oObject2Delivery->oxobject2delivery__oxtype       = new oxField("oxcategories");
00101                 $oObject2Delivery->save();
00102             }
00103         }
00104     }
00105 }