Add objects directly to Entry::class when rendering a template. Fix objectclasses and attributes processing for templates
This commit is contained in:
@@ -31,11 +31,12 @@ class Template
|
||||
public function __get(string $key): mixed
|
||||
{
|
||||
return match ($key) {
|
||||
'name' => Str::replaceEnd('.json','',$this->file),
|
||||
'attributes' => collect(array_map('strtolower',array_keys(Arr::get($this->template,$key)))),
|
||||
'objectclasses' => collect(array_map('strtolower',Arr::get($this->template,$key))),
|
||||
'attributes' => collect(Arr::get($this->template,$key))->keys(),
|
||||
'enabled' => Arr::get($this->template,$key,FALSE) && (! $this->invalid),
|
||||
'icon','regexp','title' => Arr::get($this->template,$key),
|
||||
'name' => Str::replaceEnd('.json','',$this->file),
|
||||
'objectclasses' => collect(Arr::get($this->template,$key)),
|
||||
'order' => collect(Arr::get($this->template,'attributes'))->map(fn($item)=>$item['order']),
|
||||
|
||||
default => throw new \Exception('Unknown key: '.$key),
|
||||
};
|
||||
|
@@ -58,8 +58,13 @@ class HomeController extends Controller
|
||||
$template = $o->template($request->validated('template'));
|
||||
$o->objectclass = [Entry::TAG_NOTAG=>$template->objectclasses->toArray()];
|
||||
|
||||
foreach ($o->getAvailableAttributes()->filter(fn($item)=>$item->names_lc->intersect($template->attributes)->count()) as $ao)
|
||||
$o->{$ao->name} = [Entry::TAG_NOTAG=>''];
|
||||
foreach ($o->getAvailableAttributes()
|
||||
->filter(fn($item)=>$item->names_lc->intersect($template->attributes->map('strtolower'))->count())
|
||||
->sortBy(fn($item)=>Arr::get($template->order,$item->name)) as $ao)
|
||||
{
|
||||
$o->addObjectItem($ao->name,
|
||||
Factory::create(dn: '',attribute: $ao->name,values: [Entry::TAG_NOTAG=>''],oc: $o->objectclass));
|
||||
}
|
||||
}
|
||||
|
||||
$step = $request->step ? $request->step+1 : old('step');
|
||||
|
@@ -130,7 +130,7 @@ class Entry extends Model
|
||||
$o = $this->objects->get($attribute) ?: Factory::create($this->dn ?: '',$attribute,[],Arr::get($this->attributes,'objectclass',[]));
|
||||
$o->values = collect($value);
|
||||
|
||||
$this->objects->put($key,$o);
|
||||
$this->addObjectItem($key,$o);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -159,8 +159,11 @@ class Entry extends Model
|
||||
if ($this->dn && (! in_array(strtolower($this->dn),['cn=subschema']))) {
|
||||
$this->templates = $this->templates
|
||||
->filter(fn($item)=>$item->enabled
|
||||
&& (! count($item->objectclasses->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass'))))))
|
||||
->sortBy(fn($item)=>$item);
|
||||
&& (! $item->objectclasses
|
||||
->map('strtolower')
|
||||
->diff(array_map('strtolower',Arr::get($this->attributes,'objectclass')))
|
||||
->count()))
|
||||
->sortBy(fn($item)=>$item->title);
|
||||
}
|
||||
|
||||
return $this;
|
||||
@@ -208,7 +211,19 @@ class Entry extends Model
|
||||
$o = $this->objects->get($attribute) ?: Attribute\Factory::create($this->dn ?: '',$attribute,[]);
|
||||
$o->addValue($tag,[$value]);
|
||||
|
||||
$this->objects->put($attribute,$o);
|
||||
$this->addObjectItem($attribute,$o);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a new object item directly
|
||||
*
|
||||
* @param string $name
|
||||
* @param Attribute $o
|
||||
* @return void
|
||||
*/
|
||||
public function addObjectItem(string $name,Attribute $o): void
|
||||
{
|
||||
$this->objects->put($name,$o);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user