/** * Parse cur module * * @param \App $app */ public function __construct($app) { $this->app = $app; $this->moduleName = get_class($this); $this->path = Router::getLoadedClassPath($this->moduleName); $this->info = $this->getInfo(); $this->config = Config::module($this->moduleName, !empty($this->info['systemConfig'])); $that = $this; Inji::$inst->listen('Config-change-module-' . $this->app->name . '-' . $this->moduleName, $this->app->name . '-' . $this->moduleName . 'config', function ($event) use($that) { $that->config = $event['eventObject']; return $event['eventObject']; }); }
public function configureAction() { $appOptions = Apps\App::get(filter_input(INPUT_GET, 'item_pk', FILTER_SANITIZE_NUMBER_INT)); $app = new App(); $app->name = $appOptions->name; $app->system = true; $app->staticPath = "/" . $appOptions->dir . "/static"; $app->templatesPath = "/" . $appOptions->dir . "/static/templates"; $app->path = INJI_PROGRAM_DIR . '/' . $appOptions->dir; $app->type = 'app'; $app->installed = true; $app->params = []; $app->config = Config::app($app); $modules = Module::getInstalled($app, $app); $inputs = []; foreach ($modules as $module) { $info = Module::getInfo($module); if (!empty($info['configure'])) { $config = Config::module($module, false, $app); foreach ($info['configure'] as $optionName => $params) { if (filter_input(INPUT_POST, $optionName)) { $config[$optionName] = filter_input(INPUT_POST, $optionName); Config::save('module', $config, $module, $app); } $input = []; $input['name'] = $optionName; $input['type'] = $params['type']; $input['label'] = $params['label']; $input['options']['value'] = !empty($config[$optionName]) ? $config[$optionName] : ''; $input['options']['values'] = ['' => 'Не выбрано']; $input['options']['values'] += $params['model']::getList(['forSelect' => true, 'key' => $params['col']]); $inputs[] = $input; } } } if (!empty($_POST)) { Tools::redirect('/setup'); } $this->view->page(['data' => compact('inputs')]); }
/** * Delete item from module storage * * @param array $options * @return boolean */ public function deleteFromModuleStorage($options) { $col = static::index(); $id = $this->pk(); $appType = ''; $classPath = explode('\\', get_called_class()); if (!empty(static::$storage['options']['share'])) { $moduleConfig = Config::share($classPath[0]); } else { $moduleConfig = Config::module($classPath[0], strpos(static::$storage['type'], 'system') !== false); } if (!empty($moduleConfig['storage']['appTypeSplit'])) { if (empty($options['appType'])) { $appType = App::$cur->type; } else { $appType = $options['appType']; } $storage = !empty($moduleConfig['storage'][$appType]) ? $moduleConfig['storage'][$appType] : []; } else { $storage = !empty($moduleConfig['storage']) ? $moduleConfig['storage'] : []; } if (empty($storage[$classPath[1]])) { $storage[$classPath[1]] = []; } foreach ($storage[$classPath[1]] as $key => $item) { if ($item[$col] == $id) { unset($storage[$classPath[1]][$key]); break; } } if (!empty($moduleConfig['storage']['appTypeSplit'])) { $moduleConfig['storage'][$appType] = $storage; } else { $moduleConfig['storage'] = $storage; } if (empty(static::$storage['options']['share'])) { Config::save('module', $moduleConfig, $classPath[0]); } else { Config::save('share', $moduleConfig, $classPath[0]); } return true; }