article_crossselling.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Crossselling extends oxAdminDetails
00010 {
00011 
00019     public function render()
00020     {
00021         parent::render();
00022 
00023         $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00024 
00025         // crossselling
00026         $sChosenArtCat = $this->_getCategoryTree( "artcattree", oxConfig::getParameter( "artcat"));
00027 
00028         // accessoires
00029         $sChosenArtCat2 = $this->_getCategoryTree( "artcattree2", oxConfig::getParameter( "artcat2"));
00030 
00031         $soxId = oxConfig::getParameter( "oxid");
00032         if ( $soxId != "-1" && isset( $soxId ) ) {   // load object
00033             $oArticle->load( $soxId);
00034 
00035             if ($oArticle->isDerived())
00036                 $this->_aViewData['readonly'] = true;
00037         }
00038 
00039         $aColumns = array();
00040         $iAoc = oxConfig::getParameter("aoc");
00041         if ( $iAoc == 1 ) {
00042 
00043             include_once 'inc/article_crossselling.inc.php';
00044             $this->_aViewData['oxajax'] = $aColumns;
00045 
00046             return "popups/article_crossselling.tpl";
00047         } elseif ( $iAoc == 2 ) {
00048 
00049             include_once 'inc/article_accessories.inc.php';
00050             $this->_aViewData['oxajax'] = $aColumns;
00051 
00052             return "popups/article_accessories.tpl";
00053         }
00054         return "article_crossselling.tpl";
00055     }
00056 
00064     public function setSorting( $sTable = null)
00065     {
00066         if ( $sTable == null)
00067             $sTable = oxConfig::getParameter("stable");
00068         $soxId     = oxConfig::getParameter("oxid");
00069         $sSorting  = oxConfig::getParameter("sorting");
00070         $sTarget   = oxConfig::getParameter("starget");
00071         $aObjectId = oxConfig::getParameter( $sTarget);
00072 
00073 
00074         if ( !isset($soxId) || $soxId == "-1" || $sTable == null || !$sTable)
00075             return 0;
00076 
00077         $oDB = oxDb::getDb();
00078         //means appending article to the end, sorting number will be last number
00079         if ( !isset($sSorting) || !$sSorting) {
00080             $sSelect = "select count(*) from $sTable where $sTable.oxarticlenid = '".$soxId."' ";
00081             return $oDB->getOne( $sSelect);
00082         } else if ( count($aObjectId) > 0) {
00083             if ( $sSorting == "up") {
00084                 $aList = $this->_getSortingList( $sTable);
00085                 $sFItmId = $aObjectId[0];
00086                 foreach ( $aList as $iNum => $aItem) {
00087                     if ( $aItem[2] == $sFItmId && $iNum > 0) {
00088                         $sSelect = "update $sTable set $sTable.oxsort=".( $iNum + count($aObjectId) - 1 )." where $sTable.oxobjectid='".$aList[$iNum-1][2]."'";
00089                         $oDB->execute( $sSelect);
00090                         foreach ( $aObjectId as $iSNum => $sItem) {
00091                             $sSelect = "update $sTable set $sTable.oxsort=".( $iNum + $iSNum - 1 )." where $sTable.oxobjectid='".$sItem."'";
00092                             $oDB->execute( $sSelect);
00093                         }
00094                         break;
00095                     }
00096                 }
00097             } elseif ( $sSorting == "down") {
00098                 $aList = $this->_getSortingList( $sTable);
00099                 $sFItmId = $aObjectId[count($aObjectId)-1];
00100                 foreach ( $aList as $iNum => $aItem) {
00101                     if ( $aItem[2] == $sFItmId && $iNum < (count($aList)-1)) {
00102                         $sSelect = "update $sTable set $sTable.oxsort=".( $iNum - count($aObjectId) + 1 )." where $sTable.oxobjectid='".$aList[$iNum+1][2]."'";
00103                         $oDB->execute( $sSelect);
00104                         foreach ( $aObjectId as $iSNum => $sItem) {
00105                             $sSelect = "update $sTable set $sTable.oxsort=".( $iNum - $iSNum + 1 )." where $sTable.oxobjectid='".$sItem."'";
00106                             $oDB->execute( $sSelect);
00107                         }
00108                         break;
00109                     }
00110                 }
00111             }
00112             $this->updateSorting( $sTable );
00113         }
00114     }
00115 
00116 
00124     public function updateSorting( $sTable )
00125     {
00126         $soxId = oxConfig::getParameter( "oxid");
00127         if ( !isset($soxId) && $soxId == "-1")
00128             return;
00129 
00130         $aList = $this->_getSortingList( $sTable);
00131         // updates sorting
00132         $oDB = oxDb::getDb();
00133         foreach ( $aList as $iNum => $aItem) {
00134             if ( $aItem[1] != $iNum) {
00135                 $sSelect = "update $sTable set $sTable.oxsort=$iNum where $sTable.oxid='".$aItem[0]."'";
00136                 $oDB->execute( $sSelect);
00137             }
00138         }
00139     }
00140 
00141 
00149     protected function _getSortingList( $sTable)
00150     {
00151         $soxId    = oxConfig::getParameter( "oxid");
00152 
00153 
00154         if ( !isset($soxId) && $soxId == "-1")
00155             return;
00156         $sSelect  = "select $sTable.oxid, $sTable.oxsort, $sTable.oxobjectid , ";
00157         $sSelect .= "$sTable.oxarticlenid from $sTable where $sTable.oxarticlenid = '".$soxId."' order by $sTable.oxsort";
00158         $oDB = oxDb::getDb();
00159         $aList = array();
00160         $rs = $oDB->selectLimit( $sSelect, 1000, 0);
00161         //fetches assigned article list
00162         if ($rs != false && $rs->recordCount() > 0) {
00163             while (!$rs->EOF) {
00164                 $aList[] = array($rs->fields[0], $rs->fields[1], $rs->fields[2], $rs->fields[3]);
00165                 $rs->moveNext();
00166             }
00167         }
00168         return $aList;
00169     }
00170 
00171 }

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