/** * 返回树形选择 * @param string 分类模型 * @param integer $unShowId 排除显示的节点 * @return array */ public function treeSelect($model = '', $unShowId = 0) { $map['status'] = 1; if ($unShowId) { $map['id'] = ['neq', $unShowId]; } if ($model) { $map['model'] = $model; } $categorys = Db::name('category')->where($map)->order('sort asc')->select(); return Tree::toFormatTree($categorys); }
public function index($title = '', $pid = '') { if ($title) { $map['title'] = ['like', "%{$title}%"]; } if (is_numeric($pid)) { $map['pid'] = $pid; } else { $map['pid'] = 0; } $map['status'] = ['egt', 0]; $list = parent::_list('Category', $map, 'sort asc'); $this->assign('list', $list); $tree = Db::name('Category')->where('status', 'egt', 0)->order('sort asc,id asc')->select(); $this->assign('tree', \tools\Tree::listTree($tree)); return $this->fetch(); }
private function _treeShow($id = 0) { $map = []; if ($id) { $map['id'] = ['neq', $id]; } $menus = Db::name('Menu')->where($map)->order('sort asc')->select(); $menus = \tools\Tree::toFormatTree($menus); $menus = array_merge([0 => ['id' => 0, 'title_show' => '顶级菜单']], $menus); return $menus; }
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output) { $name = $input->getArgument('name'); $settingPath = $input->getArgument('path'); $values = $input->getArgument('values'); // $multiline = $input->getOption('multiline'); if (empty($values)) { // enable multiline input $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, '<question>Would you like to provide multiline input? Answering no, quits the command. (y/n) </question> ', false)) { return; } else { $input = array(); $output->writeln('Type <info>EOT</info> in a new line when you finished inputting all the options.'); while (1) { $input[] = $dialog->ask($output, null, 'foo'); if (end($input) == 'EOT') { array_pop($input); break; } } $values[] = implode(PHP_EOL, $input); // $values = $input; //var_dump($values); } } ApplicationsDB::LoadAll(); foreach (StringTools::TypeList($name) as $argument) { if ($argument['exclamation'] !== false) { // TODO: actually handle the exclamators LogCLI::MessageResult('Exclamation: ' . $argument['exclamation'], 4, LogCLI::INFO); } else { //siteYML $file = Paths::getFullPath($argument['text']); if ($file !== false) { $application = 'nginx'; $basicScope = 'server'; $settings = ApplicationsDB::GetSettingsList($application, $basicScope); $value = ArrayTools::dearraizeIfNotRequired($values); //$chain = StringTools::Delimit($chain, '.'); //$settingPath = implode('/', $chain); LogCLI::MessageResult('Path of the setting: ' . $settingPath, 4, LogCLI::INFO); if ($path = SettingsDB::findPathForSetting($settings, $settingPath, $basicScope)) { $settingsDB = new ConfigScopes\SettingsDB(); // load the original file first $settingsDB->mergeFromYAML($file); $currentSetting = $settingsDB->returnOneByPath($settingPath); /** * if there is a difference * TODO: probably dearraize not required here */ if (ArrayTools::dearraizeIfNotRequired($currentSetting) != $value) { $formatter = $this->getHelperSet()->get('xformatter'); $displayValues = array(); foreach ($values as $valueLine) { $displayValues = array_merge($displayValues, StringTools::multilineStringToArray($valueLine)); } $displayCurrentSetting = array(); foreach ((array) $currentSetting as $valueLine) { $displayCurrentSetting = array_merge($displayCurrentSetting, StringTools::multilineStringToArray($valueLine)); } $toFormat = array(array('messages' => $displayCurrentSetting, 'style' => 'error'), array('messages' => array('> >'), 'style' => 'fg=yellow;bg=black;other=blink;other=bold', 'large' => false), array('messages' => $displayValues, 'style' => 'fg=black;bg=yellow;other=bold')); //array_merge(array('With the following data:'), (array) $values) $output->writeln($formatter->formatMultipleBlocks($toFormat, ' ', true)); $dialog = $this->getHelperSet()->get('dialog'); if (!$dialog->askConfirmation($output, 'Are you sure that you want to make this change? (type "y" to confirm) ', false)) { return; } // make the tree $setting = Tree::addToTreeAndSet(explode('/', $path), $value); //var_dump($setting); // add/replace the setting $settingsDB->mergeFromArray($setting); // save the file with the new setting $settingsDB->returnYAML($file); } else { /** * nothing to do, it's all the same */ $output->writeln('<fg=yellow;other=bold>No need to change, the values are already identical!</fg=yellow;other=bold>'); } } else { // TODO } } else { LogCLI::Fail('Sorry, no site by name: ' . $argument['text']); } } } }