[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 3 /** 4 * Base plugin class. 5 */ 6 require_once 'Savant2/Plugin.php'; 7 8 /** 9 * 10 * Cycles through a series of values. 11 * 12 * $Id: Savant2_Plugin_cycle.php 18360 2005-05-26 19:38:09Z mipmip $ 13 * 14 * @author Paul M. Jones <pmjones@ciaweb.net> 15 * 16 * @package Savant2 17 * 18 * @license http://www.gnu.org/copyleft/lesser.html LGPL 19 * 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. 24 * 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. 29 * 30 */ 31 32 class Savant2_Plugin_cycle extends Savant2_Plugin { 33 34 /** 35 * 36 * An associative array of predefined cycle value sets. 37 * 38 * You can preset cycle values via Savant::loadPlugin(). 39 * 40 * $conf = array( 41 * 'values' => array( 42 * 'lightdark' => array('light', 'dark'), 43 * 'threesome' => array('one', 'two', 'three') 44 * ) 45 * ); 46 * 47 * $Savant->loadPlugin('cycle', $conf); 48 * 49 * ... and in your template you can call: 50 * 51 * $this->plugin('cycle', 'lightdark', $iteration); 52 * 53 * @access public 54 * 55 * @var array 56 * 57 */ 58 59 var $values = array(); 60 61 62 /** 63 * 64 * Cycles through a series of values. 65 * 66 * @access public 67 * 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. 70 * 71 * @param int $iteration The iteration number for the cycle. 72 * 73 * @param int $repeat The number of times to repeat each cycle value. 74 * 75 * @return mixed The value of the cycle iteration. 76 * 77 */ 78 79 function plugin($cycle, $iteration, $repeat = 1) 80 { 81 // get the proper value set as an array 82 if (is_string($cycle) && isset($this->values[$cycle])) { 83 $values = (array) $this->values[$cycle]; 84 } else { 85 $values = (array) $cycle; 86 } 87 88 // prevent divide-by-zero errors 89 if ($repeat == 0) { 90 $repeat = 1; 91 } 92 93 // return the perper value for iteration and repetition 94 return $values[($iteration / $repeat) % count($values)]; 95 } 96 } 97 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |