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             $suffix = oxLang::getInstance()->getLanguageTag( $this->_iEditLang);
00052             $sSelect  = "select oxcategory2attribute.oxid, oxattribute.oxtitle$suffix from oxcategory2attribute, oxattribute ";
00053             $sSelect .= "where oxcategory2attribute.oxobjectid='$sChosenCatId' and oxattribute.oxid=oxcategory2attribute.oxattrid ";
00054             $sSelect .= "order by oxcategory2attribute.oxsort, oxattribute.oxpos, oxattribute.oxtitle$suffix ";
00055             $oDB = oxDb::getDb();
00056             $aList = array();
00057             $rs = $oDB->selectLimit( $sSelect, 1000, 0);
00058             if ($rs != false && $rs->recordCount() > 0) {
00059                 while (!$rs->EOF) {
00060                     $oSel = new stdClass(); // #663
00061                     $oSel->oxcategory2attribute__oxid = new oxField($rs->fields[0]);
00062                     $oSel->oxattribute__oxtitle       = new oxField($rs->fields[1]);
00063                     $aList[] = $oSel;
00064                     $rs->moveNext();
00065                 }
00066             }
00067             $this->_aViewData["chosenCatSel"] =  $aList;
00068             $this->_aViewData["chosenCatId"] = $sChosenCatId;
00069         }
00070     }
00071 
00080     public function setSorting( $sTable = null, $soxId = null)
00081     {
00082         if ( $sTable == null)
00083             $sTable = oxConfig::getParameter("stable");
00084         if ( $soxId == null)
00085             $soxId =  oxConfig::getParameter("chosenCatId");
00086         $sSorting  = oxConfig::getParameter("sorting");
00087         $sTarget   = oxConfig::getParameter("starget");
00088         $aObjectId = oxConfig::getParameter( $sTarget);
00089         if ( !isset($soxId) || $soxId == "-1" || $sTable == null || !$sTable)
00090             return 0;
00091         $oDB = oxDb::getDb();
00092 
00093         //means appending article to the end, sorting number will be last number
00094         if ( !isset($sSorting) || !$sSorting) {
00095             $sSelect = "select count(*) from $sTable where $sTable.oxobjectid = '".$soxId."' ";
00096             return $oDB->getOne( $sSelect);
00097         } else if ( count($aObjectId) > 0) {
00098             if ( $sSorting == "up") {
00099                 $aList = $this->_getSortingList( $sTable, $soxId);
00100                 $sFItmId = $aObjectId[0];
00101                 foreach ( $aList as $iNum => $aItem) {
00102                     if ( $aItem[0] == $sFItmId && $iNum > 0) {
00103                         //echo "$iNum + ".sizeof($aObjectId)." - 1";
00104                         $sSelect = "update $sTable set $sTable.oxsort=".( $iNum + count($aObjectId) - 1 )." where $sTable.oxid='".$aList[$iNum-1][0]."'";
00105                         $oDB->execute( $sSelect);
00106                         foreach ( $aObjectId as $iSNum => $sItem) {
00107                             $sSelect = "update $sTable set $sTable.oxsort=".( $iNum + $iSNum - 1)." where $sTable.oxid='".$sItem."'";
00108                             $oDB->execute( $sSelect);
00109                         }
00110                         break;
00111                     }
00112                 }
00113             } elseif ( $sSorting == "down") {
00114                 $aList = $this->_getSortingList( $sTable, $soxId);
00115                 $sFItmId = $aObjectId[count($aObjectId)-1];
00116                 foreach ( $aList as $iNum => $aItem) {
00117                     if ( $aItem[0] == $sFItmId && $iNum < (count($aList)-1)) {
00118                         $sSelect = "update $sTable set $sTable.oxsort=".( $iNum - count($aObjectId) + 1 )." where $sTable.oxid='".$aList[$iNum+1][0]."'";
00119                         $oDB->execute( $sSelect);
00120                         foreach ( $aObjectId as $iSNum => $sItem) {
00121                             $sSelect = "update $sTable set $sTable.oxsort=".( $iNum - (count($aObjectId)-$iSNum) + 2 )." where $sTable.oxid='".$sItem."'";
00122                             $oDB->execute( $sSelect);
00123                         }
00124                         break;
00125                     }
00126                 }
00127             }
00128             $this->updateSorting( $sTable, array($soxId));
00129             $this->_loadCategory();
00130         }
00131     }
00132 
00141     protected function _getSortingList( $sTable, $soxId)
00142     {
00143         //$soxId    = oxConfig::getParameter( "oxid");
00144         //if ( !isset($soxId) && $soxId == "-1")
00145         //    return;
00146         $sSelect  = "select $sTable.oxid, $sTable.oxsort, $sTable.oxattrid , ";
00147         $sSelect .= "$sTable.oxobjectid from $sTable where $sTable.oxobjectid = '".$soxId."' order by $sTable.oxsort";
00148         $oDB = oxDb::getDb();
00149         $aList = array();
00150         $rs = $oDB->selectLimit( $sSelect, 1000, 0);
00151         //fetches assigned article list
00152         if ($rs != false && $rs->recordCount() > 0) {
00153             while (!$rs->EOF) {
00154                 $aList[] = array($rs->fields[0], $rs->fields[1], $rs->fields[2], $rs->fields[3]);
00155                 $rs->moveNext();
00156             }
00157         }
00158         return $aList;
00159     }
00160 
00169     function updateSorting( $sTable, $aIds)
00170     {
00171         $oDB = oxDb::getDb();
00172         foreach ( $aIds as $soxId) {
00173             //$soxId    = oxConfig::getParameter( "oxid");
00174             //if ( !isset($soxId) && $soxId == "-1")
00175             //    return;
00176             $aList = $this->_getSortingList( $sTable, $soxId);
00177             // updates sorting
00178             foreach ( $aList as $iNum => $aItem) {
00179                 if ( $aItem[1] != $iNum) {
00180                     $sSelect = "update $sTable set $sTable.oxsort=$iNum where $sTable.oxid='".$aItem[0]."'";
00181                     $oDB->execute( $sSelect);
00182                 }
00183             }
00184         }
00185     }
00186 
00187 }

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5