article_attribute_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_attribute_ajax extends ajaxListComponent
00007 {
00013     protected $_aColumns = array( 'container1' => array(    // field , table,         visible, multilanguage, ident
00014                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00015                                         array( 'oxid',    'oxattribute', 0, 0, 1 )
00016                                         ),
00017                                 'container2' => array(
00018                                         array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
00019                                         array( 'oxid',    'oxobject2attribute', 0, 0, 1 ),
00020                                         array( 'oxvalue', 'oxobject2attribute', 0, 1, 1 ),
00021                                         array( 'oxattrid', 'oxobject2attribute', 0, 0, 1 ),
00022                                         )
00023                                 );
00024 
00030     protected function _getQuery()
00031     {
00032         $oDb         = oxDb::getDb();
00033         $sArtId      = oxConfig::getParameter( 'oxid' );
00034         $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
00035 
00036         $sAttrViewName = $this->_getViewName('oxattribute');
00037         $sO2AViewName  = $this->_getViewName('oxobject2attribute');
00038         if ( $sArtId ) {
00039             // all categories article is in
00040             $sQAdd  = " from $sO2AViewName left join $sAttrViewName on $sAttrViewName.oxid=$sO2AViewName.oxattrid ";
00041             $sQAdd .= " where $sO2AViewName.oxobjectid = " . $oDb->quote( $sArtId ) . " ";
00042         } else {
00043             $sQAdd  = " from $sAttrViewName where $sAttrViewName.oxid not in ( select $sO2AViewName.oxattrid from $sO2AViewName left join $sAttrViewName on $sAttrViewName.oxid=$sO2AViewName.oxattrid ";
00044             $sQAdd .= " where $sO2AViewName.oxobjectid = " . $oDb->quote( $sSynchArtId ) . " ) ";
00045         }
00046 
00047         return $sQAdd;
00048     }
00049 
00055     public function removeAttr()
00056     {
00057         $aChosenArt = $this->_getActionIds( 'oxobject2attribute.oxid' );
00058         $sOxid = oxConfig::getParameter( 'oxid' );
00059         if ( oxConfig::getParameter( 'all' ) ) {
00060             $sO2AViewName  = $this->_getViewName('oxobject2attribute');
00061             $sQ = $this->_addFilter( "delete $sO2AViewName.* ".$this->_getQuery() );
00062             oxDb::getDb()->Execute( $sQ );
00063 
00064         } elseif ( is_array( $aChosenArt ) ) {
00065             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
00066             oxDb::getDb()->Execute( $sQ );
00067         }
00068 
00069     }
00070 
00076     public function addAttr()
00077     {
00078         $aAddCat = $this->_getActionIds( 'oxattribute.oxid' );
00079         $soxId   = oxConfig::getParameter( 'synchoxid');
00080 
00081         if ( oxConfig::getParameter( 'all' ) ) {
00082             $sAttrViewName = $this->_getViewName('oxattribute');
00083             $aAddCat = $this->_getAll( $this->_addFilter( "select $sAttrViewName.oxid ".$this->_getQuery() ) );
00084         }
00085 
00086         if ( $soxId && $soxId != "-1" && is_array( $aAddCat ) ) {
00087             foreach ($aAddCat as $sAdd) {
00088                 $oNew = oxNew( "oxbase" );
00089                 $oNew->init( "oxobject2attribute" );
00090                 $oNew->oxobject2attribute__oxobjectid = new oxField($soxId);
00091                 $oNew->oxobject2attribute__oxattrid   = new oxField($sAdd);
00092                 $oNew->save();
00093             }
00094 
00095         }
00096     }
00097 
00103     public function saveAttributeValue ()
00104     {
00105         $oDb = oxDb::getDb();
00106 
00107         $soxId = oxConfig::getParameter( "oxid");
00108         $sAttributeId = oxConfig::getParameter( "attr_oxid");
00109         $sAttributeValue      = oxConfig::getParameter( "attr_value");
00110         if (!$this->getConfig()->isUtf()) {
00111             $sAttributeValue = iconv( 'UTF-8', oxRegistry::getLang()->translateString("charset"), $sAttributeValue );
00112         }
00113 
00114         $oArticle = oxNew( "oxarticle" );
00115         if ( $oArticle->load( $soxId ) ) {
00116 
00117 
00118             if ( isset( $sAttributeId) && ("" != $sAttributeId ) ) {
00119                 $sO2AViewName = $this->_getViewName( "oxobject2attribute" );
00120                 $sSelect = "select * from $sO2AViewName where $sO2AViewName.oxobjectid= " . $oDb->quote( $oArticle->oxarticles__oxid->value ) . " and
00121                             $sO2AViewName.oxattrid= " . $oDb->quote( $sAttributeId );
00122                 $oO2A = oxNew( "oxi18n" );
00123                 $oO2A->setLanguage( oxConfig::getParameter( 'editlanguage' ) );
00124                 $oO2A->init( "oxobject2attribute" );
00125                 if ( $oO2A->assignRecord( $sSelect ) ) {
00126                     $oO2A->oxobject2attribute__oxvalue->setValue( $sAttributeValue );
00127                     $oO2A->save();
00128                 }
00129             }
00130 
00131         }
00132     }
00133 }