Replace objectOutputTableRow() with objectGetTableRow(). Redesign the table output mechanism so

that we fetch a table row from a class instead of letting the class display it. Move adding of
edit/delete links from the classes to the objectManager. Fix a hole in the distribution class
where an uninitialized variable could have been used in the constructor.
This commit is contained in:
Alexander Nicolaysen Sørnes
2007-06-14 00:50:35 +00:00
committed by WineHQ
parent 46f4f20ce6
commit cd198f44d7
14 changed files with 134 additions and 108 deletions

View File

@@ -488,8 +488,7 @@ class appData
} }
} }
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectGetTableRow()
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
{ {
$oVersion = new Version($this->iVersionId); $oVersion = new Version($this->iVersionId);
@@ -504,11 +503,7 @@ class appData
$oApp->objectMakeLink(), $oApp->objectMakeLink(),
$this->iVersionId ? $oVersion->objectMakeLink() : "N/A"); $this->iVersionId ? $oVersion->objectMakeLink() : "N/A");
if(appData::canEdit($oObject->sClass)) return array($aCells, null, false, null);
$aCells[] = "[ <a href=\"".$oObject->makeUrl("edit",
$this->iId)."\">$sEditLinkLabel</a> ]";
echo html_tr($aCells, $sClass);
} }
function objectDisplayQueueProcessingHelp() function objectDisplayQueueProcessingHelp()
@@ -555,6 +550,11 @@ class appData
" submitted application data here"; " submitted application data here";
return $sReplyText; return $sReplyText;
} }
function objectGetId()
{
return $this->iId;
}
} }
?> ?>

View File

@@ -849,7 +849,7 @@ class Application {
return $aCells; return $aCells;
} }
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) function objectGetTableRow()
{ {
$oUser = new user($this->iSubmitterId); $oUser = new user($this->iSubmitterId);
$oVendor = new vendor($this->iVendorId); $oVendor = new vendor($this->iVendorId);
@@ -864,14 +864,7 @@ class Application {
$sVendor, $sVendor,
$this->sName); $this->sName);
/* Display an edit link if the user has proper permissions */ return array($aCells, null, false, null);
if($this->canEdit())
{
$aCells[] = "[ <a href=\"".$oObject->makeUrl("edit", $this->iAppId,
"Edit Application")."\">$sEditLinkLabel</a> ]";
}
echo html_tr($aCells, $sClass);
} }
function canEdit() function canEdit()
@@ -1002,6 +995,11 @@ class Application {
{ {
return FALSE; return FALSE;
} }
function objectGetId()
{
return $this->iAppId;
}
} }
function get_vendor_from_keywords($sKeywords) function get_vendor_from_keywords($sKeywords)

View File

@@ -302,9 +302,9 @@ class application_queue
return $this->oApp->objectGetHeader(); return $this->oApp->objectGetHeader();
} }
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) function objectGetTableRow()
{ {
return $this->oApp->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); return $this->oApp->objectGetTableRow();
} }
function objectMoveChildren($iNewId) function objectMoveChildren($iNewId)
@@ -321,6 +321,11 @@ class application_queue
{ {
return application::allowAnonymousSubmissions(); return application::allowAnonymousSubmissions();
} }
function objectGetId()
{
return $this->oApp->objectGetId();
}
} }
?> ?>

View File

@@ -67,7 +67,7 @@ class distribution {
ORDER BY testedRating;"; ORDER BY testedRating;";
} }
if($hResult = query_parameters($sQuery, $iDistributionId)) if($hResult = query_parameters($sQuery, $this->iDistributionId))
{ {
while($oRow = mysql_fetch_object($hResult)) while($oRow = mysql_fetch_object($hResult))
{ {
@@ -453,32 +453,17 @@ class distribution {
$iStart, $iRows); $iStart, $iRows);
} }
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectGetTableRow()
function objectOutputTableRow($oManager, $sClass, $sEditLinkLabel)
{ {
$aCells = array( $aCells = array(
"<a href=\"".$oManager->makeUrl("view", $this->iDistributionId, $this->objectMakeLink(),
"View distribution")."\">$this->sName.</a>",
"<a href=\"$this->sUrl\">$this->sUrl</a>", "<a href=\"$this->sUrl\">$this->sUrl</a>",
array(sizeof($this->aTestingIds), "align=\"right\"")); array(sizeof($this->aTestingIds), "align=\"right\""));
// add actions if the current user has permission to edit this object
if($this->canEdit())
{
// enable the 'delete' action if this distribution has no testing results // enable the 'delete' action if this distribution has no testing results
if(!sizeof($this->aTestingIds)) $bDeleteLink = sizeof($this->aTestingIds) ? FALSE : TRUE;
{
$shDeleteLink = " &nbsp; [<a href='".$oManager->makeUrl("delete",
$this->iDistributionId)."'>delete</a>]";
}
$aCells[] = array( return array($aCells, null, $bDeleteLink, null);
"[<a href='".$oManager->makeUrl("edit",
$this->iDistributionId)."'>$sEditLinkLabel</a>]$shDeleteLink",
"align=\"center\"");
}
echo html_tr($aCells, $sClass);
} }
// Whether the user has permission to edit distributions // Whether the user has permission to edit distributions

View File

@@ -405,11 +405,10 @@ class downloadurl
return appData::objectGetHeader("downloadurl"); return appData::objectGetHeader("downloadurl");
} }
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectGetTableRow()
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
{ {
$oAppData = new AppData(); $oAppData = new AppData();
$oAppData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); return $oAppData->objectGetTableRow();
} }
function getOutputEditorValues($aClean) function getOutputEditorValues($aClean)
@@ -446,6 +445,11 @@ class downloadurl
/* FIXME: not implemented */ /* FIXME: not implemented */
return TRUE; return TRUE;
} }
function objectGetId()
{
return $this->iId;
}
} }
?> ?>

View File

@@ -461,8 +461,7 @@ class maintainer
return $aCells; return $aCells;
} }
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function ObjectGetTableRow()
function ObjectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
{ {
$oUser = new User($this->iUserId); $oUser = new User($this->iUserId);
$oApp = new Application($this->iAppId); $oApp = new Application($this->iAppId);
@@ -475,12 +474,7 @@ class maintainer
($this->bSuperMaintainer) ? "Yes" : "No", ($this->bSuperMaintainer) ? "Yes" : "No",
$oUser->objectMakeLink()); $oUser->objectMakeLink());
if(maintainer::canEdit()) return array($aCells, null, false, null);
$aCells[sizeof($aCells)] = "[ <a href=\"".$oObject->makeUrl("edit",
$this->iMaintainerId)."\">$sEditLinkLabel</a> ]";
echo html_tr($aCells,
$sClass);
} }
function ObjectDisplayQueueProcessingHelp() function ObjectDisplayQueueProcessingHelp()

View File

@@ -11,6 +11,7 @@ class ObjectManager
var $iId; var $iId;
var $bIsRejected; var $bIsRejected;
var $oMultiPage; var $oMultiPage;
var $oTableRow;
function ObjectManager($sClass, $sTitle = "list", $iId = false) function ObjectManager($sClass, $sTitle = "list", $iId = false)
{ {
@@ -18,6 +19,7 @@ class ObjectManager
$this->sTitle = $sTitle; $this->sTitle = $sTitle;
$this->iId = $iId; $this->iId = $iId;
$this->oMultiPage = new MultiPage(FALSE); $this->oMultiPage = new MultiPage(FALSE);
$this->oTableRow = new TableRow(null);
} }
/* Check whether the associated class has the given method */ /* Check whether the associated class has the given method */
@@ -59,7 +61,7 @@ class ObjectManager
function display_table($aClean) function display_table($aClean)
{ {
$this->checkMethods(array("ObjectGetEntries", "ObjectGetHeader", $this->checkMethods(array("ObjectGetEntries", "ObjectGetHeader",
"ObjectOutputTableRow", "canEdit")); "objectGetTableRow", "objectGetId", "canEdit"));
$oObject = new $this->sClass(); $oObject = new $this->sClass();
@@ -110,9 +112,28 @@ class ObjectManager
{ {
$oObject = new $this->sClass(null, $oRow); $oObject = new $this->sClass(null, $oRow);
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ $this->oTableRow->TableRow($oObject->objectGetTableRow());
$oObject->objectOutputTableRow($this, ($iCount % 2) ? "color0" : "color1",
$this->bIsQueue ? "process" : "edit"); if(!$this->oTableRow->sStyle)
$this->oTableRow->sStyle = ($iCount % 2) ? "color0" : "color1";
$sEditLinkLabel = $this->bIsQueue ? "process" : "edit";
/* We add some action links */
if($oObject->canEdit())
{
$shDeleteLink = "";
if($this->oTableRow->bDeleteLink)
{
$shDeleteLink = ' [ <a href="'.$this->makeUrl("delete", $oObject->objectGetid()).
'">delete</a> ]';
}
$this->oTableRow->aCells[] = '[ <a href="'.$this->makeUrl("edit",
$oObject->objectGetId()).'">'.$sEditLinkLabel.'</a> ]'.$shDeleteLink;
}
echo html_tr($this->oTableRow->aCells, $this->oTableRow->sStyle);
} }
echo "</table>"; echo "</table>";
@@ -640,4 +661,33 @@ class MultiPage
} }
} }
class TableRow
{
var $aCells;
var $sStyle;
var $sEditLinkLabel;
var $bDeleteLink;
var $aRowClickable;
var $bCanEdit;
var $iId;
function TableRow($aInput)
{
if(!$aInput)
return;
/* aInput is returned from objectGetTableRow(); an array with the following members
0: an array with the contents of the table row
1: CSS style to be used. If it is null we use the default
2: Is TRUE if we should display a delete link with the edit link
3: Contains an array with info if we should make the entrie table row clickable,
null otherwise */
$this->aCells = $aInput[0];
$this->sStyle = $aInput[1];
$this->bDeleteLink = $aInput[2];
$this->aRowClickable = $aInput[3];
}
}
?> ?>

View File

@@ -559,11 +559,10 @@ class Screenshot {
return appData::mustBeQueued(); return appData::mustBeQueued();
} }
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectGetTableRow()
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
{ {
$oAppData = new AppData($this->iScreenshotId, null, $this); $oAppData = new AppData($this->iScreenshotId, null, $this);
$oAppData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); return $oAppData->objectGetTableRow();
} }
function objectDisplayQueueProcessingHelp() function objectDisplayQueueProcessingHelp()
@@ -646,6 +645,11 @@ class Screenshot {
{ {
return FALSE; return FALSE;
} }
function objectGetId()
{
return $this->iScreenshotId;
}
} }
?> ?>

View File

@@ -939,13 +939,12 @@ class testData{
return $aCells; return $aCells;
} }
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) function objectGetTableRow()
{ {
$oVersion = new version($this->iVersionId); $oVersion = new version($this->iVersionId);
$oApp = new application($oVersion->iAppId); $oApp = new application($oVersion->iAppId);
$oUser = new user($this->iSubmitterId); $oUser = new user($this->iSubmitterId);
//
$hMaintainers = maintainer::getMaintainersForAppIdVersionId(null, $this->iVersionId); $hMaintainers = maintainer::getMaintainersForAppIdVersionId(null, $this->iVersionId);
$bHasMaintainer = (mysql_num_rows($hMaintainers) == 0) ? false : true; $bHasMaintainer = (mysql_num_rows($hMaintainers) == 0) ? false : true;
@@ -958,18 +957,7 @@ class testData{
($bHasMaintainer ? "YES" : "no"), ($bHasMaintainer ? "YES" : "no"),
$this->sTestedRating); $this->sTestedRating);
if($this->canEdit() or $this->sQueued == "rejected") return array($aCells, $this->sTestedRating, true, null);
{
$shDeleteLink = "[ <a href=\"".$oObject->makeUrl("delete",
$this->iTestingId).
"\"> delete</a> ]";
$aCells[] = "[ <a href=\"".$oObject->makeUrl("edit",
$this->iTestingId)."\">$sEditLinkLabel</a> ]".
$shDeleteLink;
}
echo html_tr($aCells, $this->sTestedRating);
} }
function canEdit() function canEdit()
@@ -1068,6 +1056,11 @@ class testData{
$iDefaultPerPage = 25; $iDefaultPerPage = 25;
return array($aItemsPerPage, $iDefaultPerPage); return array($aItemsPerPage, $iDefaultPerPage);
} }
function objectGetId()
{
return $this->iTestingId;
}
} }
?> ?>

View File

@@ -137,36 +137,30 @@ class testData_queue
return $this->oTestData->objectGetHeader(); return $this->oTestData->objectGetHeader();
} }
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) function objectGetTableRow()
{ {
return $this->oTestData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); return $this->oTestData->objectGetTableRow();
} }
function objectDisplayQueueProcessingHelp() function objectDisplayQueueProcessingHelp()
{ {
$oTest = new testData(); $oTest = new testData();
echo "<p>"; $oTest->objectDisplayQueueProcessingHelp();
if($oTest->canEdit)
echo "This is the list of rejected test results, waiting to be resubmitted or deleted.";
else
echo "This is the list of your rejected test results. Here you can make changes to ".
"them and resubmit them into the database.";
echo "</p>\n";
} }
function display() function display()
{ {
return $this->oTest->display(); return $this->oTestData->display();
} }
function objectMakeUrl() function objectMakeUrl()
{ {
return $this->oTest->objectMakeUrl(); return $this->oTestData->objectMakeUrl();
} }
function objectMakeLink() function objectMakeLink()
{ {
return $this->oTest->objectMakeLink(); return $this->oTestData->objectMakeLink();
} }
function allowAnonymousSubmissions() function allowAnonymousSubmissions()
@@ -178,6 +172,11 @@ class testData_queue
{ {
return testData::objectGetItemsPerPage($bQueued); return testData::objectGetItemsPerPage($bQueued);
} }
function objectGetId()
{
return $this->oTestData->objectGetId();
}
} }
?> ?>

View File

@@ -222,27 +222,16 @@ class Vendor {
return $aCells; return $aCells;
} }
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */ function objectGetTableRow()
function objectOutputTableRow($oObject, $sClass = "", $sEditLinkLabel)
{ {
$aCells = array( $aCells = array(
"<a href=\"".$oObject->makeUrl("view", $this->iVendorId, $this->objectMakeLink(),
"View Vendor")."\">$this->sName</a>",
"<a href=\"$this->sWebpage\">$this->sWebpage</a>", "<a href=\"$this->sWebpage\">$this->sWebpage</a>",
array(sizeof($this->aApplicationsIds), "align=\"right\"")); array(sizeof($this->aApplicationsIds), "align=\"right\""));
if($this->canEdit()) $bDeleteLink = sizeof($this->aApplicationsIds) ? FALSE : TRUE;
{
if(!sizeof($this->aApplicationsIds))
$shDeleteLink = " &nbsp; [<a href=\"".$oObject->makeUrl("delete",
$this->iVendorId, "View Vendors")."\">".
"delete</a>]";
$aCells[sizeof($aCells)] = "[<a href=\"".$oObject->makeUrl("edit", return array($aCells, null, $bDeleteLink, null);
$this->iVendorId, "Edit Vendor")."\">$sEditLinkLabel</a>]$shDeleteLink";
}
echo html_tr($aCells, $sClass);
} }
function canEdit() function canEdit()

View File

@@ -1340,7 +1340,7 @@ class Version {
return $hResult; return $hResult;
} }
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) function objectGetTableRow()
{ {
$oUser = new user($this->iSubmitterId); $oUser = new user($this->iSubmitterId);
$oApp = new application($this->iAppId); $oApp = new application($this->iAppId);
@@ -1352,13 +1352,7 @@ class Version {
$oApp->objectMakeLink(), $oApp->objectMakeLink(),
$this->sName); $this->sName);
if($this->canEdit()) return array($aCells, null, false, null);
{
$aCells[] = "[ <a href=\"".$oObject->makeUrl("edit",
$this->iVersionId)."\">$sEditLinkLabel</a> ]";
}
echo html_tr($aCells, $sClass);
} }
function objectDisplayQueueProcessingHelp() function objectDisplayQueueProcessingHelp()
@@ -1416,6 +1410,11 @@ class Version {
{ {
return FALSE; return FALSE;
} }
function objectGetId()
{
return $this->iVersionId;
}
} }
?> ?>

View File

@@ -166,9 +166,9 @@ class version_queue
return $this->oVersion->objectGetHeader(); return $this->oVersion->objectGetHeader();
} }
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel) function objectGetTableRow()
{ {
return $this->oVersion->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel); return $this->oVersion->objectGetTableRow();
} }
function display() function display()
@@ -247,6 +247,11 @@ class version_queue
{ {
return version::allowAnonymousSubmissions(); return version::allowAnonymousSubmissions();
} }
function objectGetId()
{
return $this->oVersion->objectGetId();
}
} }
?> ?>

View File

@@ -227,7 +227,8 @@ function test_object_methods()
"getOutputEditorValues", "getOutputEditorValues",
"objectGetEntries", "objectGetEntries",
"objectGetHeader", "objectGetHeader",
"objectOutputTableRow", "objectGetId",
"objectGetTableRow",
"objectMakeLink", "objectMakeLink",
"objectMakeUrl", "objectMakeUrl",
"outputEditor", "outputEditor",