PageRenderTime 53ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/vendors/Zend/View/Helper/PartialLoop.php

https://bitbucket.org/negge/tlklan2
PHP | 98 lines | 38 code | 10 blank | 50 comment | 11 complexity | a8ab7518e4f98ee33b184586805c4999 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, BSD-2-Clause, GPL-3.0
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_View
  17. * @subpackage Helper
  18. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @version $Id: PartialLoop.php 24593 2012-01-05 20:35:02Z matthew $
  20. * @license http://framework.zend.com/license/new-bsd New BSD License
  21. */
  22. /** Zend_View_Helper_Partial */
  23. require_once 'Zend/View/Helper/Partial.php';
  24. /**
  25. * Helper for rendering a template fragment in its own variable scope; iterates
  26. * over data provided and renders for each iteration.
  27. *
  28. * @package Zend_View
  29. * @subpackage Helper
  30. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_View_Helper_PartialLoop extends Zend_View_Helper_Partial
  34. {
  35. /**
  36. * Marker to where the pointer is at in the loop
  37. * @var integer
  38. */
  39. protected $partialCounter = 0;
  40. /**
  41. * Renders a template fragment within a variable scope distinct from the
  42. * calling View object.
  43. *
  44. * If no arguments are provided, returns object instance.
  45. *
  46. * @param string $name Name of view script
  47. * @param string|array $module If $model is empty, and $module is an array,
  48. * these are the variables to populate in the
  49. * view. Otherwise, the module in which the
  50. * partial resides
  51. * @param array $model Variables to populate in the view
  52. * @return string
  53. */
  54. public function partialLoop($name = null, $module = null, $model = null)
  55. {
  56. if (0 == func_num_args()) {
  57. return $this;
  58. }
  59. if ((null === $model) && (null !== $module)) {
  60. $model = $module;
  61. $module = null;
  62. }
  63. if (!is_array($model)
  64. && (!$model instanceof Traversable)
  65. && (is_object($model) && !method_exists($model, 'toArray'))
  66. ) {
  67. require_once 'Zend/View/Helper/Partial/Exception.php';
  68. $e = new Zend_View_Helper_Partial_Exception('PartialLoop helper requires iterable data');
  69. $e->setView($this->view);
  70. throw $e;
  71. }
  72. if (is_object($model)
  73. && (!$model instanceof Traversable)
  74. && method_exists($model, 'toArray')
  75. ) {
  76. $model = $model->toArray();
  77. }
  78. $content = '';
  79. // reset the counter if it's call again
  80. $this->partialCounter = 0;
  81. foreach ($model as $item) {
  82. // increment the counter variable
  83. $this->partialCounter++;
  84. $content .= $this->partial($name, $module, $item);
  85. }
  86. return $content;
  87. }
  88. }