article_crossselling.php

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

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5