Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #1 from librenms/master
Browse files Browse the repository at this point in the history
Updated to allow the use of indexes within columns
  • Loading branch information
laf authored May 6, 2017
2 parents 6d231e5 + 0c38366 commit 57c01a2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/cli/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Table {
protected $_footers = array();
protected $_width = array();
protected $_rows = array();
protected $_use_index = false;

/**
* Initializes the `Table` class.
Expand Down Expand Up @@ -79,6 +80,7 @@ public function resetTable()
$this->_width = array();
$this->_rows = array();
$this->_footers = array();
$this->_use_index = false;
return $this;
}

Expand Down Expand Up @@ -212,6 +214,14 @@ public function addRow(array $row) {
$this->_rows[] = $this->checkRow($row);
}

/**
* Sets if we should output the arrays index
*/
public function useIndex()
{
$this->_use_index = true;
}

/**
* Clears all previous rows and adds the given rows.
*
Expand All @@ -220,7 +230,10 @@ public function addRow(array $row) {
*/
public function setRows(array $rows) {
$this->_rows = array();
foreach ($rows as $row) {
foreach ($rows as $id => $row) {
if ($this->_use_index === true) {
$row = array_merge(array($id), $row);
}
$this->addRow($row);
}
}
Expand Down

0 comments on commit 57c01a2

Please sign in to comment.