attribute_category.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',    'oxcategory2attribute', 0, 0, 1 ),
00014                                         array( 'oxid',    'oxcategories', 0, 0, 1 )
00015                                         ),
00016                      'container3' => array(
00017                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00018                                         array( 'oxsort',  'oxcategory2attribute', 1, 0, 0 ),
00019                                         array( 'oxid',    'oxcategory2attribute', 0, 0, 1 )
00020                                         )
00021                     );
00025 class ajaxComponent extends ajaxListComponent
00026 {
00032     protected function _getQuery()
00033     {
00034         $myConfig = $this->getConfig();
00035         $oDb      = oxDb::getDb();
00036 
00037         $sCatTable = $this->_getViewName('oxcategories');
00038         $sDiscountId      = oxConfig::getParameter( 'oxid' );
00039         $sSynchDiscountId = oxConfig::getParameter( 'synchoxid' );
00040 
00041         // category selected or not ?
00042         if ( !$sDiscountId) {
00043             $sQAdd  = " from $sCatTable where $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
00044             $sQAdd .= " and $sCatTable.oxactive = '1' ";
00045         } else {
00046             $sQAdd  = " from $sCatTable left join oxcategory2attribute on $sCatTable.oxid=oxcategory2attribute.oxobjectid ";
00047             $sQAdd .= " where oxcategory2attribute.oxattrid = " . $oDb->quote( $sDiscountId ) . " and $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
00048             $sQAdd .= " and $sCatTable.oxactive = '1' ";
00049         }
00050 
00051         if ( $sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
00052             $sQAdd .= " and $sCatTable.oxid not in ( select $sCatTable.oxid from $sCatTable left join oxcategory2attribute on $sCatTable.oxid=oxcategory2attribute.oxobjectid ";
00053             $sQAdd .= " where oxcategory2attribute.oxattrid = " . $oDb->quote( $sSynchDiscountId ) . " and $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
00054             $sQAdd .= " and $sCatTable.oxactive = '1' ) ";
00055         }
00056 
00057         return $sQAdd;
00058     }
00059 
00065     public function removecatfromattr()
00066     {
00067         $aChosenCat = $this->_getActionIds( 'oxcategory2attribute.oxid' );
00068         if ( oxConfig::getParameter( 'all' ) ) {
00069 
00070             $sQ = $this->_addFilter( "delete oxcategory2attribute.* ".$this->_getQuery() );
00071             oxDb::getDb()->Execute( $sQ );
00072 
00073         } elseif ( is_array( $aChosenCat ) ) {
00074             $sQ = "delete from oxcategory2attribute where oxcategory2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00075             oxDb::getDb()->Execute( $sQ );
00076         }
00077 
00078         $this->resetContentCache();
00079     }
00080 
00086     public function addcattoattr()
00087     {
00088         $aAddCategory = $this->_getActionIds( 'oxcategories.oxid' );
00089         $soxId        = oxConfig::getParameter( 'synchoxid');
00090 
00091         $oAttribute   = oxNew( "oxattribute" );
00092         // adding
00093         if ( oxConfig::getParameter( 'all' ) ) {
00094             $sCatTable = $this->_getViewName('oxcategories');
00095             $aAddCategory = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
00096         }
00097 
00098         if ( $oAttribute->load( $soxId ) && is_array( $aAddCategory ) ) {
00099             $oDb = oxDb::getDb();
00100             foreach ($aAddCategory as $sAdd) {
00101                 $oNewGroup = oxNew( "oxbase" );
00102                 $oNewGroup->init( "oxcategory2attribute" );
00103                 $oNewGroup->oxcategory2attribute__oxobjectid = new oxField($sAdd);
00104                 $oNewGroup->oxcategory2attribute__oxattrid = new oxField($oAttribute->oxattribute__oxid->value);
00105                 $oNewGroup->oxcategory2attribute__oxsort   = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxcategory2attribute where oxobjectid = '$sAdd' ", false, false ) );
00106                 $oNewGroup->save();
00107             }
00108         }
00109 
00110         $this->resetContentCache();
00111     }
00112 
00113 }