post 1.3 fixes (#1106)

This commit is contained in:
Kevin Papst
2019-09-17 22:20:36 +02:00
committed by GitHub
parent 13f5e76015
commit 24cbe3d281
12 changed files with 200 additions and 61 deletions

View File

@@ -73,11 +73,13 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface
// by using array_pop we make sure that at least one activity has NO entry!
array_pop($activities);
$all = 0;
foreach ($allUser as $user) {
// random amount of timesheet entries for every user
$timesheetForUser = rand(self::MIN_TIMESHEETS_PER_USER, self::MAX_TIMESHEETS_PER_USER);
for ($i = 1; $i <= $timesheetForUser; $i++) {
if ($i > self::MAX_TIMESHEETS_TOTAL) {
if ($all > self::MAX_TIMESHEETS_TOTAL) {
break;
}
@@ -96,6 +98,8 @@ class TimesheetFixtures extends Fixture implements DependentFixtureInterface
true
);
$all++;
$manager->persist($entry);
if ($i % self::BATCH_SIZE == 0) {

View File

@@ -133,4 +133,19 @@ interface MetaTableTypeInterface
* @return MetaTableTypeInterface
*/
public function setConstraints(array $constraints): MetaTableTypeInterface;
/**
* Returns the label shown to the end-user.
*
* @return string
*/
public function getLabel(): ?string;
/**
* Sets the label shown to the end-user.
*
* @param string $label
* @return MetaTableTypeInterface
*/
public function setLabel(string $label): MetaTableTypeInterface;
}

View File

@@ -9,6 +9,7 @@
namespace App\Entity;
use App\Form\Type\YesNoType;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\IntegerType;
@@ -49,6 +50,11 @@ trait MetaTableTypeTrait
*/
private $visible = false;
/**
* @var string
*/
private $label;
/**
* @var string
*/
@@ -66,7 +72,11 @@ trait MetaTableTypeTrait
public function getName(): ?string
{
return $this->name;
if (null === $this->name) {
return null;
}
return strtolower($this->name);
}
public function setName(string $name): MetaTableTypeInterface
@@ -82,6 +92,7 @@ trait MetaTableTypeTrait
public function getValue()
{
switch ($this->type) {
case YesNoType::class:
case CheckboxType::class:
return (bool) $this->value;
case IntegerType::class:
@@ -176,4 +187,20 @@ trait MetaTableTypeTrait
return $this;
}
public function getLabel(): ?string
{
if (null === $this->label) {
return $this->name;
}
return $this->label;
}
public function setLabel(string $label): MetaTableTypeInterface
{
$this->label = $label;
return $this;
}
}

View File

@@ -43,7 +43,7 @@ class EntityMetaDefinitionType extends AbstractType
}
$event->getForm()->add('value', $definition->getType(), [
'label' => $definition->getName(),
'label' => $definition->getLabel(),
'constraints' => $definition->getConstraints(),
'required' => $definition->isRequired(),
]);

View File

@@ -0,0 +1,24 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Repository\Loader;
final class DefaultLoader implements LoaderInterface
{
/**
* @param array $results
*/
public function loadResults(array $results): void
{
// nothing to do here, the results are already fully populated
// if your entities have lazy collections or other data that needs population,
// consider to create a custom loader!
}
}

View File

@@ -0,0 +1,62 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Repository\Paginator;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
final class QueryBuilderPaginator implements PaginatorInterface
{
/**
* @var QueryBuilder
*/
private $query;
/**
* @var int
*/
private $results = 0;
public function __construct(QueryBuilder $query, int $results)
{
$this->query = $query;
$this->results = $results;
}
/**
* {@inheritdoc}
*/
public function getNbResults()
{
return $this->results;
}
/**
* {@inheritdoc}
*/
public function getSlice($offset, $length)
{
$query = $this->query
->getQuery()
->setFirstResult($offset)
->setMaxResults($length);
return $this->getResults($query);
}
private function getResults(Query $query)
{
return $query->execute();
}
public function getAll(): iterable
{
return $this->getResults($this->query->getQuery());
}
}