article_crossselling_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_crossselling_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',     'oxobject2article', 0, 0, 1 )
00037                                         )
00038                                 );
00039 
00045     protected function _getQuery()
00046     {
00047         $myConfig      = $this->getConfig();
00048         $sArticleTable = $this->_getViewName( 'oxarticles' );
00049         $sO2CView      = $this->_getViewName( 'oxobject2category' );
00050 
00051         $sSelId      = oxConfig::getParameter( 'oxid' );
00052         $sSynchSelId = oxConfig::getParameter( 'synchoxid' );
00053         $oDb         = oxDb::getDb();
00054 
00055         // category selected or not ?
00056         if ( !$sSelId ) {
00057             $sQAdd  = " from $sArticleTable where 1 ";
00058             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )? '':" and $sArticleTable.oxparentid = '' ";
00059         } elseif ( $sSynchSelId && $sSelId != $sSynchSelId ) {
00060             // selected category ?
00061             $sQAdd  = " from $sO2CView 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( $sSelId ) . " ";
00064         } elseif ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00065             $sQAdd  = " from oxobject2article ";
00066             $sQAdd .= " inner join $sArticleTable on ( oxobject2article.oxobjectid = $sArticleTable.oxid ";
00067             $sQAdd .= " or oxobject2article.oxarticlenid = $sArticleTable.oxid ) ";
00068             $sQAdd .= " where ( oxobject2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " or oxobject2article.oxobjectid = " . $oDb->quote( $sSelId ) . " ) ";
00069             $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sSelId ) . " ";
00070         } else {
00071             $sQAdd  = " from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00072             $sQAdd .= " where oxobject2article.oxarticlenid = " . $oDb->quote( $sSelId ) . " ";
00073         }
00074 
00075         if ( $sSynchSelId && $sSynchSelId != $sSelId) {
00076             if ( $myConfig->getConfigParam( 'blBidirectCross' ) ) {
00077                 $sSubSelect  = "select $sArticleTable.oxid from oxobject2article left join $sArticleTable on (oxobject2article.oxobjectid=$sArticleTable.oxid or oxobject2article.oxarticlenid=$sArticleTable.oxid) ";
00078                 $sSubSelect .= "where (oxobject2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " or oxobject2article.oxobjectid = " . $oDb->quote( $sSynchSelId ) . " )";
00079             } else {
00080                 $sSubSelect  = "select $sArticleTable.oxid from oxobject2article left join $sArticleTable on oxobject2article.oxobjectid=$sArticleTable.oxid ";
00081                 $sSubSelect .= "where oxobject2article.oxarticlenid = " . $oDb->quote( $sSynchSelId ) . " ";
00082             }
00083 
00084             $sSubSelect .= " and $sArticleTable.oxid IS NOT NULL ";
00085             $sQAdd .= " and $sArticleTable.oxid not in ( $sSubSelect ) ";
00086         }
00087 
00088         // #1513C/#1826C - skip references, to not existing articles
00089         $sQAdd .= " and $sArticleTable.oxid IS NOT NULL ";
00090 
00091         // skipping self from list
00092         $sId = ( $sSynchSelId ) ? $sSynchSelId : $sSelId ;
00093         $sQAdd .= " and $sArticleTable.oxid != " . $oDb->quote( $sId ) . " ";
00094 
00095         return $sQAdd ;
00096     }
00097 
00103     public function removeArticleCross()
00104     {
00105         $aChosenArt = $this->_getActionIds( 'oxobject2article.oxid' );
00106         // removing all
00107         if ( oxConfig::getParameter( 'all' ) ) {
00108             $sQ = $this->_addFilter( "delete oxobject2article.* ".$this->_getQuery() );
00109             oxDb::getDb()->Execute( $sQ );
00110         } elseif ( is_array( $aChosenArt ) ) {
00111             $sQ = "delete from oxobject2article where oxobject2article.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00112             oxDb::getDb()->Execute( $sQ );
00113         }
00114 
00115     }
00116 
00122     public function addArticleCross()
00123     {
00124         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00125         $soxId      = oxConfig::getParameter( 'synchoxid');
00126 
00127         // adding
00128         if ( oxConfig::getParameter( 'all' ) ) {
00129             $sArtTable = $this->_getViewName('oxarticles');
00130             $aChosenArt = $this->_getAll( parent::_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00131         }
00132 
00133         $oArticle = oxNew( "oxarticle" );
00134         if ( $oArticle->load( $soxId) && $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00135             foreach ( $aChosenArt as $sAdd ) {
00136                 $oNewGroup = oxNew( 'oxbase' );
00137                 $oNewGroup->init( 'oxobject2article' );
00138                 $oNewGroup->oxobject2article__oxobjectid   = new oxField($sAdd);
00139                 $oNewGroup->oxobject2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00140                 $oNewGroup->oxobject2article__oxsort       = new oxField(0);
00141                 $oNewGroup->save();
00142             }
00143 
00144         }
00145     }
00146 }