/**
* The required files
*/
require_once(HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
require_once(HTML_TABLE_COMPONENT_PATH.'/Table.php');
if (defined('HTML_DTO_UTIL_PATH')) {
require_once(HTML_DTO_UTIL_PATH.'/DataReaderFactory.php');
}
require_once(HTML_BASIC_UTIL_PATH.'/Message.php');
require_once(HTML_BASE_UTIL_PATH.'/Raw.php');
require_once(HTML_BASE_UTIL_PATH.'/Ul.php');
require_once(HTML_BASE_UTIL_PATH.'/Li.php');
require_once(HTML_BASE_UTIL_PATH.'/Links.php');
require_once(HTML_BASE_UTIL_PATH.'/Link.php');
require_once(HTML_BASE_UTIL_PATH.'/Images.php');
require_once(HTML_BASE_UTIL_PATH.'/Image.php');
require_once(HTML_UTIL_COMPONENT_PATH.'/Request.php');
if (defined('HTML_COMPONENT_PAGE_PATH')) {
require_once(HTML_COMPONENT_PAGE_PATH.'/Googlebox.php');
}
if (defined('HTML_LANGUAGE_UTIL_PATH')) {
require_once(HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}
if (defined('HTML_LOG_UTIL_PATH')) {
require_once(HTML_LOG_UTIL_PATH.'/Log.php');
}
/**
* Generates the html for a table
* <code>
* Usage:
* $rows = array(
* array('head_1'=>'dat_0_1', 'head_2'=>'dat_0_2', 'head_3'=>'dat_0_3',),
* array('head_1'=>'dat_1_1', 'head_2'=>'dat_1_2', 'head_3'=>'dat_1_3',),
* );
* $datareader = DataReaderFactory::newDataReader($rows);
* $table = new TableDataReader($datareader,$text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
* print $table->getHtml();
* Or
* Table::display($datareader,$text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
*
* Generates a complete table interface with data supplied by the DataReader object
* ------------------------------+
* | Text header |
* ------------------------------+
* | head_1 | head_2 | head_3 |
* ------------------------------+
* | dat_0_1 | dat_0_2 | dat_0_3 |
* | dat_1_1 | dat_1_2 | dat_1_3 |
* ------------------------------+
* </code>
* @package table
*/
class TableDataReader extends Table {
/**
* @var DataReader The Data Reader object
*/
var $datareader = '';
/**
* @var $layout The different layouts to use
* image link | image link | etc. on the same line
* image link | image link | etc. on the same line and google search
* image and link on each line
* <li> image and link on each line
* image <br> link etc. on the same line
*/
var $layout = '';
/**
* Constructor
* @param DataReader $datareader The Data Reader object
* @param String $text The text header for the table
* @param String $width The Width for the table
* @param String $class The Class
* @param String $border The Border
* @param String $cellpadding The CellSpacing
* @param String $cellspacing The CellPadding
* @param String $summary The Summary
* @param String $caption The Caption
*/
function TableDataReader($datareader='',$text='',$width='',$class='',$border='',$cellpadding='',$cellspacing='',$summary='',$caption='') {
$this->Table($text,$width,$class,$border,$cellpadding,$cellspacing,$summary,$caption);
$this->datareader = $this->getDatareader($datareader);
$this->adjustColumns();
}
/**
* Get the DataReader to use for this class
* @param DataReader $datareader The DataReader object, if defined
* @return DataReader or array The DataReader object or an array of default data
*/
function getDatareader($datareader) {
$theDatareader = $datareader;
if ($theDatareader == '') {
$print = new Links(LINK_PRINT);
/**
* Return the column data for the view
* @param String $value The value to use
* @param String $css The CSS to use
* @param String $valign The valign to use
* @return Object The html as an object
*/
function newData($value='', $css='', $valign='') {
$text = $value!=''?$value:'';
$object = new Td($css,$valign,'',$text);
if ($this->layout & LINK_LAYOUT_LI) {
$object = new Raw($text);
}
return $object;
}
/**
* Get the CSS class Name for this component
* You may override this function if you need another CSS class name
* @abstract
* @return String The CSS class name
*/
function getCssClass() {
return CSS_BODY;
}
/**
* Return the column data as html
* The column data may be
* - LINK_NAME
* - IMAGE_NAME
* - link
* - image
* - link + image
* <code>
* </code>
* @param String $page The page key
* @param array $column The column to loop for key/value pairs
* @param boolean $isActivetab The Tab is active
* @param boolean $isActiveindex The Index is active
* @return Object The html as an object
*/
function newColumn($page, $column, $isActiveTab=false, $isActiveIndex=false) {
$object = new Raw();
if (count($column)>0) {
$text = '';
$href = '';
$title = '';
$src = '';
$width = '';
$height = '';
$alt = '';
$class = $this->getCssClass();
$theValue = '';
$valign = 'middle';
foreach($column as $key=>$value) {
switch ($key) {
case KEY_TRIANGLE:
$aux = '';
if ($this->layout & LINK_LAYOUT_LI) {
$aux = LINK_LAYOUT_LI;
}
$theValue = $this->newTriangle($value, $class, $aux);
$class .= ' '.CSS_ONEPC;
break;
case KEY_LINK:
$class .= ' '.CSS_ALIGN_LEFT; // Intentionally fall through
case KEY_POWERED:
if ($class == $this->getCssClass()) {
$class .= ' '.CSS_ALIGN_RIGHT;
}
$theValue = new Links($value,'',$class);
break;
case KEY_VERSION:
$theValue = TEXT_VERSION.' '; // Intentionally fall through
case KEY_PLAIN:
case KEY_GOOGLE:
$theValue .= $value;
break;
default:
$$key = $value;
break;
}
}
if ($theValue == '') {
$theValue = new Raw();
if ($href != '' || $text != '') {
if (defined('HTML_LANGUAGE_UTIL_PATH')) {
$text = ucfirst(Translate::get($text));
}
$aux = '';
if ($this->layout & LINK_LAYOUT_LI) {
$aux = LINK_LAYOUT_LI;
} else if ($this->layout & LINK_LAYOUT_BR) {
$aux = LINK_LAYOUT_BR;
}
if ($isActiveTab || $isActiveIndex ) {
// The selected Tab
if ($this->layout & LINK_LAYOUT_TAB) {
$class = CSS_ATAB_ACTIVE;
}
$theValue = new Raw('<b class="'.$class.'">'.$text."</b> ");
if ($src != '') {
$theValue->add(new Image($src,$width,$height,$alt,$class));
}
if ($this->layout & LINK_LAYOUT_TAB) {
$class = CSS_TAB_ACTIVE;
}
} else {
$theValue = new Link($text,$href,$class,$title,$aux);
if ($src != '') {
$theValue->add(new Image($src,$width,$height,$alt,$class));
}
if ($this->layout & LINK_LAYOUT_TAB) {
$class = CSS_TAB;
}
}
}
}
if ($key == KEY_GOOGLE) {
$object->add(new Raw($theValue));
} else {
if ($theValue != '') {
$object->add($this->newData($theValue, $class, $valign));
} else {
// TODO what
}
}
} else {
// Ignore
}
return $object;
}
/**
* Return true if this is an active item
* @param String $page The current item to test
* @param String $request The name of the key request
* @param String $default The default request parameter to use, of no request parameter
* @return boolean True if this is an active Tab, else return false
*/
function isActive($page, $request='', $default='') {
$isActive = false;
$item = '';
if (defined('REQUEST_TAB')) {
if (TAB_SHOW & TAB_SHOW_URL) {
$item = Request::get($request, $default);
} else {
$item = $default;
}
}
if ($item != '' && strtolower($page)==strtolower($item) ) {
$isActive = true;
}
return $isActive;
}
/**
* Return true if this is an active Tab
* @param String $page The current item to test
* @param String $request The name of the key request
* @param String $default The default request parameter to use, of no request parameter
* @return boolean True if this is an active Tab, else return false
*/
function isActiveTab($page) {
return $this->isActive($page, REQUEST_TAB, TAB_INDEX);
}
/**
* Return true if this is an active Index
* @param String $page The current item to test
* @param String $request The name of the key request
* @param String $default The default request parameter to use, of no request parameter
* @return boolean True if this is an active Index, else return false
*/
function isActiveIndex($page) {
return $this->isActive($page, REQUEST_INDEX, "");
}
/**
* Return the content as a row object
* @return Object The content as an object
*/
function newColumns() {
$object = new Tr();
// Menu Corner Left
if ($this->layout & LINK_LAYOUT_CORNER) {
if (!($this->layout & LINK_LAYOUT_TAB)) {
$object->add($this->newCorner()); // L Border
}
}
$numrows = 0;
if (is_a($this->datareader,DATA_READER_CLASS_NAME)) {
$numrows = $this->datareader->getNumRows();
}
if ($numrows > 0) {
if ($this->layout & LINK_LAYOUT_LI) {
$object = new Ul($this->getCssClass());
}
foreach($this->datareader->getRows() as $page=>$column) {
$isActiveTab = $this->isActiveTab($page);
$isActiveIndex = $this->isActiveIndex($page);
if ($this->layout & LINK_LAYOUT_CORNER && $this->layout & LINK_LAYOUT_TAB) {
$object->add($this->newCorner($isActiveTab?IMAGE_TAB_LEFT_WHITE:IMAGE_TAB_LEFT)); // L Tab
}
$object->add($this->newColumn($page, $column, $isActiveTab, $isActiveIndex));
if ($this->layout & LINK_LAYOUT_CORNER && $this->layout & LINK_LAYOUT_TAB) {
$object->add($this->newCorner($isActiveTab?IMAGE_TAB_RIGHT_WHITE:IMAGE_TAB_RIGHT)); // R Tab
}
}
// Menu Corner No Data
if ($this->layout & LINK_LAYOUT_LI) {
$tr = new Tr();
if ($this->layout & LINK_LAYOUT_CORNER) {
if (!($this->layout & LINK_LAYOUT_TAB)) {
$tr->add($this->newCorner()); // L Border
}
}
$td = new Td($this->getCssClass(),'','','<!-- LINK_LAYOUT_XX='.$this->layout.' -->');
$td->add($object);
$tr->add($td);
$object = $tr; // Return the final object
}
} else {
$object->add($this->newTextRow(TEXT_NO_DATA,'',$this->getCssClass()));
}
// Menu Corner Right
if ($this->layout & LINK_LAYOUT_CORNER) {
if (!($this->layout & LINK_LAYOUT_TAB)) {
$object->add($this->newCorner()); // R Border
}
}
return $object;
}
/**
* Adjust the columns for the horizontal view, and add the triangle gif
*/
function adjustColumns() {
if ($this->datareader != '' && is_array($this->datareader)) {
$columns = array();
if ($this->layout & LINK_LAYOUT_TRIANGLE) {
if ($this->layout & LINK_LAYOUT_TAB) {
$columns[-2] = array(KEY_TRIANGLE=>IMAGE_TRIANGLE);
} else {
$columns[] = array(KEY_TRIANGLE=>IMAGE_TRIANGLE);
}
}
$index = false;
foreach($this->datareader as $key=>$column) {
if ($this->layout & LINK_LAYOUT_TAB) {
$columns[$key] = $column; // Speciel case for TAB
} else {
$columns[] = $column;
}
if ($this->layout & LINK_LAYOUT_HORIZONTAL) {
$columns[] = array(KEY_PLAIN=>' ¦ ',);
}
}
if ($this->layout & LINK_LAYOUT_FILL_OUT) {
if ($this->layout & LINK_LAYOUT_TAB) {
$columns[-1] = array(KEY_PLAIN=>' ','class'=>$this->getCssClass().' '.CSS_FILL_OUT,);
} else {
$columns[] = array(KEY_PLAIN=>' ','class'=>$this->getCssClass().' '.CSS_FILL_OUT,);
}
}
if ($this->layout & LINK_LAYOUT_GOOGLE && defined('HTML_COMPONENT_PAGE_PATH')) {
if (LINK_SHOW & LINK_SHOW_GOOGLE_TOP) {
$googlebox = new Raw("<!-- Googlebox is disabled -->");
if (defined('HTML_COMPONENT_PAGE_PATH')) {
$googlebox = new Googlebox('',$this->getCssClass());
}
// Form start/end are defined in pagestart.php
$columns[] = array(KEY_PLAIN=>' ','class'=>$this->getCssClass().' '.CSS_FILL_OUT,);
$columns[] = array(KEY_GOOGLE=>$googlebox->getHtml(),);
$columns[] = array(KEY_PLAIN=>' ',);
}
}
if (defined('HTML_DTO_UTIL_PATH')) {
$this->datareader = DataReaderFactory::newDataReader($columns);
}
}
if (!is_a($this->datareader,DATA_READER_CLASS_NAME)) {
$msg = $this->getClassName().'(), '.DATA_READER_CLASS_NAME." object expected, unknown datareader type=".gettype($this->datareader);
if (defined('HTML_LOG_UTIL_PATH')) {
Log::error(__FILE__,__LINE__,$msg);
} else {
}
Message::add($msg,__FILE__,__LINE__);
}
}
/**
* Return a new Corner or Border object
* Corner: only the gif file should be added with no class name
* Border: only the class name should be added
* @param String $imageName The name of the image to get
* @return Td The new Td object
*/
function newCorner($imageName='') {
$class = $imageName!=''?"":$this->getCssClass();
$valign = "";
$colspan = "";
$text = "";
$width = "1px"; // NOT XHTML 1.0 strict compliant
$object = new Td($class, $valign, $colspan, $text, $width);
if ($imageName != '') {
/**
* CSS_FLOAT_LEFT is a Bugfix for Firefox strict compliant
* @see http://www.webmasterworld.com/css/3458552.htm
*/
$object->add(new Images($imageName,'','','',CSS_FLOAT_LEFT,'0'));
} else {
$object->add(new Raw(' '));
}
return $object;
}
/**
* Get the content for the columns
* Each row is definition of a column
* @return String The html
*/
function getColumns() {
$html = '';
// Menu Corner Top
if ($this->layout & LINK_LAYOUT_CORNER) {
if (!($this->layout & LINK_LAYOUT_TAB)) {
$tr = new Tr();
$tr->add($this->newCorner(IMAGE_CORNER_TOP_LEFT));
$tr->add($this->newCorner()); // MT border
$tr->add($this->newCorner(IMAGE_CORNER_TOP_RIGHT));
$this->add($tr);
}
}
$this->add($this->newColumns());
// Menu Corner Bottom
if ($this->layout & LINK_LAYOUT_CORNER) {
if (!($this->layout & LINK_LAYOUT_TAB)) {
$tr = new Tr();
$tr->add($this->newCorner(IMAGE_CORNER_BOTTOM_LEFT));
$tr->add($this->newCorner()); // MB border
$tr->add($this->newCorner(IMAGE_CORNER_BOTTOM_RIGHT));
$this->add($tr);
}
}
// Render it
if ($this->text != '') {
$html .= $this->getTableHeader();
}
$html .= $this->getStart();
$html .= $this->getEnd();
return $html;
}
}
?>
HTML source code
Den fulde HTML kildekode for TableDataReader klassen
<?
<!-- No text in TableHeader -->
<table width="100%" class="theTable" border="0" cellpadding="2" cellspacing="0">
<tr>
<td valign="top">Der er ikke fundet noget</td>
</tr>
</table>
?>
Class methods
Her er 'klasse metoderne' for TableDataReader klassen:
object
getclassname
getmsg
addhtml
gethtml
tostring
getcachefilename
save
content
stop
html
setobject
set
get
getattribute
gettag
add
getsizeof
getelement
getelements
gettoogle
getmaximize
getminimize
newtriangle
display
showsource
table
newtextrow
gettableheader
getstart
getend
start
end
tabledatareader
getdatareader
newdata
getcssclass
newcolumn
isactive
isactivetab
isactiveindex
newcolumns
adjustcolumns
newcorner
getcolumns
Object vars
Her er 'objekt variable' for TableDataReader klassen:
html =>
sql =>
elements => Array
sizeof => 0
text =>
width => 100%
class => theTable
border => 0
cellpadding => 2
cellspacing => 0
summary =>
caption =>
datareader => Object
layout =>
DataReader.php
Her er felterne i DataReader for TableDataReader klassen: