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