OXID eShop CE  4.9.8
 All Classes Files Functions Variables Pages
article_extend_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', 'oxobject2category', 0, 0, 1),
25  array('oxtime', 'oxobject2category', 0, 0, 1),
26  array('oxid', 'oxcategories', 0, 0, 1)
27  ),
28  );
29 
35  protected function _getQuery()
36  {
37  $sCategoriesTable = $this->_getViewName('oxcategories');
38  $sO2CView = $this->_getViewName('oxobject2category');
39  $oDb = oxDb::getDb();
40 
41  $sOxid = oxRegistry::getConfig()->getRequestParameter('oxid');
42  $sSynchOxid = oxRegistry::getConfig()->getRequestParameter('synchoxid');
43 
44  if ($sOxid) {
45  // all categories article is in
46  $sQAdd = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
47  $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote($sOxid)
48  . " and $sCategoriesTable.oxid is not null ";
49  } else {
50  $sQAdd = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
51  $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView "
52  . "left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
53  $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote($sSynchOxid)
54  . " and $sCategoriesTable.oxid is not null ) and $sCategoriesTable.oxpriceto = '0'";
55  }
56 
57  return $sQAdd;
58  }
59 
67  protected function _getDataFields($sQ)
68  {
69  $aDataFields = parent::_getDataFields($sQ);
70  if (oxRegistry::getConfig()->getRequestParameter('oxid') && is_array($aDataFields) && count($aDataFields)) {
71 
72  // looking for smallest time value to mark record as main category ..
73  $iMinPos = null;
74  $iMinVal = null;
75  reset($aDataFields);
76  while (list($iPos, $aField) = each($aDataFields)) {
77 
78  // already set ?
79  if ($aField['_3'] == '0') {
80  $iMinPos = null;
81  break;
82  }
83 
84  if (!$iMinVal) {
85  $iMinVal = $aField['_3'];
86  $iMinPos = $iPos;
87  } elseif ($iMinVal > $aField['_3']) {
88  $iMinPos = $iPos;
89  }
90  }
91 
92  // setting primary category
93  if (isset($iMinPos)) {
94  $aDataFields[$iMinPos]['_3'] = '0';
95  }
96  }
97 
98  return $aDataFields;
99  }
100 
104  public function removeCat()
105  {
106  $myConfig = $this->getConfig();
107  $aRemoveCat = $this->_getActionIds('oxcategories.oxid');
108 
109  $soxId = oxRegistry::getConfig()->getRequestParameter('oxid');
110  $sShopID = $myConfig->getShopId();
111  $oDb = oxDb::getDb();
112 
113  // adding
114  if (oxRegistry::getConfig()->getRequestParameter('all')) {
115  $sCategoriesTable = $this->_getViewName('oxcategories');
116  $aRemoveCat = $this->_getAll($this->_addFilter("select {$sCategoriesTable}.oxid " . $this->_getQuery()));
117  }
118 
119  // removing all
120  if (is_array($aRemoveCat) && count($aRemoveCat)) {
121 
122  $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= "
123  . oxDb::getDb()->quote($soxId) . " and ";
124  $sQ .= " oxcatnid in (" . implode(', ', oxDb::getInstance()->quoteArray($aRemoveCat)) . ')';
125  $oDb->Execute($sQ);
126 
127  // updating oxtime values
128  $this->_updateOxTime($soxId);
129  }
130 
131  $this->resetArtSeoUrl($soxId, $aRemoveCat);
132  $this->resetContentCache();
133 
134  }
135 
139  public function addCat()
140  {
141  $myConfig = $this->getConfig();
142  $oDb = oxDb::getDb();
143  $aAddCat = $this->_getActionIds('oxcategories.oxid');
144  $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
145  $sShopID = $myConfig->getShopId();
146  $sO2CView = $this->_getViewName('oxobject2category');
147 
148  // adding
149  if (oxRegistry::getConfig()->getRequestParameter('all')) {
150  $sCategoriesTable = $this->_getViewName('oxcategories');
151  $aAddCat = $this->_getAll($this->_addFilter("select $sCategoriesTable.oxid " . $this->_getQuery()));
152  }
153 
154  if (isset($aAddCat) && is_array($aAddCat)) {
155 
156  $oDb = oxDb::getDb();
157 
158  $oNew = oxNew('oxobject2category');
159  $myUtilsObj = oxUtilsObject::getInstance();
160 
161  foreach ($aAddCat as $sAdd) {
162  // check, if it's already in, then don't add it again
163  $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= "
164  . $oDb->quote($sAdd) . " and oxobject2category.oxobjectid = " . $oDb->quote($soxId) . " ";
165  if ($oDb->getOne($sSelect, false, false)) {
166  continue;
167  }
168 
169  $oNew->setId(md5($soxId . $sAdd . $sShopID));
170  $oNew->oxobject2category__oxobjectid = new oxField($soxId);
171  $oNew->oxobject2category__oxcatnid = new oxField($sAdd);
172  $oNew->oxobject2category__oxtime = new oxField(time());
173 
174  $oNew->save();
175  }
176 
177  $this->_updateOxTime($soxId);
178 
179  $this->resetArtSeoUrl($soxId);
180  $this->resetContentCache();
181 
182  }
183  }
184 
190  protected function _updateOxTime($soxId)
191  {
192  $oDb = oxDb::getDb();
193  $sO2CView = $this->_getViewName('oxobject2category');
194  $soxId = $oDb->quote($soxId);
195  $sSqlShopFilter = "";
196  // updating oxtime values
197  $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} {$sSqlShopFilter} and oxid = (
198  select oxid from (
199  select oxid from {$sO2CView} where oxobjectid = {$soxId} {$sSqlShopFilter}
200  order by oxtime limit 1
201  ) as _tmp
202  )";
203  $oDb->execute($sQ);
204  }
205 
209  public function setAsDefault()
210  {
211  $sDefCat = oxRegistry::getConfig()->getRequestParameter("defcat");
212  $soxId = oxRegistry::getConfig()->getRequestParameter("oxid");
213  $oDb = oxDb::getDb();
214 
215  $sQuotedOxId = $oDb->quote($soxId);
216  $sQuotedDefCat = $oDb->quote($sDefCat);
217 
218  $sSqlShopFilter = "";
219 
220  // #0003650: increment all product references independent to active shop
221  $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = {$sQuotedOxId} {$sSqlShopFilter}";
222  oxDb::getInstance()->getDb()->Execute($sQ);
223 
224  // set main category for active shop
225  $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$sQuotedOxId} " .
226  "and oxcatnid = {$sQuotedDefCat} {$sSqlShopFilter}";
227  oxDb::getInstance()->getDb()->Execute($sQ);
228  //echo "\n$sQ\n";
229 
230  // #0003366: invalidate article SEO for all shops
231  oxRegistry::get("oxSeoEncoder")->markAsExpired($soxId, null, 1, null, "oxtype='oxarticle'");
232  $this->resetContentCache();
233  }
234 }