AgeDisplayViewHelper

Eigener ViewHelper für Ausgabe als Balken

Ein sehr spezieller ViewHelper der einen Balken rendert mit einem hervorgehobenen Bereich. Weiterhin sind bestimmte Zahlen fett gedruckt. So sieht das aus:

 

Aufruf

<rsys:AgeDisplay min="{project.ageMin}" max="{project.ageMax}" />

oder

<rsys:AgeDisplay min="{project.ageMin}" max="{project.ageMax}" limitMin="10", limitMax="25" />

Parameter

min und max sind der hervorgehobene Bereich
limitMin und limitMax bestimmt den standardmässig angezeigten Bereich. Wenn min und max diese Werte Über- oder Unterschreiten wird die Balkenbreite angepasst.

Typoscript

plugin.tx_rsyssocialprojects {
    settings {
        # age
        age_display {
            # wraps
            item_wrap = <div class="age_bar_item">|</div>
            item_wrap_selected = <div class="age_bar_item_selected">|</div>
            wrap_highlight = <span class="strong">|</span>

            # highligted entries
            highlight = 14,18,22
           
            # max width of bar:
            cutoff = 17
        }
    }
}

Listing

<?php

/*                                                                        *
 * This script belongs to the FLOW3 package "Fluid".                      *
*                                                                        *
* It is free software; you can redistribute it and/or modify it under    *
* the terms of the GNU Lesser General Public License as published by the *
* Free Software Foundation, either version 3 of the License, or (at your *
        * option) any later version.                                             *
*                                                                        *
* This script is distributed in the hope that it will be useful, but     *
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN-    *
* TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser       *
* General Public License for more details.                               *
*                                                                        *
* You should have received a copy of the GNU Lesser General Public       *
* License along with the script.                                         *
* If not, see www.gnu.org/licenses/lgpl.html                    &nbsp; *
*                                                                        *
* The TYPO3 project - inspiring people to share!                         *
*                                                                        */

/**
 *
* = Examples =
*
* <code title="default notation">
* {namespace rsys=Tx_Rsysproductbase_ViewHelpers}
* <rsys:AgeDisplay min="{person.ageMin}" max="{person.ageMax}" />
* </code>
* <output>
* a bar with ages selected
* </output>
*
* @license www.gnu.org/licenses/lgpl.html GNU Lesser General Public License, version 3 or later
* @api
*/
class Tx_Rsyssocialprojects_ViewHelpers_AgeDisplayViewHelper extends Tx_Fluid_ViewHelpers_Format_AbstractEncodingViewHelper implements t3lib_Singleton {


    /**
     * shows a detail row wrapped with TS settings
     *
     * @param int $min miniumum age selected
     * @param int $max maximum age selected
     * @param int $limitMin miniumum age limit
     * @param int $limitMax maximum age limit
     * @return string the rendered html
     * @author Erwin Knoll <typo3coding@rootsystem.de>, Rootsystem
     * @api
     */
    public function render($min=NULL, $max=NULL, $limitMin=11, $limitMax=27) {

        // init
        $content = '';
        $stop = false;
        if($min < $limitMin) $limitMin = $min;
        if($max > $limitMax) $limitMax = $max;

        // settings
        $settings = $this->templateVariableContainer->get('settings');
        $wrap = $settings['age_display']['item_wrap'];
        $wrap_selected = $settings['age_display']['item_wrap_selected'];
        $highlight = $settings['age_display']['highlight'];
        $wrap_highlight = $settings['age_display']['wrap_highlight'];
        $cutoff  = $settings['age_display']['cutoff'];


        $highlightList = explode(',',$highlight);

        for ($i = $limitMin; $i <= $limitMax; $i++) {
            $start = $limitMin > $min ? $min : $limitMin;
            if( $i - $start   > $cutoff ) {
                $stop = true;
                break;
            } else {
                if($i >= $min && $i <= $max) {
                    if(in_array($i, $highlightList)) {
                        $item =  preg_replace ('/\|/', $i, $wrap_highlight, 1);
                    } else {
                        $item = $i;
                    }
                    $content .=  preg_replace ('/\|/', $item, $wrap_selected, 1);
                } else {
                    if(in_array($i, $highlightList)) {
                        $item =  preg_replace ('/\|/', $i, $wrap_highlight, 1);
                    } else {
                        $item = $i;
                    }
                    $content .=  preg_replace ('/\|/', $item, $wrap, 1);
                }
            }
        }
        if($stop) {
            $content .=  preg_replace ('/\|/', '...', $wrap_selected, 1);
            $content .=  preg_replace ('/\|/', $max, $wrap_selected, 1);
        }



        return $content;
    }

}
?>

Erstellt: 09/2012| Geändert: 10/2015