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