delivery_articles.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',     'oxobject2delivery', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00026 class ajaxComponent extends ajaxListComponent
00027 {
00033     protected function _getQuery()
00034     {
00035         $myConfig = $this->getConfig();
00036 
00037         // looking for table/view
00038         $sArtTable = getViewName('oxarticles');
00039         $sCatTable = getViewName('oxcategories');
00040         $sO2CView  = getViewName('oxobject2category');
00041 
00042         $sDelId      = oxConfig::getParameter( 'oxid' );
00043         $sSynchDelId = oxConfig::getParameter( 'synchoxid' );
00044 
00045         // category selected or not ?
00046         if ( !$sDelId) {
00047             // dodger performance
00048             $sQAdd  = " from $sArtTable where 1 ";
00049             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':"and $sArtTable.oxparentid = '' ";
00050         } else {
00051             // selected category ?
00052             if ( $sSynchDelId && $sDelId != $sSynchDelId ) {
00053                 $sQAdd  = " from $sO2CView left join $sArtTable on ";
00054                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArtTable.oxid=$sO2CView.oxobjectid or $sArtTable.oxparentid=$sO2CView.oxobjectid)":" $sArtTable.oxid=$sO2CView.oxobjectid ";
00055                 $sQAdd .= "where $sO2CView.oxcatnid = '$sDelId' ";
00056             } else {
00057                 $sQAdd  = ' from oxobject2delivery left join '.$sArtTable.' on '.$sArtTable.'.oxid=oxobject2delivery.oxobjectid ';
00058                 $sQAdd .= 'where oxobject2delivery.oxdeliveryid = "'.$sDelId.'" and oxobject2delivery.oxtype = "oxarticles" ';
00059             }
00060         }
00061 
00062         if ( $sSynchDelId && $sSynchDelId != $sDelId) {
00063             $sQAdd .= 'and '.$sArtTable.'.oxid not in ( ';
00064             $sQAdd .= 'select '.$sArtTable.'.oxid from oxobject2delivery left join '.$sArtTable.' on '.$sArtTable.'.oxid=oxobject2delivery.oxobjectid ';
00065             $sQAdd .= 'where oxobject2delivery.oxdeliveryid = "'.$sSynchDelId.'" and oxobject2delivery.oxtype = "oxarticles" ) ';
00066         }
00067 
00068         return $sQAdd;
00069     }
00070 
00078     protected function _addFilter( $sQ )
00079     {
00080         $sArtTable = getViewName('oxarticles');
00081         $sQ = parent::_addFilter( $sQ );
00082 
00083         // display variants or not ?
00084         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00085         return $sQ;
00086     }
00087 
00093     public function removeartfromdel()
00094     {
00095         $aChosenArt = $this->_getActionIds( 'oxobject2delivery.oxid' );
00096         // removing all
00097         if ( oxConfig::getParameter( 'all' ) ) {
00098 
00099             $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
00100             oxDb::getDb()->Execute( $sQ );
00101 
00102         } elseif ( is_array( $aChosenArt ) ) {
00103             $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00104             oxDb::getDb()->Execute( $sQ );
00105         }
00106     }
00107 
00113     public function addarttodel()
00114     {
00115         $aChosenArt = $this->_getActionIds( 'oxarticles.oxid' );
00116         $soxId      = oxConfig::getParameter( 'synchoxid');
00117 
00118         // adding
00119         if ( oxConfig::getParameter( 'all' ) ) {
00120             $sArtTable = getViewName('oxarticles');
00121             $aChosenArt = $this->_getAll( $this->_addFilter( "select $sArtTable.oxid ".$this->_getQuery() ) );
00122         }
00123 
00124         if ( $soxId && $soxId != "-1" && is_array( $aChosenArt ) ) {
00125             foreach ( $aChosenArt as $sChosenArt) {
00126                 $oObject2Delivery = oxNew( 'oxbase' );
00127                 $oObject2Delivery->init( 'oxobject2delivery' );
00128                 $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
00129                 $oObject2Delivery->oxobject2delivery__oxobjectid   = new oxField($sChosenArt);
00130                 $oObject2Delivery->oxobject2delivery__oxtype       = new oxField("oxarticles");
00131                 $oObject2Delivery->save();
00132             }
00133         }
00134     }
00135 
00142     protected function _getQueryCols()
00143     {
00144         $myConfig = $this->getConfig();
00145         $sLangTag = oxLang::getInstance()->getLanguageTag();
00146 
00147         $sQ = '';
00148         $blSep = false;
00149         $aVisiblecols = $this->_getVisibleColNames();
00150         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00151             if ( $blSep )
00152                 $sQ .= ', ';
00153             $sViewTable = getViewName( $aCol[1] );
00154             // multilanguage
00155             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00156             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00157                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00158                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00159             } else {
00160                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00161             }
00162             $blSep = true;
00163         }
00164 
00165         $aIdentCols = $this->_getIdentColNames();
00166         foreach ( $aIdentCols as $iCnt => $aCol ) {
00167             if ( $blSep )
00168                 $sQ .= ', ';
00169 
00170             // multilanguage
00171             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00172             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00173         }
00174 
00175         return " $sQ ";
00176     }
00177 
00178 }