OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
discount_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', 'oxobject2discount', 0, 0, 1 ),
24  array( 'oxid', 'oxcategories', 0, 0, 1 )
25  ),
26  );
27 
33  protected function _getQuery()
34  {
35  $oDb = oxDb::getDb();
36  $oConfig = $this->getConfig();
37  $sId = $oConfig->getRequestParameter( 'oxid' );
38  $sSynchId = $oConfig->getRequestParameter( 'synchoxid' );
39 
40  $sCategoryTable = $this->_getViewName('oxcategories');
41 
42  // category selected or not ?
43  if ( !$sId) {
44  $sQAdd = " from $sCategoryTable";
45  } else {
46  $sQAdd = " from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
47  $sQAdd .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sId )." and oxobject2discount.oxtype = 'oxcategories' ";
48  }
49 
50  if ( $sSynchId && $sSynchId != $sId) {
51  // dodger performance
52  $sSubSelect = " select $sCategoryTable.oxid from oxobject2discount, $sCategoryTable where $sCategoryTable.oxid=oxobject2discount.oxobjectid ";
53  $sSubSelect .= " and oxobject2discount.oxdiscountid = ".$oDb->quote( $sSynchId )." and oxobject2discount.oxtype = 'oxcategories' ";
54  if ( stristr( $sQAdd, 'where' ) === false )
55  $sQAdd .= ' where ';
56  else
57  $sQAdd .= ' and ';
58  $sQAdd .= " $sCategoryTable.oxid not in ( $sSubSelect ) ";
59  }
60 
61  return $sQAdd;
62  }
63 
69  public function removeDiscCat()
70  {
71  $oConfig = $this->getConfig();
72  $aChosenCat = $this->_getActionIds( 'oxobject2discount.oxid' );
73 
74 
75  if ( $oConfig->getRequestParameter( 'all' ) ) {
76 
77  $sQ = $this->_addFilter( "delete oxobject2discount.* ".$this->_getQuery() );
78  oxDb::getDb()->Execute( $sQ );
79 
80  } elseif ( is_array( $aChosenCat ) ) {
81  $sQ = "delete from oxobject2discount where oxobject2discount.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
82  oxDb::getDb()->Execute( $sQ );
83  }
84  }
85 
91  public function addDiscCat()
92  {
93  $oConfig = $this->getConfig();
94  $aChosenCat = $this->_getActionIds( 'oxcategories.oxid' );
95  $soxId = $oConfig->getRequestParameter( 'synchoxid');
96 
97 
98  if ( $oConfig->getRequestParameter( 'all' ) ) {
99  $sCategoryTable = $this->_getViewName('oxcategories');
100  $aChosenCat = $this->_getAll( $this->_addFilter( "select $sCategoryTable.oxid ".$this->_getQuery() ) );
101  }
102  if ( $soxId && $soxId != "-1" && is_array( $aChosenCat ) ) {
103  foreach ( $aChosenCat as $sChosenCat) {
104  $oObject2Discount = oxNew( "oxbase" );
105  $oObject2Discount->init( 'oxobject2discount' );
106  $oObject2Discount->oxobject2discount__oxdiscountid = new oxField($soxId);
107  $oObject2Discount->oxobject2discount__oxobjectid = new oxField($sChosenCat);
108  $oObject2Discount->oxobject2discount__oxtype = new oxField("oxcategories");
109  $oObject2Discount->save();
110  }
111  }
112 
113  }
114 }