attribute_main.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',     'oxobject2attribute', 0, 0, 1 )
00020                                         )
00021                     );
00022 
00023 
00027 class ajaxComponent extends ajaxListComponent
00028 {
00034     protected function _getQuery()
00035     {
00036         $myConfig = $this->getConfig();
00037         $oDb      = oxDb::getDb();
00038 
00039         $sArticleTable = getViewName('oxarticles');
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 $sArticleTable where 1 ";
00049             $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00050         } else {
00051             // selected category ?
00052             if ( $sSynchDelId && $sDelId != $sSynchDelId ) {
00053                 $sQAdd  = " from $sO2CView as oxobject2category left join $sArticleTable on ";
00054                 $sQAdd .= $myConfig->getConfigParam( 'blVariantsSelection' )?" ( $sArticleTable.oxid=oxobject2category.oxobjectid or $sArticleTable.oxparentid=oxobject2category.oxobjectid)":" $sArticleTable.oxid=oxobject2category.oxobjectid ";
00055                 $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote( $sDelId ) . " ";
00056             } else {
00057                 $sQAdd  = " from oxobject2attribute left join $sArticleTable on $sArticleTable.oxid=oxobject2attribute.oxobjectid ";
00058                 $sQAdd .= " where oxobject2attribute.oxattrid = " . $oDb->quote( $sDelId ) . " and $sArticleTable.oxid is not null ";
00059             }
00060         }
00061 
00062         if ( $sSynchDelId && $sSynchDelId != $sDelId ) {
00063             $sQAdd .= " and $sArticleTable.oxid not in ( select oxobject2attribute.oxobjectid from oxobject2attribute where oxobject2attribute.oxattrid = " . $oDb->quote( $sSynchDelId ) . " ) ";
00064         }
00065 
00066         return $sQAdd;
00067     }
00068 
00076     protected function _addFilter( $sQ )
00077     {
00078         $sArtTable = getViewName('oxarticles');
00079         $sQ = parent::_addFilter( $sQ );
00080 
00081         // display variants or not ?
00082         $sQ .= $this->getConfig()->getConfigParam( 'blVariantsSelection' ) ? ' group by '.$sArtTable.'.oxid ' : '';
00083         return $sQ;
00084     }
00085 
00091     public function removeattrarticle()
00092     {
00093         $aChosenCat = $this->_getActionIds( 'oxobject2attribute.oxid' );
00094         if ( oxConfig::getParameter( 'all' ) ) {
00095 
00096             $sQ = $this->_addFilter( "delete oxobject2attribute.* ".$this->_getQuery() );
00097             oxDb::getDb()->Execute( $sQ );
00098 
00099         } elseif ( is_array( $aChosenCat ) ) {
00100             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
00101             oxDb::getDb()->Execute( $sQ );
00102         }
00103     }
00104 
00110     public function addattrarticle()
00111     {
00112         $aAddArticle = $this->_getActionIds( 'oxarticles.oxid' );
00113         $soxId       = oxConfig::getParameter( 'synchoxid' );
00114 
00115         // adding
00116         if ( oxConfig::getParameter( 'all' ) ) {
00117             $sArticleTable = getViewName( 'oxarticles' );
00118             $aAddArticle = $this->_getAll( $this->_addFilter( "select $sArticleTable.oxid ".$this->_getQuery() ) );
00119         }
00120 
00121         $oCategory = oxNew( "oxattribute" );
00122 
00123 
00124         if ( $oCategory->load( $soxId) && is_array( $aAddArticle ) ) {
00125             foreach ($aAddArticle as $sAdd) {
00126                 $oNewGroup = oxNew( "oxbase" );
00127                 $oNewGroup->init( "oxobject2attribute" );
00128                 $oNewGroup->oxobject2attribute__oxobjectid = new oxField($sAdd);
00129                 $oNewGroup->oxobject2attribute__oxattrid   = new oxField($oCategory->oxattribute__oxid->value);
00130                 $oNewGroup->save();
00131             }
00132         }
00133     }
00134 
00141     protected function _getQueryCols()
00142     {
00143         $myConfig = $this->getConfig();
00144         $sLangTag = oxLang::getInstance()->getLanguageTag();
00145 
00146         $sQ = '';
00147         $blSep = false;
00148         $aVisiblecols = $this->_getVisibleColNames();
00149         foreach ( $aVisiblecols as $iCnt => $aCol ) {
00150             if ( $blSep )
00151                 $sQ .= ', ';
00152             $sViewTable = getViewName( $aCol[1] );
00153             // multilanguage
00154             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00155             if ( $myConfig->getConfigParam( 'blVariantsSelection' ) && $aCol[0] == 'oxtitle' ) {
00156                 $sVarSelect = "$sViewTable.oxvarselect".$sLangTag;
00157                 $sQ .= " IF( $sViewTable.$sCol != '', $sViewTable.$sCol, CONCAT((select oxart.$sCol from $sViewTable as oxart where oxart.oxid = $sViewTable.oxparentid),', ',$sVarSelect)) as _" . $iCnt;
00158             } else {
00159                 $sQ  .= $sViewTable . '.' . $sCol . ' as _' . $iCnt;
00160             }
00161             $blSep = true;
00162         }
00163 
00164         $aIdentCols = $this->_getIdentColNames();
00165         foreach ( $aIdentCols as $iCnt => $aCol ) {
00166             if ( $blSep )
00167                 $sQ .= ', ';
00168 
00169             // multilanguage
00170             $sCol = $aCol[3]?$aCol[0].$sLangTag:$aCol[0];
00171             $sQ  .= getViewName( $aCol[1] ) . '.' . $sCol . ' as _' . $iCnt;
00172         }
00173 
00174         return " $sQ ";
00175     }
00176 
00177 }

Generated by  doxygen 1.6.2