forked from networking/init-cms-bundle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPagesBlockService.php
125 lines (110 loc) · 3.49 KB
/
PagesBlockService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/**
* This file is part of the Networking package.
*
* (c) net working AG <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Networking\InitCmsBundle\Block;
use Doctrine\ORM\Query;
use Networking\InitCmsBundle\Model\PageInterface;
use Networking\InitCmsBundle\Model\PageManagerInterface;
use Sonata\BlockBundle\Block\BaseBlockService;
use Sonata\BlockBundle\Model\BlockInterface;
use Sonata\AdminBundle\Form\FormMapper;
use Sonata\AdminBundle\Validator\ErrorElement;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
/**
* Class PagesBlockService
* @package Networking\InitCmsBundle\Block
* @author Yorkie Chadwick <[email protected]>
*/
class PagesBlockService extends BaseBlockService
{
/**
* @var PageManagerInterface $em
*/
protected $em;
/**
* @param string $name
* @param EngineInterface $templating
* @param PageManagerInterface $em
*/
public function __construct($name, EngineInterface $templating, PageManagerInterface $em)
{
$this->name = $name;
$this->templating = $templating;
$this->em = $em;
}
/**
* {@inheritdoc}
*/
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
$pages = $this->em->getAllSortBy('updatedAt', 'DESC', Query::HYDRATE_ARRAY);
$draftPageCount = 0;
$reviewPageCount = 0;
$publishedPageCount = 0;
$reviewPages = array();
$draftPages = array();
foreach ($pages as $page) {
if (array_key_exists('snapshots', $page) && count($page['snapshots']) > 0) {
$publishedPageCount++;
}
if ($page['status'] == PageInterface::STATUS_REVIEW) {
$reviewPageCount++;
$draftPageCount++;
$reviewPages[\Locale::getDisplayLanguage($page['locale'])][] = $page;
}
if ($page['status'] == PageInterface::STATUS_DRAFT) {
$draftPageCount++;
$draftPages[\Locale::getDisplayLanguage($page['locale'])][] = $page;
}
}
return $this->renderResponse(
$blockContext->getTemplate(),
array(
'block' => $blockContext->getBlock(),
'draft_pages' => $draftPageCount,
'review_pages' => $reviewPageCount,
'published_pages' => $publishedPageCount,
'pages' => $pages,
'reviewPages' => $reviewPages,
'draftPages' => $draftPages
),
$response
);
}
/**
* {@inheritdoc}
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
// TODO: Implement validateBlock() method.
}
/**
* {@inheritdoc}
*/
public function buildEditForm(FormMapper $formMapper, BlockInterface $block)
{
}
/**
* {@inheritdoc}
*/
public function getName()
{
return 'Online Users Block';
}
/**
* {@inheritdoc}
*/
public function setDefaultSettings(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array('template' => 'NetworkingInitCmsBundle:Block:block_page_status.html.twig'));
}
}