household list of accompanying periods + upgrade DBAL version to 3.1

This commit is contained in:
2021-11-08 10:57:14 +00:00
committed by Julien Fastré
parent 092ea4d57f
commit 7fabe0214e
49 changed files with 353 additions and 286 deletions

View File

@@ -20,7 +20,7 @@
namespace Chill\MainBundle\Timeline;
use Doctrine\ORM\Query\ResultSetMapping;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Doctrine\ORM\Query;
@@ -31,38 +31,38 @@ use Doctrine\ORM\NativeQuery;
*/
class TimelineBuilder implements ContainerAwareInterface
{
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
/**
*
* @var \Doctrine\ORM\EntityManagerInterface
*/
private $em;
/**
* Record provider
*
*
* This array has the structure `[ 'service id' => $service ]`
*
* @var TimelineProviderInterface[]
*/
private $providers = [];
/**
* Record provider and their context
*
*
* This array has the structure `[ 'context' => [ 'service id' ] ]`
*
* @var array
*/
private $providersByContext = [];
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* return an HTML string with timeline
*
@@ -79,18 +79,18 @@ class TimelineBuilder implements ContainerAwareInterface
public function getTimelineHTML($context, array $args, $firstItem = 0, $number = 20)
{
list($union, $parameters) = $this->buildUnionQuery($context, $args);
//add ORDER BY clause and LIMIT
$query = $union . sprintf(' ORDER BY date DESC LIMIT %d OFFSET %d',
$number, $firstItem);
// run query and handle results
$fetched = $this->runUnionQuery($query, $parameters);
$entitiesByKey = $this->getEntities($fetched, $context);
return $this->render($fetched, $entitiesByKey, $context, $args);
}
/**
* Return the number of items for the given context and args
*
@@ -101,7 +101,7 @@ class TimelineBuilder implements ContainerAwareInterface
public function countItems($context, array $args)
{
$rsm = (new ResultSetMapping())
->addScalarResult('total', 'total', Type::INTEGER);
->addScalarResult('total', 'total', Types::INTEGER);
list($select, $parameters) = $this->buildUnionQuery($context, $args);
@@ -110,10 +110,10 @@ class TimelineBuilder implements ContainerAwareInterface
$nq = $this->em->createNativeQuery($countQuery, $rsm);
$nq->setParameters($parameters);
return $nq->getSingleScalarResult();
}
/**
* add a provider id
*
@@ -127,7 +127,7 @@ class TimelineBuilder implements ContainerAwareInterface
$this->providersByContext[$context][] = $id;
$this->providers[$id] = $provider;
}
/**
* Get providers by context
*
@@ -141,16 +141,16 @@ class TimelineBuilder implements ContainerAwareInterface
throw new \LogicException(sprintf('No builders have been defined for "%s"'
. ' context', $context));
}
$providers = [];
foreach($this->providersByContext[$context] as $providerId) {
$providers[] = $this->providers[$providerId];
}
return $providers;
}
/**
* build the UNION query with all providers
*
@@ -172,7 +172,7 @@ class TimelineBuilder implements ContainerAwareInterface
$union .= $append;
$parameters = array_merge($parameters, $selectParameters);
}
return [$union, $parameters];
}
@@ -195,7 +195,7 @@ class TimelineBuilder implements ContainerAwareInterface
return $s;
}
*/
/**
* return the SQL SELECT query as a string,
*
@@ -222,9 +222,9 @@ class TimelineBuilder implements ContainerAwareInterface
);
return [$sql, $data['WHERE'][1]];
}
/**
* run the UNION query and return result as an array
*
@@ -236,12 +236,12 @@ class TimelineBuilder implements ContainerAwareInterface
->addScalarResult('id', 'id')
->addScalarResult('type', 'type')
->addScalarResult('date', 'date');
return $this->em->createNativeQuery($query, $resultSetMapping)
->setParameters($parameters)
->getArrayResult();
}
/**
*
* @param array $queriedIds
@@ -252,11 +252,11 @@ class TimelineBuilder implements ContainerAwareInterface
{
//gather entities by type to pass all id with same type to the TimelineProvider.
$idsByType = array();
foreach($queriedIds as $result) {
$idsByType[$result['type']][] = $result['id'];
}
//fetch entities from providers
$entitiesByType = array();
foreach ($idsByType as $type => $ids) {
@@ -268,10 +268,10 @@ class TimelineBuilder implements ContainerAwareInterface
}
}
}
return $entitiesByType;
}
/**
* render the timeline as HTML
*
@@ -294,17 +294,17 @@ class TimelineBuilder implements ContainerAwareInterface
$timelineEntry['date'] = new \DateTime($result['date']);
$timelineEntry['template'] = $data['template'];
$timelineEntry['template_data'] = $data['template_data'];
$timelineEntries[] = $timelineEntry;
}
return $this->container->get('templating')
->render('@ChillMain/Timeline/chain_timelines.html.twig', array(
'results' => $timelineEntries
));
}
/**
* get the template data from the provider for the given entity, by type.
*