appdb/ ./vendorview.php include/vendor.php

WineHQ wineowner at wine.codeweavers.com
Wed Jan 31 20:07:24 CST 2007


ChangeSet ID:	30922
CVSROOT:	/opt/cvs-commit
Module name:	appdb
Changes by:	wineowner at winehq.org	2007/01/31 20:07:24

Modified files:
	.              : vendorview.php 
	include        : vendor.php 

Log message:
	Alexander Nicolaysen Sørnes <alex at thehandofagony.com>
	Add and use vendor::objectGetInstanceFromRow() and vendor::objectOutputTableRow()

Patch: http://cvs.winehq.org/patch.py?id=30922

Old revision  New revision  Changes     Path
 1.26          1.27          +3 -18      appdb/vendorview.php
 1.12          1.13          +47 -11     appdb/include/vendor.php

Index: appdb/vendorview.php
diff -u -p appdb/vendorview.php:1.26 appdb/vendorview.php:1.27
--- appdb/vendorview.php:1.26	1 Feb 2007  2: 7:24 -0000
+++ appdb/vendorview.php	1 Feb 2007  2: 7:24 -0000
@@ -52,25 +52,10 @@ else
 
     vendor::objectOutputHeader("color4");
 
-    $c = 1;
-    while($oRow = mysql_fetch_object($hResult))
+    for($c = 0; $oRow = mysql_fetch_object($hResult); $c++)
     {
-        if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; }
-        $oVendor = new Vendor($oRow->vendorId);
-        echo '<tr class="'.$bgcolor.'">',"\n";
-        echo '<td><a href="'.BASE.'vendorview.php?iVendorId='.$oVendor->iVendorId.'">'.$oVendor->sName.'</a></td>',"\n";
-        echo '<td><a href="'.$oVendor->sWebpage.'">'.substr($oVendor->sWebpage,0,30).'</a></td>',"\n";
-        echo '<td align="right">'.sizeof($oVendor->aApplicationsIds).'</td>',"\n";
-        if ($_SESSION['current']->hasPriv("admin"))
-        {
-            echo '<td align="center">',"\n";
-            echo '[<a href="'.BASE.'admin/editVendor.php?iVendorId='.$oVendor->iVendorId.'">edit</a>]',"\n";
-            if(!sizeof($oVendor->aApplicationsIds)) 
-                echo '&nbsp[<a href="'.$_SERVER['PHP_SELF'].'?sSub=delete&iVendorId='.$oVendor->iVendorId.'">delete</a>]',"\n";
-            echo '</td>',"\n";
-        }
-        echo '</tr>',"\n";
-        $c++;
+        $oVendor = vendor::objectGetInstanceFromRow($oRow);
+        $oVendor->objectOutputTableRow(($c % 2) ? "color0" : "color1");
     }
 
     echo '<tr><td>',"\n";
Index: appdb/include/vendor.php
diff -u -p appdb/include/vendor.php:1.12 appdb/include/vendor.php:1.13
--- appdb/include/vendor.php:1.12	1 Feb 2007  2: 7:24 -0000
+++ appdb/include/vendor.php	1 Feb 2007  2: 7:24 -0000
@@ -15,20 +15,25 @@ class Vendor {
     /**    
      * constructor, fetches the data.
      */
-    function Vendor($iVendorId = null)
+    function Vendor($iVendorId = null, $oRow = null)
     {
         // we are working on an existing vendor
         if(is_numeric($iVendorId))
         {
-            /*
-             * We fetch the data related to this vendor.
-             */
-            $sQuery = "SELECT *
-                       FROM vendor
-                       WHERE vendorId = '?'";
-            if($hResult = query_parameters($sQuery, $iVendorId))
+            if(!$oRow)
+            {
+                /*
+                 * We fetch the data related to this vendor.
+                 */
+                $sQuery = "SELECT *
+                           FROM vendor
+                           WHERE vendorId = '?'";
+                if($hResult = query_parameters($sQuery, $iVendorId))
+                    $oRow = mysql_fetch_object($hResult);
+            }
+
+            if($oRow)
             {
-                $oRow = mysql_fetch_object($hResult);
                 $this->iVendorId = $iVendorId;
                 $this->sName = $oRow->vendorName;
                 $this->sWebpage = $oRow->vendorURL;
@@ -140,14 +145,18 @@ class Vendor {
         echo "</table>\n";
     }
 
-    function objectGetEntries($bQueued)
+    function objectGetEntries($bQueued, $iRows = 0, $iStart = 0)
     {
         /* Vendor queueing is not implemented yet */
         if($bQueued)
             return NULL;
 
+        if(!$iRows)
+            $iRows = getNumberOfVendors();
+
         $hResult = query_parameters("SELECT * FROM vendor
-                   ORDER BY vendorName");
+                       ORDER BY vendorName LIMIT ?,?",
+                           $iStart, $iRows);
 
         if(!$hResult)
             return FALSE;
@@ -168,6 +177,33 @@ class Vendor {
         echo html_tr($sCells, $sClass);
     }
 
+    function objectGetInstanceFromRow($oRow)
+    {
+        return new vendor($oRow->vendorId, $oRow);
+    }
+
+    function objectOutputTableRow($sClass = "")
+    {
+        $aCells = array(
+            "<a href=\"".BASE."vendorview.php?iVendorId=$this->iVendorId\">".
+            "$this->sName</a>",
+            "<a href=\"$this->sWebpage\">$this->sWebpage</a>",
+            array(sizeof($this->aApplicationsIds), "align=\"right\""));
+
+        if($this->canEdit())
+        {
+            if(!sizeof($this->aApplicationsIds))
+                $sDelete = " &nbsp; [<a href=\"".BASE."vendorview.php?sSub=delete&".
+                "iVendorId=$this->iVendorId\">".
+                "delete</a>]";
+
+            $aCells[sizeof($aCells)] = "[<a href=\"".BASE."admin/editVendor.php?".
+            "iVendorId=$this->iVendorId\">edit</a>]$sDelete";
+        }
+
+        echo html_tr($aCells, $sClass);
+    }
+
     function canEdit()
     {
         if($_SESSION['current']->hasPriv("admin"))



More information about the wine-cvs mailing list