attribute_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class attribute_main_ajax extends ajaxListComponent
00007 {
00013     protected $_blAllowExtColumns = true;
00014 
00020     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00021                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00022                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00023                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00024                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00025                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00026                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00027                                         array( 'oxid',     'oxarticles', 0, 0, 1 )
00028                                         ),
00029                                     'container2' => array(
00030                                         array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00031                                         array( 'oxtitle',  'oxarticles', 1, 1, 0 ),
00032                                         array( 'oxean',    'oxarticles', 1, 0, 0 ),
00033                                         array( 'oxmpn',    'oxarticles', 0, 0, 0 ),
00034                                         array( 'oxprice',  'oxarticles', 0, 0, 0 ),
00035                                         array( 'oxstock',  'oxarticles', 0, 0, 0 ),
00036                                         array( 'oxid',     'oxobject2attribute', 0, 0, 1 )
00037                                         )
00038                                 );
00039 
00045     protected function _getQuery()
00046     {
00047         $myConfig = $this->getConfig();
00048         $oDb      = oxDb::getDb();
00049 
00050         $sArticleTable    = $this->_getViewName('oxarticles');
00051         $sO2CategoryView  = $this->_getViewName('oxobject2category');
00052         $sO2AttributeView = $this->_getViewName('oxobject2attribute');
00053 
00054         $sDelId      = oxConfig::getParameter( 'oxid' );
00055         $sSynchDelId = oxConfig::getParameter( 'synchoxid' );
00056 
00057         // category selected or not ?
00058         if ( !$sDelId) {
00059             // dodger performance
00060             $sQAdd  = " from $sArticleTable where 1 ";
00061             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00062         } elseif ( $sSynchDelId && $sDelId != $sSynchDelId ) {
00063             // selected category ?
00064             $sQAdd  = " from $sO2CategoryView as oxobject2category left join $sArticleTable on ";
00065             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
00066             $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sDelId ) . " ";
00067         } else {
00068             $sQAdd  = " from $sO2AttributeView left join $sArticleTable on $sArticleTable.oxid=$sO2AttributeView.oxobjectid ";
00069             $sQAdd .= " where $sO2AttributeView.oxattrid = " . $oDb->quote( $sDelId ) . " and $sArticleTable.oxid is not null ";
00070         }
00071 
00072         if ( $sSynchDelId && $sSynchDelId != $sDelId ) {
00073             $sQAdd .= " and $sArticleTable.oxid not in ( select $sO2AttributeView.oxobjectid from $sO2AttributeView where $sO2AttributeView.oxattrid = " . $oDb->quote( $sSynchDelId ) . " ) ";
00074         }
00075 
00076         return $sQAdd;
00077     }
00078 
00086     protected function _addFilter( $sQ )
00087     {
00088         $sQ = parent::_addFilter( $sQ );
00089 
00090         // display variants or not ?
00091         if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00092             $sQ .= ' group by '.$this->_getViewName( 'oxarticles' ).'.oxid ';
00093 
00094             $oStr = getStr();
00095             if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
00096                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00097             }
00098         }
00099         return $sQ;
00100     }
00101 
00107     public function removeAttrArticle()
00108     {
00109         $aChosenCat = $this->_getActionIds( 'oxobject2attribute.oxid' );
00110 
00111 
00112         if ( oxConfig::getParameter( 'all' ) ) {
00113             $sO2AttributeView = $this->_getViewName('oxobject2attribute');
00114 
00115             $sQ = parent::_addFilter( "delete $sO2AttributeView.* ".$this->_getQuery() );
00116             oxDb::getDb()->Execute( $sQ );
00117         } elseif ( is_array( $aChosenCat ) ) {
00118             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00119             oxDb::getDb()->Execute( $sQ );
00120         }
00121     }
00122 
00128     public function addAttrArticle()
00129     {
00130         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00131         $soxId       = oxConfig::getParameter( 'synchoxid' );
00132 
00133         // adding
00134         if ( oxConfig::getParameter( 'all' ) ) {
00135             $sArticleTable = $this->_getViewName( 'oxarticles' );
00136             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00137         }
00138 
00139         $oAttribute = oxNew( "oxattribute" );
00140 
00141         if ( $oAttribute->load( $soxId) && is_array( $aAddArticle ) ) {
00142             foreach ( $aAddArticle as $sAdd ) {
00143                 $oNewGroup = oxNew( "oxbase" );
00144                 $oNewGroup->init( "oxobject2attribute" );
00145                 $oNewGroup->oxobject2attribute__oxobjectid = new oxField( $sAdd );
00146                 $oNewGroup->oxobject2attribute__oxattrid   = new oxField( $oAttribute->oxattribute__oxid->value );
00147                 $oNewGroup->save();
00148 
00149             }
00150         }
00151     }
00152 }