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

@@ -15,17 +15,17 @@ use Doctrine\DBAL\Types\ConversionException;
class NativeDateIntervalType extends DateIntervalType
{
const FORMAT = '%rP%YY%MM%DDT%HH%IM%SS';
public function getName(): string
{
return \Doctrine\DBAL\Types\Type::DATEINTERVAL;
return \Doctrine\DBAL\Types\Types::DATEINTERVAL;
}
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return 'INTERVAL';
}
/**
* {@inheritdoc}
*/
@@ -41,36 +41,36 @@ class NativeDateIntervalType extends DateIntervalType
throw ConversionException::conversionFailedInvalidType($value, $this->getName(), ['null', 'DateInterval']);
}
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value === null || $value instanceof \DateInterval) {
return $value;
}
try {
$strings = explode(' ', $value);
if (count($strings) === 0) {
return null;
}
$intervalSpec = 'P';
\reset($strings);
do {
$intervalSpec .= $this->convertEntry($strings);
} while (next($strings) !== FALSE);
return new \DateInterval($intervalSpec);
} catch (\Exception $exception) {
throw $this->createConversionException($value, $exception);
}
}
private function convertEntry(&$strings)
{
$current = \current($strings);
if (is_numeric($current)) {
$next = \next($strings);
switch($next) {
@@ -79,7 +79,7 @@ class NativeDateIntervalType extends DateIntervalType
$unit = 'Y';
break;
case 'mon':
case 'mons':
case 'mons':
$unit = 'M';
break;
case 'day':
@@ -89,20 +89,20 @@ class NativeDateIntervalType extends DateIntervalType
default:
throw $this->createConversionException(implode('', $strings));
}
return $current.$unit;
} elseif (\preg_match('/([0-9]{2}\:[0-9]{2}:[0-9]{2})/', $current) === 1) {
$tExploded = explode(':', $current);
$intervalSpec = 'T';
$intervalSpec.= $tExploded[0].'H';
$intervalSpec.= $tExploded[1].'M';
$intervalSpec.= $tExploded[2].'S';
return $intervalSpec;
}
}
protected function createConversionException($value, $exception = null)
{
return ConversionException::conversionFailedFormat($value, $this->getName(), 'xx year xx mons xx days 01:02:03', $exception);

View File

@@ -28,7 +28,7 @@ class Country
/**
* @var string
*
* @ORM\Column(type="json_array")
* @ORM\Column(type="json")
* @groups({"read"})
*
*/

View File

@@ -43,14 +43,14 @@ class Language
/**
* @var string array
*
* @ORM\Column(type="json_array")
* @ORM\Column(type="json")
*/
private $name;
/**
* Get id
*
* @return string
* @return string
*/
public function getId()
{
@@ -59,7 +59,7 @@ class Language
/**
* Set id
*
*
* @param string $id
* @return Language
*/
@@ -78,17 +78,17 @@ class Language
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* @return string array
* @return string array
*/
public function getName()
{
return $this->name;
}
}
}

View File

@@ -52,7 +52,7 @@ class Scope
*
* @var array
*
* @ORM\Column(type="json_array")
* @ORM\Column(type="json")
* @Groups({"read"})
*/
private $name = [];

View File

@@ -116,7 +116,7 @@ class User implements AdvancedUserInterface {
* Array where SAML attributes's data are stored
* @var array
*
* @ORM\Column(type="json_array", nullable=true)
* @ORM\Column(type="json", nullable=true)
*/
private $attributes;

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.
*

View File

@@ -20,7 +20,6 @@ final class Version20210304085819 extends AbstractMigration
public function up(Schema $schema) : void
{
$this->addSql('ALTER TABLE users ADD attributes JSONB DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN users.attributes IS \'(DC2Type:json_array)\'');
}
public function down(Schema $schema) : void