Top  Branding  Banner 
blank.gif
blank.gif
triangle.gif Du er her: /  Forsiden  /  Kildekoden  /  Base  /  Sortby   Login nu   Login
blank.gif
««« Se kilde koden
blank.gif
tls.gif     Base  trs.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 tl.gif Mvc tr.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 Index
MenuLink  MenuLeft  
Tilbage

Skjul: Navn

Sortby.php


Vis: Sample code, tutorial

Sortby, Sample code, tutorial

Sådan benyttes komponenten Sortby klassen

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

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

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

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

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

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

Skjul: Sådan vises komponenten

Sortby, Sådan vises komponenten

Sådan vises komponenten Sortby klassen

desc.gif  mvcSORT_BY

Vis: PHP source code

Sortby, PHP source code

Den fulde PHP kildekode for Sortby klassen

<?php
/**
 * @package base
 * @see HTML_BASE_UTIL_PATH.'/Sortby.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_COMMON_PATH.'/Html.php');
require_once(
HTML_BASE_UTIL_PATH.'/Link.php');
require_once(
HTML_BASE_UTIL_PATH.'/Image.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Params.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Request.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Server.php');
require_once(
HTML_UTIL_COMPONENT_PATH.'/Encrypt.php');
if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
    require_once(
HTML_LANGUAGE_UTIL_PATH.'/Translate.php');
}

/**
 * Returns a complete Sort By Link as HTML
 * The link may be terminated by a <br /> or surronded by <li> tags
 * as specified by the $aux parameter
 *
 * <code>
 *    <a class="$class" href="$href" title="$title">$text</a>
 * Usage:
 *   $link = new Sortby($text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
 *   print $link->getHtml();
 * Or 
 *   Sortby::display($text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
 * </code>
 * @package base
 */

class Sortby extends Link {
   
/**
    * Constructor
    * @param String $text      The text for the link
    * @param String $href      The url for the link
    * @param String $class     The class of the link
    * @param String $title     The tool tip of the link
    * @param String $aux       Add 'br' or 'li' html tags, if required
    * @param String $target    The target for the link I.e. _BLANK
    * @param String $name      The name for the link
    * @param String $tabindex  The name of the tab index
    * @param String $onclick   The javascript onclick function name
    * @param String $accesskey The access key
    */
    
function __construct($text=''$href=''$class=''$title=''$aux=''$target=''$name=''$tabindex=''$onclick=''$accesskey='') {
        
$orderby  Request::get(REQUEST_ORDER_BY_NAME''__FILE____LINE__true);
        
$sortby   Request::get(REQUEST_SORT_BY_NAMESORT_BY_DEFAULT__FILE____LINE__true);
        
$theText  $this->getText($text);
        
$theHref  $this->getHref($href$text$sortby$orderby);
        
$theClass $this->getClass($class);
        
$theTitle $this->getTitle($title$sortby$orderby);
        
parent::__construct($theText$theHref$theClass$theTitle$aux$target$name$tabindex$onclick$accesskey);
        
$this->addImage($text$sortby$orderby$theClass);
    }
    
    
/**
     * Get the text for the Sort By link, where the sort order is defined
     * @param  String $text  The text to show
     * @return String The html
     */
    
function getText($text) {
        
$theText str_replace(SELECT_TABLE_ID,''$text);
        
$translatedText $text;
        if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
            
$translatedText Translate::sql($textTRANSLATE_QUERY);
//            print "$text - $translatedText<br />\r\n";
        
}
        
$theText ucfirst(str_replace('_',' '$translatedText));
        if (
$theText == '') {
            
$theText REQUEST_SORT_BY_NAME;
        }
        return 
$theText;
    }

    
/**
     * Get the href for the Sort By link, where the sort order is defined
     * @param  String $href    The href to use, The table name
     * @param  String $text    The text to show
     * @param  String $sortby  The Sort  By request parameter
     * @param  String $orderby The Order By request parameter
     * @return String The html
     */
    
function getHref($href$text$sortby$orderby) {
        
$theHref Server::getPhpSelf();
        
$params  '';
        
$extra = array();
        
$extra[@REQUEST_TABLE] = Encrypt::it$href ); // Which in fact is the table name
        
switch ($sortby) {
            case 
SORT_BY_DESC:
                
$extra[REQUEST_SORT_BY_NAME] = SORT_BY_ASC;
                break;
            case 
SORT_BY_ASC:
                
$extra[REQUEST_SORT_BY_NAME] = SORT_BY_DESC;
                break;
            default:
                
$extra[REQUEST_SORT_BY_NAME] = SORT_BY_DEFAULT;
                break;
        }
// Cosmic Radiason: for some reason, the FireFox could not accept that the orderBy line was before the sort order
// When the request orderBy = text and sorBy = asc
// When http://localhost/www/myphp-1.11/myphp-1.11-dto/html/test/index.php?mvcORDER_BY=text&mvcSORT_BY=asc
// The æøå was translated to a < ? >
        
if ($text != '') {
            
$extra[REQUEST_ORDER_BY_NAME] = $text;
            if (
defined('HTML_LANGUAGE_UTIL_PATH')) {
                
$translatedText  Translate::sql($textTRANSLATE_TEXT);
                
$translatedQuery Translate::sql($textTRANSLATE_QUERY);
                
$extra[REQUEST_ORDER_BY_NAME] = $translatedText;
            }
        }
        
$urlencode true;
        
$params Params::get($extra$urlencode__FILE____LINE__);
        return 
$theHref.$params;
    }

     
/**
     * Get the CSS class name for the Sort By link, where the sort order is defined
     * @param  String $class  The class to use
     * @return String The html
     */
    
function getClass($class) {
        return 
$class != '' $class CSS_COLOR_HEADER;
    }

    
/**
     * Get the title for the Sort By link, where the sort order is defined
     * @param  String $title   The title to show
     * @param  String $sortby  The Sort  By request parameter
     * @param  String $orderby The Order By request parameter
     * @return String The html
     */
    
function getTitle($title$sortby$orderby) {
        return 
$title != '' $title ucfirst(strtolower(REQUEST_ORDER_BY_NAME)).' '.$orderby.' '.$sortby;
    }

    
/**
     * Add the image to use for the Sort By link, where the sort order is defined
     * @param  String $text    The text to show
     * @param  String $sortby  The Sort  By request parameter
     * @param  String $orderby The Order By request parameter
     * @param  String $class   The CSS class name to use
     * @return String The html
     */
    
function addImage($text$sortby$orderby$class) {
        
$image '';
        if (
$text == $orderby) {
            
$width  "";
            
$height "";
            
$alt    "";
            
$image  = new Images($sortby$width$height$alt$class);
        }
        if (
$image !== '') {
            
$this->add($image);
        }
    }

   
/**
    * Display a Sort By link
    * <code>
    * Usage:
    *    Sortby::display($text, $href, $class, $title, $aux, $target, $name, $tabindex, $onclick, $accesskey);
    * </code>
    * @static
    * @param String $text      The text for the link
    * @param String $href      The url for the link
    * @param String $class     The css class of the link
    * @param String $title     The tool tip of the link
    * @param String $aux       Add 'br' or 'li' html tags, if required
    * @param String $target    The target for the link. I.e. _BLANK
    * @param String $name      The name for the link
    * @param String $tabindex  The name of the tab index
    * @param String $onclick   The javascript onclick function name
    * @param String $accesskey The access key
    */
    
public static function display($text=''$href=''$class=''$title=''$aux=''$target=''$name=''$tabindex=''$onclick=''$accesskey='') {
        
$html = new Sortby($text$href$class$title$aux$target$name$tabindex$onclick$accesskey);
        
$html->addHtml();
    }
}
?>

Vis: HTML source code

Sortby, HTML source code

Den fulde HTML kildekode for Sortby klassen

<?
<!-- DEBUGSortby -->
<!-- 
mvcSORT_BY --><class="baseColorHeader" href="/source-code/base/Sortby/index.php?mvcSORT_BY=asc" title="Mvcorder_by  desc"><!-- DEBUGImages -->
<
img src="http://borebiller.info/images/desc.gif" width="5" height="10" alt="desc.gif" class="baseColorHeader" />
&
nbsp;mvcSORT_BY</a>
?>

Vis: Class methods

Sortby, Class methods

Her er 'klasse metoderne' for Sortby klassen:

  • __construct
  • getText
  • getHref
  • getClass
  • getTitle
  • addImage
  • display
  • getParams
  • getHtml
  • getValue
  • setId
  • setOnfocus
  • setOnblur
  • id
  • setObject
  • set
  • get
  • getAttribute
  • getTag
  • add
  • getSizeof
  • getElement
  • getElements
  • getToogle
  • getMaximize
  • getMinimize
  • newTriangle
  • getStartHtml
  • getEndHtml
  • showsource
  • getClassName
  • getMsg
  • addHtml
  • __toString
  • getCacheFileName
  • save
  • content

Vis: Object vars

Sortby, Object vars

Her er 'objekt variable' for Sortby klassen:

  • html =>
  • sql =>

MenuRight 
triangle.gif

Dansk

Deutch

English (UK)

France

Italy

Norsk

Svensk

English (USA)


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