00001 <?php
00002
00010 class Attribute_Category extends oxAdminDetails
00011 {
00017 public function render()
00018 {
00019 parent::render();
00020
00021 $soxId = oxConfig::getParameter( "oxid");
00022 $this->_aViewData["oxid"] = $soxId;
00023
00024 $aListAllIn = array();
00025 if ( $soxId != "-1" && isset( $soxId)) {
00026
00027 $oAttr = oxNew( "oxattribute" );
00028 $oAttr->load( $soxId);
00029 $this->_aViewData["edit"] = $oAttr;
00030 }
00031
00032 if ( oxConfig::getParameter("aoc") ) {
00033
00034 $aColumns = array();
00035 include_once 'inc/'.strtolower(__CLASS__).'.inc.php';
00036 $this->_aViewData['oxajax'] = $aColumns;
00037
00038 return "popups/attribute_category.tpl";
00039 }
00040 return "attribute_category.tpl";
00041 }
00042
00043
00048 protected function _loadCategory()
00049 {
00050 $sChosenCatId = oxConfig::getParameter("chosenCatId");
00051 if ( isset($sChosenCatId) && $sChosenCatId) {
00052 $suffix = oxLang::getInstance()->getLanguageTag( $this->_iEditLang);
00053 $sSelect = "select oxcategory2attribute.oxid, oxattribute.oxtitle$suffix from oxcategory2attribute, oxattribute ";
00054 $sSelect .= "where oxcategory2attribute.oxobjectid='$sChosenCatId' and oxattribute.oxid=oxcategory2attribute.oxattrid ";
00055 $sSelect .= "order by oxcategory2attribute.oxsort, oxattribute.oxpos, oxattribute.oxtitle$suffix ";
00056 $oDB = oxDb::getDb();
00057 $aList = array();
00058 $rs = $oDB->selectLimit( $sSelect, 1000, 0);
00059 if ($rs != false && $rs->recordCount() > 0) {
00060 while (!$rs->EOF) {
00061 $oSel = new stdClass();
00062 $oSel->oxcategory2attribute__oxid = new oxField($rs->fields[0]);
00063 $oSel->oxattribute__oxtitle = new oxField($rs->fields[1]);
00064 $aList[] = $oSel;
00065 $rs->moveNext();
00066 }
00067 }
00068 $this->_aViewData["chosenCatSel"] = $aList;
00069 $this->_aViewData["chosenCatId"] = $sChosenCatId;
00070 }
00071 }
00072
00081 public function setSorting( $sTable = null, $soxId = null)
00082 {
00083 if ( $sTable == null)
00084 $sTable = oxConfig::getParameter("stable");
00085 if ( $soxId == null)
00086 $soxId = oxConfig::getParameter("chosenCatId");
00087 $sSorting = oxConfig::getParameter("sorting");
00088 $sTarget = oxConfig::getParameter("starget");
00089 $aObjectId = oxConfig::getParameter( $sTarget);
00090 if ( !isset($soxId) || $soxId == "-1" || $sTable == null || !$sTable)
00091 return 0;
00092 $oDB = oxDb::getDb();
00093
00094
00095 if ( !isset($sSorting) || !$sSorting) {
00096 $sSelect = "select count(*) from $sTable where $sTable.oxobjectid = '".$soxId."' ";
00097 return $oDB->getOne( $sSelect);
00098 } else if ( count($aObjectId) > 0) {
00099 if ( $sSorting == "up") {
00100 $aList = $this->_getSortingList( $sTable, $soxId);
00101 $sFItmId = $aObjectId[0];
00102 foreach ( $aList as $iNum => $aItem) {
00103 if ( $aItem[0] == $sFItmId && $iNum > 0) {
00104
00105 $sSelect = "update $sTable set $sTable.oxsort=".( $iNum + count($aObjectId) - 1 )." where $sTable.oxid='".$aList[$iNum-1][0]."'";
00106 $oDB->execute( $sSelect);
00107 foreach ( $aObjectId as $iSNum => $sItem) {
00108 $sSelect = "update $sTable set $sTable.oxsort=".( $iNum + $iSNum - 1)." where $sTable.oxid='".$sItem."'";
00109 $oDB->execute( $sSelect);
00110 }
00111 break;
00112 }
00113 }
00114 } elseif ( $sSorting == "down") {
00115 $aList = $this->_getSortingList( $sTable, $soxId);
00116 $sFItmId = $aObjectId[count($aObjectId)-1];
00117 foreach ( $aList as $iNum => $aItem) {
00118 if ( $aItem[0] == $sFItmId && $iNum < (count($aList)-1)) {
00119 $sSelect = "update $sTable set $sTable.oxsort=".( $iNum - count($aObjectId) + 1 )." where $sTable.oxid='".$aList[$iNum+1][0]."'";
00120 $oDB->execute( $sSelect);
00121 foreach ( $aObjectId as $iSNum => $sItem) {
00122 $sSelect = "update $sTable set $sTable.oxsort=".( $iNum - (count($aObjectId)-$iSNum) + 2 )." where $sTable.oxid='".$sItem."'";
00123 $oDB->execute( $sSelect);
00124 }
00125 break;
00126 }
00127 }
00128 }
00129 $this->updateSorting( $sTable, array($soxId));
00130 $this->_loadCategory();
00131 }
00132 }
00133
00142 protected function _getSortingList( $sTable, $soxId)
00143 {
00144
00145
00146
00147 $sSelect = "select $sTable.oxid, $sTable.oxsort, $sTable.oxattrid , ";
00148 $sSelect .= "$sTable.oxobjectid from $sTable where $sTable.oxobjectid = '".$soxId."' order by $sTable.oxsort";
00149 $oDB = oxDb::getDb();
00150 $aList = array();
00151 $rs = $oDB->selectLimit( $sSelect, 1000, 0);
00152
00153 if ($rs != false && $rs->recordCount() > 0) {
00154 while (!$rs->EOF) {
00155 $aList[] = array($rs->fields[0], $rs->fields[1], $rs->fields[2], $rs->fields[3]);
00156 $rs->moveNext();
00157 }
00158 }
00159 return $aList;
00160 }
00161
00170 function updateSorting( $sTable, $aIds)
00171 {
00172 foreach ( $aIds as $soxId) {
00173
00174
00175
00176 $aList = $this->_getSortingList( $sTable, $soxId);
00177
00178 $oDB = oxDb::getDb();
00179 foreach ( $aList as $iNum => $aItem) {
00180 if ( $aItem[1] != $iNum) {
00181 $sSelect = "update $sTable set $sTable.oxsort=$iNum where $sTable.oxid='".$aItem[0]."'";
00182 $oDB->execute( $sSelect);
00183 }
00184 }
00185 }
00186 }
00187
00188 }