Backend\Modules\Groups\Engine\Model::getSetting PHP Méthode

getSetting() public static méthode

Get a group setting
public static getSetting ( integer $groupId, string $name ) : array
$groupId integer The id of the group of the setting.
$name string The name of the setting to fetch.
Résultat array
    public static function getSetting($groupId, $name)
    {
        $setting = (array) BackendModel::getContainer()->get('database')->getRecord('SELECT i.value
             FROM groups_settings AS i
             WHERE i.group_id = ? AND i.name = ?', array((int) $groupId, (string) $name));
        if (!$setting) {
            return array();
        }
        if (isset($setting['value'])) {
            return unserialize($setting['value']);
        }
    }

Usage Example

Exemple #1
0
 /**
  * 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);
     }
 }
All Usage Examples Of Backend\Modules\Groups\Engine\Model::getSetting