OXID eShop CE  4.10.8
 All Classes Namespaces Files Functions Variables Pages
article_selection_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', 'oxselectlist', 1, 1, 0),
16  array('oxident', 'oxselectlist', 1, 0, 0),
17  array('oxvaldesc', 'oxselectlist', 1, 0, 0),
18  array('oxid', 'oxselectlist', 0, 0, 1)
19  ),
20  'container2' => array(
21  array('oxtitle', 'oxselectlist', 1, 1, 0),
22  array('oxident', 'oxselectlist', 1, 0, 0),
23  array('oxvaldesc', 'oxselectlist', 1, 0, 0),
24  array('oxid', 'oxobject2selectlist', 0, 0, 1)
25  )
26  );
27 
33  protected function _getQuery()
34  {
35  $sSLViewName = $this->_getViewName('oxselectlist');
36  $sArtViewName = $this->_getViewName('oxarticles');
37  $oDb = oxDb::getDb();
38 
39  $sArtId = oxRegistry::getConfig()->getRequestParameter('oxid');
40  $sSynchArtId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
41 
42  $sOxid = ($sArtId) ? $sArtId : $sSynchArtId;
43  $sQ = "select oxparentid from {$sArtViewName} where oxid = " . $oDb->quote($sOxid) . " and oxparentid != '' ";
44  $sQ .= "and (select count(oxobjectid) from oxobject2selectlist " .
45  "where oxobjectid = " . $oDb->quote($sOxid) . ") = 0";
46  $sParentId = oxDb::getDb()->getOne($sQ, false, false);
47 
48  // all selectlists article is in
49  $sQAdd = " from oxobject2selectlist left join {$sSLViewName} " .
50  "on {$sSLViewName}.oxid=oxobject2selectlist.oxselnid " .
51  "where oxobject2selectlist.oxobjectid = " . $oDb->quote($sOxid) . " ";
52  if ($sParentId) {
53  $sQAdd .= "or oxobject2selectlist.oxobjectid = " . $oDb->quote($sParentId) . " ";
54  }
55  // all not assigned selectlists
56  if ($sSynchArtId) {
57  $sQAdd = " from {$sSLViewName} " .
58  "where {$sSLViewName}.oxid not in ( select oxobject2selectlist.oxselnid {$sQAdd} ) ";
59  }
60 
61  return $sQAdd;
62  }
63 
67  public function removeSel()
68  {
69  $aChosenArt = $this->_getActionIds('oxobject2selectlist.oxid');
70  if (oxRegistry::getConfig()->getRequestParameter('all')) {
71 
72  $sQ = $this->_addFilter("delete oxobject2selectlist.* " . $this->_getQuery());
73  oxDb::getDb()->Execute($sQ);
74  } elseif (is_array($aChosenArt)) {
75  $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
76  $sQ = "delete from oxobject2selectlist " .
77  "where oxobject2selectlist.oxid in (" . $sChosenArticles . ") ";
78  oxDb::getDb()->Execute($sQ);
79  }
80 
81  }
82 
86  public function addSel()
87  {
88  $aAddSel = $this->_getActionIds('oxselectlist.oxid');
89  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
90 
91  // adding
92  if (oxRegistry::getConfig()->getRequestParameter('all')) {
93  $sSLViewName = $this->_getViewName('oxselectlist');
94  $aAddSel = $this->_getAll($this->_addFilter("select $sSLViewName.oxid " . $this->_getQuery()));
95  }
96 
97  if ($soxId && $soxId != "-1" && is_array($aAddSel)) {
98  $oDb = oxDb::getDb();
99  foreach ($aAddSel as $sAdd) {
100  $oNew = oxNew("oxbase");
101  $oNew->init("oxobject2selectlist");
102  $sObjectIdField = 'oxobject2selectlist__oxobjectid';
103  $sSelectetionIdField = 'oxobject2selectlist__oxselnid';
104  $sOxSortField = 'oxobject2selectlist__oxsort';
105  $oNew->$sObjectIdField = new oxField($soxId);
106  $oNew->$sSelectetionIdField = new oxField($sAdd);
107  $sSql = "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = {$oDb->quote($soxId)} ";
108  $oNew->$sOxSortField = new oxField(( int ) $oDb->getOne($sSql, false, false));
109  $oNew->save();
110  }
111 
112  }
113  }
114 }