00001 <?php
00002
00003 $aColumns = array( 'container1' => array(
00004 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00005 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00006 array( 'oxean', 'oxarticles', 1, 0, 0 ),
00007 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00008 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00009 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00010 array( 'oxid', 'oxarticles', 0, 0, 1 )
00011 ),
00012 'container2' => array(
00013 array( 'oxartnum', 'oxarticles', 1, 0, 0 ),
00014 array( 'oxtitle', 'oxarticles', 1, 1, 0 ),
00015 array( 'oxean', 'oxarticles', 1, 0, 0 ),
00016 array( 'oxmpn', 'oxarticles', 0, 0, 0 ),
00017 array( 'oxprice', 'oxarticles', 0, 0, 0 ),
00018 array( 'oxstock', 'oxarticles', 0, 0, 0 ),
00019 array( 'oxid', 'oxobject2attribute', 0, 0, 1 )
00020 )
00021 );
00022
00023
00027 class ajaxComponent extends ajaxListComponent
00028 {
00034 protected $_blAllowExtColumns = true;
00035
00041 protected function _getQuery()
00042 {
00043 $myConfig = $this->getConfig();
00044 $oDb = oxDb::getDb();
00045
00046 $sArticleTable = $this->_getViewName('oxarticles');
00047 $sO2CategoryView = $this->_getViewName('oxobject2category');
00048 $sO2AttributeView = $this->_getViewName('oxobject2attribute');
00049
00050 $sDelId = oxConfig::getParameter( 'oxid' );
00051 $sSynchDelId = oxConfig::getParameter( 'synchoxid' );
00052
00053
00054 if ( !$sDelId) {
00055
00056 $sQAdd = " from $sArticleTable where 1 ";
00057 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00058 } else {
00059
00060 if ( $sSynchDelId && $sDelId != $sSynchDelId ) {
00061 $sQAdd = " from $sO2CategoryView as oxobject2category left join $sArticleTable on ";
00062 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
00063 $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sDelId ) . " ";
00064 } else {
00065 $sQAdd = " from $sO2AttributeView left join $sArticleTable on $sArticleTable.oxid=$sO2AttributeView.oxobjectid ";
00066 $sQAdd .= " where $sO2AttributeView.oxattrid = " . $oDb->quote( $sDelId ) . " and $sArticleTable.oxid is not null ";
00067 }
00068 }
00069
00070 if ( $sSynchDelId && $sSynchDelId != $sDelId ) {
00071 $sQAdd .= " and $sArticleTable.oxid not in ( select $sO2AttributeView.oxobjectid from $sO2AttributeView where $sO2AttributeView.oxattrid = " . $oDb->quote( $sSynchDelId ) . " ) ";
00072 }
00073
00074 return $sQAdd;
00075 }
00076
00084 protected function _addFilter( $sQ )
00085 {
00086 $sQ = parent::_addFilter( $sQ );
00087
00088
00089 if ( $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ) {
00090 $sQ .= ' group by '.$this->_getViewName( 'oxarticles' ).'.oxid ';
00091
00092 $oStr = getStr();
00093 if ( $oStr->strpos( $sQ, "select count( * ) " ) === 0 ) {
00094 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00095 }
00096 }
00097 return $sQ;
00098 }
00099
00105 public function removeattrarticle()
00106 {
00107 $aChosenCat = $this->_getActionIds( 'oxobject2attribute.oxid' );
00108 if ( oxConfig::getParameter( 'all' ) ) {
00109 $sO2AttributeView = $this->_getViewName('oxobject2attribute');
00110
00111 $sQ = parent::_addFilter( "delete $sO2AttributeView.* ".$this->_getQuery() );
00112 oxDb::getDb()->Execute( $sQ );
00113
00114 } elseif ( is_array( $aChosenCat ) ) {
00115 $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00116 oxDb::getDb()->Execute( $sQ );
00117 }
00118 }
00119
00125 public function addattrarticle()
00126 {
00127 $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00128 $soxId = oxConfig::getParameter( 'synchoxid' );
00129
00130
00131 if ( oxConfig::getParameter( 'all' ) ) {
00132 $sArticleTable = $this->_getViewName( 'oxarticles' );
00133 $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00134 }
00135
00136 $oCategory = oxNew( "oxattribute" );
00137
00138
00139 if ( $oCategory->load( $soxId) && is_array( $aAddArticle ) ) {
00140 foreach ($aAddArticle as $sAdd) {
00141 $oNewGroup = oxNew( "oxbase" );
00142 $oNewGroup->init( "oxobject2attribute" );
00143 $oNewGroup->oxobject2attribute__oxobjectid = new oxField($sAdd);
00144 $oNewGroup->oxobject2attribute__oxattrid = new oxField($oCategory->oxattribute__oxid->value);
00145 $oNewGroup->save();
00146 }
00147 }
00148 }
00149 }