00001 <?php
00002
00006 class delivery_categories_ajax extends ajaxListComponent
00007 {
00013 protected $_aColumns = array( 'container1' => array(
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', 'oxobject2delivery', 0, 0, 1 ),
00024 array( 'oxid', 'oxcategories', 0, 0, 1 )
00025 ),
00026 );
00027
00033 protected function _getQuery()
00034 {
00035
00036 $sCatTable = $this->_getViewName('oxcategories');
00037 $oDb = oxDb::getDb();
00038 $sDelId = $this->getConfig()->getRequestParameter( 'oxid' );
00039 $sSynchDelId = $this->getConfig()->getRequestParameter( 'synchoxid' );
00040
00041
00042 if ( !$sDelId) {
00043 $sQAdd = " from $sCatTable ";
00044 } else {
00045 $sQAdd = " from oxobject2delivery left join $sCatTable on $sCatTable.oxid=oxobject2delivery.oxobjectid ";
00046 $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sDelId )." and oxobject2delivery.oxtype = 'oxcategories' ";
00047 }
00048
00049 if ( $sSynchDelId && $sSynchDelId != $sDelId) {
00050
00051 $sSubSelect = " select $sCatTable.oxid from oxobject2delivery left join $sCatTable on $sCatTable.oxid=oxobject2delivery.oxobjectid ";
00052 $sSubSelect .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sSynchDelId )." and oxobject2delivery.oxtype = 'oxcategories' ";
00053 if ( stristr( $sQAdd, 'where' ) === false )
00054 $sQAdd .= ' where ';
00055 else
00056 $sQAdd .= ' and ';
00057 $sQAdd .= " $sCatTable.oxid not in ( $sSubSelect ) ";
00058 }
00059
00060 return $sQAdd;
00061 }
00062
00068 public function removeCatFromDel()
00069 {
00070 $aChosenCat = $this->_getActionIds( 'oxobject2delivery.oxid' );
00071
00072
00073 if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00074
00075 $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
00076 oxDb::getDb()->Execute( $sQ );
00077
00078 } elseif ( is_array( $aChosenCat ) ) {
00079 $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00080 oxDb::getDb()->Execute( $sQ );
00081 }
00082 }
00083
00089 public function addCatToDel()
00090 {
00091 $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
00092 $soxId = $this->getConfig()->getRequestParameter( 'synchoxid');
00093
00094
00095 if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
00096 $sCatTable = $this->_getViewName('oxcategories');
00097 $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
00098 }
00099
00100 if ( isset( $soxId) && $soxId != "-1" && isset( $aChosenCat) && $aChosenCat) {
00101 foreach ( $aChosenCat as $sChosenCat) {
00102 $oObject2Delivery = oxNew( 'oxbase' );
00103 $oObject2Delivery->init( 'oxobject2delivery' );
00104 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00105 $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCat);
00106 $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxcategories");
00107 $oObject2Delivery->save();
00108 }
00109 }
00110 }
00111 }