article_attribute.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00003 $aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00004                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00005                                         array( 'oxid',    'oxattribute', 0, 0, 1 )
00006                                         ),
00007                      'container2' => array(
00008                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00009                                         array( 'oxid',    'oxobject2attribute', 0, 0, 1 ),
00010                                         array( 'oxvalue', 'oxobject2attribute', 0, 1, 1 ),
00011                                         array( 'oxattrid', 'oxobject2attribute', 0, 0, 1 ),
00012                                         )
00013                     );
00017 class ajaxComponent extends ajaxListComponent
00018 {
00024     protected function _getQuery()
00025     {
00026         $oDb         = oxDb::getDb();
00027         $sArtId      = oxConfig::getParameter( 'oxid' );
00028         $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
00029 
00030         $sAttrViewName = $this->_getViewName('oxattribute');
00031         $sO2AViewName  = $this->_getViewName('oxobject2attribute');
00032         if ( $sArtId ) {
00033             // all categories article is in
00034             $sQAdd  = " from $sO2AViewName left join $sAttrViewName on $sAttrViewName.oxid=$sO2AViewName.oxattrid ";
00035             $sQAdd .= " where $sO2AViewName.oxobjectid = " . $oDb->quote( $sArtId ) . " ";
00036         } else {
00037             $sQAdd  = " from $sAttrViewName where $sAttrViewName.oxid not in ( select $sO2AViewName.oxattrid from $sO2AViewName left join $sAttrViewName on $sAttrViewName.oxid=$sO2AViewName.oxattrid ";
00038             $sQAdd .= " where $sO2AViewName.oxobjectid = " . $oDb->quote( $sSynchArtId ) . " ) ";
00039         }
00040 
00041         return $sQAdd;
00042     }
00043 
00049     public function removeattr()
00050     {
00051         $aChosenArt = $this->_getActionIds( 'oxobject2attribute.oxid' );
00052         $sOxid = oxConfig::getParameter( 'oxid' );
00053         if ( oxConfig::getParameter( 'all' ) ) {
00054             $sO2AViewName  = $this->_getViewName('oxobject2attribute');
00055             $sQ = $this->_addFilter( "delete $sO2AViewName.* ".$this->_getQuery() );
00056             oxDb::getDb()->Execute( $sQ );
00057 
00058         } elseif ( is_array( $aChosenArt ) ) {
00059             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00060             oxDb::getDb()->Execute( $sQ );
00061         }
00062     }
00063 
00069     public function addattr()
00070     {
00071         $aAddCat = $this->_getActionIds( 'oxattribute.oxid' );
00072         $soxId   = oxConfig::getParameter( 'synchoxid');
00073 
00074         if ( oxConfig::getParameter( 'all' ) ) {
00075             $sAttrViewName = $this->_getViewName('oxattribute');
00076             $aAddCat = $this->_getAll( $this->_addFilter( "select $sAttrViewName.oxid ".$this->_getQuery() ) );
00077         }
00078 
00079         if ( $soxId && $soxId != "-1" && is_array( $aAddCat ) ) {
00080             foreach ($aAddCat as $sAdd) {
00081                 $oNew = oxNew( "oxbase" );
00082                 $oNew->init( "oxobject2attribute" );
00083                 $oNew->oxobject2attribute__oxobjectid = new oxField($soxId);
00084                 $oNew->oxobject2attribute__oxattrid   = new oxField($sAdd);
00085                 $oNew->save();
00086             }
00087         }
00088     }
00089 
00095     public function saveAttributeValue ()
00096     {
00097         $oDb = oxDb::getDb();
00098 
00099         $soxId = oxConfig::getParameter( "oxid");
00100         $sAttributeId = oxConfig::getParameter( "attr_oxid");
00101         $sAttributeValue      = oxConfig::getParameter( "attr_value");
00102         if (!$this->getConfig()->isUtf()) {
00103             $sAttributeValue = iconv( 'UTF-8', oxLang::getInstance()->translateString("charset"), $sAttributeValue );
00104         }
00105 
00106         $oArticle = oxNew( "oxarticle" );
00107         if ( $oArticle->load( $soxId ) ) {
00108 
00109 
00110             if ( isset( $sAttributeId) && ("" != $sAttributeId ) ) {
00111                 $sO2AViewName = $this->_getViewName( "oxobject2attribute" );
00112                 $sSelect = "select * from $sO2AViewName where $sO2AViewName.oxobjectid= " . $oDb->quote( $oArticle->oxarticles__oxid->value ) . " and
00113                             $sO2AViewName.oxattrid= " . $oDb->quote( $sAttributeId );
00114                 $oO2A = oxNew( "oxi18n" );
00115                 $oO2A->setLanguage( oxConfig::getParameter( 'editlanguage' ) );
00116                 $oO2A->init( "oxobject2attribute" );
00117                 if ( $oO2A->assignRecord( $sSelect ) ) {
00118                     $oO2A->oxobject2attribute__oxvalue->setValue( $sAttributeValue );
00119                     $oO2A->save();
00120                 }
00121             }
00122         }
00123     }
00124 }