improvements

This commit is contained in:
Kevin Papst
2016-10-23 21:27:11 +02:00
parent c492d30be3
commit 8940b766b6
27 changed files with 728 additions and 138 deletions

View File

@@ -36,7 +36,7 @@ class TimesheetController extends Controller
*/
public function indexAction($page)
{
$entries = $this->getDoctrine()->getRepository(Timesheet::class)->findLatest($page);
$entries = $this->getDoctrine()->getRepository(Timesheet::class)->findAll($page);
return $this->render('TimesheetBundle:timesheet:index.html.twig', ['entries' => $entries]);
}

View File

@@ -30,13 +30,14 @@ class TimesheetController extends Controller
{
/**
* @Route("/", defaults={"page": 1}, name="timesheet")
* @Route("/timesheet/{page}", requirements={"page": "[1-9]\d*"}, name="timesheet_paginated")
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="timesheet_paginated")
* @Method("GET")
* @Cache(smaxage="10")
*/
public function indexAction($page)
{
$entries = $this->getDoctrine()->getRepository(Timesheet::class)->findLatest($page);
$user = $this->getUser();
$entries = $this->getDoctrine()->getRepository(Timesheet::class)->findLatest($user, $page);
return $this->render('TimesheetBundle:timesheet:index.html.twig', ['entries' => $entries]);
}

View File

@@ -11,6 +11,7 @@
namespace TimesheetBundle\Repository;
use AppBundle\Entity\User;
use TimesheetBundle\Entity\Timesheet;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
@@ -26,16 +27,33 @@ class TimesheetRepository extends EntityRepository
{
/**
* @param User $user
* @return Query
*/
public function queryLatest()
public function queryLatest(User $user = null)
{
return $this->getEntityManager()
->createQuery('
SELECT p
FROM TimesheetBundle:Timesheet p
ORDER BY p.start DESC
');
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('p')
->from('TimesheetBundle:Timesheet', 'p')
->orderBy('p.start', 'DESC');
if (null !== $user) {
$qb->where('p.user = :user')
->setParameter('user', $user);
}
return $qb->getQuery();
}
/**
* @param User $user
* @param int $page
* @return Pagerfanta
*/
public function findLatest(User $user, $page = 1)
{
return $this->getPager($this->queryLatest($user), $page);
}
/**
@@ -43,9 +61,19 @@ class TimesheetRepository extends EntityRepository
*
* @return Pagerfanta
*/
public function findLatest($page = 1)
public function findAll($page = 1)
{
$paginator = new Pagerfanta(new DoctrineORMAdapter($this->queryLatest(), false));
return $this->getPager($this->queryLatest(), $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);

View File

@@ -9,17 +9,17 @@
<thead>
<tr>
<th><i class="fa fa-calendar"></i> {{ 'label.date'|trans }}</th>
<th><i class="fa fa-circle-o"></i> {{ 'label.start'|trans }}</th>
<th><i class="fa fa-circle"></i> {{ 'label.end'|trans }}</th>
<th><i class="fa fa-hourglass-start"></i> {{ 'label.starttime'|trans }}</th>
<th><i class="fa fa-hourglass-end"></i> {{ 'label.endtime'|trans }}</th>
<th><i class="fa fa-clock-o"></i> {{ 'label.duration'|trans }}</th>
<th><i class="fa fa-user"></i> {{ 'label.user'|trans }}</th>
<th>{{ 'label.description'|trans }}</th>
<th><i class="fa fa-user"></i> {{ 'label.username'|trans }}</th>
<th><i class="fa fa-pencil-square-o"></i> {{ 'label.description'|trans }}</th>
</tr>
</thead>
<tbody>
{% for entry in entries %}
<tr>
<td>{{ entry.start|date("m/d/Y") }}</td>
<td>{{ entry.start|date(kimai_context.date_1) }}</td>
<td>{{ entry.start|date("H:i") }}</td>
<td>{{ entry.end|date("H:i") }}</td>
<td>{{ entry.duration|gmdate }}</td>