Completed
Pull Request — develop (#948)
by Luke
03:51
created

ListCommand::_getBlockModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace N98\Magento\Command\Cms\Block;
4
5
use N98\Magento\Command\AbstractMagentoCommand;
6
use N98\Util\Console\Helper\Table\Renderer\RendererFactory;
7
use N98\Util\Console\Helper\TableHelper;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Input\InputOption;
10
use Symfony\Component\Console\Output\OutputInterface;
11
12
/**
13
 * CMS Block ToggleCommand
14
 *
15
 * @package N98\Magento\Command\Cms\Block
16
 */
17
class ListCommand extends AbstractMagentoCommand
18
{
19
    /**
20
     * Configure command
21
     */
22 View Code Duplication
    protected function configure()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
    {
24
        $this
25
            ->setName('cms:block:list')
26
            ->setDescription('List all cms blocks')
27
            ->addOption(
28
                'format',
29
                null,
30
                InputOption::VALUE_OPTIONAL,
31
                'Output Format. One of [' . implode(',', RendererFactory::getFormats()) . ']'
32
            )
33
        ;
34
    }
35
36
    /**
37
     * Get an instance of cms/block
38
     *
39
     * @return \Mage_Cms_Model_Block
40
     */
41
    protected function _getBlockModel()
42
    {
43
        return $this->_getModel('cms/block', '\Mage_Cms_Model_Block');
44
    }
45
46
    /**
47
     * Execute the command
48
     *
49
     * @param InputInterface  $input
50
     * @param OutputInterface $output
51
     *
52
     * @return int|null|void
53
     */
54
    protected function execute(InputInterface $input, OutputInterface $output)
55
    {
56
        $this->detectMagento($output, true);
57
        if (!$this->initMagento()) {
58
            return;
59
        }
60
61
        $cmsBlockCollection = $this->_getBlockModel()->getCollection()->addFieldToSelect('*');
62
63
        /** @var \Mage_Cms_Model_Resource_Block $resourceModel */
64
        $resourceModel = $this->_getBlockModel()->getResource();
65
66
        $table = array();
67
        foreach ($cmsBlockCollection as $cmsBlock) {
68
            $storeIds = implode(',', $resourceModel->lookupStoreIds($cmsBlock->getId()));
69
70
            $table[] = array(
71
                $cmsBlock->getData('block_id'),
72
                $cmsBlock->getData('identifier'),
73
                $cmsBlock->getData('title'),
74
                $cmsBlock->getData('is_active') ? 'active' : 'inactive',
75
                $storeIds,
76
            );
77
        }
78
79
        /* @var $tableHelper TableHelper */
80
        $tableHelper = $this->getHelper('table');
81
        $tableHelper
82
            ->setHeaders(array('block_id', 'identifier', 'title', 'is_active', 'store_ids'))
83
            ->renderByFormat($output, $table, $input->getOption('format'));
84
    }
85
}
86