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