blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Basic  /  Rowcolor   Login nu   Login
blank.gif
 ««« Se kilde koden
blank.gif
triangle.gif Basic  Base Component Db Dto Form Form-elements Jquery Layout Menu Menu-fisheye Mvc Tab Table Template Util
blank.gif
blank.gif
 
arrow-headline.gif Index
 
  Tilbage

Navn : Rowcolor.php


Sample code, tutorial

Sådan benyttes komponenten Rowcolor klassen

Først skal du inkludere den fil der beskriver komponenten, som en klasse fil

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

Dernæst kan du enten benytte komponenten som et taglib (statiske metoder):

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

eller du kan lave en instance af komponenten og benytte metoderne direkte:

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

Parent html

Sådan vises komponenten Rowcolor klassen

baseColorLight

PHP source code

Den fulde PHP kildekode for Rowcolor klassen

<?
/**
* @package basic
* @see HTML_BASIC_UTIL_PATH.'/Rowcolor.php'
* @copyright (c) http://Finn-Rasmussen.com
* @license http://Finn-Rasmussen.com/license/ myPHP License conditions
* @author http://Finn-Rasmussen.com
* @version 1.10
* @since 22-feb-2007
*/

/**
* Generates a new Row Color
* <code>
* Usage:
*   $html = new Rowcolor($count++,,$light,$dark);
*   print $html->getHtml();
* Or
*   $rowcolor = Rowcolor::get($count++,$light,$dark);
* Or
*   $imgcolor = Rowcolor::img($color);
* </code>
* @package basic
*/

class Rowcolor {
    
/**
    * @var int $count The row counter
    */
    
var $count = 0;

    
/**
    * @var String $light The light row
    */
    
var $light = 0;

    
/**
    * @var String $dark The dark row
    */
    
var $dark = 0;

    
/**
     * Constructor
     * @param int    $count The next row
     * @param String $light The light row
     * @param String $dark  The dark  row
     */
    
function Rowcolor($count,$light='',$dark='') {
        
$this->count = $count;
        
$this->light = $light!=''?$light:CSS_COLOR_LIGHT;
        
$this->dark  = $dark !=''?$dark :CSS_COLOR_DARK;
    }

    
/**
     * Get the complete html for a Row Color
     * @see CSS_COLOR_LIGHT The css color Light
     * @see CSS_COLOR_DARK  The css color Dark
     * @return String the html
     */
    
function getHtml() {
        return
$this->count%2?$this->light:$this->dark;
    }

    
/**
     * Returns 6 digits css color code from the supplied 3 digits hex color
     * The color is hex I.e. 1F3 => 11FF34 (where the last color digit is counted one up)
     * This function ia a bugfix for xhtml 1.0 strict compliant validator
     * where <img border="0" ... /> is not allowed, however we must have it
     * <code>
     * Usage:
     *    $imgcolor = Rowcolor::img($color);
     * </code>
     * @static
     * @param  int $hexcolor The css hex color, i.e. a2b
     * @return String the img css color (6 digits) i.e. 'aa22bc' (c=b+1)
     */
    
function img($hexcolor) {
        
$html = '';
        
$len = strlen($hexcolor);
        if (
$len!=3) {
            
//die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".' Rowcolor::img($hexcolor), The color MUST be 3 digits, like 2fc, found length='.$len.' in $hexcolor='.$hexcolor);
        
}
        for (
$i=0;$i<$len;$i++) {
            
$digit = hexdec(substr($hexcolor,$i,1));
            if (!
is_numeric($digit)) {
                die(
'File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".' Rowcolor::img($hexcolor), The color is not a numeric, found $digit='.$digit.' in $hexcolor='.$hexcolor);
            }
            switch (
$i) {
                case
0:
                case
1:
                    
$html .= ''.dechex($digit).dechex($digit);
                    break;
                case
4:
                case
3:
                case
2:
                    
$html .= ''.dechex($digit);
                    if (
$digit+1>0xF) {
                        
$html .= dechex($digit-1);
                    } else {
                        
$html .= dechex($digit+1);
                    }
                    break;
                default:
                    
//die('File: '.__FILE__."<br />\r\nLine: ".__LINE__."<br />\r\n".', Rowcolor::img($hexcolor), Should never end up here!');
                    
break;
            }
        }
        return
$html;
    }

    
/**
     * Get the rowcolor for the odd/even count
     * <code>
     * Usage:
     *    Rowcolor::get($count++,$light,$dark);
     * </code>
     * @static
     * @param  int    $count The next row
     * @param  String $light The light row
     * @param  String $dark  The dark  row
     * @return String the html
     */
    
function get($count,$light='',$dark='') {
        
$html = new Rowcolor($count,$light,$dark);
        return
$html->getHtml();
    }
}
?>

HTML source code

Den fulde HTML kildekode for Rowcolor klassen

<?
baseColorLight
?>

Class methods

Her er 'klasse metoderne' for Rowcolor klassen:

  • rowcolor
  • gethtml
  • img
  • get

Object vars

Her er 'objekt variable' for Rowcolor klassen:

  • count => 3
  • light => baseColorLight
  • dark => baseColorDark

 
triangle.gif

danmark

Germany

England

France

Italy

Norge

Sverige

USA


 
blank.gif