From 497307c0dc750c6e8bf70cf3e38b49684fe865fc Mon Sep 17 00:00:00 2001 From: aynsix Date: Fri, 21 Feb 2020 17:37:04 +0300 Subject: [PATCH] add jsonformat to collection:list --- .../Collection/ListCollectionCommand.php | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php b/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php index e76796e8b7..7cf2d91ced 100644 --- a/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php +++ b/lib/Alchemy/Phrasea/Command/Collection/ListCollectionCommand.php @@ -24,20 +24,30 @@ class ListCollectionCommand extends Command parent::__construct('collection:list'); $this->setDescription('List all collection in Phraseanet') ->addOption('databox_id', 'd', InputOption::VALUE_REQUIRED, 'The id of the databox to list collection') + ->addOption('jsonformat', null, InputOption::VALUE_NONE, 'Output in json format') ->setHelp(''); return $this; } protected function doExecute(InputInterface $input, OutputInterface $output) { try { - $databox = $this->container->findDataboxById($input->getOption('databox_id')); - $collections = $this->listDataboxCollections($databox); + $jsonformat = $input->getOption('jsonformat'); + $databox = $this->container->findDataboxById($input->getOption('databox_id')); + $collections = $this->listDataboxCollections($databox); + + if ($jsonformat) { + foreach ($collections as $collection) { + $collectionList[] = array_combine(['id local for API', 'id distant', 'name','label','status','total records'], $collection); + } + echo json_encode($collectionList); + } else { + $table = $this->getHelperSet()->get('table'); + $table + ->setHeaders(['id local for API', 'id distant', 'name','label','status','total records']) + ->setRows($collections) + ->render($output); + } - $table = $this->getHelperSet()->get('table'); - $table - ->setHeaders(['id local for API', 'id distant', 'name','label','status','total records']) - ->setRows($collections) - ->render($output); } catch (\Exception $e) { $output->writeln("{$e->getMessage()}"); }