formats and style

This commit is contained in:
2024-08-08 17:08:46 +03:00
parent d0f136e484
commit 38d5deb36a
6 changed files with 50 additions and 15 deletions

View File

@ -25,15 +25,16 @@ class JasonTable
if (is_array($this->beforePrintCell)) {
if (isset($this->beforePrintCell[$key])) {
if (is_array($this->beforePrintCell[$key])){
if (!isset($this->beforePrintCell[$key]['format'])){
$this->beforePrintCell[$key]['format'] = "text";
}
$format = explode(":", $this->beforePrintCell[$key]['format']);
$formatClass = FormatMapper::getFormat()[$format[0]];
$cell = $formatClass::fetch($cell, $format[1] ?? "");
if (isset($this->beforePrintCell[$key]['value'])){
$hook = $this->beforePrintCell[$key]['value'];
$cell = $hook($cell);
}
elseif (isset($this->beforePrintCell[$key]['format'])){
$format = explode(":", $this->beforePrintCell[$key]['format']);
$formatClass = FormatMapper::getFormat()[$format[0]];
$cell = $formatClass::fetch($cell, $format[1] ?? null);
}
}
else {
$hook = $this->beforePrintCell[$key];
@ -58,4 +59,35 @@ class JasonTable
{
$this->beforePrintHook = $closure;
}
protected function getParamFromCustomColumn(string $column, string $paramName)
{
if (is_array($this->beforePrintCell)) {
if (isset($this->beforePrintCell[$column])) {
if (is_array($this->beforePrintCell[$column])){
if (isset($this->beforePrintCell[$column][$paramName])){
return $this->beforePrintCell[$column][$paramName];
}
}
}
}
return null;
}
protected function getStyleFromCustomColumn(string $column)
{
$styleStr = '';
$style = $this->getParamFromCustomColumn($column, "style");
if (is_array($style)){
foreach ($style as $key => $value){
$styleStr .= $key . ": " . $value . ";";
}
}
else {
$styleStr = $style;
}
return $styleStr;
}
}

View File

@ -91,7 +91,7 @@ class ListJsonTable extends JasonTable
if($this->beforePrintCell) {
$cell = $this->getCustomCell($key, $cell);
}
$this->html .= "<td>" . $cell . "</td>";
$this->html .= "<td style='" . $this->getStyleFromCustomColumn($key) . "'>" . $cell . "</td>";
}
}
$this->getCustomColumns($row["id"] ?? null);
@ -163,6 +163,8 @@ class ListJsonTable extends JasonTable
return $keys;
}
private function getColumnKeys(): array
{
$columnKeys = [];

View File

@ -7,8 +7,8 @@ use Itguild\Tables\formats\BaseFormat;
class HtmlFormat extends BaseFormat
{
static function fetch(?string $data, string $options = "")
static function fetch(?string $data, string $options = ""): string
{
return;
return (string)$data;
}
}

View File

@ -7,7 +7,7 @@ class TextFormat extends BaseFormat
public static function fetch($data, string $options = ""): string
{
return (string)$data;
return strip_tags((string)$data);
}
}