Now injecting services with JMSDiExtraBundle
Signed-off-by: Gergely POLONKAI <polesz@w00d5t0ck.info>
This commit is contained in:
@@ -4,64 +4,78 @@ namespace KekRozsak\FrontBundle\Twig;
|
||||
|
||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @DI\Service
|
||||
* @DI\Tag("twig.extension")
|
||||
*/
|
||||
class EventsExtension extends \Twig_Extension
|
||||
{
|
||||
protected $_doctrine;
|
||||
protected $_securityContext;
|
||||
protected $_doctrine;
|
||||
protected $_securityContext;
|
||||
|
||||
public function __construct(RegistryInterface $doctrine, SecurityContextInterface $securityContext)
|
||||
{
|
||||
$this->_doctrine = $doctrine;
|
||||
$this->_securityContext = $securityContext;
|
||||
}
|
||||
/**
|
||||
* @DI\InjectParams({
|
||||
* "doctrine" = @DI\Inject("doctrine"),
|
||||
* "securityContext" = @DI\Inject("security.context")
|
||||
* })
|
||||
*
|
||||
* @param \Symfony\Bridge\Doctrine\RegistryInterface $doctrine
|
||||
* @param \Symfony\Component\Security\Core\SecurityContextInterface $securityContext
|
||||
*/
|
||||
public function __construct(RegistryInterface $doctrine, SecurityContextInterface $securityContext)
|
||||
{
|
||||
$this->_doctrine = $doctrine;
|
||||
$this->_securityContext = $securityContext;
|
||||
}
|
||||
|
||||
public function getGlobals()
|
||||
{
|
||||
$today = new \DateTime('now');
|
||||
$firstDay = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-01'));
|
||||
$firstDayWeekday = $firstDay->format('N');
|
||||
$numDays = $firstDay->format('t');
|
||||
$lastDay = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-' . sprintf("%02d", $numDays)));
|
||||
public function getGlobals()
|
||||
{
|
||||
$today = new \DateTime('now');
|
||||
$firstDay = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-01'));
|
||||
$firstDayWeekday = $firstDay->format('N');
|
||||
$numDays = $firstDay->format('t');
|
||||
$lastDay = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-' . sprintf("%02d", $numDays)));
|
||||
|
||||
/*
|
||||
* Get all events in today's month. Iterate through this
|
||||
* collection, adding each element to $monthEvents array's
|
||||
* 'day'th element array.
|
||||
*/
|
||||
$query = $this->_doctrine->getEntityManager()->createQuery('SELECT e FROM KekRozsakFrontBundle:Event e WHERE e.cancelled = FALSE AND ((e.startDate < :firstDay AND e.endDate >= :firstDay) OR e.startDate BETWEEN :firstDay AND :lastDay)');
|
||||
$query->setParameter('firstDay', $firstDay, \Doctrine\DBAL\Types\Type::DATE);
|
||||
$query->setParameter('lastDay', $lastDay, \Doctrine\DBAL\Types\Type::DATE);
|
||||
$events = $query->getResult();
|
||||
/*
|
||||
* Get all events in today's month. Iterate through this
|
||||
* collection, adding each element to $monthEvents array's
|
||||
* 'day'th element array.
|
||||
*/
|
||||
$query = $this->_doctrine->getEntityManager()->createQuery('SELECT e FROM KekRozsakFrontBundle:Event e WHERE e.cancelled = FALSE AND ((e.startDate < :firstDay AND e.endDate >= :firstDay) OR e.startDate BETWEEN :firstDay AND :lastDay)');
|
||||
$query->setParameter('firstDay', $firstDay, \Doctrine\DBAL\Types\Type::DATE);
|
||||
$query->setParameter('lastDay', $lastDay, \Doctrine\DBAL\Types\Type::DATE);
|
||||
$events = $query->getResult();
|
||||
|
||||
$eventList = array();
|
||||
for ($i = 1; $i <= $numDays; $i++)
|
||||
{
|
||||
$date = \DateTime::createFromFormat('Y-m-d', $today->format('Y-m-' . sprintf('%02d', $i)));
|
||||
$eventList[$i]['date'] = $date;
|
||||
$eventList[$i]['events'] = array();
|
||||
foreach ($events as $event)
|
||||
{
|
||||
if ($event->isOnDate($date))
|
||||
{
|
||||
$eventList[$i]['events'][] = $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
$eventList = array();
|
||||
for ($i = 1; $i <= $numDays; $i++) {
|
||||
$date = \DateTime::createFromFormat(
|
||||
'Y-m-d',
|
||||
$today->format('Y-m-' . sprintf('%02d', $i))
|
||||
);
|
||||
$eventList[$i]['date'] = $date;
|
||||
$eventList[$i]['events'] = array();
|
||||
foreach ($events as $event) {
|
||||
if ($event->isOnDate($date)) {
|
||||
$eventList[$i]['events'][] = $event;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return array(
|
||||
'events' => $events,
|
||||
'eventList' => $eventList,
|
||||
'today' => $today,
|
||||
'firstDay' => $firstDay,
|
||||
'lastDay' => $lastDay,
|
||||
'firstDayWeekday' => $firstDayWeekday,
|
||||
'numDays' => $numDays,
|
||||
);
|
||||
}
|
||||
return array(
|
||||
'events' => $events,
|
||||
'eventList' => $eventList,
|
||||
'today' => $today,
|
||||
'firstDay' => $firstDay,
|
||||
'lastDay' => $lastDay,
|
||||
'firstDayWeekday' => $firstDayWeekday,
|
||||
'numDays' => $numDays,
|
||||
);
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'Events';
|
||||
}
|
||||
public function getName()
|
||||
{
|
||||
return 'Events';
|
||||
}
|
||||
}
|
||||
|
@@ -2,15 +2,26 @@
|
||||
namespace KekRozsak\FrontBundle\Twig;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @DI\Service
|
||||
* @DI\Tag("twig.extension")
|
||||
*
|
||||
*/
|
||||
class TwigBBExtension extends \Twig_Extension
|
||||
{
|
||||
private $container;
|
||||
private $assets;
|
||||
|
||||
/**
|
||||
* @DI\InjectParams({
|
||||
* "container" = @DI\Inject("service_container")
|
||||
* })
|
||||
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->assets = $container->get('templating.helper.assets');
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
@@ -67,8 +78,7 @@ class TwigBBExtension extends \Twig_Extension
|
||||
$sentence,
|
||||
'<img src="'
|
||||
. $this
|
||||
->container
|
||||
->get('templating.helper.assets')
|
||||
->assets
|
||||
->getUrl(
|
||||
'upload/images/'
|
||||
. (($ns == '') ? '' : $ns . '/')
|
||||
|
Reference in New Issue
Block a user