You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
1.7 KiB
67 lines
1.7 KiB
<?php
|
|
|
|
namespace App\Domains\Finance\Support\Schema;
|
|
|
|
use App\UI\Enums\InputType;
|
|
use App\UI\Support\Settings\BaseSchema;
|
|
use App\UI\Support\Settings\SettingSchema;
|
|
|
|
class InvoiceSchema implements BaseSchema
|
|
{
|
|
protected array $context = [];
|
|
protected string $form = '';
|
|
|
|
public function __construct(
|
|
protected array $uiSchema = [],
|
|
protected bool $coaVisibility = false
|
|
){}
|
|
|
|
public static function make(bool $coaVisible = false): static
|
|
{
|
|
return new self([], $coaVisible);
|
|
}
|
|
|
|
public function addSchema(string$key, string $label, SettingSchema $schema): static
|
|
{
|
|
$schema = $schema->attributes(['label' => $label]);
|
|
$uiSchema = array_merge($this->uiSchema, [[
|
|
'key' => $key,
|
|
'schema' => $schema
|
|
]]);
|
|
return new self($uiSchema, $this->coaVisibility);
|
|
}
|
|
|
|
public function withContext(array $context): static
|
|
{
|
|
$this->context = $context;
|
|
return $this;
|
|
}
|
|
|
|
public function withFormString(string $form): static
|
|
{
|
|
$this->form = $form;
|
|
return $this;
|
|
}
|
|
|
|
public function getSchema(): array
|
|
{
|
|
$fields = [];
|
|
foreach($this->uiSchema as $field) {
|
|
/** @var SettingSchema $schema */
|
|
$schema = $field['schema'];
|
|
$attributes['options'] =$schema->type->isSelect() ? $schema->resolveOptions($this->context) : '';
|
|
|
|
$fields[$field['key']] = (object) [
|
|
'attributes' => array_merge($schema->attributes, $attributes),
|
|
'schema' => $schema,
|
|
];
|
|
}
|
|
|
|
return $fields;
|
|
}
|
|
|
|
public function isCoaVisible(): bool
|
|
{
|
|
return $this->coaVisibility;
|
|
}
|
|
}
|
|
|