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

Commit 57c01a2

Browse files
authored
Merge pull request #1 from librenms/master
Updated to allow the use of indexes within columns
2 parents 6d231e5 + 0c38366 commit 57c01a2

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

lib/cli/Table.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Table {
2727
protected $_footers = array();
2828
protected $_width = array();
2929
protected $_rows = array();
30+
protected $_use_index = false;
3031

3132
/**
3233
* Initializes the `Table` class.
@@ -79,6 +80,7 @@ public function resetTable()
7980
$this->_width = array();
8081
$this->_rows = array();
8182
$this->_footers = array();
83+
$this->_use_index = false;
8284
return $this;
8385
}
8486

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

217+
/**
218+
* Sets if we should output the arrays index
219+
*/
220+
public function useIndex()
221+
{
222+
$this->_use_index = true;
223+
}
224+
215225
/**
216226
* Clears all previous rows and adds the given rows.
217227
*
@@ -220,7 +230,10 @@ public function addRow(array $row) {
220230
*/
221231
public function setRows(array $rows) {
222232
$this->_rows = array();
223-
foreach ($rows as $row) {
233+
foreach ($rows as $id => $row) {
234+
if ($this->_use_index === true) {
235+
$row = array_merge(array($id), $row);
236+
}
224237
$this->addRow($row);
225238
}
226239
}

0 commit comments

Comments
 (0)