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 objectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
function objectGetTableRow()
{
$oVersion = new Version($this->iVersionId);
@@ -504,11 +503,7 @@ class appData
$oApp->objectMakeLink(),
$this->iVersionId ? $oVersion->objectMakeLink() : "N/A");
if(appData::canEdit($oObject->sClass))
$aCells[] = "[ <a href=\"".$oObject->makeUrl("edit",
$this->iId)."\">$sEditLinkLabel</a> ]";
echo html_tr($aCells, $sClass);
return array($aCells, null, false, null);
}
function objectDisplayQueueProcessingHelp()
@@ -555,6 +550,11 @@ class appData
" submitted application data here";
return $sReplyText;
}
function objectGetId()
{
return $this->iId;
}
}
?>

View File

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

View File

@@ -302,9 +302,9 @@ class application_queue
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)
@@ -321,6 +321,11 @@ class application_queue
{
return application::allowAnonymousSubmissions();
}
function objectGetId()
{
return $this->oApp->objectGetId();
}
}
?>

View File

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

View File

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

View File

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

View File

@@ -11,6 +11,7 @@ class ObjectManager
var $iId;
var $bIsRejected;
var $oMultiPage;
var $oTableRow;
function ObjectManager($sClass, $sTitle = "list", $iId = false)
{
@@ -18,6 +19,7 @@ class ObjectManager
$this->sTitle = $sTitle;
$this->iId = $iId;
$this->oMultiPage = new MultiPage(FALSE);
$this->oTableRow = new TableRow(null);
}
/* Check whether the associated class has the given method */
@@ -59,7 +61,7 @@ class ObjectManager
function display_table($aClean)
{
$this->checkMethods(array("ObjectGetEntries", "ObjectGetHeader",
"ObjectOutputTableRow", "canEdit"));
"objectGetTableRow", "objectGetId", "canEdit"));
$oObject = new $this->sClass();
@@ -110,9 +112,28 @@ class ObjectManager
{
$oObject = new $this->sClass(null, $oRow);
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */
$oObject->objectOutputTableRow($this, ($iCount % 2) ? "color0" : "color1",
$this->bIsQueue ? "process" : "edit");
$this->oTableRow->TableRow($oObject->objectGetTableRow());
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>";
@@ -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();
}
/* arg1 = OM object, arg2 = CSS style, arg3 = text for edit link */
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
function objectGetTableRow()
{
$oAppData = new AppData($this->iScreenshotId, null, $this);
$oAppData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel);
return $oAppData->objectGetTableRow();
}
function objectDisplayQueueProcessingHelp()
@@ -646,6 +645,11 @@ class Screenshot {
{
return FALSE;
}
function objectGetId()
{
return $this->iScreenshotId;
}
}
?>

View File

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

View File

@@ -137,36 +137,30 @@ class testData_queue
return $this->oTestData->objectGetHeader();
}
function objectOutputTableRow($oObject, $sClass, $sEditLinkLabel)
function objectGetTableRow()
{
return $this->oTestData->objectOutputTableRow($oObject, $sClass, $sEditLinkLabel);
return $this->oTestData->objectGetTableRow();
}
function objectDisplayQueueProcessingHelp()
{
$oTest = new testData();
echo "<p>";
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";
$oTest->objectDisplayQueueProcessingHelp();
}
function display()
{
return $this->oTest->display();
return $this->oTestData->display();
}
function objectMakeUrl()
{
return $this->oTest->objectMakeUrl();
return $this->oTestData->objectMakeUrl();
}
function objectMakeLink()
{
return $this->oTest->objectMakeLink();
return $this->oTestData->objectMakeLink();
}
function allowAnonymousSubmissions()
@@ -178,6 +172,11 @@ class testData_queue
{
return testData::objectGetItemsPerPage($bQueued);
}
function objectGetId()
{
return $this->oTestData->objectGetId();
}
}
?>

View File

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

View File

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

View File

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

View File

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