added drag and drop for new records via calendar (#1962)
This commit is contained in:
@@ -23,10 +23,14 @@ use App\Repository\Loader\TimesheetLoader;
|
||||
use App\Repository\Paginator\LoaderPaginator;
|
||||
use App\Repository\Paginator\PaginatorInterface;
|
||||
use App\Repository\Query\TimesheetQuery;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use PDO;
|
||||
|
||||
/**
|
||||
* @extends \Doctrine\ORM\EntityRepository<Timesheet>
|
||||
@@ -74,7 +78,7 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
/**
|
||||
* @param Timesheet[] $timesheets
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function deleteMultiple(iterable $timesheets): void
|
||||
{
|
||||
@@ -87,12 +91,15 @@ class TimesheetRepository extends EntityRepository
|
||||
}
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 1.11 use TimesheetService::stopTimesheet() instead
|
||||
*/
|
||||
public function add(Timesheet $timesheet, int $maxRunningEntries)
|
||||
{
|
||||
$em = $this->getEntityManager();
|
||||
@@ -106,7 +113,7 @@ class TimesheetRepository extends EntityRepository
|
||||
$em->persist($timesheet);
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
@@ -126,7 +133,7 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
/**
|
||||
* @param Timesheet[] $timesheets
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function saveMultiple(array $timesheets): void
|
||||
{
|
||||
@@ -139,7 +146,7 @@ class TimesheetRepository extends EntityRepository
|
||||
}
|
||||
$em->flush();
|
||||
$em->commit();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
$em->rollback();
|
||||
throw $ex;
|
||||
}
|
||||
@@ -152,6 +159,7 @@ class TimesheetRepository extends EntityRepository
|
||||
* @throws RepositoryException
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @deprecated since 1.11 use TimesheetService::stopTimesheet() instead
|
||||
*/
|
||||
public function stopRecording(Timesheet $entry, bool $flush = true)
|
||||
{
|
||||
@@ -161,7 +169,7 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
// seems to be necessary so Doctrine will recognize a changed timestamp
|
||||
$begin = clone $entry->getBegin();
|
||||
$end = new \DateTime('now', $begin->getTimezone());
|
||||
$end = new DateTime('now', $begin->getTimezone());
|
||||
|
||||
$entry->setBegin($begin);
|
||||
$entry->setEnd($end);
|
||||
@@ -208,7 +216,7 @@ class TimesheetRepository extends EntityRepository
|
||||
$what = 'COUNT(t.id)';
|
||||
break;
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid query type: ' . $type);
|
||||
throw new InvalidArgumentException('Invalid query type: ' . $type);
|
||||
}
|
||||
|
||||
return $this->queryTimeRange($what, $begin, $end, $user);
|
||||
@@ -401,7 +409,7 @@ class TimesheetRepository extends EntityRepository
|
||||
$results = [];
|
||||
/** @var Timesheet $result */
|
||||
foreach ($timesheets as $result) {
|
||||
/** @var \DateTime $beginTmp */
|
||||
/** @var DateTime $beginTmp */
|
||||
$beginTmp = $result->getBegin();
|
||||
/** @var DateTime $endTmp */
|
||||
$endTmp = $result->getEnd();
|
||||
@@ -412,7 +420,7 @@ class TimesheetRepository extends EntityRepository
|
||||
|
||||
if ($dateKey !== $dateKeyEnd) {
|
||||
$newDateBegin = clone $beginTmp;
|
||||
$newDateBegin->add(new \DateInterval('P1D'));
|
||||
$newDateBegin->add(new DateInterval('P1D'));
|
||||
// overlapping records should always start at midnight
|
||||
$newDateBegin->setTime(0, 0, 0);
|
||||
} else {
|
||||
@@ -490,7 +498,7 @@ class TimesheetRepository extends EntityRepository
|
||||
* @param DateTime $begin
|
||||
* @param DateTime $end
|
||||
* @return Day[]
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function getDailyStats(?User $user, DateTime $begin, DateTime $end): array
|
||||
{
|
||||
@@ -557,6 +565,7 @@ class TimesheetRepository extends EntityRepository
|
||||
* @throws RepositoryException
|
||||
* @throws \Doctrine\ORM\ORMException
|
||||
* @throws \Doctrine\ORM\OptimisticLockException
|
||||
* @deprecated since 1.11 use TimesheetService::stopTimesheet() instead
|
||||
*/
|
||||
public function stopActiveEntries(User $user, int $hardLimit, bool $flush = true)
|
||||
{
|
||||
@@ -573,7 +582,7 @@ class TimesheetRepository extends EntityRepository
|
||||
foreach ($activeEntries as $activeEntry) {
|
||||
if ($i > $limit) {
|
||||
if ($hardLimit > 1) {
|
||||
throw new \Exception('timesheet.start.exceeded_limit');
|
||||
throw new Exception('timesheet.start.exceeded_limit');
|
||||
}
|
||||
|
||||
$this->stopRecording($activeEntry, $flush);
|
||||
@@ -773,15 +782,15 @@ class TimesheetRepository extends EntityRepository
|
||||
}
|
||||
|
||||
if ($query->isExported()) {
|
||||
$qb->andWhere('t.exported = :exported')->setParameter('exported', true, \PDO::PARAM_BOOL);
|
||||
$qb->andWhere('t.exported = :exported')->setParameter('exported', true, PDO::PARAM_BOOL);
|
||||
} elseif ($query->isNotExported()) {
|
||||
$qb->andWhere('t.exported = :exported')->setParameter('exported', false, \PDO::PARAM_BOOL);
|
||||
$qb->andWhere('t.exported = :exported')->setParameter('exported', false, PDO::PARAM_BOOL);
|
||||
}
|
||||
|
||||
if ($query->isBillable()) {
|
||||
$qb->andWhere('t.billable = :billable')->setParameter('billable', true, \PDO::PARAM_BOOL);
|
||||
$qb->andWhere('t.billable = :billable')->setParameter('billable', true, PDO::PARAM_BOOL);
|
||||
} elseif ($query->isNotBillable()) {
|
||||
$qb->andWhere('t.billable = :billable')->setParameter('billable', false, \PDO::PARAM_BOOL);
|
||||
$qb->andWhere('t.billable = :billable')->setParameter('billable', false, PDO::PARAM_BOOL);
|
||||
}
|
||||
|
||||
if (null !== $query->getModifiedAfter()) {
|
||||
@@ -848,7 +857,7 @@ class TimesheetRepository extends EntityRepository
|
||||
* @return array|mixed
|
||||
* @throws \Doctrine\ORM\Query\QueryException
|
||||
*/
|
||||
public function getRecentActivities(User $user = null, \DateTime $startFrom = null, $limit = 10)
|
||||
public function getRecentActivities(User $user = null, DateTime $startFrom = null, $limit = 10)
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
@@ -865,7 +874,7 @@ class TimesheetRepository extends EntityRepository
|
||||
->groupBy('a.id', 'p.id')
|
||||
->orderBy('maxid', 'DESC')
|
||||
->setMaxResults($limit)
|
||||
->setParameter('visible', true, \PDO::PARAM_BOOL)
|
||||
->setParameter('visible', true, PDO::PARAM_BOOL)
|
||||
;
|
||||
|
||||
if (null !== $user) {
|
||||
@@ -909,7 +918,7 @@ class TimesheetRepository extends EntityRepository
|
||||
->update(Timesheet::class, 't')
|
||||
->set('t.exported', ':exported')
|
||||
->where($qb->expr()->in('t.id', ':ids'))
|
||||
->setParameter('exported', true, \PDO::PARAM_BOOL)
|
||||
->setParameter('exported', true, PDO::PARAM_BOOL)
|
||||
->setParameter('ids', $timesheets)
|
||||
->getQuery()
|
||||
->execute();
|
||||
@@ -1008,21 +1017,35 @@ class TimesheetRepository extends EntityRepository
|
||||
$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());
|
||||
$end = clone $timesheet->getEnd();
|
||||
$end->sub(new DateInterval('PT1S'));
|
||||
$qb->setParameter('end', $end);
|
||||
}
|
||||
|
||||
// one second is added, because people normally either use the calendar / times which are rounded to the full minute
|
||||
// for an existing entry like 12:45-13:00 it is impossible to add a new one from 13:00-13:15 as the between() query find the first one
|
||||
// by adding one second the between() select will not match any longer
|
||||
|
||||
$begin = clone $timesheet->getBegin();
|
||||
$begin->add(new DateInterval('PT1S'));
|
||||
|
||||
$qb->select($qb->expr()->count('t.id'))
|
||||
->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())
|
||||
->setParameter('begin', $begin)
|
||||
->setParameter('user', $timesheet->getUser()->getId())
|
||||
;
|
||||
|
||||
// if we edit an existing entry, make sure we do not find "the same entry" when only updating eg. the description
|
||||
if ($timesheet->getId() !== null) {
|
||||
$qb->andWhere($qb->expr()->neq('t.id', $timesheet->getId()));
|
||||
}
|
||||
|
||||
try {
|
||||
$result = (int) $qb->getQuery()->getSingleScalarResult();
|
||||
} catch (\Exception $ex) {
|
||||
} catch (Exception $ex) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user