article_attribute_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class article_attribute_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxtitle', 'oxattribute', 1, 1, 0),
00016         array('oxid', 'oxattribute', 0, 0, 1)
00017     ),
00018                                  'container2' => array(
00019                                      array('oxtitle', 'oxattribute', 1, 1, 0),
00020                                      array('oxid', 'oxobject2attribute', 0, 0, 1),
00021                                      array('oxvalue', 'oxobject2attribute', 0, 1, 1),
00022                                      array('oxattrid', 'oxobject2attribute', 0, 0, 1),
00023                                  )
00024     );
00025 
00031     protected function _getQuery()
00032     {
00033         $oDb = oxDb::getDb();
00034         $sArtId = oxRegistry::getConfig()->getRequestParameter('oxid');
00035         $sSynchArtId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00036 
00037         $sAttrViewName = $this->_getViewName('oxattribute');
00038         $sO2AViewName = $this->_getViewName('oxobject2attribute');
00039         if ($sArtId) {
00040             // all categories article is in
00041             $sQAdd = " from {$sO2AViewName} left join {$sAttrViewName} " .
00042                      "on {$sAttrViewName}.oxid={$sO2AViewName}.oxattrid " .
00043                      " where {$sO2AViewName}.oxobjectid = " . $oDb->quote($sArtId) . " ";
00044         } else {
00045             $sQAdd = " from {$sAttrViewName} where {$sAttrViewName}.oxid not in ( select {$sO2AViewName}.oxattrid " .
00046                      "from {$sO2AViewName} left join {$sAttrViewName} " .
00047                      "on {$sAttrViewName}.oxid={$sO2AViewName}.oxattrid " .
00048                      " where {$sO2AViewName}.oxobjectid = " . $oDb->quote($sSynchArtId) . " ) ";
00049         }
00050 
00051         return $sQAdd;
00052     }
00053 
00057     public function removeAttr()
00058     {
00059         $aChosenArt = $this->_getActionIds('oxobject2attribute.oxid');
00060         $sOxid = oxRegistry::getConfig()->getRequestParameter('oxid');
00061         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00062             $sO2AViewName = $this->_getViewName('oxobject2attribute');
00063             $sQ = $this->_addFilter("delete $sO2AViewName.* " . $this->_getQuery());
00064             oxDb::getDb()->Execute($sQ);
00065 
00066         } elseif (is_array($aChosenArt)) {
00067             $sChosenArticles = implode(", ", oxDb::getInstance()->quoteArray($aChosenArt));
00068             $sQ = "delete from oxobject2attribute where oxobject2attribute.oxid in ({$sChosenArticles}) ";
00069             oxDb::getDb()->Execute($sQ);
00070         }
00071 
00072     }
00073 
00077     public function addAttr()
00078     {
00079         $aAddCat = $this->_getActionIds('oxattribute.oxid');
00080         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00081 
00082         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00083             $sAttrViewName = $this->_getViewName('oxattribute');
00084             $aAddCat = $this->_getAll($this->_addFilter("select $sAttrViewName.oxid " . $this->_getQuery()));
00085         }
00086 
00087         if ($soxId && $soxId != "-1" && is_array($aAddCat)) {
00088             foreach ($aAddCat as $sAdd) {
00089                 $oNew = oxNew("oxbase");
00090                 $oNew->init("oxobject2attribute");
00091                 $oNew->oxobject2attribute__oxobjectid = new oxField($soxId);
00092                 $oNew->oxobject2attribute__oxattrid = new oxField($sAdd);
00093                 $oNew->save();
00094             }
00095 
00096         }
00097     }
00098 
00104     public function saveAttributeValue()
00105     {
00106         $oDb = oxDb::getDb();
00107 
00108         $soxId = oxRegistry::getConfig()->getRequestParameter("oxid");
00109         $sAttributeId = oxRegistry::getConfig()->getRequestParameter("attr_oxid");
00110         $sAttributeValue = oxRegistry::getConfig()->getRequestParameter("attr_value");
00111         if (!$this->getConfig()->isUtf()) {
00112             $sAttributeValue = iconv('UTF-8', oxRegistry::getLang()->translateString("charset"), $sAttributeValue);
00113         }
00114 
00115         $oArticle = oxNew("oxarticle");
00116         if ($oArticle->load($soxId)) {
00117 
00118 
00119             if (isset($sAttributeId) && ("" != $sAttributeId)) {
00120                 $sViewName = $this->_getViewName("oxobject2attribute");
00121                 $sOxIdField = 'oxarticles__oxid';
00122                 $sQuotedOxid = $oDb->quote($oArticle->$sOxIdField->value);
00123                 $sSelect = "select * from {$sViewName} where {$sViewName}.oxobjectid= {$sQuotedOxid} and
00124                             {$sViewName}.oxattrid= " . $oDb->quote($sAttributeId);
00125                 $oO2A = oxNew("oxi18n");
00126                 $oO2A->setLanguage(oxRegistry::getConfig()->getRequestParameter('editlanguage'));
00127                 $oO2A->init("oxobject2attribute");
00128                 if ($oO2A->assignRecord($sSelect)) {
00129                     $oO2A->oxobject2attribute__oxvalue->setValue($sAttributeValue);
00130                     $oO2A->save();
00131                 }
00132             }
00133 
00134         }
00135     }
00136 }