00001 <?php
00002
00006 class selectlist_main_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_blAllowExtColumns = true;
00015
00021 protected $_aColumns = array('container1' => array(
00022 array('oxartnum', 'oxarticles', 1, 0, 0),
00023 array('oxtitle', 'oxarticles', 1, 1, 0),
00024 array('oxean', 'oxarticles', 0, 0, 0),
00025 array('oxmpn', 'oxarticles', 0, 0, 0),
00026 array('oxprice', 'oxarticles', 0, 0, 0),
00027 array('oxstock', 'oxarticles', 0, 0, 0),
00028 array('oxid', 'oxarticles', 0, 0, 1)
00029 ),
00030 'container2' => array(
00031 array('oxartnum', 'oxarticles', 1, 0, 0),
00032 array('oxtitle', 'oxarticles', 1, 1, 0),
00033 array('oxean', 'oxarticles', 0, 0, 0),
00034 array('oxmpn', 'oxarticles', 0, 0, 0),
00035 array('oxprice', 'oxarticles', 0, 0, 0),
00036 array('oxstock', 'oxarticles', 0, 0, 0),
00037 array('oxid', 'oxobject2selectlist', 0, 0, 1),
00038 array('oxid', 'oxarticles', 0, 0, 1)
00039 ),
00040 'container3' => array(
00041 array('oxtitle', 'oxselectlist', 1, 1, 0),
00042 array('oxsort', 'oxobject2selectlist', 1, 0, 0),
00043 array('oxident', 'oxselectlist', 0, 0, 0),
00044 array('oxvaldesc', 'oxselectlist', 0, 0, 0),
00045 array('oxid', 'oxselectlist', 0, 0, 1)
00046 )
00047 );
00048
00054 protected function _getQuery()
00055 {
00056 $myConfig = $this->getConfig();
00057
00058
00059 $sArtTable = $this->_getViewName('oxarticles');
00060 $sCatTable = $this->_getViewName('oxcategories');
00061 $sO2CView = $this->_getViewName('oxobject2category');
00062 $oDb = oxDb::getDb();
00063 $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00064 $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00065
00066
00067 if (!$sSelId) {
00068
00069 $sQAdd = " from $sArtTable where 1 ";
00070 $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArtTable.oxparentid = '' ";
00071 } else {
00072
00073 if ($sSynchSelId && $sSelId != $sSynchSelId) {
00074 $sQAdd = " from $sO2CView as oxobject2category left join $sArtTable on ";
00075 $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? " ( $sArtTable.oxid=oxobject2category.oxobjectid or $sArtTable.oxparentid=oxobject2category.oxobjectid ) " : " $sArtTable.oxid=oxobject2category.oxobjectid ";
00076 $sQAdd .= " where oxobject2category.oxcatnid = " . $oDb->quote($sSelId);
00077 } else {
00078 $sQAdd = " from $sArtTable left join oxobject2selectlist on $sArtTable.oxid=oxobject2selectlist.oxobjectid ";
00079 $sQAdd .= " where oxobject2selectlist.oxselnid = " . $oDb->quote($sSelId);
00080 }
00081 }
00082
00083 if ($sSynchSelId && $sSynchSelId != $sSelId) {
00084
00085 $sQAdd .= " and $sArtTable.oxid not in ( select oxobject2selectlist.oxobjectid from oxobject2selectlist ";
00086 $sQAdd .= " where oxobject2selectlist.oxselnid = " . $oDb->quote($sSynchSelId) . " ) ";
00087 }
00088
00089 return $sQAdd;
00090 }
00091
00095 public function removeArtFromSel()
00096 {
00097 $aChosenArt = $this->_getActionIds('oxobject2selectlist.oxid');
00098
00099
00100
00101
00102 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00103
00104 $sQ = parent::_addFilter("delete oxobject2selectlist.* " . $this->_getQuery());
00105 oxDb::getDb()->Execute($sQ);
00106
00107 } elseif (is_array($aChosenArt)) {
00108 $sQ = "delete from oxobject2selectlist where oxobject2selectlist.oxid in (" . implode(", ", oxDb::getInstance()->quoteArray($aChosenArt)) . ") ";
00109 oxDb::getDb()->Execute($sQ);
00110 }
00111 }
00112
00116 public function addArtToSel()
00117 {
00118 $aAddArticle = $this->_getActionIds('oxarticles.oxid');
00119 $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00120
00121 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00122 $sArtTable = $this->_getViewName('oxarticles');
00123 $aAddArticle = $this->_getAll(parent::_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00124 }
00125
00126 if ($soxId && $soxId != "-1" && is_array($aAddArticle)) {
00127 $oDb = oxDb::getDb();
00128 foreach ($aAddArticle as $sAdd) {
00129 $oNewGroup = oxNew("oxbase");
00130 $oNewGroup->init("oxobject2selectlist");
00131 $oNewGroup->oxobject2selectlist__oxobjectid = new oxField($sAdd);
00132 $oNewGroup->oxobject2selectlist__oxselnid = new oxField($soxId);
00133 $oNewGroup->oxobject2selectlist__oxsort = new oxField(( int ) $oDb->getOne("select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = " . $oDb->quote($sAdd) . " ", false, false));
00134 $oNewGroup->save();
00135
00136 }
00137 }
00138
00139
00140 }
00141 }