new system-config to prevent overlapping records (#1720)
This commit is contained in:
@@ -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[]
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user