added user-specific rates (#1455)

This commit is contained in:
Kevin Papst
2020-02-10 20:29:43 +01:00
committed by GitHub
parent 465d7166d4
commit 52c7437076
83 changed files with 2054 additions and 520 deletions

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;
use App\Entity\Customer;
use App\Entity\CustomerRate;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\ORMException;
class CustomerRateRepository extends EntityRepository
{
public function saveRate(CustomerRate $rate)
{
$entityManager = $this->getEntityManager();
$entityManager->persist($rate);
$entityManager->flush();
}
public function deleteRate(CustomerRate $rate)
{
$em = $this->getEntityManager();
$em->beginTransaction();
try {
$em->remove($rate);
$em->flush();
$em->commit();
} catch (ORMException $ex) {
$em->rollback();
throw $ex;
}
}
/**
* @param Customer $customer
* @return CustomerRate[]
*/
public function getRatesForCustomer(Customer $customer): array
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('r, u, c')
->from(CustomerRate::class, 'r')
->leftJoin('r.user', 'u')
->leftJoin('r.customer', 'c')
->andWhere(
$qb->expr()->eq('r.customer', ':customer')
)
->addOrderBy('u.alias')
->setParameter('customer', $customer)
;
return $qb->getQuery()->getResult();
}
}