article_accessories.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
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',     'oxaccessoire2article', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00026 class ajaxComponent extends ajaxListComponent
00027 {
00033     protected $_blAllowExtColumns = true;
00034 
00040     protected function _getQuery()
00041     {
00042         $myConfig    = $this->getConfig();
00043         $sSelId      = oxConfig::getParameter( 'oxid' );
00044         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00045         $oDb         = oxDb::getDb();
00046 
00047         $sArticleTable = $this->_getViewName('oxarticles');
00048         $sO2CView      = $this->_getViewName('oxobject2category');
00049 
00050         // category selected or not ?
00051         if ( !$sSelId ) {
00052             $sQAdd  = " from $sArticleTable where 1 ";
00053             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00054         } else {
00055             // selected category ?
00056             if ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00057                 $sQAdd  = " from $sO2CView left join $sArticleTable on ";
00058                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=$sO2CView.oxobjectid or $sArticleTable.oxparentid=$sO2CView.oxobjectid )":" $sArticleTable.oxid=$sO2CView.oxobjectid ";
00059                 $sQAdd .= " where $sO2CView.oxcatnid = " . $oDb->quote( $sSelId ) . " ";
00060             } else {
00061                 $sQAdd  = " from oxaccessoire2article left join $sArticleTable on oxaccessoire2article.oxobjectid=$sArticleTable.oxid ";
00062                 $sQAdd .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " ";
00063             }
00064         }
00065 
00066         if ( $sSynchSelId && $sSynchSelId != $sSelId ) {
00067             // dodger performance
00068             $sSubSelect .= " select oxaccessoire2article.oxobjectid from oxaccessoire2article ";
00069             $sSubSelect .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " ";
00070             $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
00071         }
00072 
00073         // creating AJAX component
00074         return $sQAdd;
00075     }
00076 
00082     public function removearticleacc()
00083     {
00084         $aChosenArt = $this->_getActionIds( 'oxaccessoire2article.oxid' );
00085         // removing all
00086         if ( oxConfig::getParameter( 'all' ) ) {
00087 
00088             $sQ = $this->_addFilter( "delete oxaccessoire2article.* ".$this->_getQuery() );
00089             oxDb::getDb()->Execute( $sQ );
00090 
00091         } elseif ( is_array( $aChosenArt ) ) {
00092             $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00093             oxDb::getDb()->Execute( $sQ );
00094         }
00095 
00096     }
00097 
00103     public function addarticleacc()
00104     {
00105         $oArticle   = oxNew( "oxarticle" );
00106         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00107         $soxId      = oxConfig::getParameter( 'synchoxid');
00108 
00109         // adding
00110         if ( oxConfig::getParameter( 'all' ) ) {
00111             $sArtTable = $this->_getViewName('oxarticles');
00112             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00113         }
00114 
00115         if ( $oArticle->load( $soxId ) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00116             foreach ( $aChosenArt as $sChosenArt ) {
00117                 $oNewGroup = oxNew( "oxbase" );
00118                 $oNewGroup->init( "oxaccessoire2article" );
00119                 $oNewGroup->oxaccessoire2article__oxobjectid   = new oxField($sChosenArt);
00120                 $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00121                 $oNewGroup->oxaccessoire2article__oxsort       = new oxField(0);
00122                 $oNewGroup->save();
00123             }
00124         }
00125     }
00126 }