From 5c91961d12b88a9ea6952aedaa792b29f286bb04 Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 18 Sep 2007 21:22:43 -0400 Subject: [PATCH] Php5 improvements to table code. Add some accessor methods to classes so we can make class variables private. --- include/bugs.php | 2 +- include/distribution.php | 2 +- include/objectManager.php | 7 +- include/table.php | 135 ++++++++++++++++++++++---------------- include/testData.php | 2 +- include/vendor.php | 2 +- 6 files changed, 86 insertions(+), 64 deletions(-) diff --git a/include/bugs.php b/include/bugs.php index 51710bb..e57f6a1 100644 --- a/include/bugs.php +++ b/include/bugs.php @@ -422,7 +422,7 @@ class Bug // enable the deletion link, the objectManager will check // for appropriate permissions before adding the link - $oOMTableRow->SetRowHasDeleteLink(true); + $oOMTableRow->SetHasDeleteLink(true); return $oOMTableRow; } diff --git a/include/distribution.php b/include/distribution.php index df89501..52c08a9 100644 --- a/include/distribution.php +++ b/include/distribution.php @@ -543,7 +543,7 @@ class distribution { $bDeleteLink = sizeof($this->aTestingIds) ? FALSE : TRUE; $oOMTableRow = new OMTableRow($oTableRow); - $oOMTableRow->SetRowHasDeleteLink($bDeleteLink); + $oOMTableRow->SetHasDeleteLink($bDeleteLink); return $oOMTableRow; } diff --git a/include/objectManager.php b/include/objectManager.php index 0c1a3ea..d31f92a 100644 --- a/include/objectManager.php +++ b/include/objectManager.php @@ -157,14 +157,15 @@ class ObjectManager $sColor = ($iCount % 2) ? "color0" : "color1"; - //TODO: we shouldn't access this method directly, should make an accessor for it - if(!$this->oTableRow->oTableRow->sClass) + // if there is no class set for a given row use the + // default one in $sColor + if(!$this->oTableRow->oTableRow->GetClass()) { $this->oTableRow->oTableRow->SetClass($sColor); } // if this row is clickable, make it highlight appropirately - $oTableRowClick = $this->oTableRow->oTableRow->oTableRowClick; + $oTableRowClick = $this->oTableRow->oTableRow->GetTableRowClick(); if($oTableRowClick) { $oTableRowHighlight = GetStandardRowHighlight($iCount); diff --git a/include/table.php b/include/table.php index 6e2e9dc..1a52751 100644 --- a/include/table.php +++ b/include/table.php @@ -5,17 +5,14 @@ // class for managing the highlighting/inactive state of a row class TableRowHighlight { - //TODO: php5, make these private - var $oHighlightColor; - var $oInactiveColor; + private $oHighlightColor; + private $oInactiveColor; // properties to apply to text when highlighted or inactive - // TODO: php5, make these private - var $sTextDecorationHighlight; - var $sTextDecorationInactive; + private $sTextDecorationHighlight; + private $sTextDecorationInactive; - //TODO: php5, type hint to color class - function TableRowHighlight($oHighlightColor, $oInactiveColor, + function TableRowHighlight(color $oHighlightColor, color $oInactiveColor, $sTextDecorationHighlight = "", $sTextDecorationInactive = "") { @@ -25,6 +22,26 @@ class TableRowHighlight $this->sTextDecorationHighlight = $sTextDecorationHighlight; $this->sTextDecorationInactive = $sTextDecorationInactive; } + + function GetHighlightColor() + { + return $this->oHighlightColor; + } + + function GetInactiveColor() + { + return $this->oInactiveColor; + } + + function GetTextDecorationHighlight() + { + return $this->sTextDecorationHighlight; + } + + function GetTextDecorationInactive() + { + return $this->sTextDecorationInactive; + } } class TableRowClick @@ -40,8 +57,7 @@ class TableRowClick $this->oTableRowHighlight = null; } - //TODO: php5, type hint to TableRowHighlight class - function SetHighlight($oTableRowHighlight) + function SetHighlight(TableRowHighlight $oTableRowHighlight) { $this->oTableRowHighlight = $oTableRowHighlight; } @@ -55,15 +71,15 @@ class TableRowClick if($this->oTableRowHighlight) { $sStr.= 'onmouseover="ChangeTr(this, true,'. - '\''.$this->oTableRowHighlight->oHighlightColor->GetHexString().'\','. - '\''.$this->oTableRowHighlight->oInactiveColor->GetHexString().'\','. - '\''.$this->oTableRowHighlight->sTextDecorationHighlight.'\','. - '\''.$this->oTableRowHighlight->sTextDecorationInactive.'\');"'; + '\''.$this->oTableRowHighlight->getHighlightColor()->GetHexString().'\','. + '\''.$this->oTableRowHighlight->getInactiveColor()->GetHexString().'\','. + '\''.$this->oTableRowHighlight->getTextDecorationHighlight().'\','. + '\''.$this->oTableRowHighlight->getTextDecorationInactive().'\');"'; $sStr.= ' onmouseout="ChangeTr(this, false,'. - '\''.$this->oTableRowHighlight->oHighlightColor->GetHexString().'\','. - '\''.$this->oTableRowHighlight->oInactiveColor->GetHexString().'\','. - '\''.$this->oTableRowHighlight->sTextDecorationHighlight.'\','. - '\''.$this->oTableRowHighlight->sTextDecorationInactive.'\');"'; + '\''.$this->oTableRowHighlight->getHighlightColor()->GetHexString().'\','. + '\''.$this->oTableRowHighlight->getInactiveColor()->GetHexString().'\','. + '\''.$this->oTableRowHighlight->getTextDecorationHighlight().'\','. + '\''.$this->oTableRowHighlight->getTextDecorationInactive().'\');"'; } $sStr.= ' onclick="DoNav(\''.$this->shUrl.'\');"'; @@ -74,15 +90,14 @@ class TableRowClick class TableCell { - //TODO: make these private when we move to php5 - var $sCell; - var $sStyle; - var $sClass; - var $sAlign; // align="$sAlign" will be output if this is not null - var $sValign; // valign="$sValign" will be output if this is not null - var $sWidth; // width="$sWidth" - var $sUrl; // wraps the cell contents in an anchor tag if $sUrl is not null - var $bBold; // if true will output the cell contents as bold + private $sCell; + private $sStyle; + private $sClass; + private $sAlign; // align="$sAlign" will be output if this is not null + private $sValign; // valign="$sValign" will be output if this is not null + private $sWidth; // width="$sWidth" + private $sUrl; // wraps the cell contents in an anchor tag if $sUrl is not null + private $bBold; // if true will output the cell contents as bold // NOTE: We specifically have limited the parameters to the constructor // to only the contents of the cell. Additional parameters, while @@ -134,7 +149,6 @@ class TableCell $this->sUrl = $sUrl; } - //php5 make sure this type is boolean function SetBold($bBold) { $this->bBold = $bBold; @@ -186,13 +200,12 @@ class TableCell class TableRow { - //TODO: make these private when we get php5 - var $aTableCells; // array that contains the cells for the table row - var $sStyle; // CSS style to be used - var $sClass; // CSS class to be used - var $sValign; // valign="$sValign" - if this variable is set + private $aTableCells; // array that contains the cells for the table row + private $sStyle; // CSS style to be used + private $sClass; // CSS class to be used + private $sValign; // valign="$sValign" - if this variable is set - var $oTableRowClick; // information about whether the table row is clickable etc + private $oTableRowClick; // information about whether the table row is clickable etc function TableRow() { @@ -203,8 +216,7 @@ class TableRow $this->oTableRowClick = null; } - // TODO: php5 need to add type hinting here to make sure this is a TableCell instance - function AddCell($oTableCell) + function AddCell(TableCell $oTableCell) { $this->aTableCells[] = $oTableCell; } @@ -217,7 +229,6 @@ class TableRow } } - // TODO: php5 type hint as text function AddTextCell($sCellText) { $this->AddCell(new TableCell($sCellText)); @@ -275,6 +286,16 @@ class TableRow return $sStr; } + + function GetClass() + { + return $this->sClass; + } + + function GetTableRowClick() + { + return $this->oTableRowClick; + } } // object manager table row, has additional parameters used by the object manager @@ -283,9 +304,9 @@ class TableRow // extension of that class class OMTableRow { - var $oTableRow; - var $bHasDeleteLink; - var $bCanEdit; + private $oTableRow; + private $bHasDeleteLink; + private $bCanEdit; function OMTableRow($oTableRow) { @@ -294,14 +315,17 @@ class OMTableRow $this->bCanEdit = false; } - // php5 hint that type is bool - function SetRowHasDeleteLink($bHasDeleteLink) + function SetHasDeleteLink($bHasDeleteLink) { $this->bHasDeleteLink = $bHasDeleteLink; } - // php5 hint type here - function SetRowClickable($oTableRowClick) + function GetHasDeleteLink() + { + return $this->bHasDeleteLink; + } + + function SetRowClickable(TableRowClick $oTableRowClick) { $this->oTableRowClick = $oTableRowClick; } @@ -325,15 +349,14 @@ class OMTableRow class Table { - //TODO: make private when we have php5 - var $oTableRowHeader; - var $aTableRows; - var $sClass; - var $sWidth; - var $iBorder; - var $sAlign; // align="$sAlign" - deprecated in html standards - var $iCellSpacing; // cellspacing="$iCellSpacing" - var $iCellPadding; // cellpadding="$iCellPadding" + private $oTableRowHeader; + private $aTableRows; + private $sClass; + private $sWidth; + private $iBorder; + private $sAlign; // align="$sAlign" - deprecated in html standards + private $iCellSpacing; // cellspacing="$iCellSpacing" + private $iCellPadding; // cellpadding="$iCellPadding" function Table() { @@ -352,8 +375,7 @@ class Table $this->aTableRows[] = $oTableRow; } - // TODO: php5 force type to HtmlTableRow - function SetHeader($oTableRowHeader) + function SetHeader(TableRow $oTableRowHeader) { $this->oTableRowHeader = $oTableRowHeader; } @@ -447,9 +469,8 @@ function GetStandardRowHighlight($iRowIndex) return $oTableRowHighlight; } -// TODO: php5 type hint this to color class // returns a color class instance -function GetHighlightColorFromInactiveColor($oInactiveColor) +function GetHighlightColorFromInactiveColor(color $oInactiveColor) { $oHighlightColor = new color($oInactiveColor->iRed, $oInactiveColor->iGreen, diff --git a/include/testData.php b/include/testData.php index c52b8b5..dc5d7de 100644 --- a/include/testData.php +++ b/include/testData.php @@ -1074,7 +1074,7 @@ class testData{ $oTableRow->SetClass($this->sTestedRating); $oOMTableRow = new OMTableRow($oTableRow); - $oOMTableRow->SetRowHasDeleteLink(true); + $oOMTableRow->SetHasDeleteLink(true); return $oOMTableRow; } diff --git a/include/vendor.php b/include/vendor.php index 9de276a..59919c9 100644 --- a/include/vendor.php +++ b/include/vendor.php @@ -270,7 +270,7 @@ class Vendor { // create the object manager specific row $oOMTableRow = new OMTableRow($oTableRow); - $oOMTableRow->SetRowHasDeleteLink($bDeleteLink); + $oOMTableRow->SetHasDeleteLink($bDeleteLink); return $oOMTableRow; }