Sådan benyttes komponenten DivDataReader klassen
Først skal du inkludere den fil der beskriver komponenten, som en klasse fil
<? require_once(HTML_PACKAGE_PATH.'/DivDataReader.php'); ?>
Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):
<? DivDataReader::display($param1, $param2, $param3, ...); ?>
eller du kan lave en instance af komponenten og benytte metoderne direkte:
<? $object = new DivDataReader($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Sådan vises komponenten DivDataReader klassen
Den fulde PHP kildekode for DivDataReader klassen
<?php/** * @package dto * @filesource * @see HTML_DTO_UTIL_PATH.'/DivDataReader.php' * @copyright (c) http://Finn-Rasmussen.com * @license http://Finn-Rasmussen.com/license/ myPHP License conditions * @author http://Finn-Rasmussen.com * @version 1.11 * @since 27-nov-2009 *//** * The required files */require_once(HTML_BASE_UTIL_PATH.'/Div.php');require_once(HTML_BASE_UTIL_PATH.'/Span.php');require_once(HTML_BASE_UTIL_PATH.'/Link.php');require_once(HTML_BASE_UTIL_PATH.'/Image.php');require_once(HTML_BASE_UTIL_PATH.'/Img.php');require_once(HTML_BASE_UTIL_PATH.'/Ul.php');require_once(HTML_DTO_UTIL_PATH.'/DataReaderFactory.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 a * <div class="$class" align="$align" id="$id">$text</div> * <code> * Usage: * $html = new DivDataReader($datareader, $text, $class, $align, $id, $limit, $layout); * print $html->getHtml(); * Or * DivDataReader::display($datareader, $text, $class, $align, $id, $limit, $layout); * </code> * @package dto */class DivDataReader extends Div { /** * @var DataReader The Data Reader object */ protected $datareader = ''; /** * @protected $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 */ protected $layout = ''; /** * Constructor * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text, The text for the Div tag or an object * @param String $class The css class name * @param String $align The align attribute * @param String $id The ID attribute * @param int $limit The limit to use for the array * @param String $layout The layout to use */ function __construct($datareader=null, $text='', $class='', $align='', $id='', $limit='', $layout='') { parent::__construct($text, $class, $align, $id); $this->datareader = $this->getDatareader($datareader); $this->adjustColumns($limit); $this->layout = $layout; } /** * Get the DataReader to use for this class * @param $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 (!is_object($theDatareader) && $theDatareader == '') { $columns = array( LINK_TEXT_CONTACT_US=>array('text'=>LINK_TEXT_CONTACT_US,'href'=>LINK_HREF_EMAIL.'?'.REQUEST_EMNE.'=','title'=>LINK_TITLE_CONTACT_US,), // ,'class'=>'email' LINK_TEXT_COMPANY_PROFILE=>array('text'=>LINK_TEXT_COMPANY_PROFILE,'href'=>LINK_HREF_URL.'/hvepseboguide/About/','title'=>LINK_TITLE_COMPANY_PROFILE,), ); $theDatareader = $columns; } return $theDatareader; } /** * Get the CSS class Name for this component * @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 * @return Object The html as an object */ function newColumn($page, $column) { $object = new Raw(); if (count($column)>0) { $text = ''; $href = ''; $title = ''; $aux = ''; $src = ''; $width = ''; $height = ''; $alt = ''; $span = ''; $class = $this->getCssClass(); $theValue = ''; foreach($column as $key=>$value) { switch ($key) { case KEY_TRIANGLE: $theValue = $this->newTriangle($value, $class); $class .= ' '.CSS_ONEPC; break; default: $$key = $value; break; } } if ($theValue == '') { 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 (defined('CLASS_NAME_MENU_FISHEYE') && $this instanceof MenuFisheye ) { $theValue = new Link('', $href, $class, $title, $aux); $divClass = ""; // display: none; $theValue->add(new Span($text,'','', $divClass)); // The Menu Fish Eye } else { $theValue = new Link($text, $href, $class, $title, $aux); } if ($src != '') { $theValue->add(new Img($src, $width, $height, $alt, $class)); } else { // Ignore } } $object->add($theValue); } else { // Ignore } return $object; } /** * Return the content as a row object * @return Object The content as an object */ function newColumns() { $object = new Raw(); $numrows = 0; if ($this->datareader instanceof DataReader ) { $numrows = ''.$this->datareader->getNumRows(); } if ($numrows > 0) { if ($this->layout & LINK_LAYOUT_LI) { $object = new Ul(); } foreach($this->datareader->getRows() as $page=>$column) { $column = $this->newColumn($page, $column); $object->add($column); } } else { $object->add(new Raw(TEXT_NO_DATA)); } return $object; } /** * Adjust the columns for the different views * @param int $limit The limit to use for the array * @param boolean $sort The sort functionality is enabled if true */ function adjustColumns($limit='', $sort=true) { if (!is_object($this->datareader) && $this->datareader != '' && is_array($this->datareader)) { $columns = array(); // DOES not work together with ViewLimit, so skip LINK_LAYOUT_TRIANGLE if ($this->layout & LINK_LAYOUT_TRIANGLE) { $columns[] = array(KEY_TRIANGLE=>IMAGE_TRIANGLE); } foreach($this->datareader as $key=>$column) { $columns[] = $column; } $header = ''; $default = ''; $this->datareader = DataReaderFactory::newDataReader($columns, $header, $default, $limit, $sort); } if (! $this->datareader instanceof DataReader ) { $msg = $this->getClassName().'(), '.DATA_READER_CLASS_NAME." object expected, unknown datareader type=".gettype($this->datareader); if (defined('HTML_LOG_UTIL_PATH')) { Log::error($msg, __FILE__, __LINE__); } else { } Message::add($msg, __FILE__, __LINE__); } } /** * Get the content for the columns * Each row is definition of a column * @return String The html */ function getColumns() { $html = ''; $this->add($this->newColumns()); $html .= $this->getStart(); $html .= $this->getEnd(); return $html; } /** * Display html * <code> * Usage: * DivDataReader::display($datareader, $text, $class, $align, $id, $layout); * </code> * @static * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text The text for the div or an object * @param String $class The css class of the div * @param String $align The align attribute * @param String $id The ID attribute * @param int $limit The limit to use for the array * @param String $layout The layout to use */ public static function display($datareader=null, $text='', $class='', $align='', $id='', $limit='', $layout='') { $html = new DivDataReader($datareader, $text, $class, $align, $id, $limit, $layout); $html->addHtml(); }}?>
Den fulde HTML kildekode for DivDataReader klassen
<? <!-- DEBUG: Test --> <!-- Test --> <div><!-- DEBUG: Link --> <!-- Kontakt --><a class="baseBody" href="http://www.hvepseeksperten.dk/FormMail/?baseEMNE=" title="Kontakt via email
">Kontakt</a> <!-- DEBUG: Link --> <!-- Firma profil --><a class="baseBody" href="http://www.hvepseeksperten.dk/hvepseboguide/About/" title="Hvem er vi egentlig?">Firma profil</a> </div> ?>
Her er 'klasse metoderne' for DivDataReader klassen:
Her er 'objekt variable' for DivDataReader klassen: