attribute_main_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class attribute_main_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_blAllowExtColumns = true;
00015 
00021     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
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', 'oxobject2attribute', 0, 0, 1)
00038                                  )
00039     );
00040 
00046     protected function _getQuery()
00047     {
00048         $myConfig = $this->getConfig();
00049         $oDb = oxDb::getDb();
00050 
00051         $sArticleTable = $this->_getViewName('oxarticles');
00052         $sOCatView = $this->_getViewName('oxobject2category');
00053         $sOAttrView = $this->_getViewName('oxobject2attribute');
00054 
00055         $sDelId = oxRegistry::getConfig()->getRequestParameter('oxid');
00056         $sSynchDelId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00057 
00058         // category selected or not ?
00059         if (!$sDelId) {
00060             // performance
00061             $sQAdd = " from $sArticleTable where 1 ";
00062             $sQAdd .= $myConfig->getConfigParam('blVariantsSelection') ? '' : " and $sArticleTable.oxparentid = '' ";
00063         } elseif ($sSynchDelId && $sDelId != $sSynchDelId) {
00064             // selected category ?
00065             $blVariantsSelectionParameter = $myConfig->getConfigParam('blVariantsSelection');
00066             $sSqlIfTrue = " ( {$sArticleTable}.oxid=oxobject2category.oxobjectid " .
00067                           "or {$sArticleTable}.oxparentid=oxobject2category.oxobjectid)";
00068             $sSqlIfFalse = " {$sArticleTable}.oxid=oxobject2category.oxobjectid ";
00069             $sVariantSelectionSql = $blVariantsSelectionParameter ? $sSqlIfTrue : $sSqlIfFalse;
00070             $sQAdd = " from {$sOCatView} as oxobject2category left join {$sArticleTable} on {$sVariantSelectionSql}" .
00071                      " where oxobject2category.oxcatnid = " . $oDb->quote($sDelId) . " ";
00072         } else {
00073             $sQAdd = " from {$sOAttrView} left join {$sArticleTable} " .
00074                      "on {$sArticleTable}.oxid={$sOAttrView}.oxobjectid " .
00075                      "where {$sOAttrView}.oxattrid = " . $oDb->quote($sDelId) .
00076                      " and {$sArticleTable}.oxid is not null ";
00077         }
00078 
00079         if ($sSynchDelId && $sSynchDelId != $sDelId) {
00080             $sQAdd .= " and {$sArticleTable}.oxid not in ( select {$sOAttrView}.oxobjectid from {$sOAttrView} " .
00081                       "where {$sOAttrView}.oxattrid = " . $oDb->quote($sSynchDelId) . " ) ";
00082         }
00083 
00084         return $sQAdd;
00085     }
00086 
00094     protected function _addFilter($sQ)
00095     {
00096         $sQ = parent::_addFilter($sQ);
00097 
00098         // display variants or not ?
00099         if ($this->getConfig()->getConfigParam('blVariantsSelection')) {
00100             $sQ .= ' group by ' . $this->_getViewName('oxarticles') . '.oxid ';
00101 
00102             $oStr = getStr();
00103             if ($oStr->strpos($sQ, "select count( * ) ") === 0) {
00104                 $sQ = "select count( * ) from ( {$sQ} ) as _cnttable";
00105             }
00106         }
00107 
00108         return $sQ;
00109     }
00110 
00114     public function removeAttrArticle()
00115     {
00116         $aChosenCat = $this->_getActionIds('oxobject2attribute.oxid');
00117 
00118 
00119         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00120             $sO2AttributeView = $this->_getViewName('oxobject2attribute');
00121 
00122             $sQ = parent::_addFilter("delete $sO2AttributeView.* " . $this->_getQuery());
00123             oxDb::getDb()->Execute($sQ);
00124         } elseif (is_array($aChosenCat)) {
00125             $sChosenCategories = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
00126             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in (" . $sChosenCategories . ") ";
00127             oxDb::getDb()->Execute($sQ);
00128         }
00129     }
00130 
00134     public function addAttrArticle()
00135     {
00136         $aAddArticle = $this->_getActionIds('oxarticles.oxid');
00137         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00138 
00139         // adding
00140         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00141             $sArticleTable = $this->_getViewName('oxarticles');
00142             $aAddArticle = $this->_getAll($this->_addFilter("select $sArticleTable.oxid " . $this->_getQuery()));
00143         }
00144 
00145         $oAttribute = oxNew("oxattribute");
00146 
00147         if ($oAttribute->load($soxId) && is_array($aAddArticle)) {
00148             foreach ($aAddArticle as $sAdd) {
00149                 $oNewGroup = oxNew("oxbase");
00150                 $oNewGroup->init("oxobject2attribute");
00151                 $oNewGroup->oxobject2attribute__oxobjectid = new oxField($sAdd);
00152                 $oNewGroup->oxobject2attribute__oxattrid = new oxField($oAttribute->oxattribute__oxid->value);
00153                 $oNewGroup->save();
00154 
00155             }
00156         }
00157     }
00158 }