2
0

TableMessage.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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_Wildfire
  17. * @subpackage Plugin
  18. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Wildfire_Plugin_FirePhp */
  22. require_once 'Zend/Wildfire/Plugin/FirePhp.php';
  23. /** Zend_Wildfire_Plugin_FirePhp_Message */
  24. require_once 'Zend/Wildfire/Plugin/FirePhp/Message.php';
  25. /**
  26. * A message envelope that can be updated for the duration of the requet before
  27. * it gets flushed at the end of the request.
  28. *
  29. * @category Zend
  30. * @package Zend_Wildfire
  31. * @subpackage Plugin
  32. * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_Wildfire_Plugin_FirePhp_TableMessage extends Zend_Wildfire_Plugin_FirePhp_Message
  36. {
  37. /**
  38. * The header of the table containing all columns
  39. * @var array
  40. */
  41. protected $_header = null;
  42. /**
  43. * The rows of the table
  44. * $var array
  45. */
  46. protected $_rows = array();
  47. /**
  48. * Constructor
  49. *
  50. * @param string $label The label of the table
  51. */
  52. function __construct($label)
  53. {
  54. parent::__construct(Zend_Wildfire_Plugin_FirePhp::TABLE, null);
  55. $this->setLabel($label);
  56. }
  57. /**
  58. * Set the table header
  59. *
  60. * @param array $header The header columns
  61. * @return void
  62. */
  63. public function setHeader($header)
  64. {
  65. $this->_header = $header;
  66. }
  67. /**
  68. * Append a row to the end of the table.
  69. *
  70. * @param array $row An array of column values representing a row.
  71. * @return void
  72. */
  73. public function addRow($row)
  74. {
  75. $this->_rows[] = $row;
  76. }
  77. /**
  78. * Get the actual message to be sent in its final format.
  79. *
  80. * @return mixed Returns the message to be sent.
  81. */
  82. public function getMessage()
  83. {
  84. $table = $this->_rows;
  85. if($this->_header) {
  86. array_unshift($table,$this->_header);
  87. }
  88. return $table;
  89. }
  90. /**
  91. * Returns the row at the given index
  92. *
  93. * @param integer $index The index of the row
  94. * @return array Returns the row
  95. * @throws Zend_Wildfire_Exception
  96. */
  97. public function getRowAt($index)
  98. {
  99. $count = $this->getRowCount();
  100. if($index < 0 || $index > $count-1) {
  101. require_once 'Zend/Wildfire/Exception.php';
  102. throw new Zend_Wildfire_Exception('Row index('.$index.') out of bounds('.$count.')!');
  103. }
  104. return $this->_rows[$index];
  105. }
  106. /**
  107. * Sets the row on the given index to a new row
  108. *
  109. * @param integer $index The index of the row
  110. * @param array $row The new data for the row
  111. * @throws Zend_Wildfire_Exception
  112. */
  113. public function setRowAt($index, $row)
  114. {
  115. $count = $this->getRowCount();
  116. if($index < 0 || $index > $count-1) {
  117. require_once 'Zend/Wildfire/Exception.php';
  118. throw new Zend_Wildfire_Exception('Row index('.$index.') out of bounds('.$count.')!');
  119. }
  120. $this->_rows[$index] = $row;
  121. }
  122. /**
  123. * Returns the number of rows
  124. *
  125. * @return integer
  126. */
  127. public function getRowCount()
  128. {
  129. return count($this->_rows);
  130. }
  131. /**
  132. * Returns the last row of the table
  133. *
  134. * @return array Returns the last row
  135. * @throws Zend_Wildfire_Exception
  136. */
  137. public function getLastRow()
  138. {
  139. $count = $this->getRowCount();
  140. if($count==0) {
  141. require_once 'Zend/Wildfire/Exception.php';
  142. throw new Zend_Wildfire_Exception('Cannot get last row as no rows exist!');
  143. }
  144. return $this->_rows[$count-1];
  145. }
  146. }