00001 <?php
00002
00006 class category_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', 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', 'oxarticles', 0, 0, 1)
00038 )
00039 );
00040
00046 protected function _getQuery()
00047 {
00048 $myConfig = $this->getConfig();
00049
00050 $sArticleTable = $this->_getViewName('oxarticles');
00051 $sO2CView = $this->_getViewName('oxobject2category');
00052
00053 $sOxid = oxRegistry::getConfig()->getRequestParameter('oxid');
00054 $sSynchOxid = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00055 $oDb = oxDb::getDb();
00056
00057 $sShopID = $myConfig->getShopId();
00058
00059
00060 if (!$sOxid && $sSynchOxid) {
00061
00062
00063 $sQAdd = ' from ' . $sArticleTable . ' where 1 ';
00064 } else {
00065
00066
00067 $sJoin = " {$sArticleTable}.oxid={$sO2CView}.oxobjectid ";
00068
00069 $sSubSelect = '';
00070 if ($sSynchOxid && $sOxid != $sSynchOxid) {
00071
00072 $sSubSelect = ' and ' . $sArticleTable . '.oxid not in ( ';
00073 $sSubSelect .= "select $sArticleTable.oxid from $sO2CView left join $sArticleTable ";
00074 $sSubSelect .= "on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote($sSynchOxid) . " ";
00075 $sSubSelect .= 'and ' . $sArticleTable . '.oxid is not null ) ';
00076 }
00077
00078 $sQAdd = " from $sO2CView join $sArticleTable ";
00079 $sQAdd .= " on $sJoin where $sO2CView.oxcatnid = " . $oDb->quote($sOxid);
00080 $sQAdd .= " and $sArticleTable.oxid is not null $sSubSelect ";
00081 }
00082
00083 return $sQAdd;
00084 }
00085
00093 protected function _addFilter($sQ)
00094 {
00095 $sArtTable = $this->_getViewName('oxarticles');
00096 $sQ = parent::_addFilter($sQ);
00097
00098
00099 if (!$this->getConfig()->getConfigParam('blVariantsSelection')) {
00100 $sQ .= " and {$sArtTable}.oxparentid = '' ";
00101 }
00102
00103 return $sQ;
00104 }
00105
00110 public function addArticle()
00111 {
00112 $myConfig = $this->getConfig();
00113
00114 $aArticles = $this->_getActionIds('oxarticles.oxid');
00115 $sCategoryID = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00116 $sShopID = $myConfig->getShopId();
00117 $oDb = oxDb::getDb();
00118 $sArticleTable = $this->_getViewName('oxarticles');
00119
00120
00121 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00122 $aArticles = $this->_getAll($this->_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
00123 }
00124
00125 if (is_array($aArticles)) {
00126
00127 $sO2CView = $this->_getViewName('oxobject2category');
00128
00129 $oNew = oxNew('oxobject2category');
00130 $myUtilsObject = oxUtilsObject::getInstance();
00131 $oActShop = $myConfig->getActiveShop();
00132
00133 $sProdIds = "";
00134 foreach ($aArticles as $sAdd) {
00135
00136
00137 $sSelect = "select 1 from $sO2CView as oxobject2category where oxobject2category.oxcatnid= "
00138 . $oDb->quote($sCategoryID) . " and oxobject2category.oxobjectid = " . $oDb->quote($sAdd) . "";
00139 if ($oDb->getOne($sSelect, false, false)) {
00140 continue;
00141 }
00142
00143 $oNew->oxobject2category__oxid = new oxField($oNew->setId(md5($sAdd . $sCategoryID . $sShopID)));
00144 $oNew->oxobject2category__oxobjectid = new oxField($sAdd);
00145 $oNew->oxobject2category__oxcatnid = new oxField($sCategoryID);
00146 $oNew->oxobject2category__oxtime = new oxField(time());
00147
00148 $oNew->save();
00149
00150 if ($sProdIds) {
00151 $sProdIds .= ",";
00152 }
00153 $sProdIds .= $oDb->quote($sAdd);
00154 }
00155
00156
00157 $this->_updateOxTime($sProdIds);
00158
00159 $this->resetArtSeoUrl($aArticles);
00160 $this->resetCounter("catArticle", $sCategoryID);
00161
00162 }
00163 }
00164
00170 protected function _updateOxTime($sProdIds)
00171 {
00172 if ($sProdIds) {
00173 $sO2CView = $this->_getViewName('oxobject2category');
00174 $sSqlShopFilter = "";
00175 $sSqlWhereShopFilter = "";
00176 $sQ = "update oxobject2category set oxtime = 0 where oxid in (
00177 select _tmp.oxid from (
00178 select oxobject2category.oxid from (
00179 select min(oxtime) as oxtime, oxobjectid from {$sO2CView}
00180 where oxobjectid in ( {$sProdIds} ) {$sSqlShopFilter} group by oxobjectid
00181 ) as _subtmp
00182 left join oxobject2category on oxobject2category.oxtime = _subtmp.oxtime
00183 and oxobject2category.oxobjectid = _subtmp.oxobjectid
00184 {$sSqlWhereShopFilter}
00185 ) as _tmp
00186 ) {$sSqlShopFilter}";
00187
00188 oxDb::getDb()->execute($sQ);
00189 }
00190 }
00191
00195 public function removeArticle()
00196 {
00197 $aArticles = $this->_getActionIds('oxarticles.oxid');
00198 $sCategoryID = oxRegistry::getConfig()->getRequestParameter('oxid');
00199 $sShopID = $this->getConfig()->getShopId();
00200 $oDb = oxDb::getDb();
00201
00202
00203 if (oxRegistry::getConfig()->getRequestParameter('all')) {
00204 $sArticleTable = $this->_getViewName('oxarticles');
00205 $aArticles = $this->_getAll($this->_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
00206 }
00207
00208
00209 if (is_array($aArticles) && count($aArticles)) {
00210 $sProdIds = implode(", ", oxDb::getInstance()->quoteArray($aArticles));
00211
00212 $sDelete = "delete from oxobject2category where";
00213 $sWhere = " oxcatnid=" . $oDb->quote($sCategoryID);
00214 if (!$this->getConfig()->getConfigParam('blVariantsSelection')) {
00215 $sQ = $sDelete . $sWhere . " and oxobjectid in
00216 ( select oxid from oxarticles where oxparentid in ( {$sProdIds} ) )";
00217 $oDb->execute($sQ);
00218 }
00219 $sQ = $sDelete . $sWhere . " and oxobjectid in ( {$sProdIds} )";
00220 $oDb->execute($sQ);
00221
00222
00223 $this->_updateOxTime($sProdIds);
00224 }
00225
00226 $this->resetArtSeoUrl($aArticles, $sCategoryID);
00227 $this->resetCounter("catArticle", $sCategoryID);
00228
00229 }
00230 }