jcb-compiler/src/5f8e8fa6-3793-44af-882d-9cf.../code.power

79 lines
1.8 KiB
Plaintext

/**
* The BuilderCustomAlias Class.
*
* @var BuilderCustomAlias
* @since 3.2.0
*/
protected BuilderCustomAlias $customalias;
/**
* The Name Class.
*
* @var FieldName
* @since 3.2.0
*/
protected FieldName $fieldname;
/**
* Constructor.
*
* @param BuilderCustomAlias $customalias The CustomAlias Class.
* @param FieldName $fieldname The Name Class.
*
* @since 3.2.0
*/
public function __construct(BuilderCustomAlias $customalias, FieldName $fieldname)
{
$this->customalias = $customalias;
$this->fieldname = $fieldname;
}
/**
* Set activate alias builder
*
* @param object $item The item data
*
* @return void
* @since 3.2.0
*/
public function set(object &$item)
{
if (!$this->customalias->get($item->name_single_code)
&& isset($item->alias_builder_type) && 2 == $item->alias_builder_type
&& isset($item->alias_builder) && JsonHelper::check($item->alias_builder))
{
// get the aliasFields
$alias_fields = (array) json_decode((string) $item->alias_builder, true);
// get the active fields
$alias_fields = (array) array_filter(
$item->fields, function ($field) use ($alias_fields) {
// check if field is in view fields
if (in_array($field['field'], $alias_fields))
{
return true;
}
return false;
}
);
// check if all is well
if (ArrayHelper::check($alias_fields))
{
// load the field names
$this->customalias->set($item->name_single_code,
(array) array_map(
function ($field) use (&$item) {
return $this->fieldname->get(
$field, $item->name_list_code
);
}, $alias_fields
)
);
}
}
// unset
unset($item->alias_builder);
}