|
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 ListCommand |
|
14
|
|
|
* |
|
15
|
|
|
* @package N98\Magento\Command\Cms\Block |
|
16
|
|
|
*/ |
|
17
|
|
|
class ListCommand extends AbstractMagentoCommand |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* Configure command |
|
21
|
|
|
*/ |
|
22
|
|
|
protected function configure() |
|
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
|
|
|
|