improvements

This commit is contained in:
Kevin Papst
2016-10-30 23:39:55 +01:00
parent 55ac11d517
commit 1678129fe9
47 changed files with 4390 additions and 1746 deletions

View File

@@ -0,0 +1,45 @@
<?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\Admin;
use AppBundle\Entity\User;
use Pagerfanta\Pagerfanta;
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;
/**
* Controller used to manage users in the admin part of the site.
*
* @Route("/admin/user")
* @Security("has_role('ROLE_ADMIN')")
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserController extends Controller
{
/**
* @Route("/", defaults={"page": 1}, name="admin_user")
* @Route("/page/{page}", requirements={"page": "[1-9]\d*"}, name="admin_user_paginated")
* @Method("GET")
* @Cache(smaxage="10")
*/
public function indexAction($page)
{
/* @var $entries Pagerfanta */
$entries = $this->getDoctrine()->getRepository(User::class)->findAll($page);
return $this->render('admin/user.html.twig', ['entries' => $entries]);
}
}

View File

@@ -11,6 +11,9 @@
namespace AppBundle\Controller;
use AppBundle\Entity\User;
use TimesheetBundle\Entity\Activity;
use TimesheetBundle\Entity\Project;
use TimesheetBundle\Entity\Timesheet;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
@@ -34,6 +37,22 @@ class DashboardController extends Controller
*/
public function indexAction()
{
return $this->render('dashboard/index.html.twig', []);
$user = $this->getUser();
$timesheetRepo = $this->getDoctrine()->getRepository(Timesheet::class);
$timesheetUserStats = $timesheetRepo->getUserStatistics($user);
$timesheetGlobalStats = $timesheetRepo->getGlobalStatistics();
$activityStats = $this->getDoctrine()->getRepository(Activity::class)->getGlobalStatistics();
$projectStats = $this->getDoctrine()->getRepository(Project::class)->getGlobalStatistics();
$userStats = $this->getDoctrine()->getRepository(User::class)->getGlobalStatistics();
return $this->render('dashboard/index.html.twig', [
'timesheetGlobal' => $timesheetGlobalStats,
'timesheetUser' => $timesheetUserStats,
'activity' => $activityStats,
'project' => $projectStats,
'user' => $userStats,
]);
}
}

View File

@@ -35,37 +35,39 @@ class ProfileController extends Controller
*/
public function indexAction($ident)
{
$user = $this->getUser();
$isAdmin = false;
if ($isAdmin) {
} else {
}
$timesheetRepo = $this->getDoctrine()->getRepository(Timesheet::class);
$userStats = $timesheetRepo->getUserStatistics($user);
// FIXME fetch values dynamically and add trans filter to macros
$items = [
[
'title' => 'Projects',
'title' => 'Stundenlohn',
'url' => '#',
'color' => 'blue',
'amount' => 12
'color' => 'blue', // aqua, red, green
'value' => 70
],
[
'title' => 'Tasks',
'title' => 'Sprache',
'url' => '#',
'color' => 'aqua',
'amount' => 5
],
[
'title' => 'Projects',
'url' => '#',
'color' => 'red',
'amount' => 27
],
[
'title' => 'Einträge',
'url' => '#',
'color' => 'green',
'amount' => 842
'color' => 'green', // aqua, red, green
'value' => 'deutsch'
],
];
return $this->render(
'user/profile.html.twig',
['user' => $this->getUser(), 'items' => $items]
[
'user' => $this->getUser(),
'settings' => $items,
'stats' => $userStats
]
);
}
}

View File

@@ -10,30 +10,37 @@ use Symfony\Component\Security\Core\User\UserInterface;
* User
*
* @ORM\Entity(repositoryClass="AppBundle\Repository\UserRepository")
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"}), @ORM\UniqueConstraint(name="apikey", columns={"apikey"})})
* @ORM\Entity
* @ORM\Table(name="users", uniqueConstraints={@ORM\UniqueConstraint(name="name", columns={"name"})})
*/
class User implements UserInterface
{
/**
* @var int
*
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="userID", type="integer")
* @ORM\Column(name="id", type="integer")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="name", type="string", length=160, nullable=false, unique=true)
*/
private $username;
/**
* @var string
*
* @ORM\Column(name="mail", type="string", length=160, nullable=false, unique=true)
*/
private $email;
/**
* @var string
*
* @ORM\Column(name="password", type="string", length=254, nullable=true)
*/
private $password;
@@ -45,89 +52,26 @@ class User implements UserInterface
*/
private $alias;
/**
* FIXME remove me
*
* @var boolean
*
* @ORM\Column(name="trash", type="boolean", nullable=false)
*/
private $trash = '0';
/**
* @var boolean
*
* @ORM\Column(name="active", type="boolean", nullable=false)
*/
private $active = '1';
private $active = true;
/**
* @var string
* @var \DateTime
*
* @ORM\Column(name="passwordResetHash", type="string", length=32, nullable=true)
* @ORM\Column(name="start_timeframe", type="datetime", nullable=true)
*/
private $passwordresethash;
private $timeframeBegin;
/**
* @var string
* @var \DateTime
*
* @ORM\Column(name="secure", type="string", length=60, nullable=false)
* @ORM\Column(name="end_timeframe", type="datetime", nullable=true)
*/
private $secure = '0';
/**
* FIXME manytoone relation
*
* @var integer
*
* @ORM\Column(name="lastProject", type="integer", nullable=false)
*/
private $lastproject = '1';
/**
* FIXME manytoone
*
* @var integer
*
* @ORM\Column(name="lastActivity", type="integer", nullable=false)
*/
private $lastactivity = '1';
/**
* FIXME manytoone
*
* @var integer
*
* @ORM\Column(name="lastRecord", type="integer", nullable=false)
*/
private $lastrecord = '0';
/**
* @var string
*
* @ORM\Column(name="timeframeBegin", type="string", length=60, nullable=false)
*/
private $timeframebegin = '0';
/**
* @var string
*
* @ORM\Column(name="timeframeEnd", type="string", length=60, nullable=false)
*/
private $timeframeend = '0';
/**
* @var string
*
* @ORM\Column(name="apikey", type="string", length=30, nullable=true)
*/
private $apikey;
// ======= new columns for kimai 2 =======
/**
* @ORM\Column(type="json_array")
*/
private $roles = [];
private $timeframeEnd;
/**
* @var string
@@ -144,11 +88,55 @@ class User implements UserInterface
private $avatar;
/**
* Set alias
* @var string[]
*
* @ORM\Column(type="json_array")
*/
private $roles = [];
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @return string
*/
public function getTimeframeBegin()
{
return $this->timeframeBegin;
}
/**
* @param string $timeframeBegin
*/
public function setTimeframeBegin($timeframeBegin)
{
$this->timeframeBegin = $timeframeBegin;
}
/**
* @return string
*/
public function getTimeframeEnd()
{
return $this->timeframeEnd;
}
/**
* @param string $timeframeEnd
*/
public function setTimeframeEnd($timeframeEnd)
{
$this->timeframeEnd = $timeframeEnd;
}
/**
* @param string $alias
*
* @return User
* @return $this
*/
public function setAlias($alias)
{
@@ -158,8 +146,6 @@ class User implements UserInterface
}
/**
* Get alias
*
* @return string
*/
public function getAlias()
@@ -168,35 +154,8 @@ class User implements UserInterface
}
/**
* Set trash
*
* @param boolean $trash
*
* @return User
*/
public function setTrash($trash)
{
$this->trash = $trash;
return $this;
}
/**
* Get trash
*
* @return boolean
*/
public function getTrash()
{
return $this->trash;
}
/**
* Set active
*
* @param boolean $active
*
* @return User
* @return $this
*/
public function setActive($active)
{
@@ -206,8 +165,6 @@ class User implements UserInterface
}
/**
* Get active
*
* @return boolean
*/
public function getActive()
@@ -216,11 +173,8 @@ class User implements UserInterface
}
/**
* Set password
*
* @param string $password
*
* @return User
* @return $this
*/
public function setPassword($password)
{
@@ -240,273 +194,82 @@ class User implements UserInterface
}
/**
* Set passwordresethash
*
* @param string $passwordresethash
*
* @return User
*/
public function setPasswordresethash($passwordresethash)
{
$this->passwordresethash = $passwordresethash;
return $this;
}
/**
* Get passwordresethash
*
* @return string
*/
public function getPasswordresethash()
{
return $this->passwordresethash;
}
/**
* Set ban
*
* @param integer $ban
*
* @return User
*/
public function setBan($ban)
{
$this->ban = $ban;
return $this;
}
/**
* Get ban
*
* @return integer
*/
public function getBan()
{
return $this->ban;
}
/**
* Set bantime
*
* @param integer $bantime
*
* @return User
*/
public function setBantime($bantime)
{
$this->bantime = $bantime;
return $this;
}
/**
* Get bantime
*
* @return integer
*/
public function getBantime()
{
return $this->bantime;
}
/**
* Set secure
*
* @param string $secure
*
* @return User
*/
public function setSecure($secure)
{
$this->secure = $secure;
return $this;
}
/**
* Get secure
*
* @return string
*/
public function getSecure()
{
return $this->secure;
}
/**
* Set lastproject
*
* @param integer $lastproject
*
* @return User
*/
public function setLastproject($lastproject)
{
$this->lastproject = $lastproject;
return $this;
}
/**
* Get lastproject
*
* @return integer
*/
public function getLastproject()
{
return $this->lastproject;
}
/**
* Set lastactivity
*
* @param integer $lastactivity
*
* @return User
*/
public function setLastactivity($lastactivity)
{
$this->lastactivity = $lastactivity;
return $this;
}
/**
* Get lastactivity
*
* @return integer
*/
public function getLastactivity()
{
return $this->lastactivity;
}
/**
* Set lastrecord
*
* @param integer $lastrecord
*
* @return User
*/
public function setLastrecord($lastrecord)
{
$this->lastrecord = $lastrecord;
return $this;
}
/**
* Get lastrecord
*
* @return integer
*/
public function getLastrecord()
{
return $this->lastrecord;
}
/**
* Set timeframebegin
*
* @param string $timeframebegin
*
* @return User
*/
public function setTimeframebegin($timeframebegin)
{
$this->timeframebegin = $timeframebegin;
return $this;
}
/**
* Get timeframebegin
*
* @return string
*/
public function getTimeframebegin()
{
return $this->timeframebegin;
}
/**
* Set timeframeend
*
* @param string $timeframeend
*
* @return User
*/
public function setTimeframeend($timeframeend)
{
$this->timeframeend = $timeframeend;
return $this;
}
/**
* Get timeframeend
*
* @return string
*/
public function getTimeframeend()
{
return $this->timeframeend;
}
/**
* Set apikey
*
* @param string $apikey
*
* @return User
*/
public function setApikey($apikey)
{
$this->apikey = $apikey;
return $this;
}
/**
* Get apikey
*
* @return string
*/
public function getApikey()
{
return $this->apikey;
}
public function getId()
{
return $this->id;
}
/**
* {@inheritdoc}
*/
public function getUsername()
{
return $this->username;
}
/**
* @param string $username
* @return $this
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* @return string
*/
public function getEmail()
{
return $this->email;
}
/**
* @param string $email
* @return $this
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
* @return $this
*/
public function setTitle($title)
{
$this->title = $title;
return $this;
}
/**
* @return string
*/
public function getAvatar()
{
return $this->avatar;
}
/**
* @param string $avatar
* @return $this
*/
public function setAvatar($avatar)
{
$this->avatar = $avatar;
return $this;
}
/**
* Returns the roles or permissions granted to the user for security.
*
* @return string[]
*/
public function getRoles()
{
@@ -520,9 +283,14 @@ class User implements UserInterface
return array_unique($roles);
}
/**
* @param string[] $roles
* @return $this
*/
public function setRoles(array $roles)
{
$this->roles = $roles;
return $this;
}
/**
@@ -549,35 +317,6 @@ class User implements UserInterface
/**
* @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->getAlias() ?: $this->getUsername();

View File

@@ -61,7 +61,7 @@ class MenuBuilder
$isAdmin = $isLoggedIn && $this->security->isGranted('ROLE_ADMIN');
$event->addItem(
new MenuItemModel('dashboard', 'menu.homepage', 'dashboard', [], 'fa fa-home')
new MenuItemModel('dashboard', 'menu.homepage', 'dashboard', [], 'fa fa-dashboard') // fa-home
);
$this->eventDispatcher->dispatch(
@@ -74,8 +74,10 @@ class MenuBuilder
);
if ($isAdmin) {
$event->addItem(
new MenuItemModel('admin', 'menu.admin', '', [], 'fa fa-dashboard')
$admin = new MenuItemModel('admin', 'menu.admin', '', [], 'fa fa-wrench');
$event->addItem($admin);
$admin->addChild(
new MenuItemModel('user_admin', 'menu.admin_user', 'admin_user', [], 'fa fa-user')
);
$this->eventDispatcher->dispatch(

View File

@@ -0,0 +1,41 @@
<?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\Model;
/**
* User statistics
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserStatistic
{
/**
* @var int
*/
protected $totalAmount = 0;
/**
* @return int
*/
public function getTotalAmount()
{
return $this->totalAmount;
}
/**
* @param int $totalAmount
*/
public function setTotalAmount($totalAmount)
{
$this->totalAmount = $totalAmount;
}
}

View File

@@ -1,9 +1,9 @@
<?php
/*
* This file is part of the Symfony package.
* This file is part of the Kimai package.
*
* (c) Fabien Potencier <fabien@symfony.com>
* (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.
@@ -11,18 +11,76 @@
namespace AppBundle\Repository;
use AppBundle\Model\UserStatistic;
use Doctrine\ORM\Query;
use Doctrine\ORM\EntityRepository;
use Pagerfanta\Adapter\DoctrineORMAdapter;
use Pagerfanta\Pagerfanta;
/**
* Class UserRepository
*
* This custom Doctrine repository is empty because so far we don't need any custom
* method to query for application user information. But it's always a good practice
* to define a custom repository that will be used when the application grows.
* See http://symfony.com/doc/current/book/doctrine.html#custom-repository-classes
*
* @author Ryan Weaver <weaverryan@gmail.com>
* @author Javier Eguiluz <javier.eguiluz@gmail.com>
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class UserRepository extends EntityRepository
{
/**
* Return statistic data for all user.
*
* @return UserStatistic
*/
public function getGlobalStatistics()
{
$countAll = $this->getEntityManager()
->createQuery('SELECT COUNT(u.id) FROM AppBundle:User u')
->getSingleScalarResult();
$stats = new UserStatistic();
$stats->setTotalAmount($countAll);
return $stats;
}
/**
* @return Query
*/
protected function queryAll()
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('u')
->from('AppBundle:User', 'u')
->orderBy('u.id', 'ASC');
return $qb->getQuery();
}
public function findByUsername($username)
{
return $this->findOneBy(['']);
}
/**
* @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

@@ -13,11 +13,11 @@ namespace AppBundle\Twig;
use AppBundle\Utils\Markdown;
use Symfony\Component\Intl\Intl;
use DateTime;
use DateInterval;
/**
* This Twig extension adds new filters:
* - 'md2html' to transform Markdown contents into HTML contents
* - 'gmdate' to transform timestamps into a gmdate() formatted string
* Multiple Twig extensions: filters and functions
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
@@ -51,7 +51,8 @@ class Extensions extends \Twig_Extension
{
return [
new \Twig_SimpleFilter('md2html', [$this, 'markdownToHtml'], ['is_safe' => ['html']]),
new \Twig_SimpleFilter('gmdate', array($this, 'gmdate')),
new \Twig_SimpleFilter('duration', array($this, 'duration')),
new \Twig_SimpleFilter('money', array($this, 'money')),
];
}
@@ -66,15 +67,37 @@ class Extensions extends \Twig_Extension
}
/**
* Transform a timestamp into a gmdate() formatted string.
* Transforms seconds into a duration string.
*
* @param $seconds
* @param string $format
* @return false|string
* @param bool $includeSeconds
* @return string
*/
public function gmdate($seconds, $format = 'H:i')
public function duration($seconds, $includeSeconds = false)
{
return gmdate($format, $seconds);
$hour = floor($seconds / 3600);
$minute = floor(($seconds / 60) % 60);
$hour = $hour > 9 ? $hour : '0' . $hour;
$minute = $minute > 9 ? $minute : '0' . $minute;
if (!$includeSeconds) {
return $hour . ':' . $minute;
}
$second = $seconds % 60;
$second = $second > 9 ? $second : '0' . $second;
return $hour . ':' . $minute . ':' . $second;
}
/**
* @param float $amount
* @return string
*/
public function money($amount)
{
return round($amount) . ' €';
}
/**