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

@@ -0,0 +1,71 @@
<?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 AppBundle\Controller;
use TimesheetBundle\Entity\Timesheet;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
/**
* User profile controller
*
* @Route("/profile")
* @Security("has_role('ROLE_USER')")
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ProfileController extends Controller
{
/**
* @Route("/", defaults={"ident": null}, name="user_profile")
* @Route("/{ident}/", requirements={"ident": "[a-zA-Z0-9\-].*"}, name="user_profile_ident")
* @Method("GET")
*/
public function indexAction($ident)
{
// FIXME fetch values dynamically and add trans filter to macros
$items = [
[
'title' => 'Projects',
'url' => '#',
'color' => 'blue',
'amount' => 12
],
[
'title' => 'Tasks',
'url' => '#',
'color' => 'aqua',
'amount' => 5
],
[
'title' => 'Projects',
'url' => '#',
'color' => 'red',
'amount' => 27
],
[
'title' => 'Einträge',
'url' => '#',
'color' => 'green',
'amount' => 842
],
];
return $this->render(
'user/profile.html.twig',
['user' => $this->getUser(), 'items' => $items]
);
}
}

View File

@@ -31,6 +31,7 @@ class SecurityController extends Controller
{
$helper = $this->get('security.authentication_utils');
//return $this->render('AvanzuAdminThemeBundle:Security:login.html.twig', [
return $this->render('security/login.html.twig', [
// last username entered by the user (if any)
'last_username' => $helper->getLastUsername(),

View File

@@ -41,6 +41,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
$passwordEncoder = $this->container->get('security.password_encoder');
$claraCustomer = new User();
$claraCustomer->setAlias('Clara Haynes');
$claraCustomer->setTitle('CFO');
$claraCustomer->setUsername('clara_customer');
$claraCustomer->setEmail('clara_customer@example.com');
$claraCustomer->setRoles(['ROLE_CUSTOMER']);
@@ -49,6 +51,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
$manager->persist($claraCustomer);
$johnUser = new User();
$johnUser->setAlias('John Doe');
$johnUser->setTitle('Lead Developer');
$johnUser->setUsername('john_user');
$johnUser->setEmail('john_user@example.com');
$johnUser->setRoles(['ROLE_USER']);
@@ -57,6 +61,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
$manager->persist($johnUser);
$tonyTeamlead = new User();
$tonyTeamlead->setAlias('Tony Maier');
$tonyTeamlead->setTitle('Head of Development');
$tonyTeamlead->setUsername('tony_teamlead');
$tonyTeamlead->setEmail('tony_teamlead@example.com');
$tonyTeamlead->setRoles(['ROLE_TEAMLEAD']);
@@ -65,6 +71,8 @@ class LoadFixtures implements FixtureInterface, ContainerAwareInterface
$manager->persist($tonyTeamlead);
$annaAdmin = new User();
$annaAdmin->setAlias('Anna Smith');
$annaAdmin->setTitle('Administrator');
$annaAdmin->setUsername('anna_admin');
$annaAdmin->setEmail('anna_admin@example.com');
$annaAdmin->setRoles(['ROLE_ADMIN']);

View File

@@ -7,7 +7,7 @@ use Symfony\Component\Security\Core\User\UserInterface;
/**
* KimaiUsers
* User
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"}), @ORM\UniqueConstraint(name="apikey", columns={"apikey"})})
@@ -46,6 +46,8 @@ class User implements UserInterface
private $alias;
/**
* FIXME remove me
*
* @var boolean
*
* @ORM\Column(name="trash", type="boolean", nullable=false)
@@ -67,6 +69,8 @@ class User implements UserInterface
private $passwordresethash;
/**
* FIXME remove me
*
* @var integer
*
* @ORM\Column(name="ban", type="integer", nullable=false)
@@ -74,6 +78,7 @@ class User implements UserInterface
private $ban = '0';
/**
* FIXME remove me
* @var integer
*
* @ORM\Column(name="banTime", type="integer", nullable=false)
@@ -88,7 +93,7 @@ class User implements UserInterface
private $secure = '0';
/**
* FIXME
* FIXME manytoone relation
*
* @var integer
*
@@ -97,7 +102,7 @@ class User implements UserInterface
private $lastproject = '1';
/**
* FIXME
* FIXME manytoone
*
* @var integer
*
@@ -133,17 +138,32 @@ class User implements UserInterface
*/
private $apikey;
// ======= new columns for kimai 2 =======
/**
* @ORM\Column(type="json_array")
*/
private $roles = [];
/**
* @var string
*
* @ORM\Column(name="title", type="string", length=50, nullable=true)
*/
private $title;
/**
* @var string
*
* @ORM\Column(name="avatar", type="string", length=50, nullable=true)
*/
private $avatar;
/**
* Set alias
*
* @param string $alias
*
* @return KimaiUsers
* @return User
*/
public function setAlias($alias)
{
@@ -167,7 +187,7 @@ class User implements UserInterface
*
* @param boolean $trash
*
* @return KimaiUsers
* @return User
*/
public function setTrash($trash)
{
@@ -191,7 +211,7 @@ class User implements UserInterface
*
* @param boolean $active
*
* @return KimaiUsers
* @return User
*/
public function setActive($active)
{
@@ -215,7 +235,7 @@ class User implements UserInterface
*
* @param string $password
*
* @return KimaiUsers
* @return User
*/
public function setPassword($password)
{
@@ -239,7 +259,7 @@ class User implements UserInterface
*
* @param string $passwordresethash
*
* @return KimaiUsers
* @return User
*/
public function setPasswordresethash($passwordresethash)
{
@@ -263,7 +283,7 @@ class User implements UserInterface
*
* @param integer $ban
*
* @return KimaiUsers
* @return User
*/
public function setBan($ban)
{
@@ -287,7 +307,7 @@ class User implements UserInterface
*
* @param integer $bantime
*
* @return KimaiUsers
* @return User
*/
public function setBantime($bantime)
{
@@ -311,7 +331,7 @@ class User implements UserInterface
*
* @param string $secure
*
* @return KimaiUsers
* @return User
*/
public function setSecure($secure)
{
@@ -335,7 +355,7 @@ class User implements UserInterface
*
* @param integer $lastproject
*
* @return KimaiUsers
* @return User
*/
public function setLastproject($lastproject)
{
@@ -359,7 +379,7 @@ class User implements UserInterface
*
* @param integer $lastactivity
*
* @return KimaiUsers
* @return User
*/
public function setLastactivity($lastactivity)
{
@@ -383,7 +403,7 @@ class User implements UserInterface
*
* @param integer $lastrecord
*
* @return KimaiUsers
* @return User
*/
public function setLastrecord($lastrecord)
{
@@ -407,7 +427,7 @@ class User implements UserInterface
*
* @param string $timeframebegin
*
* @return KimaiUsers
* @return User
*/
public function setTimeframebegin($timeframebegin)
{
@@ -431,7 +451,7 @@ class User implements UserInterface
*
* @param string $timeframeend
*
* @return KimaiUsers
* @return User
*/
public function setTimeframeend($timeframeend)
{
@@ -455,7 +475,7 @@ class User implements UserInterface
*
* @param string $apikey
*
* @return KimaiUsers
* @return User
*/
public function setApikey($apikey)
{
@@ -474,30 +494,6 @@ class User implements UserInterface
return $this->apikey;
}
/**
* Set globalroleid
*
* @param integer $globalroleid
*
* @return KimaiUsers
*/
public function setGlobalroleid($globalroleid)
{
$this->globalroleid = $globalroleid;
return $this;
}
/**
* Get globalroleid
*
* @return integer
*/
public function getGlobalroleid()
{
return $this->globalroleid;
}
public function getId()
{
return $this->id;
@@ -565,8 +561,40 @@ class User implements UserInterface
// $this->plainPassword = null;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getAvatar()
{
return $this->avatar;
}
/**
* @param string $avatar
*/
public function setAvatar($avatar)
{
$this->avatar = $avatar;
}
public function __toString()
{
return $this->getUsername();
return $this->getAlias() ?: $this->getUsername();
}
}

View File

@@ -75,7 +75,7 @@ class MenuBuilder
if ($isAdmin) {
$event->addItem(
new MenuItemModel('admin', 'menu.admin_dashboard', '', [], 'fa fa-dashboard')
new MenuItemModel('admin', 'menu.admin', '', [], 'fa fa-dashboard')
);
$this->eventDispatcher->dispatch(

View File

@@ -0,0 +1,59 @@
<?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 AppBundle\EventListener;
use AppBundle\Entity\User;
use Avanzu\AdminThemeBundle\Event\ShowUserEvent;
use Avanzu\AdminThemeBundle\Model\UserModel;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\User\UserInterface;
/**
* Class NavbarShowUserListener
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class NavbarShowUserListener
{
/**
* @var TokenStorageInterface
*/
protected $storage;
public function __construct(TokenStorageInterface $tokenStorage)
{
$this->storage = $tokenStorage;
}
public function onShowUser(ShowUserEvent $event)
{
/* @var $myUser User */
$myUser = $this->storage->getToken()->getUser();
$titles = [];
$roles = $this->storage->getToken()->getRoles();
foreach ($roles as $role) {
$titles[] = ucfirst(strtolower(str_replace('ROLE_', '', $role->getRole())));
}
$user = new UserModel();
$user->setName($myUser->getAlias() ?: $myUser->getUsername())
->setUsername($myUser->getUsername())
->setIsOnline(true)
->setTitle($myUser->getTitle())
->setAvatar($myUser->getAvatar())
->setMemberSince(new \DateTime()) // FIXME add column to entity
;
$event->setUser($user);
}
}

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>