OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
article_selection_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', 'oxselectlist', 1, 1, 0 ),
15  array( 'oxident', 'oxselectlist', 1, 0, 0 ),
16  array( 'oxvaldesc', 'oxselectlist', 1, 0, 0 ),
17  array( 'oxid', 'oxselectlist', 0, 0, 1 )
18  ),
19  'container2' => array(
20  array( 'oxtitle', 'oxselectlist', 1, 1, 0 ),
21  array( 'oxident', 'oxselectlist', 1, 0, 0 ),
22  array( 'oxvaldesc', 'oxselectlist', 1, 0, 0 ),
23  array( 'oxid', 'oxobject2selectlist', 0, 0, 1 )
24  )
25  );
26 
32  protected function _getQuery()
33  {
34  $sSLViewName = $this->_getViewName('oxselectlist');
35  $sArtViewName = $this->_getViewName('oxarticles');
36  $oDb = oxDb::getDb();
37 
38  $sArtId = oxConfig::getParameter( 'oxid' );
39  $sSynchArtId = oxConfig::getParameter( 'synchoxid' );
40 
41  $sOxid = ( $sArtId ) ? $sArtId : $sSynchArtId;
42  $sQ = "select oxparentid from $sArtViewName where oxid = " . $oDb->quote( $sOxid ) . " and oxparentid != '' ";
43  $sQ .= "and (select count(oxobjectid) from oxobject2selectlist where oxobjectid = " . $oDb->quote( $sOxid ) . ") = 0";
44  $sParentId = oxDb::getDb()->getOne( $sQ, false, false );
45 
46  // all selectlists article is in
47  $sQAdd = " from oxobject2selectlist left join $sSLViewName on $sSLViewName.oxid=oxobject2selectlist.oxselnid ";
48  $sQAdd .= " where oxobject2selectlist.oxobjectid = " . $oDb->quote( $sOxid ) . " ";
49  if ( $sParentId ) {
50  $sQAdd .= "or oxobject2selectlist.oxobjectid = " . $oDb->quote( $sParentId ) . " ";
51  }
52  // all not assigned selectlists
53  if ( $sSynchArtId ) {
54  $sQAdd = " from $sSLViewName where $sSLViewName.oxid not in ( select oxobject2selectlist.oxselnid $sQAdd ) ";
55  }
56 
57  return $sQAdd;
58  }
59 
65  public function removeSel()
66  {
67  $aChosenArt = $this->_getActionIds( 'oxobject2selectlist.oxid' );
68  if ( oxConfig::getParameter( 'all' ) ) {
69 
70  $sQ = $this->_addFilter( "delete oxobject2selectlist.* ".$this->_getQuery() );
71  oxDb::getDb()->Execute( $sQ );
72  } elseif ( is_array( $aChosenArt ) ) {
73  $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode( ", ", oxDb::getInstance()->quoteArray( $aChosenArt ) ) . ") ";
74  oxDb::getDb()->Execute( $sQ );
75  }
76 
77  }
78 
84  public function addSel()
85  {
86  $aAddSel = $this->_getActionIds( 'oxselectlist.oxid' );
87  $soxId = oxConfig::getParameter( 'synchoxid');
88 
89  // adding
90  if ( oxConfig::getParameter( 'all' ) ) {
91  $sSLViewName = $this->_getViewName('oxselectlist');
92  $aAddSel = $this->_getAll( $this->_addFilter( "select $sSLViewName.oxid ".$this->_getQuery() ) );
93  }
94 
95  if ( $soxId && $soxId != "-1" && is_array( $aAddSel ) ) {
96  $oDb = oxDb::getDb();
97  foreach ($aAddSel as $sAdd) {
98  $oNew = oxNew( "oxbase" );
99  $oNew->init( "oxobject2selectlist" );
100  $oNew->oxobject2selectlist__oxobjectid = new oxField($soxId);
101  $oNew->oxobject2selectlist__oxselnid = new oxField($sAdd);
102  $oNew->oxobject2selectlist__oxsort = new oxField( ( int ) $oDb->getOne( "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = " . $oDb->quote( $soxId ) . " ", false, false ) );
103  $oNew->save();
104  }
105 
106  }
107  }
108 }