63 lines
1.4 KiB
PHP
63 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Tables\Extensions;
|
|
|
|
use Closure;
|
|
use Mmt\GenericTable\Attributes\MappedRoute;
|
|
use Mmt\GenericTable\Interfaces\ICellData;
|
|
use Mmt\GenericTable\Interfaces\IColumn;
|
|
use Mmt\GenericTable\Interfaces\IColumnRenderer;
|
|
use Mmt\GenericTable\Interfaces\IRowData;
|
|
use Str;
|
|
|
|
class IconColumn implements IColumn, IColumnRenderer
|
|
{
|
|
public int $settings = 0;
|
|
|
|
public ?MappedRoute $mappedRoute = null;
|
|
|
|
public ?string $databaseColumnName = 'status';
|
|
|
|
public string $columnTitle = 'Status';
|
|
|
|
private Closure $setIconCallback;
|
|
|
|
public int $columnIndex;
|
|
|
|
public function __construct()
|
|
{
|
|
if($this->databaseColumnName == null)
|
|
$this->databaseColumnName = Str::snake($this->columnTitle);
|
|
}
|
|
|
|
public function renderCell(ICellData $cell, IRowData $row): string|null
|
|
{
|
|
$icon = 'bi bi-arrow-up-right-circle-fill';
|
|
if(isset($this->setIconCallback))
|
|
$icon = $this->setIconCallback->call($this, $row);
|
|
|
|
return <<<HTML
|
|
<div class = "w-100 d-flex justify-content-start">
|
|
<i class = "$icon me-2"></i>
|
|
</div>
|
|
HTML;
|
|
}
|
|
|
|
public function route(MappedRoute $route)
|
|
{
|
|
$this->mappedRoute = $route;
|
|
return $this;
|
|
}
|
|
|
|
|
|
public function setIconIf(Closure $callback)
|
|
{
|
|
$this->setIconCallback = $callback;
|
|
return $this;
|
|
}
|
|
|
|
public function isRelationship(): bool
|
|
{
|
|
return false;
|
|
}
|
|
} |