1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Smart\ContentBundle\Admin\Block; |
4
|
|
|
|
5
|
|
|
use Smart\ContentBundle\Entity\Repository\PostRepository; |
6
|
|
|
use Sonata\BlockBundle\Block\BlockContextInterface; |
7
|
|
|
use Sonata\BlockBundle\Block\Service\AbstractAdminBlockService; |
8
|
|
|
use Symfony\Component\OptionsResolver\OptionsResolver; |
9
|
|
|
use Symfony\Component\Templating\EngineInterface; |
10
|
|
|
use Symfony\Component\HttpFoundation\Response; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Nicolas Bastien <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class RecentPostBlock extends AbstractAdminBlockService |
|
|
|
|
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var PostRepository |
19
|
|
|
*/ |
20
|
|
|
private $postRepository; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string $name |
24
|
|
|
* @param EngineInterface $templating |
25
|
|
|
* @param PostRepository $postRepository |
26
|
|
|
*/ |
27
|
|
|
public function __construct($name, EngineInterface $templating, PostRepository $postRepository) |
28
|
|
|
{ |
29
|
|
|
parent::__construct($name, $templating); |
30
|
|
|
|
31
|
|
|
$this->postRepository = $postRepository; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* {@inheritdoc} |
36
|
|
|
*/ |
37
|
|
|
public function configureSettings(OptionsResolver $resolver) |
38
|
|
|
{ |
39
|
|
|
$resolver->setDefault('template', '@SmartContent/admin/block/recent_posts.html.twig'); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* {@inheritdoc} |
44
|
|
|
*/ |
45
|
|
|
public function execute(BlockContextInterface $blockContext, Response $response = null) |
46
|
|
|
{ |
47
|
|
|
$date = $this->postRepository->getLastPublishedPostDate(); |
48
|
|
|
$today = new \DateTime(); |
49
|
|
|
|
50
|
|
|
$interval = 0; |
51
|
|
|
if (null !== $date) { |
52
|
|
|
$interval = $today->diff($date)->days; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
return $this->renderPrivateResponse( |
56
|
|
|
$blockContext->getTemplate(), |
57
|
|
|
[ |
58
|
|
|
'block' => $blockContext->getBlock(), |
59
|
|
|
'settings' => $blockContext->getSettings(), |
60
|
|
|
'posts' => $this->postRepository->getLastPublishedPosts(), |
61
|
|
|
'interval' => $interval |
62
|
|
|
], |
63
|
|
|
$response |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.