OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
delivery_categories_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', 'oxobject2delivery', 0, 0, 1 ),
24  array( 'oxid', 'oxcategories', 0, 0, 1 )
25  ),
26  );
27 
33  protected function _getQuery()
34  {
35  // looking for table/view
36  $sCatTable = $this->_getViewName('oxcategories');
37  $oDb = oxDb::getDb();
38  $sDelId = $this->getConfig()->getRequestParameter( 'oxid' );
39  $sSynchDelId = $this->getConfig()->getRequestParameter( 'synchoxid' );
40 
41  // category selected or not ?
42  if ( !$sDelId) {
43  $sQAdd = " from $sCatTable ";
44  } else {
45  $sQAdd = " from oxobject2delivery left join $sCatTable on $sCatTable.oxid=oxobject2delivery.oxobjectid ";
46  $sQAdd .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sDelId )." and oxobject2delivery.oxtype = 'oxcategories' ";
47  }
48 
49  if ( $sSynchDelId && $sSynchDelId != $sDelId) {
50  // dodger performance
51  $sSubSelect = " select $sCatTable.oxid from oxobject2delivery left join $sCatTable on $sCatTable.oxid=oxobject2delivery.oxobjectid ";
52  $sSubSelect .= " where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sSynchDelId )." and oxobject2delivery.oxtype = 'oxcategories' ";
53  if ( stristr( $sQAdd, 'where' ) === false )
54  $sQAdd .= ' where ';
55  else
56  $sQAdd .= ' and ';
57  $sQAdd .= " $sCatTable.oxid not in ( $sSubSelect ) ";
58  }
59 
60  return $sQAdd;
61  }
62 
68  public function removeCatFromDel()
69  {
70  $aChosenCat = $this->_getActionIds( 'oxobject2delivery.oxid' );
71 
72  // removing all
73  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
74 
75  $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
76  oxDb::getDb()->Execute( $sQ );
77 
78  } elseif ( is_array( $aChosenCat ) ) {
79  $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
80  oxDb::getDb()->Execute( $sQ );
81  }
82  }
83 
89  public function addCatToDel()
90  {
91  $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
92  $soxId = $this->getConfig()->getRequestParameter( 'synchoxid');
93 
94  // adding
95  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
96  $sCatTable = $this->_getViewName('oxcategories');
97  $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
98  }
99 
100  if ( isset( $soxId) && $soxId != "-1" && isset( $aChosenCat) && $aChosenCat) {
101  foreach ( $aChosenCat as $sChosenCat) {
102  $oObject2Delivery = oxNew( 'oxbase' );
103  $oObject2Delivery->init( 'oxobject2delivery' );
104  $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
105  $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCat);
106  $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxcategories");
107  $oObject2Delivery->save();
108  }
109  }
110  }
111 }