attribute_category.php

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

Generated on Tue Sep 29 16:45:11 2009 for OXID eShop CE by  doxygen 1.5.5