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,20 +15,25 @@ class Vendor {
/** /**
* constructor, fetches the data. * constructor, fetches the data.
*/ */
function Vendor($iVendorId = null) function Vendor($iVendorId = null, $oRow = null)
{ {
// we are working on an existing vendor // we are working on an existing vendor
if(is_numeric($iVendorId)) if(is_numeric($iVendorId))
{ {
/* if(!$oRow)
* We fetch the data related to this vendor. {
*/ /*
$sQuery = "SELECT * * We fetch the data related to this vendor.
FROM vendor */
WHERE vendorId = '?'"; $sQuery = "SELECT *
if($hResult = query_parameters($sQuery, $iVendorId)) 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->iVendorId = $iVendorId;
$this->sName = $oRow->vendorName; $this->sName = $oRow->vendorName;
$this->sWebpage = $oRow->vendorURL; $this->sWebpage = $oRow->vendorURL;
@@ -140,14 +145,18 @@ class Vendor {
echo "</table>\n"; echo "</table>\n";
} }
function objectGetEntries($bQueued) function objectGetEntries($bQueued, $iRows = 0, $iStart = 0)
{ {
/* Vendor queueing is not implemented yet */ /* Vendor queueing is not implemented yet */
if($bQueued) if($bQueued)
return NULL; return NULL;
if(!$iRows)
$iRows = getNumberOfVendors();
$hResult = query_parameters("SELECT * FROM vendor $hResult = query_parameters("SELECT * FROM vendor
ORDER BY vendorName"); ORDER BY vendorName LIMIT ?,?",
$iStart, $iRows);
if(!$hResult) if(!$hResult)
return FALSE; return FALSE;
@@ -168,6 +177,33 @@ class Vendor {
echo html_tr($sCells, $sClass); 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() function canEdit()
{ {
if($_SESSION['current']->hasPriv("admin")) if($_SESSION['current']->hasPriv("admin"))

View File

@@ -52,25 +52,10 @@ else
vendor::objectOutputHeader("color4"); vendor::objectOutputHeader("color4");
$c = 1; for($c = 0; $oRow = mysql_fetch_object($hResult); $c++)
while($oRow = mysql_fetch_object($hResult))
{ {
if ($c % 2 == 1) { $bgcolor = 'color0'; } else { $bgcolor = 'color1'; } $oVendor = vendor::objectGetInstanceFromRow($oRow);
$oVendor = new Vendor($oRow->vendorId); $oVendor->objectOutputTableRow(($c % 2) ? "color0" : "color1");
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++;
} }
echo '<tr><td>',"\n"; echo '<tr><td>',"\n";