6 require_once 'Savant2/Plugin.php';
10 * Cycles through a series of values.
12 * $Id: Savant2_Plugin_cycle.php,v 1.2 2005/08/09 22:19:39 pmjones Exp $
14 * @author Paul M. Jones <pmjones@ciaweb.net>
18 * @license LGPL http://www.gnu.org/copyleft/lesser.html
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU Lesser General Public License as
22 * published by the Free Software Foundation; either version 2.1 of the
23 * License, or (at your option) any later version.
25 * This program is distributed in the hope that it will be useful, but
26 * WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28 * Lesser General Public License for more details.
32 class Savant2_Plugin_cycle extends Savant2_Plugin {
36 * An associative array of predefined cycle value sets.
38 * You can preset cycle values via Savant::loadPlugin().
42 * 'lightdark' => array('light', 'dark'),
43 * 'threesome' => array('one', 'two', 'three')
47 * $Savant->loadPlugin('cycle', $conf);
49 * ... and in your template you can call:
51 * $this->plugin('cycle', 'lightdark', $iteration);
59 var $values = array();
64 * Cycles through a series of values.
68 * @param string|array $cycle If a string, the preset cycle value key to use
69 * from $this->cycles; if an array, use the array as the cycle values.
71 * @param int $iteration The iteration number for the cycle.
73 * @param int $repeat The number of times to repeat each cycle value.
75 * @return mixed The value of the cycle iteration.
79 function plugin($cycle, $iteration, $repeat = 1)
81 // get the proper value set as an array
82 if (is_string($cycle) && isset($this->values[$cycle])) {
83 $values = (array) $this->values[$cycle];
85 $values = (array) $cycle;
88 // prevent divide-by-zero errors
93 // return the perper value for iteration and repetition
94 return $values[($iteration / $repeat) % count($values)];