OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
deliveryset_country_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', 'oxcountry', 1, 1, 0 ),
15  array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
16  array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
17  array( 'oxunnum3', 'oxcountry', 0, 0, 0 ),
18  array( 'oxid', 'oxcountry', 0, 0, 1 )
19  ),
20  'container2' => array(
21  array( 'oxtitle', 'oxcountry', 1, 1, 0 ),
22  array( 'oxisoalpha2', 'oxcountry', 1, 0, 0 ),
23  array( 'oxisoalpha3', 'oxcountry', 0, 0, 0 ),
24  array( 'oxunnum3', 'oxcountry', 0, 0, 0 ),
25  array( 'oxid', 'oxobject2delivery', 0, 0, 1 )
26  )
27  );
28 
34  protected function _getQuery()
35  {
36  $oDb = oxDb::getDb();
37  $sId = $this->getConfig()->getRequestParameter( 'oxid' );
38  $sSynchId = $this->getConfig()->getRequestParameter( 'synchoxid' );
39 
40  $sCountryTable = $this->_getViewName('oxcountry');
41 
42  // category selected or not ?
43  if ( !$sId ) {
44  $sQAdd = " from $sCountryTable where $sCountryTable.oxactive = '1' ";
45  } else {
46  $sQAdd = " from oxobject2delivery, $sCountryTable where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sId );
47  $sQAdd .= " and oxobject2delivery.oxobjectid = $sCountryTable.oxid and oxobject2delivery.oxtype = 'oxdelset' ";
48  }
49 
50  if ( $sSynchId && $sSynchId != $sId) {
51  $sQAdd .= "and $sCountryTable.oxid not in ( select $sCountryTable.oxid from oxobject2delivery, $sCountryTable where oxobject2delivery.oxdeliveryid = ".$oDb->quote( $sSynchId );
52  $sQAdd .= "and oxobject2delivery.oxobjectid = $sCountryTable.oxid and oxobject2delivery.oxtype = 'oxdelset' ) ";
53  }
54 
55  return $sQAdd;
56  }
57 
63  public function removeCountryFromSet()
64  {
65  $aChosenCntr = $this->_getActionIds( 'oxobject2delivery.oxid' );
66  // removing all
67  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
68 
69  $sQ = $this->_addFilter( "delete oxobject2delivery.* ".$this->_getQuery() );
70  oxDb::getDb()->Execute( $sQ );
71 
72  } elseif ( is_array( $aChosenCntr ) ) {
73  $sQ = "delete from oxobject2delivery where oxobject2delivery.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCntr ) ) . ") ";
74  oxDb::getDb()->Execute( $sQ );
75  }
76  }
77 
83  public function addCountryToSet()
84  {
85  $aChosenCntr = $this->_getActionIds( 'oxcountry.oxid' );
86  $soxId = $this->getConfig()->getRequestParameter( 'synchoxid');
87 
88  // adding
89  if ( $this->getConfig()->getRequestParameter( 'all' ) ) {
90  $sCountryTable = $this->_getViewName('oxcountry');
91  $aChosenCntr = $this->_getAll( $this->_addFilter( "select $sCountryTable.oxid ".$this->_getQuery() ) );
92  }
93 
94  if ( $soxId && $soxId != "-1" && is_array( $aChosenCntr ) ) {
95  foreach ( $aChosenCntr as $sChosenCntr) {
96  $oObject2Delivery = oxNew( 'oxbase' );
97  $oObject2Delivery->init( 'oxobject2delivery' );
98  $oObject2Delivery->oxobject2delivery__oxdeliveryid = new oxField($soxId);
99  $oObject2Delivery->oxobject2delivery__oxobjectid = new oxField($sChosenCntr);
100  $oObject2Delivery->oxobject2delivery__oxtype = new oxField("oxdelset");
101  $oObject2Delivery->save();
102  }
103  }
104  }
105 }