Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Voi siete qui: /  Inizio pagina  /  Inserisci codice sorgente  /  Mvc  /  Viewcommon   Logon ora   Logon
blank.gif
««« Inserisci Codice Sorgente
blank.gif
tl.gif Base tr.gif tl.gif Basic tr.gif tl.gif Dto tr.gif tl.gif Form tr.gif tl.gif Language tr.gif tl.gif Layout tr.gif tl.gif Menu tr.gif tls.gif     Mvc  trs.gif tl.gif Netbank.eksperter.dk tr.gif tl.gif Tab tr.gif tl.gif Table tr.gif tl.gif Util tr.gif
blank.gif
blank.gif
arrow-headline.gif Indice
MenuLink  MenuLeft  
Torna

Minimizza: Nome

ViewCommon.php


Visualizza: Sample code, tutorial

ViewCommon, Sample code, tutorial

Come utilizzare il ViewCommon classe

Includere il componente prima di file

  • <?
    require_once(HTML_PACKAGE_PATH.'/ViewCommon.php');
    ?>

Utilizzare il componente come un taglib:

  • <?
    ViewCommon
    ::display($param1$param2$param3, ...);
    ?>

O utilizzare il componente come un oggetto:

  • <?
    $object 
    = new ViewCommon($param1$param2$param3, ...);
    print 
    $object->getHtml();
    ?>

Minimizza: Un esempio di utilizzo della

ViewCommon, Un esempio di utilizzo della

Un esempio di utilizzo della ViewCommon classe


Visualizza: PHP source code

ViewCommon, PHP source code

Il codice sorgente completo di PHP per la ViewCommon classe

<?php
/**
 * @package mvc
 * @see HTML_MVC_VIEW_PATH.'/ViewCommon.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_MVC_VIEW_PATH.'/ViewLimit.php');
require_once(
HTML_MVC_UTIL_PATH.'/Utils.php');
require_once(
HTML_BASIC_UTIL_PATH.'/Rowcolor.php');
require_once(
HTML_BASE_UTIL_PATH.'/Link.php');
require_once(
HTML_BASE_UTIL_PATH.'/Raw.php');
require_once(
HTML_BASE_UTIL_PATH.'/ImageLink.php');
require_once(
HTML_BASE_UTIL_PATH.'/Links.php');
require_once(
HTML_BASE_UTIL_PATH.'/Images.php');
require_once(
HTML_FORM_COMPONENT_PATH.'/ElementFactory.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/TableHeader.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/TableDataReader.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/Tr.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/Th.php');
require_once(
HTML_TABLE_COMPONENT_PATH.'/Td.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Format.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Encrypt.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Params.php');
require_once(
HTML_DTO_UTIL_PATH.'/DataReader.php');
if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
    require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}
if (
defined('HTML_DB_RESOURCE_PATH')) {
    require_once(
HTML_DB_RESOURCE_PATH.'/TableInfo.php');
}
if (
defined('HTML_LOG_UTIL_PATH')) {
    require_once(
HTML_LOG_UTIL_PATH.'/Log.php');
}

/**
 * This is the base class for Form View or List View
 * You must extend this class, and write your own getHtml()
 * <code>
 * Usage:
 *   $view = new ViewCommon($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout);
 *   print $view->getHtml();
 * Or
 *   ViewCommon::display($datareader, $text, $width, $class, $border, $cellpadding, $cellspacing, $summary, $caption, $layout);
 *
 * Generates a complete View Common interface
 * +--------------------------------
 * |>| Text header
 * +--------------------------------
 * | head1 | head2 | head3 | etc.
 * +--------------------------------
 * | dat_1 | dat_2 | dat_3 | etc.
 * +--------------------------------
 * </code>
 * @package mvc
 */

class ViewCommon extends TableDataReader {
    
/**
     * @var int $id The primary key to use
     */
    
protected $id '';
    
/**
     * @var real $subtotal The SubTotal to use
     */
    
protected $subtotal null;
    
/**
     * @var boolean $encode If true, then call Htmlspecialchars::encode
     */
    
protected $encode false;
    
/**
     * @var boolean $striptags If true, then call Htmlspecialchars::striptags
     */
    
protected $striptags true;
    
/**
     * @var boolean $striphttp If true, then call Htmlspecialchars::striphttp
     */
    
protected $striphttp true;
    
/**
     * @var array $multipleEditColumns The Multiple Edit Columns which are used like in a basket
     */
    
protected $multipleEditColumns = array();
    
/**
     * @var String $table The table to use in a query Insert/Update/Delete
     */
    
protected $table '';
    
    
/**
     * 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='') {
        
parent::__construct($datareader$text$width$class$border$cellpadding$cellspacing$summary$caption$layout);
    }

    
/**
     * Set the attribute flag to true or false
     * @param boolean $attibute The attribute is enabled if true
     * @param Sring   $name     The name of the attribute, like 'striphttp'
     */
    
private function setCustomAttribute($attribute$name$file$line) {
        
// Sanity check
        
if ($attribute === true || $attribute === false) {
            
$this->$name $attribute;
        } else {
            die(
$this->getClassName()." File=$file Line:$line<br />Illegal value found for $name, expected true OR false, found=".$attribute);
        }
    }

    
/**
     * Set the striphttp flag to true or false
     * @param boolean $striphttp The striphttp is enabled if true
     */
    
public function setStriphttp($striphttp) {
        
$this->setCustomAttribute($striphttp'striphttp'__FILE____LINE__);
    }

    
/**
     * Set the striptags flag to true or false
     * @param boolean $striptags The striptags is enabled if true
     */
    
public function setStriptags($striptags) {
        
$this->setCustomAttribute($striptags'striptags'__FILE____LINE__);
    }

    
/**
     * Set the encoding to true or false
     * @param boolean $encode The encoding is enabled if true
     */
    
public function setEncode($encode) {
        
$this->setCustomAttribute($encode'encode'__FILE____LINE__);
    }

    
/**
     * Set the Multiple eEdit Columns
     * @param array $multipleEditColumns The array of Multiple Edit Columns
     */
    
public function setMultipleEditColumns(array $multipleEditColumns) {
        
$this->multipleEditColumns $multipleEditColumns;
    }

    
/**
     * Set the table name, where the query has be be excuted, like Insert/Update/Delete
     * @param String $table The name of the table
     */
    
public function setTable($table) {
        
$this->table $table;
    }

    
/**
     * You may override this methode in order to create your own hiddens
     * If no request parameters are supplied, then popup the login form
     * Return the Hiddens as an object
     * @param  String $default The default value to use for yhe REQUEST_COMMAND
     * @return Object The Hiddens as an Object 
     */
    
public function newHiddens($default='') {
        
$keyValue = array();
        
$validate true;
        
$keyValue[REQUEST_COMMAND] = Request::get(REQUEST_COMMAND$default    __FILE____LINE__$validate);
        
$keyValue[@REQUEST_TABLE  ] = Encrypt::it$this->table );
        
$object = new Hiddens($keyValueVIEW_LOGIN_FORM$this->getClassName()); // VIEW_LOGIN_FORM
        
return $object;
    }

    
/**
     * You may override this methode in order to create other types of buttons
     * Return the Buttons as an object
     * @static
     * @param  String $id The ID of the submit button, if any
     * @return Object The Buttons as a new Object 
     */
    
public function newButtons($id='') {
        
$view    CRUD_VIEW_FORM_READ;
        
$buttons FORM_BUTTON_SHOW;
        
$layout  CSS_ALIGN_CENTER;
        return new 
Buttons($view$buttons$layout$id);
    }

    
/**
     * Is the request valid
     * @param  array $validators The array of validators to use
     * @return boolean True if all the request params are valid 
     */
    
protected function isValid($validators='') {
        
$isValid true;
        return 
$isValid;
    }
    
    
/**
     * Return true, if the table specified as a class member is the same as the request parameter
     * @return boolean True, if the table name is the same for both the class member and the request parameter
     */
    
protected function isTable() {
        return 
Utils::same$this->table );
    }
    
    
/**
     * Return true, if this is a numeric field
     * @param  String $key The key for the current field
     * @return boolean Return true if the key is numeric
     */
    
private function isNumeric($key) {
        
$isNumeric false;
        if (
defined('COLUMN_FIELD_TYPE_FLOAT')) {
            
$type $this->datareader->getFieldType($key);
            switch (
$type) {
                case 
COLUMN_FIELD_TYPE_FLOAT:
                case 
COLUMN_FIELD_TYPE_REAL:  // Basket specific
                    // Intentionally fall through
                
case COLUMN_FIELD_TYPE_DOUBLE:
                case 
COLUMN_FIELD_TYPE_NUMERIC:
                case 
COLUMN_FIELD_TYPE_DECIMAL:
                case 
COLUMN_FIELD_TYPE_TINY:
                case 
COLUMN_FIELD_TYPE_INT:
                case 
COLUMN_FIELD_TYPE_SHORT:
                case 
COLUMN_FIELD_TYPE_LONG:
                case 
COLUMN_FIELD_TYPE_LONGLONG:
                case 
COLUMN_FIELD_TYPE_INT24:
                    
$isNumeric true;
                    break;
                    
            }
        }
        return 
$isNumeric;
    }
    
    
/**
     * Get the CSS value of the alignment if this is a numeric field
     * @param  String  $key       The key for the current field
     * @param  String  $css       The default CSS class name to use
     * @param  boolean $isHeader  True, if this is a header
     * @param  String  $value     The value of the key
     * @return String Return the alignment type if the key is numeric
     */
    
protected function getCss($key$css$isHeader$value='') {
        
$theCss $css;
        if (
$isHeader) {
            
$theCss .= " ".CSS_NO_WRAP;
        }
        if (
$this->isNumeric($key)) {
            
$theCss .= ($theCss != "" " " "").CSS_ALIGN_RIGHT;
        }
        
$theCss $this->getCssIsOnline($key$theCss$isHeader$value);
        return 
$theCss;
    }
    
    
/**
     * Get the CSS value if this is db-news/db-product and is online or offline
     * @param  String  $key       The key for the current field
     * @param  String  $css       The default CSS class name to use
     * @param  boolean $isHeader  True, if this is a header
     * @param  String  $value     The value of the key
     * @return String Return the alignment type if the key is numeric
     */
    
protected function getCssIsOnline($key$css$isHeader$value='') {
        
$theCss $css;
        
/**
         * Speciel handling for db-news/dp-product is online or is offline
         */
        
$type  $this->datareader->getFieldType($key);
        
$flags $this->datareader->getFieldFlags($key);
        switch (
$type) {
            case @
COLUMN_FIELD_TYPE_STRING// Used for the Checkbox isOnline, see db-news/db-product
                
if (is_array($flags) && in_array(COLUMN_FIELD_TYPE_ENUM$flags)) {
                    if (!
$isHeader && ($value == CHECKBOX_VALUE_YES || $value == CHECKBOX_VALUE_NO)) {
                        
$isOnlineCss $value == CHECKBOX_VALUE_YES CSS_IS_ONLINE CSS_IS_OFFLINE;
                        
$theCss  $isOnlineCss.($theCss !== "" " ".$theCss "");
                    } else {
                        
// Ignore
                    
}
                } else {
                    
// Ignore
                
}
                break;
        }
        return 
$theCss;
    }
    
    
/**
     * Get the value of the alignment if this is a numeric field
     * @param  String $key The key for the current field
     * @return String Return the alignment type if the key is numeric
     */
    
protected function getAlignment($key) {
        
$align "";
        if (
$this->isNumeric($key)) {
            
$align 'right';
        }
        return 
$align;
    }
    
    
/**
     * Get the formatted text
     * @param  String  $key       The key from the datareader
     * @param  String  $value     The value from the datareader
     * @param  String  $isHeader  True, if the key is a header
     * @param  boolean $linebreak True, Do not allow line breaks in a list view
     * @return String
     */
    
protected function getFormattedText($key$value$isHeader$linebreak=true) {
        
$text $value;
        if (
$isHeader) {
            if (
defined('DATABASE_PREFIX') && $key !== DATABASE_PREFIX.TABLE_NAME_SESSION.SELECT_TABLE_ID) {
                
/**
                 * NOTE: This methode MUST exist in the parent class
                 */
                
$text $this->getHeaderLink($key);
            }
        }
        if (
defined('COLUMN_FIELD_TYPE_FLOAT')) {
            
$type  $this->datareader->getFieldType($key);
            
$table $this->datareader->getFieldTable($key);
            switch (
$type) {
                case 
COLUMN_FIELD_TYPE_FLOAT:
                case 
COLUMN_FIELD_TYPE_REAL:  // Basket specific
                    
                    // TODO how do I know for sure, that it is money
                    // Maybe decimal(P,S) where P=10 and S=2
                    //  && $len==COLUMN_FIELD_LEN_FLOAT_LENGTH (real and 19)
    
                    
if (!$isHeader) {
                        
$text $this->format($valueFORMAT_STYLE_MONEY_SHORT$linebreak);
    
                        if (
$table !== '') {
                            
// Real column, ignore
                            // Could be SubTotal
                        
} else {
                            
// TODO redesign This is not quit logic
                            
$selectSubtotal SELECT_BASKET_SUBTOTAL;
                            if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                                
$selectSubtotal Translate::sql(SELECT_BASKET_SUBTOTAL);
                            }
                            if (
$key === $selectSubtotal || $key === SELECT_BASKET_SUBTOTAL) {
                                
$this->subtotal += $value;
                            }
                        }
                    }

                    break;
                case 
COLUMN_FIELD_TYPE_TIMESTAMP:
                case 
COLUMN_FIELD_TYPE_DATETIME:
                    if (!
$isHeader) {
                        
$text $this->format($valueFORMAT_STYLE_DATE_LONG$linebreak);
                    }
                    break;
                default:
                    
// Keep css
                    
switch ($key) {
                        case 
SELECT_MODIFIED_DATE:
                            if (!
$isHeader) {
                                
$text $this->format($valueFORMAT_STYLE_DATE_LONG$linebreak);
                            }
                            break;
                        default:
                            break;
                    }
                    break;
            }
        }
        return 
$text;
    }
    
    
/**
     * Format the text with the specified style
     * @param  String  $text  The text to format accordingly
     * @param  String  $style The format style
     * @param  boolean $linebreak True, Do not allow line breaks in a list view
     * @return The formatted text or the same text, if no formatter available
     */
    
protected function format($text$style$linebreak=true) {
        
$thetext $text;
        if (
defined('HTML_UTIL_COMPONENT_PATH')) {
            
$pattern   "";
            
$locale    "";
            
$format = new Format($text$style$pattern$locale$linebreak);
            
$thetext $format->convert();
        }
        return 
$thetext;
    }

    
/**
     * Return the Label and TexField as an object
     * <code>
     * Usage:
     *    $type     = "text";
     *    $key      = "theKey";
     *    $name     = "theName";
     *    $value    = "theValue";
     *    $len      = "100";
     *    $required = "";
     *    $debug    = "Debug text";
     *    $checked  = "";
     *    $class    = "";
     *    $field    = COLUMN_FIELD_TYPE_DATETIME;
     *    
     *    $element = $this->newElement($type, $key, $name, $value, $len, $required, $debug, $checked, $class, $field);
     * </code>
     * 
     * @see EngineObject.format2Locale(...)
     * 
     * @param  String $type     The element type to use
     * @param  String $key      The Key to use
     * @param  String $name     The name to use
     * @param  String $value    The value to use
     * @param  String $len      The maxsize to use
     * @param  String $required The required text to use, if any
     * @param  String $debug    The debug text to use, if any
     * @param  String $checked  The checked attribute if ticked off for radio/checkbox
     * @param  String $class    The CSS class name
     * @param  String $field    The column field type, like COLUMN_FIELD_TYPE_DATETIME or COLUMN_FIELD_TYPE_PRICE
     * @return Object The html as a new Object 
     */
    
protected function newElement($type$key$name$value$len=''$required=''$debug=''$checked=''$class=''$field='') {
        
$onblur "";
        if (
defined('HTML_JS_PAGE_PATH') && $field !== "") {
            switch(
$field) {
                case 
COLUMN_FIELD_TYPE_DECIMAL:
                case 
COLUMN_FIELD_TYPE_REAL:
                case 
COLUMN_FIELD_TYPE_PRICE// TODO DOES NOT WORK AS EXPECTED
                    
if (JS_SHOW JS_SHOW_AMOUNT_FORMAT) {
                        
$onblur "this.value=AmountFormat.format(this.value);";
                    }
                    break;
                case 
COLUMN_FIELD_TYPE_TIMESTAMP:
                case 
COLUMN_FIELD_TYPE_DATETIME:
                    if (
JS_SHOW JS_SHOW_DATE_FORMAT) {
                        
$onblur "this.value=DateFormat.format(this.value, DateFormat.LONG);";
                    }
                    break;
                default: 
// Ignore
                    
break;
            }
            
        }
        return 
ElementFactory::newElement($type$key$name$value$len$required$debug$checked$class$onblur);
    }
    
    
/**
     * Strip off any unwanted tags and/or http and/or encode html
     * @param String $value The text to be converted
     * @param String $file
     * @param int    $line
     * @return Ambigous <string, unknown>
     */
    
protected function strip($value$file=__FILE__$line=__LINE__) {
        
$text $value;
        if (
$this->striptags) {
            
$text Htmlspecialchars::striptags($text);
        } 
        if (
$this->striphttp) {
            
$text Htmlspecialchars::striphttp($text$this->striphttp$file$line);
        } 
        if (
$this->encode) {
            
$text Htmlspecialchars::encode($text);
        }
        return 
$text;
    }

    
/**
     * Return the content as an object
     * @return Object The content as an object
     */
    
function newContent() {
        
$object = new Raw();
        return 
$object;
    }
        
    
/**
     * Return the html
     * @return String The html
     */
    
function getHtml() {
        
$html $this->html;
        
$this->add($this->newContent());
        
//$html .= "<h1>".$this->getClassName()."->getHtml() TODO, you must override this</h1>\r\n";
        
return $html;
    }

    
/**
     * Display html
     * <code>
     * Usage:
     *    ViewCommon::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 ViewCommon($datareader$text$width$class$border$cellpadding$cellspacing$summary$caption$layout);
        
$html->addHtml();
    }
}
?>

Visualizza: HTML source code

ViewCommon, HTML source code

Il codice sorgente HTML per la ViewCommon classe

<?
<!-- DEBUGViewCommon -->

?>

Visualizza: Class methods

ViewCommon, Class methods

La 'classe di metodi' per la ViewCommon classe sono le seguenti:

  • __construct
  • setStriphttp
  • setStriptags
  • setEncode
  • setMultipleEditColumns
  • setTable
  • newHiddens
  • newButtons
  • newContent
  • getHtml
  • display
  • newData
  • getCssClass
  • newColumn
  • isActive
  • isActiveTab
  • isActiveIndex
  • newColumns
  • adjustColumns
  • newCorner
  • getColumns
  • newTextRow
  • getTableHeader
  • getStart
  • getEnd
  • start
  • end
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Visualizza: Object vars

ViewCommon, Object vars

Il 'oggetto vars' per la ViewCommon classe sono le seguenti:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


 
blank.gif
MenuBottom 
triangle.gif Copyright @ 1999-2010 Web specializzata www.Finn-Rasmussen.com Powered by myPHP Version (5.2.6-1+lenny9) 1.11
blank.gif