Comment utiliser les ViewInfo classe
Première inclure la composante de fichier
<? require_once(HTML_PACKAGE_PATH.'/ViewInfo.php'); ?>
Utilisez le composant comme un taglib :
<? ViewInfo::display($param1, $param2, $param3, ...); ?>
Ou utiliser le composant comme un objet:
<? $object = new ViewInfo($param1, $param2, $param3, ...); print $object->getHtml(); ?>
Un exemple d'utilisation de la ViewInfo classe
Le texte intégral du code source de PHP pour le ViewInfo classe
<?php/** * @package mvc * @see HTML_MVC_VIEW_PATH.'/ViewInfo.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.'/Htmlspecialchars.php');require_once(HTML_MVC_VIEW_PATH.'/ViewCommon.php');require_once(HTML_BASE_UTIL_PATH.'/Link.php');require_once(HTML_BASE_UTIL_PATH.'/EmailLink.php');if (defined('HTML_LANGUAGE_UTIL_PATH')) { require_once(HTML_LANGUAGE_UTIL_PATH.'/Translate.php');}/** * Generates the html for a View Info like a business card look-a-like * <code> * Usage: * $view = new ViewInfo($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * print $view->getHtml(); * Or * ViewInfo::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * * Generates a complete View Simple interface * +--------+ * | Header | * +--------+ * | data1 | * | data2 | * +--------+ * </code> * @package mvc */class ViewInfo extends ViewCommon { /** * Constructor * @param DataReader / array $datareader The Data Reader object OR an array * @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 * @param String $layout The layout to use */ function __construct($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $theText = $text != '' ? $text : ''; // Global table characteristics $theWidth = $width != '' ? $width : BUSINESS_CARD_VIEW_WIDTH; $theClass = $class != '' ? $class : BUSINESS_CARD_VIEW_CLASS; $theBorder = $border != '' ? $border : BUSINESS_CARD_VIEW_BORDER; $theCellPadding = $cellpadding != '' ? $cellpadding : BUSINESS_CARD_VIEW_CELLPADDING; $theCellSpacing = $cellspacing != '' ? $cellspacing : BUSINESS_CARD_VIEW_CELLSPACING; parent::__construct($datareader, $theText, $theWidth, $theClass, $theBorder, $theCellPadding, $theCellSpacing, $summary, $caption, $layout); } /** * Return the column header data as an object * @param String $key The key to use * @return Object The html as an object */ function newHeader($key) { $text = $key; if (defined('HTML_LANGUAGE_UTIL_PATH')) { $text = Translate::sql($key,TRANSLATE_QUERY); } return new Raw($text." "); } /** * Return the column data as an object * @param String $key The key to use * @param String $value The value to use * @return Object The html as an object */ function newColumnInfo($key, $value) { $object = new Raw(); $text = ''; switch ($key) {// case @SELECT_MAIL: // deprecated case SELECT_CUSTOMER_EMAIL: $text = $key; if (defined('HTML_LANGUAGE_UTIL_PATH')) { $text = Translate::sql($key,TRANSLATE_QUERY); } $object->add(new EmailLink($value, $value)); break; case SELECT_CUSTOMER_WWW: $text = $key; if (defined('HTML_LANGUAGE_UTIL_PATH')) { $text = Translate::sql($key,TRANSLATE_QUERY); } $object->add(new Link($value, $value)); break; case SELECT_CUSTOMER_PRIVATE_PHONE: case SELECT_CUSTOMER_BUSINESS_PHONE: case SELECT_CUSTOMER_MOBILE_PHONE: case SELECT_CUSTOMER_CVR: case SELECT_CUSTOMER_EAN: $text = $key; if (defined('HTML_LANGUAGE_UTIL_PATH')) { $text = Translate::sql($key, TRANSLATE_QUERY); } $object = new Raw($text.': '.$value); //$object->add(new Lookup($value)); break; default: // Use as is $object = new Raw($value != '' ? $value : " "); break; } $object->add(new Raw("<br />\r\n")); return $object; } /** * Return the row data as html * <tr><td>header 1</td><td>data 1< br />data 2<br /> ...</td></tr> * @param array $row The rows to loop * @return Object The html as an object */ function newRow($row) { $object = new Raw(); if (count($row) > 0) { $zip = ''; foreach($row as $key=>$rawvalue) { $value = $this->strip($rawvalue, __FILE__, __LINE__); switch ($key) { case SELECT_CUSTOMER_ZIP: $zip = $value; break; case SELECT_CUSTOMER_CITY: $value = $zip.' '.$value; // Intentionally fall through default: if ($value != '') { $object->add($this->newColumnInfo($key, $value)); } break; } } } else { // TODO } return $object; } /** * Return the content as an object * @return Object The content as an object */ function newContent() { $object = new Tr(); $numrows = $this->datareader->getNumRows(); if ($numrows > 0) { if ($numrows > 1) { $this->text .= $this->text != '' ? " ($numrows)" : ''; $td = new Td(); $td->add(new Raw("TODO More than one ($numrows) ...")); $object->add($td); } $td = new Td(); foreach($this->datareader->getRows() as $no=>$row) { $td->add($this->newRow($row)); } $object->add($td); } else { $object->add($this->newTextRow(TEXT_NO_DATA, LINK_BACK)); } return $object; } /** * Return the html * @return String The html */ function getHtml() { $html = $this->html; $this->add($this->newContent()); // Render it if ($this->text != '') { $html .= $this->getTableHeader(); } $html .= $this->getStart(); $html .= $this->getEnd(); return $html; } /** * Display html * <code> * Usage: * ViewInfo::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); * </code> * @static * @param DataReader / array $datareader The Data Reader object OR an array * @param String $text The text header for the table * @param String $width The width of the table * @param String $class The class of the table * @param String $border The border of the table * @param String $cellpadding The CellSpacing * @param String $cellspacing The CellPadding * @param String $summary The Summary * @param String $caption The Caption * @param String $layout The layout to use */ public static function display($datareader=null, $text='', $width='', $class='', $border='', $cellpadding='', $cellspacing='', $summary='', $caption='', $layout='') { $html = new ViewInfo($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout); $html->addHtml(); }}?>
Le code source HTML pour le ViewInfo classe
<? <!-- DEBUG: ViewInfo --> <table id="ViewInfoId" width="400" class="tableBusinessCardView baseBorder" border="0" cellpadding="2" cellspacing="0"> <tr> <td valign="top">Privé de téléphone: 48246030<br /> Finn Rasmussen<br /> HvepseEksperten.dk ApS<br /> Kongens Vænge 79<br /> 3400 Hillerød<br /> Denmark<br /> </td> </tr> </table> ?>
Le 'les méthodes de classe pour le ViewInfo classe:
Le 'objet vars' pour le ViewInfo classe: