00001 <?php
00002
00006 class article_accessories_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', 1, 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', 1, 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', 'oxaccessoire2article', 0, 0, 1)
00038 )
00039 );
00040
00046 protected function _getQuery()
00047 {
00048 $myConfig = $this->getConfig();
00049 $sSelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00050 $sSynchSelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00051 $oDb = oxDb::getDb();
00052
00053 $sArticleTable = $this->_getViewName('oxarticles');
00054 $sView = $this->_getViewName('oxobject2category');
00055
00056
00057 if (!$sSelId) {
00058 $sQAdd = " from {$sArticleTable} where 1 ";
00059 $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and {$sArticleTable}.oxparentid = '' ";
00060 } else {
00061
00062 if ($sSynchSelId && $sSelId != $sSynchSelId) {
00063 $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
00064 $sSqlIfTrue = " ( {$sArticleTable}.oxid=$sView.oxobjectid " .
00065 "or {$sArticleTable}.oxparentid=$sView.oxobjectid )";
00066 $sSqlIfFals = " {$sArticleTable}.oxid=$sView.oxobjectid ";
00067 $sVariantSelectionSql = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFals;
00068
00069 $sQAdd = " from $sView left join {$sArticleTable} on {$sVariantSelectionSql}" .
00070 " where $sView.oxcatnid = " . $oDb->quote($sSelId) . " ";
00071 } else {
00072 $sQAdd = " from oxaccessoire2article left join {$sArticleTable} " .
00073 "on oxaccessoire2article.oxobjectid={$sArticleTable}.oxid " .
00074 " where oxaccessoire2article.oxarticlenid = " . $oDb->quote($sSelId) . " ";
00075 }
00076 }
00077
00078 if ($sSynchSelId && $sSynchSelId != $sSelId) {
00079
00080 $sSubSelect .= " select oxaccessoire2article.oxobjectid from oxaccessoire2article ";
00081 $sSubSelect .= " where oxaccessoire2article.oxarticlenid = " . $oDb->quote($sSynchSelId) . " ";
00082 $sQAdd .= " and {$sArticleTable}.oxid not in ( $sSubSelect ) ";
00083 }
00084
00085
00086 $sId = ($sSynchSelId) ? $sSynchSelId : $sSelId;
00087 $sQAdd .= " and {$sArticleTable}.oxid != " . $oDb->quote($sId) . " ";
00088
00089
00090 return $sQAdd;
00091 }
00092
00096 public function removeArticleAcc()
00097 {
00098 $aChosenArt = $this->_getActionIds('oxaccessoire2article.oxid');
00099
00100 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00101
00102 $sQ = $this->_addFilter("delete oxaccessoire2article.* " . $this->_getQuery());
00103 oxDb::getDb()->Execute($sQ);
00104
00105 } elseif (is_array($aChosenArt)) {
00106 $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
00107 $sQ = "delete from oxaccessoire2article where oxaccessoire2article.oxid in ({$sChosenArticles}) ";
00108 oxDb::getDb()->Execute($sQ);
00109 }
00110
00111
00112 }
00113
00117 public function addArticleAcc()
00118 {
00119 $oArticle = oxNew("oxarticle");
00120 $aChosenArt = $this->_getActionIds('oxarticles.oxid');
00121 $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00122
00123
00124 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00125 $sArtTable = $this->_getViewName('oxarticles');
00126 $aChosenArt = $this->_getAll(parent::_addFilter("select $sArtTable.oxid " . $this->_getQuery()));
00127 }
00128
00129 if ($oArticle->load($soxId) && $soxId && $soxId != "-1" && is_array($aChosenArt)) {
00130 foreach ($aChosenArt as $sChosenArt) {
00131 $oNewGroup = oxNew("oxbase");
00132 $oNewGroup->init("oxaccessoire2article");
00133 $oNewGroup->oxaccessoire2article__oxobjectid = new oxField($sChosenArt);
00134 $oNewGroup->oxaccessoire2article__oxarticlenid = new oxField($oArticle->oxarticles__oxid->value);
00135 $oNewGroup->oxaccessoire2article__oxsort = new oxField(0);
00136 $oNewGroup->save();
00137 }
00138
00139 }
00140 }
00141 }