OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
article_extend_ajax.php
Go to the documentation of this file.
1 <?php
2 
7 {
13  protected $_aColumns = array( 'container1' => array( // field , table, visible, multilanguage, ident
14  array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
15  array( 'oxdesc', 'oxcategories', 1, 1, 0 ),
16  array( 'oxid', 'oxcategories', 0, 0, 0 ),
17  array( 'oxid', 'oxcategories', 0, 0, 1 )
18  ),
19  'container2' => array(
20  array( 'oxtitle', 'oxcategories', 1, 1, 0 ),
21  array( 'oxdesc', 'oxcategories', 1, 1, 0 ),
22  array( 'oxid', 'oxcategories', 0, 0, 0 ),
23  array( 'oxid', 'oxobject2category', 0, 0, 1 ),
24  array( 'oxtime', 'oxobject2category', 0, 0, 1 ),
25  array( 'oxid', 'oxcategories', 0, 0, 1 )
26  ),
27  );
28 
34  protected function _getQuery()
35  {
36  $sCategoriesTable = $this->_getViewName( 'oxcategories' );
37  $sO2CView = $this->_getViewName( 'oxobject2category' );
38  $oDb = oxDb::getDb();
39 
40  $sOxid = oxConfig::getParameter( 'oxid' );
41  $sSynchOxid = oxConfig::getParameter( 'synchoxid' );
42 
43  if ( $sOxid ) {
44  // all categories article is in
45  $sQAdd = " from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
46  $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sOxid ) . " and $sCategoriesTable.oxid is not null ";
47  } else {
48  $sQAdd = " from $sCategoriesTable where $sCategoriesTable.oxid not in ( ";
49  $sQAdd .= " select $sCategoriesTable.oxid from $sO2CView left join $sCategoriesTable on $sCategoriesTable.oxid=$sO2CView.oxcatnid ";
50  $sQAdd .= " where $sO2CView.oxobjectid = " . $oDb->quote( $sSynchOxid ) . " and $sCategoriesTable.oxid is not null ) and $sCategoriesTable.oxpriceto = '0'";
51  }
52 
53  return $sQAdd;
54  }
55 
63  protected function _getDataFields( $sQ )
64  {
65  $aDataFields = parent::_getDataFields( $sQ );
66  if ( oxConfig::getParameter( 'oxid' ) && is_array( $aDataFields ) && count( $aDataFields ) ) {
67 
68  // looking for smallest time value to mark record as main category ..
69  $iMinPos = null;
70  $iMinVal = null;
71  reset( $aDataFields );
72  while ( list( $iPos, $aField ) = each( $aDataFields ) ) {
73 
74  // already set ?
75  if ( $aField['_3'] == '0' ) {
76  $iMinPos = null;
77  break;
78  }
79 
80  if ( !$iMinVal ) {
81  $iMinVal = $aField['_3'];
82  $iMinPos = $iPos;
83  } elseif ( $iMinVal > $aField['_3'] ) {
84  $iMinPos = $iPos;
85  }
86  }
87 
88  // setting primary category
89  if ( isset( $iMinPos ) ) {
90  $aDataFields[$iMinPos]['_3'] = '0';
91  }
92  }
93 
94  return $aDataFields;
95  }
96 
102  public function removeCat()
103  {
104  $myConfig = $this->getConfig();
105  $aRemoveCat = $this->_getActionIds( 'oxcategories.oxid' );
106 
107  $soxId = oxConfig::getParameter( 'oxid' );
108  $sShopID = $myConfig->getShopId();
109  $oDb = oxDb::getDb();
110 
111  // adding
112  if ( oxConfig::getParameter( 'all' ) ) {
113  $sCategoriesTable = $this->_getViewName( 'oxcategories' );
114  $aRemoveCat = $this->_getAll( $this->_addFilter( "select {$sCategoriesTable}.oxid ".$this->_getQuery() ) );
115  }
116 
117  // removing all
118  if ( is_array( $aRemoveCat ) && count( $aRemoveCat ) ) {
119 
120  $sQ = "delete from oxobject2category where oxobject2category.oxobjectid= " . oxDb::getDb()->quote( $soxId ) . " and ";
121  $sQ .= " oxcatnid in (" . implode( ', ', oxDb::getInstance()->quoteArray( $aRemoveCat ) ) . ')';
122  $oDb->Execute( $sQ );
123  //echo "\n$sQ\n___________________";
124 
125 
126  // updating oxtime values
127  $this->_updateOxTime( $soxId );
128  }
129 
130  $this->resetArtSeoUrl( $soxId, $aRemoveCat );
131  $this->resetContentCache();
132 
133  }
134 
140  public function addCat()
141  {
142  $myConfig = $this->getConfig();
143  $oDb = oxDb::getDb();
144  $aAddCat = $this->_getActionIds( 'oxcategories.oxid' );
145  $soxId = oxConfig::getParameter( 'synchoxid' );
146  $sShopID = $myConfig->getShopId();
147  $sO2CView = $this->_getViewName('oxobject2category');
148 
149  // adding
150  if ( oxConfig::getParameter( 'all' ) ) {
151  $sCategoriesTable = $this->_getViewName( 'oxcategories' );
152  $aAddCat = $this->_getAll( $this->_addFilter( "select $sCategoriesTable.oxid ".$this->_getQuery() ) );
153  }
154 
155  if ( isset( $aAddCat) && is_array($aAddCat)) {
156 
157  $oDb = oxDb::getDb();
158 
159  $oNew = oxNew( 'oxbase' );
160  $oNew->init( 'oxobject2category' );
161  $myUtilsObj = oxUtilsObject::getInstance();
162 
163  foreach ( $aAddCat as $sAdd ) {
164 
165  // check, if it's already in, then don't add it again
166  $sSelect = "select 1 from " . $sO2CView . " as oxobject2category where oxobject2category.oxcatnid= " . $oDb->quote( $sAdd ) . " and oxobject2category.oxobjectid = " . $oDb->quote( $soxId ) . " ";
167  if ( $oDb->getOne( $sSelect, false, false ) )
168  continue;
169 
170  $oNew->setId( $myUtilsObj->generateUID() );
171  $oNew->oxobject2category__oxobjectid = new oxField( $soxId );
172  $oNew->oxobject2category__oxcatnid = new oxField( $sAdd );
173  $oNew->oxobject2category__oxtime = new oxField( time() );
174 
175 
176  $oNew->save();
177  }
178 
179  $this->_updateOxTime( $soxId );
180 
181  $this->resetArtSeoUrl( $soxId );
182  $this->resetContentCache();
183 
184 
185  }
186  }
187 
195  protected function _updateOxTime( $soxId )
196  {
197  $oDb = oxDb::getDb();
198  $sO2CView = $this->_getViewName('oxobject2category');
199  $soxId = $oDb->quote( $soxId );
200 
201  // updating oxtime values
202  $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = {$soxId} and oxid = (
203  select oxid from (
204  select oxid from {$sO2CView} where oxobjectid = {$soxId} order by oxtime limit 1
205  ) as _tmp
206  )";
207  $oDb->execute( $sQ );
208  }
209 
215  public function setAsDefault()
216  {
217  $myConfig = $this->getConfig();
218  $sDefCat = oxConfig::getParameter( "defcat" );
219  $soxId = oxConfig::getParameter( "oxid" );
220  $sShopId = $myConfig->getShopId();
221  $oDb = oxDb::getDb();
222 
223  $sShopCheck = "";
224 
225  // #0003650: increment all product references independent to active shop
226  $sQ = "update oxobject2category set oxtime = oxtime + 10 where oxobjectid = " . $oDb->quote( $soxId );
227  oxDb::getInstance()->getDb()->Execute($sQ);
228 
229  // set main category for active shop
230  $sQ = "update oxobject2category set oxtime = 0 where oxobjectid = " . $oDb->quote( $soxId ) . " and oxcatnid = " . $oDb->quote( $sDefCat ) . " $sShopCheck ";
231  oxDb::getInstance()->getDb()->Execute($sQ);
232  //echo "\n$sQ\n";
233 
234  // #0003366: invalidate article SEO for all shops
235  oxRegistry::get("oxSeoEncoder")->markAsExpired( $soxId, null, 1, null, "oxtype='oxarticle'" );
236  $this->resetContentCache();
237  }
238 }