attribute_category_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class attribute_category_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
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',    'oxcategory2attribute', 0, 0, 1 ),
00024                                         array( 'oxid',    'oxcategories', 0, 0, 1 )
00025                                         ),
00026                                 'container3' => array(
00027                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00028                                         array( 'oxsort',  'oxcategory2attribute', 1, 0, 0 ),
00029                                         array( 'oxid',    'oxcategory2attribute', 0, 0, 1 )
00030                                         )
00031                                 );
00032 
00038     protected function _getQuery()
00039     {
00040         $myConfig = $this->getConfig();
00041         $oDb      = oxDb::getDb();
00042 
00043         $sCatTable = $this->_getViewName('oxcategories');
00044         $sDiscountId      = oxConfig::getParameter( 'oxid' );
00045         $sSynchDiscountId = oxConfig::getParameter( 'synchoxid' );
00046 
00047         // category selected or not ?
00048         if ( !$sDiscountId) {
00049             $sQAdd  = " from $sCatTable where $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
00050             $sQAdd .= " and $sCatTable.oxactive = '1' ";
00051         } else {
00052             $sQAdd  = " from $sCatTable left join oxcategory2attribute on $sCatTable.oxid=oxcategory2attribute.oxobjectid ";
00053             $sQAdd .= " where oxcategory2attribute.oxattrid = " . $oDb->quote( $sDiscountId ) . " and $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
00054             $sQAdd .= " and $sCatTable.oxactive = '1' ";
00055         }
00056 
00057         if ( $sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
00058             $sQAdd .= " and $sCatTable.oxid not in ( select $sCatTable.oxid from $sCatTable left join oxcategory2attribute on $sCatTable.oxid=oxcategory2attribute.oxobjectid ";
00059             $sQAdd .= " where oxcategory2attribute.oxattrid = " . $oDb->quote( $sSynchDiscountId ) . " and $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
00060             $sQAdd .= " and $sCatTable.oxactive = '1' ) ";
00061         }
00062 
00063         return $sQAdd;
00064     }
00065 
00071     public function removeCatFromAttr()
00072     {
00073         $aChosenCat = $this->_getActionIds( 'oxcategory2attribute.oxid' );
00074 
00075 
00076 
00077         if ( oxConfig::getParameter( 'all' ) ) {
00078             $sQ = $this->_addFilter( "delete oxcategory2attribute.* ".$this->_getQuery() );
00079             oxDb::getDb()->Execute( $sQ );
00080         } elseif ( is_array( $aChosenCat ) ) {
00081             $sQ = "delete from oxcategory2attribute where oxcategory2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00082             oxDb::getDb()->Execute( $sQ );
00083         }
00084 
00085 
00086 
00087         $this->resetContentCache();
00088 
00089     }
00090 
00096     public function addCatToAttr()
00097     {
00098         $aAddCategory = $this->_getActionIds( 'oxcategories.oxid' );
00099         $soxId        = oxConfig::getParameter( 'synchoxid');
00100 
00101         $oAttribute   = oxNew( "oxattribute" );
00102         // adding
00103         if ( oxConfig::getParameter( 'all' ) ) {
00104             $sCatTable = $this->_getViewName('oxcategories');
00105             $aAddCategory = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
00106         }
00107 
00108         if ( $oAttribute->load( $soxId ) && is_array( $aAddCategory ) ) {
00109             $oDb = oxDb::getDb();
00110             foreach ($aAddCategory as $sAdd) {
00111                 $oNewGroup = oxNew( "oxbase" );
00112                 $oNewGroup->init( "oxcategory2attribute" );
00113                 $oNewGroup->oxcategory2attribute__oxobjectid = new oxField($sAdd);
00114                 $oNewGroup->oxcategory2attribute__oxattrid = new oxField($oAttribute->oxattribute__oxid->value);
00115                 $oNewGroup->oxcategory2attribute__oxsort   = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxcategory2attribute where oxobjectid = '$sAdd' ", false, false ) );
00116                 $oNewGroup->save();
00117             }
00118         }
00119 
00120         $this->resetContentCache();
00121     }
00122 
00123 
00124 }