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         if ( oxConfig::getParameter( 'all' ) ) {
00075             $sQ = $this->_addFilter( "delete oxcategory2attribute.* ".$this->_getQuery() );
00076             oxDb::getDb()->Execute( $sQ );
00077         } elseif ( is_array( $aChosenCat ) ) {
00078             $sQ = "delete from oxcategory2attribute where oxcategory2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00079             oxDb::getDb()->Execute( $sQ );
00080         }
00081 
00082         $this->resetContentCache();
00083     }
00084 
00090     public function addCatToAttr()
00091     {
00092         $aAddCategory = $this->_getActionIds( 'oxcategories.oxid' );
00093         $soxId        = oxConfig::getParameter( 'synchoxid');
00094 
00095         $oAttribute   = oxNew( "oxattribute" );
00096         // adding
00097         if ( oxConfig::getParameter( 'all' ) ) {
00098             $sCatTable = $this->_getViewName('oxcategories');
00099             $aAddCategory = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
00100         }
00101 
00102         if ( $oAttribute->load( $soxId ) && is_array( $aAddCategory ) ) {
00103             $oDb = oxDb::getDb();
00104             foreach ($aAddCategory as $sAdd) {
00105                 $oNewGroup = oxNew( "oxbase" );
00106                 $oNewGroup->init( "oxcategory2attribute" );
00107                 $oNewGroup->oxcategory2attribute__oxobjectid = new oxField($sAdd);
00108                 $oNewGroup->oxcategory2attribute__oxattrid = new oxField($oAttribute->oxattribute__oxid->value);
00109                 $oNewGroup->oxcategory2attribute__oxsort   = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxcategory2attribute where oxobjectid = '$sAdd' ", false, false ) );
00110                 $oNewGroup->save();
00111             }
00112         }
00113 
00114         $this->resetContentCache();
00115     }
00116 
00117 }