OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
article_attribute_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
14  array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
15  array( 'oxid', 'oxattribute', 0, 0, 1 )
16  ),
17  'container2' => array(
18  array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
19  array( 'oxid', 'oxobject2attribute', 0, 0, 1 ),
20  array( 'oxvalue', 'oxobject2attribute', 0, 1, 1 ),
21  array( 'oxattrid', 'oxobject2attribute', 0, 0, 1 ),
22  )
23  );
24 
30  protected function _getQuery()
31  {
32  $oDb = oxDb::getDb();
33  $sArtId = oxConfig::getParameter( 'oxid' );
34  $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
35 
36  $sAttrViewName = $this->_getViewName('oxattribute');
37  $sO2AViewName = $this->_getViewName('oxobject2attribute');
38  if ( $sArtId ) {
39  // all categories article is in
40  $sQAdd = " from $sO2AViewName left join $sAttrViewName on $sAttrViewName.oxid=$sO2AViewName.oxattrid ";
41  $sQAdd .= " where $sO2AViewName.oxobjectid = " . $oDb->quote( $sArtId ) . " ";
42  } else {
43  $sQAdd = " from $sAttrViewName where $sAttrViewName.oxid not in ( select $sO2AViewName.oxattrid from $sO2AViewName left join $sAttrViewName on $sAttrViewName.oxid=$sO2AViewName.oxattrid ";
44  $sQAdd .= " where $sO2AViewName.oxobjectid = " . $oDb->quote( $sSynchArtId ) . " ) ";
45  }
46 
47  return $sQAdd;
48  }
49 
55  public function removeAttr()
56  {
57  $aChosenArt = $this->_getActionIds( 'oxobject2attribute.oxid' );
58  $sOxid = oxConfig::getParameter( 'oxid' );
59  if ( oxConfig::getParameter( 'all' ) ) {
60  $sO2AViewName = $this->_getViewName('oxobject2attribute');
61  $sQ = $this->_addFilter( "delete $sO2AViewName.* ".$this->_getQuery() );
62  oxDb::getDb()->Execute( $sQ );
63 
64  } elseif ( is_array( $aChosenArt ) ) {
65  $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
66  oxDb::getDb()->Execute( $sQ );
67  }
68 
69  }
70 
76  public function addAttr()
77  {
78  $aAddCat = $this->_getActionIds( 'oxattribute.oxid' );
79  $soxId = oxConfig::getParameter( 'synchoxid');
80 
81  if ( oxConfig::getParameter( 'all' ) ) {
82  $sAttrViewName = $this->_getViewName('oxattribute');
83  $aAddCat = $this->_getAll( $this->_addFilter( "select $sAttrViewName.oxid ".$this->_getQuery() ) );
84  }
85 
86  if ( $soxId && $soxId != "-1" && is_array( $aAddCat ) ) {
87  foreach ($aAddCat as $sAdd) {
88  $oNew = oxNew( "oxbase" );
89  $oNew->init( "oxobject2attribute" );
90  $oNew->oxobject2attribute__oxobjectid = new oxField($soxId);
91  $oNew->oxobject2attribute__oxattrid = new oxField($sAdd);
92  $oNew->save();
93  }
94 
95  }
96  }
97 
103  public function saveAttributeValue ()
104  {
105  $oDb = oxDb::getDb();
106 
107  $soxId = oxConfig::getParameter( "oxid");
108  $sAttributeId = oxConfig::getParameter( "attr_oxid");
109  $sAttributeValue = oxConfig::getParameter( "attr_value");
110  if (!$this->getConfig()->isUtf()) {
111  $sAttributeValue = iconv( 'UTF-8', oxRegistry::getLang()->translateString("charset"), $sAttributeValue );
112  }
113 
114  $oArticle = oxNew( "oxarticle" );
115  if ( $oArticle->load( $soxId ) ) {
116 
117 
118  if ( isset( $sAttributeId) && ("" != $sAttributeId ) ) {
119  $sO2AViewName = $this->_getViewName( "oxobject2attribute" );
120  $sSelect = "select * from $sO2AViewName where $sO2AViewName.oxobjectid= " . $oDb->quote( $oArticle->oxarticles__oxid->value ) . " and
121  $sO2AViewName.oxattrid= " . $oDb->quote( $sAttributeId );
122  $oO2A = oxNew( "oxi18n" );
123  $oO2A->setLanguage( oxConfig::getParameter( 'editlanguage' ) );
124  $oO2A->init( "oxobject2attribute" );
125  if ( $oO2A->assignRecord( $sSelect ) ) {
126  $oO2A->oxobject2attribute__oxvalue->setValue( $sAttributeValue );
127  $oO2A->save();
128  }
129  }
130 
131  }
132  }
133 }