00001 <?php
00002
00006 class article_selection_ajax extends ajaxListComponent
00007 {
00008
00014 protected $_aColumns = array('container1' => array(
00015 array('oxtitle', 'oxselectlist', 1, 1, 0),
00016 array('oxident', 'oxselectlist', 1, 0, 0),
00017 array('oxvaldesc', 'oxselectlist', 1, 0, 0),
00018 array('oxid', 'oxselectlist', 0, 0, 1)
00019 ),
00020 'container2' => array(
00021 array('oxtitle', 'oxselectlist', 1, 1, 0),
00022 array('oxident', 'oxselectlist', 1, 0, 0),
00023 array('oxvaldesc', 'oxselectlist', 1, 0, 0),
00024 array('oxid', 'oxobject2selectlist', 0, 0, 1)
00025 )
00026 );
00027
00033 protected function _getQuery()
00034 {
00035 $sSLViewName = $this->_getViewName('oxselectlist');
00036 $sArtViewName = $this->_getViewName('oxarticles');
00037 $oDb = oxDb::getDb();
00038
00039 $sArtId = oxRegistry::getConfig()->getRequestParameter('oxid');
00040 $sSynchArtId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00041
00042 $sOxid = ($sArtId) ? $sArtId : $sSynchArtId;
00043 $sQ = "select oxparentid from {$sArtViewName} where oxid = " . $oDb->quote($sOxid) . " and oxparentid != '' ";
00044 $sQ .= "and (select count(oxobjectid) from oxobject2selectlist " .
00045 "where oxobjectid = " . $oDb->quote($sOxid) . ") = 0";
00046 $sParentId = oxDb::getDb()->getOne($sQ, false, false);
00047
00048
00049 $sQAdd = " from oxobject2selectlist left join {$sSLViewName} " .
00050 "on {$sSLViewName}.oxid=oxobject2selectlist.oxselnid " .
00051 "where oxobject2selectlist.oxobjectid = " . $oDb->quote($sOxid) . " ";
00052 if ($sParentId) {
00053 $sQAdd .= "or oxobject2selectlist.oxobjectid = " . $oDb->quote($sParentId) . " ";
00054 }
00055
00056 if ($sSynchArtId) {
00057 $sQAdd = " from {$sSLViewName} " .
00058 "where {$sSLViewName}.oxid not in ( select oxobject2selectlist.oxselnid {$sQAdd} ) ";
00059 }
00060
00061 return $sQAdd;
00062 }
00063
00067 public function removeSel()
00068 {
00069 $aChosenArt = $this->_getActionIds('oxobject2selectlist.oxid');
00070 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00071
00072 $sQ = $this->_addFilter("delete oxobject2selectlist.* " . $this->_getQuery());
00073 oxDb::getDb()->Execute($sQ);
00074 } elseif (is_array($aChosenArt)) {
00075 $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
00076 $sQ = "delete from oxobject2selectlist " .
00077 "where oxobject2selectlist.oxid in (" . $sChosenArticles . ") ";
00078 oxDb::getDb()->Execute($sQ);
00079 }
00080
00081 }
00082
00086 public function addSel()
00087 {
00088 $aAddSel = $this->_getActionIds('oxselectlist.oxid');
00089 $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00090
00091
00092 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00093 $sSLViewName = $this->_getViewName('oxselectlist');
00094 $aAddSel = $this->_getAll($this->_addFilter("select $sSLViewName.oxid " . $this->_getQuery()));
00095 }
00096
00097 if ($soxId && $soxId != "-1" && is_array($aAddSel)) {
00098 $oDb = oxDb::getDb();
00099 foreach ($aAddSel as $sAdd) {
00100 $oNew = oxNew("oxbase");
00101 $oNew->init("oxobject2selectlist");
00102 $sObjectIdField = 'oxobject2selectlist__oxobjectid';
00103 $sSelectetionIdField = 'oxobject2selectlist__oxselnid';
00104 $sOxSortField = 'oxobject2selectlist__oxsort';
00105 $oNew->$sObjectIdField = new oxField($soxId);
00106 $oNew->$sSelectetionIdField = new oxField($sAdd);
00107 $sSql = "select max(oxsort) + 1 from oxobject2selectlist where oxobjectid = {$oDb->quote($soxId)} ";
00108 $oNew->$sOxSortField = new oxField(( int ) $oDb->getOne($sSql, false, false));
00109 $oNew->save();
00110 }
00111
00112 }
00113 }
00114 }