article_accessories_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_accessories_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',     '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         // category selected or not ?
00056         if ( !$sSelId ) {
00057             $sQAdd  = " from $sArticleTable where 1 ";
00058             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00059         } else {
00060             // selected category ?
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             // dodger performance
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         // skipping self from list
00079         $sId = ( $sSynchSelId ) ? $sSynchSelId : $sSelId ;
00080         $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sId ) . " ";
00081 
00082         // creating AJAX component
00083         return $sQAdd;
00084     }
00085 
00091     public function removeArticleAcc()
00092     {
00093         $aChosenArt = $this->_getActionIds( 'oxaccessoire2article.oxid' );
00094         // removing all
00095         if ( oxConfig::getParameter( 'all' ) ) {
00096 
00097             $sQ = $this->_addFilter( "delete oxaccessoire2article.* ".$this->_getQuery() );
00098             oxDb::getDb()->Execute( $sQ );
00099 
00100         } elseif ( is_array( $aChosenArt ) ) {
00101             $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00102             oxDb::getDb()->Execute( $sQ );
00103         }
00104 
00105 
00106     }
00107 
00113     public function addArticleAcc()
00114     {
00115         $oArticle   = oxNew( "oxarticle" );
00116         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00117         $soxId      = oxConfig::getParameter( 'synchoxid');
00118 
00119         // adding
00120         if ( oxConfig::getParameter( 'all' ) ) {
00121             $sArtTable = $this->_getViewName('oxarticles');
00122             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00123         }
00124 
00125         if ( $oArticle->load( $soxId ) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00126             foreach ( $aChosenArt as $sChosenArt ) {
00127                 $oNewGroup = oxNew( "oxbase" );
00128                 $oNewGroup->init( "oxaccessoire2article" );
00129                 $oNewGroup->oxaccessoire2article__oxobjectid   = new oxField($sChosenArt);
00130                 $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00131                 $oNewGroup->oxaccessoire2article__oxsort       = new oxField(0);
00132                 $oNewGroup->save();
00133             }
00134 
00135         }
00136     }
00137 }