Doctrine 2 ORM User ?
Implements your Event Providers in Seconds (really, seconds).
CalendR provides a EventRepository
trait, that can be used in your event repository to implements the
ProviderInterface::getEvents()
mandatory method.
<?php
use Doctrine\ORM\EntityRepository;
use CalendR\Extension\Doctrine2\EventRepository as EventRepositoryTrait;
class EventRepository extends EntityRepository
{
use EventRepositoryTrait;
}
?>
And… well… That’s all.
The above example is valid and fully working (you can check, it’s used as-is in the CalendR test suite), but it assumes some little things :
begin
end
Thanks to PHP 5.4 trait methods overriding, here is a more complete example :
<?php
use Doctrine\ORM\EntityRepository;
use CalendR\Extension\Doctrine2\EventRepository as EventRepositoryTrait;
class EventRepository extends EntityRepository
{
use EventRepositoryTrait;
/**
* Returns the query builder on wich the event retrieving query will
* be append. The default table alias is `evt`
*/
public function createQueryBuilderForGetEvent(array $options)
{
// do what you want with the $option array
return $this->createQueryBuilder('evt')
->setMaxResults(10)
;
}
/**
* Returns the name of the begin field.
*/
public function getBeginFieldName()
{
return 'evt.beginDate';
}
/**
* Returns the name of the end field.
*/
public function getEndFieldName()
{
return 'evt.endDate';
}
}
getEventsQueryBuilder()
getEventsQuery()
There is a
CalendR\Extensions\Doctrine2\QueryHelper
class that provides a addEventQuery
method to add the event retrieving criteria to the QueryBuilder.
<?php
use Doctrine\ORM\EntityRepository;
use CalendR\Extension\Doctrine2\QueryHelper;
class EventRepository extends EntityRepository
{
public function getEventsQueryBuilder(\DateTime $begin, \DateTime $end, array $options = array())
{
$qb = $this->createQueryBuilder('e');
return QueryHelper::addEventQuery($qb, 'e.begin', 'e.end', $begin, $end)
->getQuery()
->getResults()
;
}
}
Warning : The PHP 5.3 way is deprecated but will be keep as long as PHP 5.3 is supported.