00001 <?php
00002
00006 class article_accessories_ajax extends ajaxListComponent
00007 {
00013 protected $_blAllowExtColumns = true;
00014
00020 protected $_aColumns = array( 'container1' => array(
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', 'oxaccessoire2article', 0, 0, 1 )
00037 )
00038 );
00039
00045 protected function _getQuery()
00046 {
00047 $myConfig = $this->getConfig();
00048 $sSelId = oxConfig::getParameter( 'oxid' );
00049 $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00050 $oDb = oxDb::getDb();
00051
00052 $sArticleTable = $this->_getViewName('oxarticles');
00053 $sO2CView = $this->_getViewName('oxobject2category');
00054
00055
00056 if ( !$sSelId ) {
00057 $sQAdd = " from $sArticleTable where 1 ";
00058 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00059 } else {
00060
00061 if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00062 $sQAdd = " from $sO2CView left join $sArticleTable on ";
00063 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid )":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00064 $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote( $sSelId ) . " ";
00065 } else {
00066 $sQAdd = " from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00067 $sQAdd .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " ";
00068 }
00069 }
00070
00071 if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00072
00073 $sSubSelect .= " select oxaccessoire2article.oxobjectid from oxaccessoire2article ";
00074 $sSubSelect .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " ";
00075 $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
00076 }
00077
00078
00079 return $sQAdd;
00080 }
00081
00087 public function removeArticleAcc()
00088 {
00089 $aChosenArt = $this->_getActionIds( 'oxaccessoire2article.oxid' );
00090
00091 if ( oxConfig::getParameter( 'all' ) ) {
00092
00093 $sQ = $this->_addFilter( "delete oxaccessoire2article.* ".$this->_getQuery() );
00094 oxDb::getDb()->Execute( $sQ );
00095
00096 } elseif ( is_array( $aChosenArt ) ) {
00097 $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00098 oxDb::getDb()->Execute( $sQ );
00099 }
00100
00101 }
00102
00108 public function addArticleAcc()
00109 {
00110 $oArticle = oxNew( "oxarticle" );
00111 $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00112 $soxId = oxConfig::getParameter( 'synchoxid');
00113
00114
00115 if ( oxConfig::getParameter( 'all' ) ) {
00116 $sArtTable = $this->_getViewName('oxarticles');
00117 $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00118 }
00119
00120 if ( $oArticle->load( $soxId ) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00121 foreach ( $aChosenArt as $sChosenArt ) {
00122 $oNewGroup = oxNew( "oxbase" );
00123 $oNewGroup->init( "oxaccessoire2article" );
00124 $oNewGroup->oxaccessoire2article__oxobjectid = new oxField($sChosenArt);
00125 $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00126 $oNewGroup->oxaccessoire2article__oxsort = new oxField(0);
00127 $oNewGroup->save();
00128 }
00129 }
00130 }
00131 }