Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Zend_Text_Table_Row Class Reference

Public Member Functions

 createColumn ($content, array $options=null)
 
 appendColumn (Zend_Text_Table_Column $column)
 
 getColumn ($index)
 
 getColumns ()
 
 getColumnWidths ()
 
 render (array $columnWidths, Zend_Text_Table_Decorator_Interface $decorator, $padding=0)
 

Protected Attributes

 $_columns = array()
 
 $_columnWidths = null
 

Detailed Description

Definition at line 30 of file Row.php.

Member Function Documentation

◆ appendColumn()

appendColumn ( Zend_Text_Table_Column  $column)

Append a column to the row

Parameters
Zend_Text_Table_Column$columnThe column to append to the row
Returns
Zend_Text_Table_Row

Definition at line 78 of file Row.php.

79  {
80  $this->_columns[] = $column;
81 
82  return $this;
83  }

◆ createColumn()

createColumn (   $content,
array  $options = null 
)

Create a new column and append it to the row

Parameters
string$content
array$options
Returns
Zend_Text_Table_Row

Definition at line 53 of file Row.php.

54  {
55  $align = null;
56  $colSpan = null;
57  $encoding = null;
58 
59  if ($options !== null) {
60  extract($options, EXTR_IF_EXISTS);
61  }
62 
63  #require_once 'Zend/Text/Table/Column.php';
64 
65  $column = new Zend_Text_Table_Column($content, $align, $colSpan, $encoding);
66 
67  $this->appendColumn($column);
68 
69  return $this;
70  }
appendColumn(Zend_Text_Table_Column $column)
Definition: Row.php:78

◆ getColumn()

getColumn (   $index)

Get a column by it's index

Returns null, when the index is out of range

Parameters
integer$index
Returns
Zend_Text_Table_Column|null

Definition at line 93 of file Row.php.

94  {
95  if (!isset($this->_columns[$index])) {
96  return null;
97  }
98 
99  return $this->_columns[$index];
100  }
$index
Definition: list.phtml:44

◆ getColumns()

getColumns ( )

Get all columns of the row

Returns
array

Definition at line 107 of file Row.php.

108  {
109  return $this->_columns;
110  }

◆ getColumnWidths()

getColumnWidths ( )

Get the widths of all columns, which were rendered last

Exceptions
Zend_Text_Table_ExceptionWhen no columns were rendered yet
Returns
integer

Definition at line 118 of file Row.php.

119  {
120  if ($this->_columnWidths === null) {
121  #require_once 'Zend/Text/Table/Exception.php';
122  throw new Zend_Text_Table_Exception('No columns were rendered yet');
123  }
124 
125  return $this->_columnWidths;
126  }

◆ render()

render ( array  $columnWidths,
Zend_Text_Table_Decorator_Interface  $decorator,
  $padding = 0 
)

Render the row

Parameters
array$columnWidthsWidth of all columns
Zend_Text_Table_Decorator_Interface$decoratorDecorator for the row borders
integer$paddingPadding for the columns
Exceptions
Zend_Text_Table_ExceptionWhen there are too many columns
Returns
string

Definition at line 137 of file Row.php.

140  {
141  // Prepare an array to store all column widths
142  $this->_columnWidths = array();
143 
144  // If there is no single column, create a column which spans over the
145  // entire row
146  if (count($this->_columns) === 0) {
147  #require_once 'Zend/Text/Table/Column.php';
148  $this->appendColumn(new Zend_Text_Table_Column(null, null, count($columnWidths)));
149  }
150 
151  // First we have to render all columns, to get the maximum height
152  $renderedColumns = array();
153  $maxHeight = 0;
154  $colNum = 0;
155  foreach ($this->_columns as $column) {
156  // Get the colspan of the column
157  $colSpan = $column->getColSpan();
158 
159  // Verify if there are enough column widths defined
160  if (($colNum + $colSpan) > count($columnWidths)) {
161  #require_once 'Zend/Text/Table/Exception.php';
162  throw new Zend_Text_Table_Exception('Too many columns');
163  }
164 
165  // Calculate the column width
166  $columnWidth = ($colSpan - 1 + array_sum(array_slice($columnWidths,
167  $colNum,
168  $colSpan)));
169 
170  // Render the column and split it's lines into an array
171  $result = explode("\n", $column->render($columnWidth, $padding));
172 
173  // Store the width of the rendered column
174  $this->_columnWidths[] = $columnWidth;
175 
176  // Store the rendered column and calculate the new max height
177  $renderedColumns[] = $result;
178  $maxHeight = max($maxHeight, count($result));
179 
180  // Set up the internal column number
181  $colNum += $colSpan;
182  }
183 
184  // If the row doesnt contain enough columns to fill the entire row, fill
185  // it with an empty column
186  if ($colNum < count($columnWidths)) {
187  $remainingWidth = (count($columnWidths) - $colNum - 1) +
188  array_sum(array_slice($columnWidths,
189  $colNum));
190  $renderedColumns[] = array(str_repeat(' ', $remainingWidth));
191 
192  $this->_columnWidths[] = $remainingWidth;
193  }
194 
195  // Add each single column line to the result
196  $result = '';
197  for ($line = 0; $line < $maxHeight; $line++) {
198  $result .= $decorator->getVertical();
199 
200  foreach ($renderedColumns as $index => $renderedColumn) {
201  if (isset($renderedColumn[$line]) === true) {
202  $result .= $renderedColumn[$line];
203  } else {
204  $result .= str_repeat(' ', $this->_columnWidths[$index]);
205  }
206 
207  $result .= $decorator->getVertical();
208  }
209 
210  $result .= "\n";
211  }
212 
213  return $result;
214  }
appendColumn(Zend_Text_Table_Column $column)
Definition: Row.php:78
$index
Definition: list.phtml:44

Field Documentation

◆ $_columns

$_columns = array()
protected

Definition at line 37 of file Row.php.

◆ $_columnWidths

$_columnWidths = null
protected

Definition at line 44 of file Row.php.


The documentation for this class was generated from the following file: