attribute_category_ajax.php

Go to the documentation of this file.
00001 <?php
00002 
00006 class attribute_category_ajax extends ajaxListComponent
00007 {
00008 
00014     protected $_aColumns = array('container1' => array( // field , table,         visible, multilanguage, ident
00015         array('oxtitle', 'oxcategories', 1, 1, 0),
00016         array('oxdesc', 'oxcategories', 1, 1, 0),
00017         array('oxid', 'oxcategories', 0, 0, 0),
00018         array('oxid', 'oxcategories', 0, 0, 1)
00019     ),
00020                                  'container2' => array(
00021                                      array('oxtitle', 'oxcategories', 1, 1, 0),
00022                                      array('oxdesc', 'oxcategories', 1, 1, 0),
00023                                      array('oxid', 'oxcategories', 0, 0, 0),
00024                                      array('oxid', 'oxcategory2attribute', 0, 0, 1),
00025                                      array('oxid', 'oxcategories', 0, 0, 1)
00026                                  ),
00027                                  'container3' => array(
00028                                      array('oxtitle', 'oxattribute', 1, 1, 0),
00029                                      array('oxsort', 'oxcategory2attribute', 1, 0, 0),
00030                                      array('oxid', 'oxcategory2attribute', 0, 0, 1)
00031                                  )
00032     );
00033 
00039     protected function _getQuery()
00040     {
00041         $myConfig = $this->getConfig();
00042         $oDb = oxDb::getDb();
00043 
00044         $sCatTable = $this->_getViewName('oxcategories');
00045         $sDiscountId = oxRegistry::getConfig()->getRequestParameter('oxid');
00046         $sSynchDiscountId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00047 
00048         // category selected or not ?
00049         if (!$sDiscountId) {
00050             $sQAdd = " from {$sCatTable} where {$sCatTable}.oxshopid = '" . $myConfig->getShopId() . "' ";
00051             $sQAdd .= " and {$sCatTable}.oxactive = '1' ";
00052         } else {
00053             $sQAdd = " from {$sCatTable} left join oxcategory2attribute " .
00054                      "on {$sCatTable}.oxid=oxcategory2attribute.oxobjectid " .
00055                      " where oxcategory2attribute.oxattrid = " . $oDb->quote($sDiscountId) .
00056                      " and {$sCatTable}.oxshopid = '" . $myConfig->getShopId() . "' " .
00057                      " and {$sCatTable}.oxactive = '1' ";
00058         }
00059 
00060         if ($sSynchDiscountId && $sSynchDiscountId != $sDiscountId) {
00061             $sQAdd .= " and {$sCatTable}.oxid not in ( select {$sCatTable}.oxid " .
00062                       "from {$sCatTable} left join oxcategory2attribute " .
00063                       "on {$sCatTable}.oxid=oxcategory2attribute.oxobjectid " .
00064                       " where oxcategory2attribute.oxattrid = " . $oDb->quote($sSynchDiscountId) .
00065                       " and {$sCatTable}.oxshopid = '" . $myConfig->getShopId() . "' " .
00066                       " and {$sCatTable}.oxactive = '1' ) ";
00067         }
00068 
00069         return $sQAdd;
00070     }
00071 
00075     public function removeCatFromAttr()
00076     {
00077         $aChosenCat = $this->_getActionIds('oxcategory2attribute.oxid');
00078 
00079 
00080 
00081         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00082             $sQ = $this->_addFilter("delete oxcategory2attribute.* " . $this->_getQuery());
00083             oxDb::getDb()->Execute($sQ);
00084         } elseif (is_array($aChosenCat)) {
00085             $sChosenCategories = implode(", ", oxDb::getInstance()->quoteArray($aChosenCat));
00086             $sQ = "delete from oxcategory2attribute where oxcategory2attribute.oxid in (" . $sChosenCategories . ") ";
00087             oxDb::getDb()->Execute($sQ);
00088         }
00089 
00090 
00091         $this->resetContentCache();
00092 
00093     }
00094 
00098     public function addCatToAttr()
00099     {
00100         $aAddCategory = $this->_getActionIds('oxcategories.oxid');
00101         $soxId = oxRegistry::getConfig()->getRequestParameter('synchoxid');
00102 
00103         $oAttribute = oxNew("oxattribute");
00104         // adding
00105         if (oxRegistry::getConfig()->getRequestParameter('all')) {
00106             $sCatTable = $this->_getViewName('oxcategories');
00107             $aAddCategory = $this->_getAll($this->_addFilter("select $sCatTable.oxid " . $this->_getQuery()));
00108         }
00109 
00110         if ($oAttribute->load($soxId) && is_array($aAddCategory)) {
00111             $oDb = oxDb::getDb();
00112             foreach ($aAddCategory as $sAdd) {
00113                 $oNewGroup = oxNew("oxbase");
00114                 $oNewGroup->init("oxcategory2attribute");
00115                 $sOxSortField = 'oxcategory2attribute__oxsort';
00116                 $sObjectIdField = 'oxcategory2attribute__oxobjectid';
00117                 $sAttributeIdField = 'oxcategory2attribute__oxattrid';
00118                 $sOxIdField = 'oxattribute__oxid';
00119                 $oNewGroup->$sObjectIdField = new oxField($sAdd);
00120                 $oNewGroup->$sAttributeIdField = new oxField($oAttribute->$sOxIdField->value);
00121                 $sSql = "select max(oxsort) + 1 from oxcategory2attribute where oxobjectid = '$sAdd' ";
00122                 $oNewGroup->$sOxSortField = new oxField(( int ) $oDb->getOne($sSql, false, false));
00123                 $oNewGroup->save();
00124             }
00125         }
00126 
00127         $this->resetContentCache();
00128     }
00129 
00130 }