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