Php5 improvements to table code. Add some accessor methods to classes so we can make class variables private.

This commit is contained in:
Chris Morgan
2007-09-18 21:22:43 -04:00
parent e0e19c26a7
commit 5c91961d12
6 changed files with 86 additions and 64 deletions

View File

@@ -422,7 +422,7 @@ class Bug
// enable the deletion link, the objectManager will check // enable the deletion link, the objectManager will check
// for appropriate permissions before adding the link // for appropriate permissions before adding the link
$oOMTableRow->SetRowHasDeleteLink(true); $oOMTableRow->SetHasDeleteLink(true);
return $oOMTableRow; return $oOMTableRow;
} }

View File

@@ -543,7 +543,7 @@ class distribution {
$bDeleteLink = sizeof($this->aTestingIds) ? FALSE : TRUE; $bDeleteLink = sizeof($this->aTestingIds) ? FALSE : TRUE;
$oOMTableRow = new OMTableRow($oTableRow); $oOMTableRow = new OMTableRow($oTableRow);
$oOMTableRow->SetRowHasDeleteLink($bDeleteLink); $oOMTableRow->SetHasDeleteLink($bDeleteLink);
return $oOMTableRow; return $oOMTableRow;
} }

View File

@@ -157,14 +157,15 @@ class ObjectManager
$sColor = ($iCount % 2) ? "color0" : "color1"; $sColor = ($iCount % 2) ? "color0" : "color1";
//TODO: we shouldn't access this method directly, should make an accessor for it // if there is no class set for a given row use the
if(!$this->oTableRow->oTableRow->sClass) // default one in $sColor
if(!$this->oTableRow->oTableRow->GetClass())
{ {
$this->oTableRow->oTableRow->SetClass($sColor); $this->oTableRow->oTableRow->SetClass($sColor);
} }
// if this row is clickable, make it highlight appropirately // if this row is clickable, make it highlight appropirately
$oTableRowClick = $this->oTableRow->oTableRow->oTableRowClick; $oTableRowClick = $this->oTableRow->oTableRow->GetTableRowClick();
if($oTableRowClick) if($oTableRowClick)
{ {
$oTableRowHighlight = GetStandardRowHighlight($iCount); $oTableRowHighlight = GetStandardRowHighlight($iCount);

View File

@@ -5,17 +5,14 @@
// class for managing the highlighting/inactive state of a row // class for managing the highlighting/inactive state of a row
class TableRowHighlight class TableRowHighlight
{ {
//TODO: php5, make these private private $oHighlightColor;
var $oHighlightColor; private $oInactiveColor;
var $oInactiveColor;
// properties to apply to text when highlighted or inactive // properties to apply to text when highlighted or inactive
// TODO: php5, make these private private $sTextDecorationHighlight;
var $sTextDecorationHighlight; private $sTextDecorationInactive;
var $sTextDecorationInactive;
//TODO: php5, type hint to color class function TableRowHighlight(color $oHighlightColor, color $oInactiveColor,
function TableRowHighlight($oHighlightColor, $oInactiveColor,
$sTextDecorationHighlight = "", $sTextDecorationHighlight = "",
$sTextDecorationInactive = "") $sTextDecorationInactive = "")
{ {
@@ -25,6 +22,26 @@ class TableRowHighlight
$this->sTextDecorationHighlight = $sTextDecorationHighlight; $this->sTextDecorationHighlight = $sTextDecorationHighlight;
$this->sTextDecorationInactive = $sTextDecorationInactive; $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 class TableRowClick
@@ -40,8 +57,7 @@ class TableRowClick
$this->oTableRowHighlight = null; $this->oTableRowHighlight = null;
} }
//TODO: php5, type hint to TableRowHighlight class function SetHighlight(TableRowHighlight $oTableRowHighlight)
function SetHighlight($oTableRowHighlight)
{ {
$this->oTableRowHighlight = $oTableRowHighlight; $this->oTableRowHighlight = $oTableRowHighlight;
} }
@@ -55,15 +71,15 @@ class TableRowClick
if($this->oTableRowHighlight) if($this->oTableRowHighlight)
{ {
$sStr.= 'onmouseover="ChangeTr(this, true,'. $sStr.= 'onmouseover="ChangeTr(this, true,'.
'\''.$this->oTableRowHighlight->oHighlightColor->GetHexString().'\','. '\''.$this->oTableRowHighlight->getHighlightColor()->GetHexString().'\','.
'\''.$this->oTableRowHighlight->oInactiveColor->GetHexString().'\','. '\''.$this->oTableRowHighlight->getInactiveColor()->GetHexString().'\','.
'\''.$this->oTableRowHighlight->sTextDecorationHighlight.'\','. '\''.$this->oTableRowHighlight->getTextDecorationHighlight().'\','.
'\''.$this->oTableRowHighlight->sTextDecorationInactive.'\');"'; '\''.$this->oTableRowHighlight->getTextDecorationInactive().'\');"';
$sStr.= ' onmouseout="ChangeTr(this, false,'. $sStr.= ' onmouseout="ChangeTr(this, false,'.
'\''.$this->oTableRowHighlight->oHighlightColor->GetHexString().'\','. '\''.$this->oTableRowHighlight->getHighlightColor()->GetHexString().'\','.
'\''.$this->oTableRowHighlight->oInactiveColor->GetHexString().'\','. '\''.$this->oTableRowHighlight->getInactiveColor()->GetHexString().'\','.
'\''.$this->oTableRowHighlight->sTextDecorationHighlight.'\','. '\''.$this->oTableRowHighlight->getTextDecorationHighlight().'\','.
'\''.$this->oTableRowHighlight->sTextDecorationInactive.'\');"'; '\''.$this->oTableRowHighlight->getTextDecorationInactive().'\');"';
} }
$sStr.= ' onclick="DoNav(\''.$this->shUrl.'\');"'; $sStr.= ' onclick="DoNav(\''.$this->shUrl.'\');"';
@@ -74,15 +90,14 @@ class TableRowClick
class TableCell class TableCell
{ {
//TODO: make these private when we move to php5 private $sCell;
var $sCell; private $sStyle;
var $sStyle; private $sClass;
var $sClass; private $sAlign; // align="$sAlign" will be output if this is not null
var $sAlign; // align="$sAlign" will be output if this is not null private $sValign; // valign="$sValign" will be output if this is not null
var $sValign; // valign="$sValign" will be output if this is not null private $sWidth; // width="$sWidth"
var $sWidth; // width="$sWidth" private $sUrl; // wraps the cell contents in an anchor tag if $sUrl is not null
var $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
var $bBold; // if true will output the cell contents as bold
// NOTE: We specifically have limited the parameters to the constructor // NOTE: We specifically have limited the parameters to the constructor
// to only the contents of the cell. Additional parameters, while // to only the contents of the cell. Additional parameters, while
@@ -134,7 +149,6 @@ class TableCell
$this->sUrl = $sUrl; $this->sUrl = $sUrl;
} }
//php5 make sure this type is boolean
function SetBold($bBold) function SetBold($bBold)
{ {
$this->bBold = $bBold; $this->bBold = $bBold;
@@ -186,13 +200,12 @@ class TableCell
class TableRow class TableRow
{ {
//TODO: make these private when we get php5 private $aTableCells; // array that contains the cells for the table row
var $aTableCells; // array that contains the cells for the table row private $sStyle; // CSS style to be used
var $sStyle; // CSS style to be used private $sClass; // CSS class to be used
var $sClass; // CSS class to be used private $sValign; // valign="$sValign" - if this variable is set
var $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() function TableRow()
{ {
@@ -203,8 +216,7 @@ class TableRow
$this->oTableRowClick = null; $this->oTableRowClick = null;
} }
// TODO: php5 need to add type hinting here to make sure this is a TableCell instance function AddCell(TableCell $oTableCell)
function AddCell($oTableCell)
{ {
$this->aTableCells[] = $oTableCell; $this->aTableCells[] = $oTableCell;
} }
@@ -217,7 +229,6 @@ class TableRow
} }
} }
// TODO: php5 type hint as text
function AddTextCell($sCellText) function AddTextCell($sCellText)
{ {
$this->AddCell(new TableCell($sCellText)); $this->AddCell(new TableCell($sCellText));
@@ -275,6 +286,16 @@ class TableRow
return $sStr; return $sStr;
} }
function GetClass()
{
return $this->sClass;
}
function GetTableRowClick()
{
return $this->oTableRowClick;
}
} }
// object manager table row, has additional parameters used by the object manager // object manager table row, has additional parameters used by the object manager
@@ -283,9 +304,9 @@ class TableRow
// extension of that class // extension of that class
class OMTableRow class OMTableRow
{ {
var $oTableRow; private $oTableRow;
var $bHasDeleteLink; private $bHasDeleteLink;
var $bCanEdit; private $bCanEdit;
function OMTableRow($oTableRow) function OMTableRow($oTableRow)
{ {
@@ -294,14 +315,17 @@ class OMTableRow
$this->bCanEdit = false; $this->bCanEdit = false;
} }
// php5 hint that type is bool function SetHasDeleteLink($bHasDeleteLink)
function SetRowHasDeleteLink($bHasDeleteLink)
{ {
$this->bHasDeleteLink = $bHasDeleteLink; $this->bHasDeleteLink = $bHasDeleteLink;
} }
// php5 hint type here function GetHasDeleteLink()
function SetRowClickable($oTableRowClick) {
return $this->bHasDeleteLink;
}
function SetRowClickable(TableRowClick $oTableRowClick)
{ {
$this->oTableRowClick = $oTableRowClick; $this->oTableRowClick = $oTableRowClick;
} }
@@ -325,15 +349,14 @@ class OMTableRow
class Table class Table
{ {
//TODO: make private when we have php5 private $oTableRowHeader;
var $oTableRowHeader; private $aTableRows;
var $aTableRows; private $sClass;
var $sClass; private $sWidth;
var $sWidth; private $iBorder;
var $iBorder; private $sAlign; // align="$sAlign" - deprecated in html standards
var $sAlign; // align="$sAlign" - deprecated in html standards private $iCellSpacing; // cellspacing="$iCellSpacing"
var $iCellSpacing; // cellspacing="$iCellSpacing" private $iCellPadding; // cellpadding="$iCellPadding"
var $iCellPadding; // cellpadding="$iCellPadding"
function Table() function Table()
{ {
@@ -352,8 +375,7 @@ class Table
$this->aTableRows[] = $oTableRow; $this->aTableRows[] = $oTableRow;
} }
// TODO: php5 force type to HtmlTableRow function SetHeader(TableRow $oTableRowHeader)
function SetHeader($oTableRowHeader)
{ {
$this->oTableRowHeader = $oTableRowHeader; $this->oTableRowHeader = $oTableRowHeader;
} }
@@ -447,9 +469,8 @@ function GetStandardRowHighlight($iRowIndex)
return $oTableRowHighlight; return $oTableRowHighlight;
} }
// TODO: php5 type hint this to color class
// returns a color class instance // returns a color class instance
function GetHighlightColorFromInactiveColor($oInactiveColor) function GetHighlightColorFromInactiveColor(color $oInactiveColor)
{ {
$oHighlightColor = new color($oInactiveColor->iRed, $oHighlightColor = new color($oInactiveColor->iRed,
$oInactiveColor->iGreen, $oInactiveColor->iGreen,

View File

@@ -1074,7 +1074,7 @@ class testData{
$oTableRow->SetClass($this->sTestedRating); $oTableRow->SetClass($this->sTestedRating);
$oOMTableRow = new OMTableRow($oTableRow); $oOMTableRow = new OMTableRow($oTableRow);
$oOMTableRow->SetRowHasDeleteLink(true); $oOMTableRow->SetHasDeleteLink(true);
return $oOMTableRow; return $oOMTableRow;
} }

View File

@@ -270,7 +270,7 @@ class Vendor {
// create the object manager specific row // create the object manager specific row
$oOMTableRow = new OMTableRow($oTableRow); $oOMTableRow = new OMTableRow($oTableRow);
$oOMTableRow->SetRowHasDeleteLink($bDeleteLink); $oOMTableRow->SetHasDeleteLink($bDeleteLink);
return $oOMTableRow; return $oOMTableRow;
} }