/**
* Load the data
*/
private function loadData()
{
$modules = BackendModel::getModules();
$userSequence = BackendAuthentication::getUser()->getSetting('dashboard_sequence');
$fs = new Filesystem();
// user sequence does not exist?
if (!isset($userSequence)) {
// get group ID of user
$groupId = BackendAuthentication::getUser()->getGroupId();
// get group preset
$userSequence = BackendGroupsModel::getSetting($groupId, 'dashboard_sequence');
}
// loop all modules
foreach ($modules as $module) {
// build pathName
$pathName = BACKEND_MODULES_PATH . '/' . $module;
// you have sufficient rights?
if (BackendAuthentication::isAllowedModule($module) && $fs->exists($pathName . '/Widgets')) {
$finder = new Finder();
$finder->name('*.php');
// loop widgets
foreach ($finder->files()->in($pathName . '/Widgets') as $file) {
/** @ver $file \SplFileInfo */
$widgetName = $file->getBaseName('.php');
$className = 'Backend\\Modules\\' . $module . '\\Widgets\\' . $widgetName;
if ($module == 'Core') {
$className = 'Backend\\Core\\Widgets\\' . $widgetName;
}
if (!class_exists($className)) {
throw new BackendException('The widgetfile ' . $className . ' could not be found.');
}
// present?
$present = isset($userSequence[$module][$widgetName]['present']) ? $userSequence[$module][$widgetName]['present'] : false;
// if not present, continue
if (!$present) {
continue;
}
// create instance
/** @var $instance BackendBaseWidget */
$instance = new $className($this->getKernel());
// has rights
if (!$instance->isAllowed()) {
continue;
}
// hidden?
$hidden = isset($userSequence[$module][$widgetName]['hidden']) ? $userSequence[$module][$widgetName]['hidden'] : false;
// execute instance if it is not hidden
if (!$hidden) {
$instance->execute();
}
// user sequence provided?
$column = isset($userSequence[$module][$widgetName]['column']) ? $userSequence[$module][$widgetName]['column'] : $instance->getColumn();
$position = isset($userSequence[$module][$widgetName]['position']) ? $userSequence[$module][$widgetName]['position'] : $instance->getPosition();
$title = \SpoonFilter::ucfirst(BL::lbl(\SpoonFilter::toCamelCase($module))) . ': ' . BL::lbl(\SpoonFilter::toCamelCase($widgetName));
$templatePath = $instance->getTemplatePath();
// reset template path
if ($templatePath == null) {
$templatePath = BACKEND_PATH . '/Modules/' . $module . '/Layout/Widgets/' . $widgetName . '.tpl';
}
// build item
$item = array('template' => $templatePath, 'module' => $module, 'widget' => $widgetName, 'title' => $title, 'hidden' => $hidden);
// add on new position if no position is set or if the position is already used
if ($position === null || isset($this->widgets[$column][$position])) {
$this->widgets[$column][] = $item;
} else {
// add on requested position
$this->widgets[$column][$position] = $item;
}
}
}
}
// sort the widgets
foreach ($this->widgets as &$column) {
ksort($column);
}
}