Advertisement
einpraegsam

Implode ViewHelper for Fluid #TYPO3

Aug 8th, 2011
432
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2. /***************************************************************
  3. *  Copyright notice
  4. *
  5. *  (c) 2011 Alex Kellner <alexander.kellner@in2code.de>, in2code.de
  6. *
  7. *  All rights reserved
  8. *
  9. *  This script is part of the TYPO3 project. The TYPO3 project is
  10. *  free software; you can redistribute it and/or modify
  11. *  it under the terms of the GNU General Public License as published by
  12. *  the Free Software Foundation; either version 3 of the License, or
  13. *  (at your option) any later version.
  14. *
  15. *  The GNU General Public License can be found at
  16. *  http://www.gnu.org/copyleft/gpl.html.
  17. *
  18. *  This script is distributed in the hope that it will be useful,
  19. *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. *  GNU General Public License for more details.
  22. *
  23. *  This copyright notice MUST APPEAR in all copies of the script!
  24. ***************************************************************/
  25.  
  26. /**
  27.  * This class contains some usefull viewhelpers
  28.  *
  29.  * @package TYPO3
  30.  * @subpackage Fluid
  31.  * @version
  32.  */
  33. class Tx_In2university_ViewHelpers_ImplodeViewHelper extends Tx_Fluid_Core_ViewHelper_AbstractViewHelper {
  34.  
  35.     /**
  36.      * Generates list from array
  37.      *
  38.      * @param   array       Any Object with some objects for an Implode
  39.      * @param   string      Field name - title for getTitle()
  40.      * @param   string      Glue sign - like ", "
  41.      * @return  string      Imploded List
  42.      */
  43.     public function render($array, $field, $glue) {
  44.         $string = '';
  45.         foreach ($array as $object) {
  46.             $string .= $object->{'get' . ucfirst($field)}();
  47.             $string .= $glue;
  48.         }
  49.         return substr($string, 0, (-1 * strlen($glue)));
  50.     }
  51. }
  52.  
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement