Add and use vendor::objectGetInstanceFromRow() and vendor::objectOutputTableRow()

This commit is contained in:
Alexander Nicolaysen Sørnes
2007-02-01 02:07:24 +00:00
committed by WineHQ
parent cbdce75b0b
commit 53d2e2f6df
2 changed files with 50 additions and 29 deletions

View File

@@ -15,10 +15,12 @@ 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))
{
if(!$oRow)
{
/*
* We fetch the data related to this vendor.
@@ -27,8 +29,11 @@ class Vendor {
FROM vendor
WHERE vendorId = '?'";
if($hResult = query_parameters($sQuery, $iVendorId))
{
$oRow = mysql_fetch_object($hResult);
}
if($oRow)
{
$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"))

View File

@@ -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";