File indexing completed on 2024-12-22 05:37:14
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_View 0017 * @subpackage Helper 0018 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0019 * @version $Id$ 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 */ 0022 0023 /** Zend_View_Helper_Partial */ 0024 // require_once 'Zend/View/Helper/Partial.php'; 0025 0026 /** 0027 * Helper for rendering a template fragment in its own variable scope; iterates 0028 * over data provided and renders for each iteration. 0029 * 0030 * @package Zend_View 0031 * @subpackage Helper 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_View_Helper_PartialLoop extends Zend_View_Helper_Partial 0036 { 0037 0038 /** 0039 * Marker to where the pointer is at in the loop 0040 * @var integer 0041 */ 0042 protected $partialCounter = 0; 0043 0044 /** 0045 * Renders a template fragment within a variable scope distinct from the 0046 * calling View object. 0047 * 0048 * If no arguments are provided, returns object instance. 0049 * 0050 * @param string $name Name of view script 0051 * @param string|array $module If $model is empty, and $module is an array, 0052 * these are the variables to populate in the 0053 * view. Otherwise, the module in which the 0054 * partial resides 0055 * @param array $model Variables to populate in the view 0056 * @return string 0057 */ 0058 public function partialLoop($name = null, $module = null, $model = null) 0059 { 0060 if (0 == func_num_args()) { 0061 return $this; 0062 } 0063 0064 if ((null === $model) && (null !== $module)) { 0065 $model = $module; 0066 $module = null; 0067 } 0068 0069 if (!is_array($model) 0070 && (!$model instanceof Traversable) 0071 && (is_object($model) && !method_exists($model, 'toArray')) 0072 ) { 0073 // require_once 'Zend/View/Helper/Partial/Exception.php'; 0074 $e = new Zend_View_Helper_Partial_Exception('PartialLoop helper requires iterable data'); 0075 $e->setView($this->view); 0076 throw $e; 0077 } 0078 0079 if (is_object($model) 0080 && (!$model instanceof Traversable) 0081 && method_exists($model, 'toArray') 0082 ) { 0083 $model = $model->toArray(); 0084 } 0085 0086 $content = ''; 0087 // reset the counter if it's call again 0088 $this->partialCounter = 0; 0089 $this->partialTotalCount = count($model); 0090 0091 foreach ($model as $item) { 0092 // increment the counter variable 0093 $this->partialCounter++; 0094 0095 $content .= $this->partial($name, $module, $item); 0096 } 0097 0098 return $content; 0099 } 0100 }