Completed
Push — master ( 68f942...d69058 )
by Rafał
18:18
created

ListOrganizationsCommand::execute()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 25
rs 8.5806
cc 4
eloc 16
nc 3
nop 2
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancyBundle.
5
 *
6
 * Copyright 2016 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2016 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\MultiTenancyBundle\Command;
15
16
use SWP\Component\MultiTenancy\Model\OrganizationInterface;
17
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
18
use Symfony\Component\Console\Helper\Table;
19
use Symfony\Component\Console\Input\InputInterface;
20
use Symfony\Component\Console\Output\OutputInterface;
21
22
class ListOrganizationsCommand extends ContainerAwareCommand
23
{
24
    /**
25
     * {@inheritdoc}
26
     */
27
    protected function configure()
28
    {
29
        $this
30
            ->setName('swp:organization:list')
31
            ->setDescription('List all available organizations.');
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    protected function execute(InputInterface $input, OutputInterface $output)
38
    {
39
        /** @var OrganizationInterface[] $organizations */
40
        $organizations = $this->getContainer()->get('swp.repository.organization')->findAll();
41
        if (0 === count($organizations)) {
42
            $output->writeln('<error>There are no organizations defined.</error>');
43
44
            return;
45
        }
46
47
        $output->writeln('<info>List of all available organizations:</info>');
48
        $table = new Table($output);
49
        $table->setHeaders(['Id', 'Code', 'Name', 'Is active?', 'Created at']);
50
        foreach ($organizations as $organization) {
51
            $table->addRow([
52
                $organization->getId(),
53
                $organization->getCode(),
54
                $organization->getName(),
55
                $organization->isEnabled() ? 'yes' : 'no',
56
                $organization->getCreatedAt()->format('Y-m-d H:i:s'),
57
            ]);
58
        }
59
60
        $table->render();
61
    }
62
}
63