backend/controllers/WidgetController.php
/**
     * Scan widget directory to get list of all available widgets and list all active widgets.
     *
     * @return mixed
     */
Scan widget directory to get list of all available widgets and list all active widgets.
@return mixed
Scan widget directory to get list of all available widgets and list all active widgets . @return mixed
public function actionIndex()
    {
        $config = [];
        $active = [];
        $available = [];
        $spaces = ArrayHelper::getValue(Yii::$app->params, 'widget', []);
        if (!is_dir($this->_dir)) {
            FileHelper::createDirectory($this->_dir, 0755);
        }
        foreach (scandir($this->_dir) as $widget) {
            if (is_dir($this->_dir . $widget) && $widget !== '.' && $widget !== '..') {
                $configPath = $this->_dir . $widget . '/config/main.php';
                if (is_file($configPath)) {
                    $config = require($configPath);
                    $config['directory'] = $widget;
                }
                $available[$widget] = $config;
            }
        }
        foreach ($spaces as $space) {
            $model = Widget::find()
                ->where(['location' => $space['location']])
                ->orderBy(['order' => SORT_ASC])
                ->all();
            $active[$space['location']] = $model;
        }
        return $this->render('index', [
            'active' => $active,
            'available' => $available,
            'spaces' => $spaces,
        ]);
    }
public function actionIndex ( ) { $ config = [ ] ; $ active = [ ] ; $ available = [ ] ; $ spaces = ArrayHelper :: getValue ( Yii :: $ app -> params , 'widget' , [ ] ) ; if ( ! is_dir ( $ this -> _dir ) ) { FileHelper :: createDirectory ( $ this -> _dir , 0755 ) ; } foreach ( scandir ( $ this -> _dir ) as $ widget ) { if ( is_dir ( $ this -> _dir . $ widget ) && $ widget !== '.' && $ widget !== '..' ) { $ configPath = $ this -> _dir . $ widget . '/config/main.php' ; if ( is_file ( $ configPath ) ) { $ config = require ( $ configPath ) ; $ config [ 'directory' ] = $ widget ; } $ available [ $ widget ] = $ config ; } } foreach ( $ spaces as $ space ) { $ model = Widget :: find ( ) -> where ( [ 'location' => $ space [ 'location' ] ] ) -> orderBy ( [ 'order' => SORT_ASC ] ) -> all ( ) ; $ active [ $ space [ 'location' ] ] = $ model ; } return $ this -> render ( 'index' , [ 'active' => $ active , 'available' => $ available , 'spaces' => $ spaces , ] ) ; }
Scan widget directory to get list of all available widgets and list all active widgets.
Scan widget directory to get list of all available widgets and list all active widgets .