added customer administration

This commit is contained in:
Kevin Papst
2018-01-02 14:20:59 +01:00
parent 719920c7f4
commit efa3646cbe
11 changed files with 608 additions and 98 deletions

View 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 TimesheetBundle\Repository;
use AppBundle\Entity\User;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Entity\Timesheet;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
use TimesheetBundle\Model\ActivityStatistic;
/**
* Class AbstractRepository
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
abstract class AbstractRepository extends EntityRepository
{
/**
* @param string $orderBy
* @return Query
*/
protected function queryAll($orderBy = 'id')
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('a')
->from($this->getEntityName(), 'a')
->orderBy('a.' . $orderBy, 'ASC');
return $qb->getQuery();
}
/**
* @param int $page
*
* @return Pagerfanta
*/
public function findAll($page = 1)
{
return $this->getPager($this->queryAll(), $page);
}
/**
* @param Query $query
* @param int $page
* @return Pagerfanta
*/
protected function getPager(Query $query, $page = 1)
{
$paginator = new Pagerfanta(new DoctrineORMAdapter($query, false));
$paginator->setMaxPerPage(25);
$paginator->setCurrentPage($page);
return $paginator;
}
}

View File

@@ -0,0 +1,50 @@
<?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 TimesheetBundle\Repository;
use TimesheetBundle\Entity\Customer;
use TimesheetBundle\Model\CustomerStatistic;
/**
* Class CustomerRepository
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class CustomerRepository extends AbstractRepository
{
/**
* @param $id
* @return null|Customer
*/
public function getById($id)
{
return $this->find($id);
}
/**
* Return statistic data for all customer.
*
* @return CustomerStatistic
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function getGlobalStatistics()
{
$countAll = $this->getEntityManager()
->createQuery('SELECT COUNT(a.id) FROM TimesheetBundle:Customer c')
->getSingleScalarResult();
$stats = new CustomerStatistic();
$stats->setTotalAmount($countAll);
return $stats;
}
}