*prechod na novsiu verziu ZF
[sport-group.git] / library / Zend / View / Helper / PartialLoop.php
blob4c9e337833c561bed57cc1c9037f1d43962838b0
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_View
17 * @subpackage Helper
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @version $Id: PartialLoop.php 16222 2009-06-21 19:55:20Z thomas $
20 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_View_Helper_Partial */
24 require_once 'Zend/View/Helper/Partial.php';
26 /**
27 * Helper for rendering a template fragment in its own variable scope; iterates
28 * over data provided and renders for each iteration.
30 * @package Zend_View
31 * @subpackage Helper
32 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
33 * @license http://framework.zend.com/license/new-bsd New BSD License
35 class Zend_View_Helper_PartialLoop extends Zend_View_Helper_Partial
38 /**
39 * Marker to where the pointer is at in the loop
40 * @var integer
42 protected $partialCounter = 0;
44 /**
45 * Renders a template fragment within a variable scope distinct from the
46 * calling View object.
48 * If no arguments are provided, returns object instance.
50 * @param string $name Name of view script
51 * @param string|array $module If $model is empty, and $module is an array,
52 * these are the variables to populate in the
53 * view. Otherwise, the module in which the
54 * partial resides
55 * @param array $model Variables to populate in the view
56 * @return string
58 public function partialLoop($name = null, $module = null, $model = null)
60 if (0 == func_num_args()) {
61 return $this;
64 if ((null === $model) && (null !== $module)) {
65 $model = $module;
66 $module = null;
69 if (!is_array($model)
70 && (!$model instanceof Traversable)
71 && (is_object($model) && !method_exists($model, 'toArray'))
72 ) {
73 require_once 'Zend/View/Helper/Partial/Exception.php';
74 throw new Zend_View_Helper_Partial_Exception('PartialLoop helper requires iterable data');
77 if (is_object($model)
78 && (!$model instanceof Traversable)
79 && method_exists($model, 'toArray')
80 ) {
81 $model = $model->toArray();
84 $content = '';
85 // reset the counter if it's call again
86 $this->partialCounter = 0;
87 foreach ($model as $item) {
88 // increment the counter variable
89 $this->partialCounter++;
91 $content .= $this->partial($name, $module, $item);
94 return $content;