new system-config to prevent overlapping records (#1720)

This commit is contained in:
Kevin Papst
2020-06-28 22:09:50 +02:00
committed by GitHub
parent e566305426
commit e22830790b
17 changed files with 246 additions and 20 deletions

View File

@@ -20,9 +20,10 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
private static $cacheByPrefix = null;
private static $cacheAll = [];
private function clearCache()
public function clearCache()
{
static::$cacheByPrefix = null;
static::$cacheAll = null;
}
private function prefillCache()
@@ -44,6 +45,14 @@ class ConfigurationRepository extends EntityRepository implements ConfigLoaderIn
}
}
public function saveConfiguration(Configuration $configuration)
{
$entityManager = $this->getEntityManager();
$entityManager->persist($configuration);
$entityManager->flush();
$this->clearCache();
}
/**
* @param string $prefix
* @return Configuration[]

View File

@@ -939,4 +939,33 @@ class TimesheetRepository extends EntityRepository
return $results;
}
public function hasRecordForTime(Timesheet $timesheet): bool
{
$qb = $this->getEntityManager()->createQueryBuilder();
$or = $qb->expr()->orX(
$qb->expr()->between(':begin', 't.begin', 't.end')
);
if (null !== $timesheet->getEnd()) {
$or->add($qb->expr()->between(':end', 't.begin', 't.end'));
$or->add($qb->expr()->between('t.begin', ':begin', ':end'));
$or->add($qb->expr()->between('t.end', ':begin', ':end'));
$qb->setParameter('end', $timesheet->getEnd());
}
$qb->select('t')
->from(Timesheet::class, 't')
->andWhere($qb->expr()->eq('t.user', ':user'))
->andWhere($qb->expr()->isNotNull('t.end'))
->andWhere($or)
->setParameter('begin', $timesheet->getBegin())
->setParameter('user', $timesheet->getUser())
;
$result = $qb->getQuery()->getResult();
return !empty($result);
}
}