View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFDEV:Zend Proposal Zone Template}

{zone-data:component-name}
Zend_View_Helper_Cycle
{zone-data}

{zone-data:proposer-list}
[Kamil Nowakowski|mailto:k.nowakowski@poczta.onet.pl]
[Matthew Weier O'Phinney (Zend Liaison)|~matthew]
{zone-data}

{zone-data:revision}
0.1 - 5 April 2008: Initial proposal
{zone-data}

{zone-data:overview}
Zend_View_Helper_Cycle is a simple component which cycles through a series of values based on an iteration number.
{zone-data}

{zone-data:references}
* [Smarty \{cycle}|http://www.smarty.net/manual/en/language.function.cycle.php]
{zone-data}

{zone-data:requirements}
* This helper *will* cycle through a series of values based on an iteration number.
* This helper *will* implement Iterator interface
{zone-data}

{zone-data:dependencies}
* none
{zone-data}

{zone-data:operation}
* You can cycle in both ways (normal or backwards) through the array
{zone-data}

{zone-data:milestones}
* Milestone 1:\[DONE\] Create proposal
* Milestone 2: Community \[DONE\] and Zend review
* Milestone 3: Unit tests exist, work, and are checked into SVN.
* Milestone 4: Initial documentation exists.
{zone-data}

{zone-data:class-list}
* Zend_View_Helper_Cycle
{zone-data}

{zone-data:use-cases}
||UC-01||
{code:php}
<?php $cycle=$this->cycle(array("#F0F0F0","#FFFFFF"));?>
<?php foreach ($this->books as $book):?>
<tr style="background-color:<?=$cycle->next()?>">
<td><?=$this->escape($book['author']) ?></td>
</tr>
<?php endforeach;?>
{code}
output
{code}
<tr style="background-color:'#F0F0F0'">
<td>First</td>
</tr>
<tr style="background-color:'#FFFFFF'">
<td>Second</td>
</tr>
{code}
||UC-02||
In backwards order
{code:php}
<?php $cycle->assign(array("#F0F0F0","#FFFFFF","#36BD25"))?>
<?php foreach ($this->books as $book):?>
<tr style="background-color:<?=$cycle->prev()?>">
<td><?=$this->escape($book['author']) ?></td>
</tr>
<?php endforeach;?>
{code}
{zone-data}

{zone-data:skeletons}
{code:php}

/**
* Cycle Helper
*
*/
class Zend_View_Helper_Cycle implements Iterator
{

/**
* pointer
*
* @var iny
*/
protected $_pointer = -1;

/**
* Data to use
*
* @var array
*/
protected $_data = null;

/**
* Add data to cycle
* @param array $data
* @return Zend_View_Helper_Cycle
*/
public function cycle(array $data = array()) {}

/**
* Add data to cycle
* @param array $data
* @return Zend_View_Helper_Cycle
*/
public function assign(array $data) {}

/**
* Turn helper into string
*
* @return string
*/
public function toString() {}

/**
* Cast to string
*
* @return string
*/
public function __toString() {}

/**
* Increase iteration number
* @return Zend_View_Helper_Cycle
*/
public function next() {}

/**
* Decrease iteration number
* @return Zend_View_Helper_Cycle
*/
public function prev() {}

/**
* Returns iteration number
* @return int
*/
public function key() {}

/**
* Rewind iteration number
* @return Zend_View_Helper_Cycle
*/
public function rewind() {}

/**
* check if current is valid
* @return boolean
*/
public function valid() {}

/**
* Returns current value
* @return string
*/
public function current() {}

}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>