OXID eShop CE  4.10.7
 All Classes Namespaces Files Functions Variables Pages
attribute_category_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', 'oxcategories', 1, 1, 0),
16  array('oxdesc', 'oxcategories', 1, 1, 0),
17  array('oxid', 'oxcategories', 0, 0, 0),
18  array('oxid', 'oxcategories', 0, 0, 1)
19  ),
20  'container2' => array(
21  array('oxtitle', 'oxcategories', 1, 1, 0),
22  array('oxdesc', 'oxcategories', 1, 1, 0),
23  array('oxid', 'oxcategories', 0, 0, 0),
24  array('oxid', 'oxcategory2attribute', 0, 0, 1),
25  array('oxid', 'oxcategories', 0, 0, 1)
26  ),
27  'container3' => array(
28  array('oxtitle', 'oxattribute', 1, 1, 0),
29  array('oxsort', 'oxcategory2attribute', 1, 0, 0),
30  array('oxid', 'oxcategory2attribute', 0, 0, 1)
31  )
32  );
33 
39  protected function _getQuery()
40  {
41  $myConfig = $this->getConfig();
42  $oDb = oxDb::getDb();
43 
44  $sCatTable = $this->_getViewName('oxcategories');
45  $sDiscountId = oxRegistry::getConfig()->getRequestParameter('oxid');
46  $sSynchDiscountId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
47 
48  // category selected or not ?
49  if (!$sDiscountId) {
50  $sQAdd = " from {$sCatTable} where {$sCatTable}.oxshopid = '" . $myConfig->getShopId() . "' ";
51  $sQAdd .= " and {$sCatTable}.oxactive = '1' ";
52  } else {
53  $sQAdd = " from {$sCatTable} left join oxcategory2attribute " .
54  "on {$sCatTable}.oxid=oxcategory2attribute.oxobjectid " .
55  " where oxcategory2attribute.oxattrid = " . $oDb->quote($sDiscountId) .
56  " and {$sCatTable}.oxshopid = '" . $myConfig->getShopId() . "' " .
57  " and {$sCatTable}.oxactive = '1' ";
58  }
59 
60  if ($sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
61  $sQAdd .= " and {$sCatTable}.oxid not in ( select {$sCatTable}.oxid " .
62  "from {$sCatTable} left join oxcategory2attribute " .
63  "on {$sCatTable}.oxid=oxcategory2attribute.oxobjectid " .
64  " where oxcategory2attribute.oxattrid = " . $oDb->quote($sSynchDiscountId) .
65  " and {$sCatTable}.oxshopid = '" . $myConfig->getShopId() . "' " .
66  " and {$sCatTable}.oxactive = '1' ) ";
67  }
68 
69  return $sQAdd;
70  }
71 
75  public function removeCatFromAttr()
76  {
77  $aChosenCat = $this->_getActionIds('oxcategory2attribute.oxid');
78 
79 
80 
81  if (oxRegistry::getConfig()->getRequestParameter('all')) {
82  $sQ = $this->_addFilter("delete oxcategory2attribute.* " . $this->_getQuery());
83  oxDb::getDb()->Execute($sQ);
84  } elseif (is_array($aChosenCat)) {
85  $sChosenCategories = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
86  $sQ = "delete from oxcategory2attribute where oxcategory2attribute.oxid in (" . $sChosenCategories . ") ";
87  oxDb::getDb()->Execute($sQ);
88  }
89 
90 
91  $this->resetContentCache();
92 
93  }
94 
98  public function addCatToAttr()
99  {
100  $aAddCategory = $this->_getActionIds('oxcategories.oxid');
101  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
102 
103  $oAttribute = oxNew("oxattribute");
104  // adding
105  if (oxRegistry::getConfig()->getRequestParameter('all')) {
106  $sCatTable = $this->_getViewName('oxcategories');
107  $aAddCategory = $this->_getAll($this->_addFilter("select $sCatTable.oxid " . $this->_getQuery()));
108  }
109 
110  if ($oAttribute->load($soxId) && is_array($aAddCategory)) {
111  $oDb = oxDb::getDb();
112  foreach ($aAddCategory as $sAdd) {
113  $oNewGroup = oxNew("oxbase");
114  $oNewGroup->init("oxcategory2attribute");
115  $sOxSortField = 'oxcategory2attribute__oxsort';
116  $sObjectIdField = 'oxcategory2attribute__oxobjectid';
117  $sAttributeIdField = 'oxcategory2attribute__oxattrid';
118  $sOxIdField = 'oxattribute__oxid';
119  $oNewGroup->$sObjectIdField = new oxField($sAdd);
120  $oNewGroup->$sAttributeIdField = new oxField($oAttribute->$sOxIdField->value);
121  $sSql = "select max(oxsort) + 1 from oxcategory2attribute where oxobjectid = '$sAdd' ";
122  $oNewGroup->$sOxSortField = new oxField(( int ) $oDb->getOne($sSql, false, false));
123  $oNewGroup->save();
124  }
125  }
126 
127  $this->resetContentCache();
128  }
129 
130 }