mirror of https://github.com/MISP/MISP
chg: [helper:BootstrapListTable] Refactored to remove warning + Linted
parent
234d92c80b
commit
b02fa216d6
|
@ -2,10 +2,9 @@
|
|||
|
||||
namespace App\View\Helper\BootstrapElements;
|
||||
|
||||
use Cake\Utility\Hash;
|
||||
|
||||
use App\View\Helper\BootstrapGeneric;
|
||||
use App\View\Helper\BootstrapHelper;
|
||||
use Cake\Utility\Hash;
|
||||
|
||||
/**
|
||||
* Creates a list looking like a table from 1-dimensional data $item.
|
||||
|
@ -101,7 +100,12 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
'elementsRootPath' => '/genericElements/SingleViews/Fields/',
|
||||
];
|
||||
|
||||
function __construct(array $options, array $data, BootstrapHelper $btHelper)
|
||||
private $fields;
|
||||
private $item;
|
||||
private $caption;
|
||||
private $btHelper;
|
||||
|
||||
public function __construct(array $options, array $data, BootstrapHelper $btHelper)
|
||||
{
|
||||
$this->allowedOptionValues = [
|
||||
'variant' => array_merge(BootstrapGeneric::$variants, [''])
|
||||
|
@ -129,7 +133,9 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
|
||||
private function genTable(): string
|
||||
{
|
||||
$html = $this->nodeOpen('table', [
|
||||
$html = $this->nodeOpen(
|
||||
'table',
|
||||
[
|
||||
'class' => [
|
||||
'table',
|
||||
"table-{$this->options['variant']}",
|
||||
|
@ -142,7 +148,8 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
!empty($this->options['variant']) ? "table-{$this->options['variant']}" : '',
|
||||
],
|
||||
'id' => $this->options['id'] ?? ''
|
||||
]);
|
||||
]
|
||||
);
|
||||
|
||||
$html .= $this->genCaption();
|
||||
$html .= $this->genBody();
|
||||
|
@ -153,9 +160,12 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
|
||||
private function genBody(): string
|
||||
{
|
||||
$body = $this->nodeOpen('tbody', [
|
||||
$body = $this->nodeOpen(
|
||||
'tbody',
|
||||
[
|
||||
'class' => $this->options['bodyClass'],
|
||||
]);
|
||||
]
|
||||
);
|
||||
foreach ($this->fields as $i => $field) {
|
||||
$body .= $this->genRow($field);
|
||||
}
|
||||
|
@ -168,15 +178,21 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
$allKeyClass = $this->convertToArrayIfNeeded($this->options['keyClass'] ?? []);
|
||||
$keyClass = $this->convertToArrayIfNeeded($field['keyClass'] ?? []);
|
||||
$rowValue = $this->genCell($field);
|
||||
$rowKey = $this->node('th', [
|
||||
$rowKey = $this->node(
|
||||
'th',
|
||||
[
|
||||
'class' => array_merge(
|
||||
$allKeyClass,
|
||||
$keyClass,
|
||||
!empty($this->options['fluid']) ? ['col flex-shrink-1'] : ['col-4 col-sm-3'],
|
||||
),
|
||||
'scope' => 'row'
|
||||
], $field['keyHtml'] ?? h($field['key']));
|
||||
$row = $this->node('tr', [
|
||||
],
|
||||
$field['keyHtml'] ?? h($field['key'])
|
||||
);
|
||||
$row = $this->node(
|
||||
'tr',
|
||||
[
|
||||
'class' => array_merge(
|
||||
$this->options['rowClass'],
|
||||
[
|
||||
|
@ -184,7 +200,9 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
!empty($field['rowVariant']) ? "table-{$field['rowVariant']}" : ''
|
||||
]
|
||||
),
|
||||
], [$rowKey, $rowValue]);
|
||||
],
|
||||
[$rowKey, $rowValue]
|
||||
);
|
||||
return $row;
|
||||
}
|
||||
|
||||
|
@ -195,10 +213,13 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
} else if (isset($field['formatter'])) {
|
||||
$cellContent = $field['formatter']($this->getValueFromObject($field), $this->item);
|
||||
} else if (isset($field['type'])) {
|
||||
$cellContent = $this->btHelper->getView()->element($this->getElementPath($field['type']), [
|
||||
$cellContent = $this->btHelper->getView()->element(
|
||||
$this->getElementPath($field['type']),
|
||||
[
|
||||
'data' => $this->item,
|
||||
'field' => $field
|
||||
]);
|
||||
]
|
||||
);
|
||||
} else {
|
||||
$cellContent = h($this->getValueFromObject($field));
|
||||
}
|
||||
|
@ -209,7 +230,9 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
}
|
||||
$allValueClass = $this->convertToArrayIfNeeded($this->options['valueClass'] ?? []);
|
||||
$valueClass = $this->convertToArrayIfNeeded($field['valueClass'] ?? []);
|
||||
return $this->node('td', [
|
||||
return $this->node(
|
||||
'td',
|
||||
[
|
||||
'class' => array_merge(
|
||||
$allValueClass,
|
||||
$valueClass,
|
||||
|
@ -218,7 +241,9 @@ class BootstrapListTable extends BootstrapGeneric
|
|||
!empty($field['cellVariant']) ? "bg-{$field['cellVariant']}" : ''
|
||||
]
|
||||
),
|
||||
], $cellContent);
|
||||
],
|
||||
$cellContent
|
||||
);
|
||||
}
|
||||
|
||||
private function getValueFromObject(array $field): string
|
||||
|
|
Loading…
Reference in New Issue