OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
attribute_category_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', 'oxcategory2attribute', 0, 0, 1 ),
24  array( 'oxid', 'oxcategories', 0, 0, 1 )
25  ),
26  'container3' => array(
27  array( 'oxtitle', 'oxattribute', 1, 1, 0 ),
28  array( 'oxsort', 'oxcategory2attribute', 1, 0, 0 ),
29  array( 'oxid', 'oxcategory2attribute', 0, 0, 1 )
30  )
31  );
32 
38  protected function _getQuery()
39  {
40  $myConfig = $this->getConfig();
41  $oDb = oxDb::getDb();
42 
43  $sCatTable = $this->_getViewName('oxcategories');
44  $sDiscountId = oxConfig::getParameter( 'oxid' );
45  $sSynchDiscountId = oxConfig::getParameter( 'synchoxid' );
46 
47  // category selected or not ?
48  if ( !$sDiscountId) {
49  $sQAdd = " from $sCatTable where $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
50  $sQAdd .= " and $sCatTable.oxactive = '1' ";
51  } else {
52  $sQAdd = " from $sCatTable left join oxcategory2attribute on $sCatTable.oxid=oxcategory2attribute.oxobjectid ";
53  $sQAdd .= " where oxcategory2attribute.oxattrid = " . $oDb->quote( $sDiscountId ) . " and $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
54  $sQAdd .= " and $sCatTable.oxactive = '1' ";
55  }
56 
57  if ( $sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
58  $sQAdd .= " and $sCatTable.oxid not in ( select $sCatTable.oxid from $sCatTable left join oxcategory2attribute on $sCatTable.oxid=oxcategory2attribute.oxobjectid ";
59  $sQAdd .= " where oxcategory2attribute.oxattrid = " . $oDb->quote( $sSynchDiscountId ) . " and $sCatTable.oxshopid = '".$myConfig->getShopId()."' ";
60  $sQAdd .= " and $sCatTable.oxactive = '1' ) ";
61  }
62 
63  return $sQAdd;
64  }
65 
71  public function removeCatFromAttr()
72  {
73  $aChosenCat = $this->_getActionIds( 'oxcategory2attribute.oxid' );
74 
75 
76 
77  if ( oxConfig::getParameter( 'all' ) ) {
78  $sQ = $this->_addFilter( "delete oxcategory2attribute.* ".$this->_getQuery() );
79  oxDb::getDb()->Execute( $sQ );
80  } elseif ( is_array( $aChosenCat ) ) {
81  $sQ = "delete from oxcategory2attribute where oxcategory2attribute.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenCat ) ) . ") ";
82  oxDb::getDb()->Execute( $sQ );
83  }
84 
85 
86 
87  $this->resetContentCache();
88 
89  }
90 
96  public function addCatToAttr()
97  {
98  $aAddCategory = $this->_getActionIds( 'oxcategories.oxid' );
99  $soxId = oxConfig::getParameter( 'synchoxid');
100 
101  $oAttribute = oxNew( "oxattribute" );
102  // adding
103  if ( oxConfig::getParameter( 'all' ) ) {
104  $sCatTable = $this->_getViewName('oxcategories');
105  $aAddCategory = $this->_getAll( $this->_addFilter( "select $sCatTable.oxid ".$this->_getQuery() ) );
106  }
107 
108  if ( $oAttribute->load( $soxId ) && is_array( $aAddCategory ) ) {
109  $oDb = oxDb::getDb();
110  foreach ($aAddCategory as $sAdd) {
111  $oNewGroup = oxNew( "oxbase" );
112  $oNewGroup->init( "oxcategory2attribute" );
113  $oNewGroup->oxcategory2attribute__oxobjectid = new oxField($sAdd);
114  $oNewGroup->oxcategory2attribute__oxattrid = new oxField($oAttribute->oxattribute__oxid->value);
115  $oNewGroup->oxcategory2attribute__oxsort = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxcategory2attribute where oxobjectid = '$sAdd' ", false, false ) );
116  $oNewGroup->save();
117  }
118  }
119 
120  $this->resetContentCache();
121  }
122 
123 
124 }