[Flow] [Fluid] How can I use dynamic array indexes in templates?

Bastian Waidelich bastian at typo3.org
Fri Jun 21 12:22:40 CEST 2013


Bastian Waidelich wrote:

> repetition: Enum (= e.g. an integer internally to support bitwise
> options, see below)

"below" as in "next post" (:

Depending on your needs it might be enough to have s.th. like:

class Task {

	const REPETITION_MONDAYS = 1;
	const REPETITION_TUESDAYS = 2;
	const REPETITION_WEDNESDAYS = 4;
	// ...

	/**
	 * @var integer
	 */
	protected $repetition = 0;

	/**
	 * @param integer $repetition one of the REPETITION_* constants
	 * @return void
	 */
	public function addRepetition($repetition) {
		$this->repetition |= $repetition;
	}

	/**
	 * @param integer $repetition one of the REPETITION_* constants
	 * @return void
	 */
	public function removeRepetition($repetition) {
		$this->repetition &= ~$repetition;
	}

	/**
	 * @param integer $repetition one of the REPETITION_* constants
	 * @return boolean
	 */
	public function isRepetitionSet($repetition) {
		return ($this->repetition & $repetition) === $repetition;
	}

}

$task = new Task();
$task->addRepetition(Task::REPETITION_MONDAYS);
$task->addRepetition(Task::REPETITION_TUESDAYS);

var_dump($task->isRepetitionSet(Task::REPETITION_TUESDAYS); // TRUE
var_dump($task->isRepetitionSet(Task::REPETITION_WEDNESDAYS); // FALSE

-- 
Bastian Waidelich
--
Core Developer Team

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the Flow mailing list