60
src/Repository/InvoiceTemplateRepository.php
Normal file
60
src/Repository/InvoiceTemplateRepository.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* 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\InvoiceTemplate;
|
||||
use App\Repository\Query\BaseQuery;
|
||||
use Doctrine\ORM\Query;
|
||||
|
||||
/**
|
||||
* Class InvoiceTemplateRepository
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class InvoiceTemplateRepository extends AbstractRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function hasTemplate()
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('COUNT(t.id) as totalRecords')
|
||||
->from(InvoiceTemplate::class, 't')
|
||||
;
|
||||
|
||||
$result = $qb->getQuery()->execute([], Query::HYDRATE_ARRAY);
|
||||
|
||||
if (!isset($result[0])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $result[0]['totalRecords'] > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param BaseQuery $query
|
||||
* @return \Doctrine\ORM\QueryBuilder|\Pagerfanta\Pagerfanta
|
||||
*/
|
||||
public function findByQuery(BaseQuery $query)
|
||||
{
|
||||
$qb = $this->getEntityManager()->createQueryBuilder();
|
||||
|
||||
$qb->select('t')
|
||||
->from(InvoiceTemplate::class, 't')
|
||||
->orderBy('t.id');
|
||||
|
||||
return $this->getBaseQueryResult($qb, $query);
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ use App\Entity\Project;
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class ActivityQuery extends VisibilityQuery
|
||||
class ActivityQuery extends ProjectQuery
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -27,29 +27,6 @@ class ActivityQuery extends VisibilityQuery
|
||||
*/
|
||||
protected $project;
|
||||
|
||||
/**
|
||||
* @var Customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Customer $customer
|
||||
* @return $this
|
||||
*/
|
||||
public function setCustomer(Customer $customer = null)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project
|
||||
*/
|
||||
|
||||
69
src/Repository/Query/InvoiceQuery.php
Normal file
69
src/Repository/Query/InvoiceQuery.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Kimai package.
|
||||
*
|
||||
* (c) Kevin Papst <kevin@kevinpapst.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace App\Repository\Query;
|
||||
|
||||
use App\Entity\InvoiceTemplate;
|
||||
|
||||
/**
|
||||
* Can be used for invoice queries.
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class InvoiceQuery extends TimesheetQuery
|
||||
{
|
||||
|
||||
/**
|
||||
* @var InvoiceTemplate
|
||||
*/
|
||||
protected $template;
|
||||
|
||||
/**
|
||||
* @var InvoiceTemplate[]
|
||||
*/
|
||||
protected $templates = [];
|
||||
|
||||
/**
|
||||
* @return InvoiceTemplate
|
||||
*/
|
||||
public function getTemplate()
|
||||
{
|
||||
return $this->template;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceTemplate $template
|
||||
* @return InvoiceQuery
|
||||
*/
|
||||
public function setTemplate($template)
|
||||
{
|
||||
$this->template = $template;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return InvoiceTemplate[]
|
||||
*/
|
||||
public function getTemplates(): array
|
||||
{
|
||||
return $this->templates;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InvoiceTemplate[] $templates
|
||||
* @return InvoiceQuery
|
||||
*/
|
||||
public function setTemplates(array $templates)
|
||||
{
|
||||
$this->templates = $templates;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ use App\Entity\Project;
|
||||
*
|
||||
* @author Kevin Papst <kevin@kevinpapst.de>
|
||||
*/
|
||||
class TimesheetQuery extends BaseQuery
|
||||
class TimesheetQuery extends ActivityQuery
|
||||
{
|
||||
|
||||
const STATE_ALL = 1;
|
||||
@@ -47,18 +47,18 @@ class TimesheetQuery extends BaseQuery
|
||||
* @var Activity
|
||||
*/
|
||||
protected $activity;
|
||||
/**
|
||||
* @var Project
|
||||
*/
|
||||
protected $project;
|
||||
/**
|
||||
* @var Customer
|
||||
*/
|
||||
protected $customer;
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $state = self::STATE_ALL;
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $begin;
|
||||
/**
|
||||
* @var \DateTime
|
||||
*/
|
||||
protected $end;
|
||||
|
||||
/**
|
||||
* @return User
|
||||
@@ -98,48 +98,6 @@ class TimesheetQuery extends BaseQuery
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Project
|
||||
*/
|
||||
public function getProject()
|
||||
{
|
||||
return $this->project;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project overwrites: setCustomer()
|
||||
* Is overwritten by: setActivity()
|
||||
*
|
||||
* @param Project $project
|
||||
* @return TimesheetQuery
|
||||
*/
|
||||
public function setProject(Project $project = null)
|
||||
{
|
||||
$this->project = $project;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Customer
|
||||
*/
|
||||
public function getCustomer()
|
||||
{
|
||||
return $this->customer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Project overwrites: none
|
||||
* Is overwritten by: setActivity() and setProject()
|
||||
*
|
||||
* @param Customer $customer
|
||||
* @return TimesheetQuery
|
||||
*/
|
||||
public function setCustomer(Customer $customer = null)
|
||||
{
|
||||
$this->customer = $customer;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
@@ -165,4 +123,40 @@ class TimesheetQuery extends BaseQuery
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getBegin()
|
||||
{
|
||||
return $this->begin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $begin
|
||||
* @return TimesheetQuery
|
||||
*/
|
||||
public function setBegin($begin)
|
||||
{
|
||||
$this->begin = $begin;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getEnd()
|
||||
{
|
||||
return $this->end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $end
|
||||
* @return TimesheetQuery
|
||||
*/
|
||||
public function setEnd($end)
|
||||
{
|
||||
$this->end = $end;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@ use App\Entity\User;
|
||||
use App\Entity\Activity;
|
||||
use App\Entity\Timesheet;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
use Pagerfanta\Pagerfanta;
|
||||
use App\Model\Statistic\Month;
|
||||
use App\Model\Statistic\Year;
|
||||
@@ -266,7 +267,7 @@ class TimesheetRepository extends AbstractRepository
|
||||
|
||||
/**
|
||||
* @param TimesheetQuery $query
|
||||
* @return Pagerfanta
|
||||
* @return QueryBuilder|Pagerfanta
|
||||
*/
|
||||
public function findByQuery(TimesheetQuery $query)
|
||||
{
|
||||
@@ -291,6 +292,15 @@ class TimesheetRepository extends AbstractRepository
|
||||
$qb->andWhere($qb->expr()->isNotNull('t.end'));
|
||||
}
|
||||
|
||||
if ($query->getBegin() !== null) {
|
||||
$qb->andWhere('t.begin >= :begin')
|
||||
->setParameter('begin', $query->getBegin());
|
||||
}
|
||||
if ($query->getEnd() !== null) {
|
||||
$qb->andWhere('t.end <= :end')
|
||||
->setParameter('end', $query->getEnd());
|
||||
}
|
||||
|
||||
if ($query->getActivity() !== null) {
|
||||
$qb->andWhere('t.activity = :activity')
|
||||
->setParameter('activity', $query->getActivity());
|
||||
|
||||
@@ -23,6 +23,14 @@ use Symfony\Bridge\Doctrine\Security\User\UserLoaderInterface;
|
||||
*/
|
||||
class UserRepository extends AbstractRepository implements UserLoaderInterface
|
||||
{
|
||||
/**
|
||||
* @param $id
|
||||
* @return null|User
|
||||
*/
|
||||
public function getById($id)
|
||||
{
|
||||
return $this->find($id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return statistic data for all user.
|
||||
|
||||
Reference in New Issue
Block a user