Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /***************************************************************
- * Copyright notice
- *
- * (c) 2013 Jan-Philipp Greth <[email protected]>
- * Based on View Helpers by:
- * - Dimitri König <[email protected]>, cab services ag ( http://forge.typo3.org/attachments/18001/IfContainsViewHelper.php )
- * - Benjamin Rau <[email protected]>, codearts ( https://gist.github.com/benjaminrau/4674180 )
- *
- * All rights reserved
- *
- * This script is part of the TYPO3 project. The TYPO3 project is
- * free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * The GNU General Public License can be found at
- * http://www.gnu.org/copyleft/gpl.html.
- *
- * This script is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * This copyright notice MUST APPEAR in all copies of the script!
- ***************************************************************/
- namespace Jpg\Events\ViewHelpers;
- use TYPO3\Flow\Annotations as Flow;
- /**
- * In Array View Helper
- *
- * For Example you could use it with multiple checkboxes to check the selected one:
- *
- *<f:for each="{persons}" as="person">
- * <ev:inArray haystack="{event.persons}" needle="{person}" >
- * <f:then>
- * <f:form.checkbox property="persons" value="{person}" checked="true" /><label>{person.name}</label><br/>
- * </f:then>
- * <f:else>
- * <f:form.checkbox property="persons" value="{person}" /><label>{person.name}</label><br/>
- * </f:else>
- * </ev:inArray>
- *</f:for>
- *
- *
- * @Flow\Scope("prototype")
- */
- class InArrayViewHelper extends \TYPO3\Fluid\Core\ViewHelper\AbstractConditionViewHelper {
- public function initializeArguments() {
- parent::initializeArguments();
- $this->registerArgument('haystack', 'mixed', 'View helper haystack ', TRUE);
- $this->registerArgument('needle', 'string', 'View helper needle', TRUE);
- }
- /**
- * Check if value is in array
- *
- *
- * @param string $needle
- * @param array $haystack
- *
- * @return boolean
- */
- public function render() {
- $needle = $this->arguments['needle'];
- $haystack = $this->arguments['haystack'];
- if(is_string($haystack)) {
- $haystack = strpos($haystack, ',') ? explode(',',$haystack) : $haystack;
- }
- if(is_object($haystack)) {
- $haystack = $haystack->toArray();
- }
- if(in_array($needle, $haystack) && is_array($haystack)) {
- return $this->renderThenChild();
- } else {
- return $this->renderElseChild();
- }
- /*************************
- $output = '';
- if ($value === NULL || $in === NULL) {
- return '';
- }
- if (is_string($in)) {
- $in = t3lib_div::trimExplode(',', $in, true);
- }
- if (is_object($in)) {
- $in = $in->toArray();
- }
- if (is_array($in) && in_array($value, $in)) {
- $output = $this->renderChildren();
- }
- return $output;
- */
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment