PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/lib/Zend/Wildfire/Plugin/FirePhp/TableMessage.php

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