179 lines
4.9 KiB
Plaintext
179 lines
4.9 KiB
Plaintext
/**
|
|
* The compiler registry
|
|
*
|
|
* @var Registry
|
|
* @since 3.2.0
|
|
*/
|
|
protected Registry $registry;
|
|
|
|
/**
|
|
* Compiler Component
|
|
*
|
|
* @var Component
|
|
* @since 3.2.0
|
|
**/
|
|
protected Component $component;
|
|
|
|
/**
|
|
* Application object.
|
|
*
|
|
* @var CMSApplication
|
|
* @since 3.2.0
|
|
**/
|
|
protected CMSApplication $app;
|
|
|
|
/**
|
|
* Constructor
|
|
*
|
|
* @param Registry|null $registry The compiler registry object.
|
|
* @param Component|null $component The component class.
|
|
* @param CMSApplication|null $app The app object.
|
|
*
|
|
* @since 3.2.0
|
|
*/
|
|
public function __construct(?Registry $registry = null, ?Component $component = null,
|
|
?CMSApplication $app = null)
|
|
{
|
|
$this->registry = $registry ?: Compiler::_('Registry');
|
|
$this->component = $component ?: Compiler::_('Component');
|
|
$this->app = $app ?: Factory::getApplication();
|
|
}
|
|
|
|
/**
|
|
* Set the Dynamic Dashboard
|
|
*
|
|
* @return void
|
|
* @since 3.2.0
|
|
*/
|
|
public function set()
|
|
{
|
|
// only add the dynamic dashboard if all checks out
|
|
if ($this->component->get('dashboard_type', 0) == 2
|
|
&& ($dashboard_ = $this->component->get('dashboard')) !== null
|
|
&& StringHelper::check($dashboard_)
|
|
&& strpos((string) $dashboard_, '_') !== false)
|
|
{
|
|
// set the default view
|
|
$getter = explode('_', (string) $dashboard_);
|
|
if (count((array) $getter) == 2 && is_numeric($getter[1]))
|
|
{
|
|
// the pointers
|
|
$t = StringHelper::safe($getter[0], 'U');
|
|
$id = (int) $getter[1];
|
|
|
|
// the dynamic stuff
|
|
$targets = array('A' => 'admin_views',
|
|
'C' => 'custom_admin_views');
|
|
$names = array('A' => 'admin view',
|
|
'C' => 'custom admin view');
|
|
$types = array('A' => 'adminview', 'C' => 'customadminview');
|
|
$keys = array('A' => 'name_list', 'C' => 'code');
|
|
|
|
// check the target values
|
|
if (isset($targets[$t]) && $id > 0)
|
|
{
|
|
// set the type name
|
|
$type_names = StringHelper::safe(
|
|
$targets[$t], 'w'
|
|
);
|
|
// set the dynamic dash
|
|
if (($target_ = $this->component->get($targets[$t])) !== null
|
|
&& ArrayHelper::check($target_))
|
|
{
|
|
// search the target views
|
|
$dashboard = (array) array_filter(
|
|
$target_,
|
|
function ($view) use ($id, $t, $types) {
|
|
if (isset($view[$types[$t]])
|
|
&& $id == $view[$types[$t]])
|
|
{
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
);
|
|
|
|
// set dashboard
|
|
if (ArrayHelper::check($dashboard))
|
|
{
|
|
$dashboard = array_values($dashboard)[0];
|
|
}
|
|
|
|
// check if view was found (this should be true)
|
|
if (isset($dashboard['settings'])
|
|
&& isset($dashboard['settings']->{$keys[$t]}))
|
|
{
|
|
$this->registry->set('build.dashboard',
|
|
StringHelper::safe(
|
|
$dashboard['settings']->{$keys[$t]}
|
|
)
|
|
);
|
|
$this->registry->set('build.dashboard.type',
|
|
$targets[$t]
|
|
);
|
|
}
|
|
else
|
|
{
|
|
// set massage that something is wrong
|
|
$this->app->enqueueMessage(
|
|
Text::_('<hr /><h3>Dashboard Error</h3>'),
|
|
'Error'
|
|
);
|
|
$this->app->enqueueMessage(
|
|
Text::sprintf('The <b>%s</b> (<b>%s</b>) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.',
|
|
$names[$t], $dashboard_,
|
|
$type_names
|
|
), 'Error'
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// set massage that something is wrong
|
|
$this->app->enqueueMessage(
|
|
Text::_('<hr /><h3>Dashboard Error</h3>'), 'Error'
|
|
);
|
|
$this->app->enqueueMessage(
|
|
Text::sprintf('The <b>%s</b> (<b>%s</b>) is not available in your component! Please insure to only used %s, for a dynamic dashboard, that are still linked to your component.',
|
|
$names[$t], $dashboard_,
|
|
$type_names
|
|
), 'Error'
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// the target value is wrong
|
|
$this->app->enqueueMessage(
|
|
Text::_('<hr /><h3>Dashboard Error</h3>'), 'Error'
|
|
);
|
|
$this->app->enqueueMessage(
|
|
Text::sprintf('The <b>%s</b> value for the dynamic dashboard is invalid.',
|
|
$dashboard_
|
|
), 'Error'
|
|
);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// the target value is wrong
|
|
$this->app->enqueueMessage(
|
|
Text::_('<hr /><h3>Dashboard Error</h3>'), 'Error'
|
|
);
|
|
$this->app->enqueueMessage(
|
|
Text::sprintf('The <b>%s</b> value for the dynamic dashboard is invalid.',
|
|
$dashboard_
|
|
), 'Error'
|
|
);
|
|
}
|
|
|
|
// if default was changed to dynamic dashboard the remove default tab and methods
|
|
if ($this->registry->get('build.dashboard'))
|
|
{
|
|
// dynamic dashboard is used
|
|
$this->component->remove('dashboard_tab');
|
|
$this->component->remove('php_dashboard_methods');
|
|
}
|
|
}
|
|
} |