OXID eShop CE  4.9.6
 All Classes Files Functions Variables Pages
selectlist_main_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
8 
14  protected $_blAllowExtColumns = true;
15 
21  protected $_aColumns = array('container1' => array( // field , table, visible, multilanguage, ident
22  array('oxartnum', 'oxarticles', 1, 0, 0),
23  array('oxtitle', 'oxarticles', 1, 1, 0),
24  array('oxean', 'oxarticles', 0, 0, 0),
25  array('oxmpn', 'oxarticles', 0, 0, 0),
26  array('oxprice', 'oxarticles', 0, 0, 0),
27  array('oxstock', 'oxarticles', 0, 0, 0),
28  array('oxid', 'oxarticles', 0, 0, 1)
29  ),
30  'container2' => array(
31  array('oxartnum', 'oxarticles', 1, 0, 0),
32  array('oxtitle', 'oxarticles', 1, 1, 0),
33  array('oxean', 'oxarticles', 0, 0, 0),
34  array('oxmpn', 'oxarticles', 0, 0, 0),
35  array('oxprice', 'oxarticles', 0, 0, 0),
36  array('oxstock', 'oxarticles', 0, 0, 0),
37  array('oxid', 'oxobject2selectlist', 0, 0, 1),
38  array('oxid', 'oxarticles', 0, 0, 1)
39  ),
40  'container3' => array(
41  array('oxtitle', 'oxselectlist', 1, 1, 0),
42  array('oxsort', 'oxobject2selectlist', 1, 0, 0),
43  array('oxident', 'oxselectlist', 0, 0, 0),
44  array('oxvaldesc', 'oxselectlist', 0, 0, 0),
45  array('oxid', 'oxselectlist', 0, 0, 1)
46  )
47  );
48 
54  protected function _getQuery()
55  {
56  $myConfig = $this->getConfig();
57 
58  // looking for table/view
59  $sArtTable = $this->_getViewName('oxarticles');
60  $sCatTable = $this->_getViewName('oxcategories');
61  $sO2CView = $this->_getViewName('oxobject2category');
62  $oDb = oxDb::getDb();
63  $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
64  $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
65 
66  // category selected or not ?
67  if (!$sSelId) {
68  // performance
69  $sQAdd = " from $sArtTable where 1 ";
70  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
71  } else {
72  // selected category ?
73  if ($sSynchSelId && $sSelId != $sSynchSelId) {
74  $sQAdd = " from $sO2CView as oxobject2category left join $sArtTable on ";
75  $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid=oxobject2category.oxobjectid or $sArtTable.oxparentid=oxobject2category.oxobjectid ) " : " $sArtTable.oxid=oxobject2category.oxobjectid ";
76  $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote($sSelId);
77  } else {
78  $sQAdd = " from $sArtTable left join oxobject2selectlist on $sArtTable.oxid=oxobject2selectlist.oxobjectid ";
79  $sQAdd .= " where oxobject2selectlist.oxselnid = " . $oDb->quote($sSelId);
80  }
81  }
82 
83  if ($sSynchSelId && $sSynchSelId != $sSelId) {
84  // performance
85  $sQAdd .= " and $sArtTable.oxid not in ( select oxobject2selectlist.oxobjectid from oxobject2selectlist ";
86  $sQAdd .= " where oxobject2selectlist.oxselnid = " . $oDb->quote($sSynchSelId) . " ) ";
87  }
88 
89  return $sQAdd;
90  }
91 
95  public function removeArtFromSel()
96  {
97  $aChosenArt = $this->_getActionIds('oxobject2selectlist.oxid');
98 
99 
100 
101 
102  if (oxRegistry::getConfig()->getRequestParameter('all')) {
103 
104  $sQ = parent::_addFilter("delete oxobject2selectlist.* " . $this->_getQuery());
105  oxDb::getDb()->Execute($sQ);
106 
107  } elseif (is_array($aChosenArt)) {
108  $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenArt)) . ") ";
109  oxDb::getDb()->Execute($sQ);
110  }
111  }
112 
116  public function addArtToSel()
117  {
118  $aAddArticle = $this->_getActionIds('oxarticles.oxid');
119  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
120 
121  if (oxRegistry::getConfig()->getRequestParameter('all')) {
122  $sArtTable = $this->_getViewName('oxarticles');
123  $aAddArticle = $this->_getAll(parent::_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
124  }
125 
126  if ($soxId && $soxId != "-1" && is_array($aAddArticle)) {
127  $oDb = oxDb::getDb();
128  foreach ($aAddArticle as $sAdd) {
129  $oNewGroup = oxNew("oxbase");
130  $oNewGroup->init("oxobject2selectlist");
131  $oNewGroup->oxobject2selectlist__oxobjectid = new oxField($sAdd);
132  $oNewGroup->oxobject2selectlist__oxselnid = new oxField($soxId);
133  $oNewGroup->oxobject2selectlist__oxsort = new oxField(( int ) $oDb->getOne("select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = " . $oDb->quote($sAdd) . " ", false, false));
134  $oNewGroup->save();
135 
136  }
137  }
138 
139 
140  }
141 }