added avatars, show user teams in list, new team dashboard widgets (#1150)

This commit is contained in:
Kevin Papst
2019-10-03 13:44:16 +02:00
committed by GitHub
parent 718ad4b398
commit e8c25d8ac5
120 changed files with 2585 additions and 642 deletions

View File

@@ -0,0 +1,21 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Type;
interface AuthorizedWidget
{
/**
* Return a list of granted syntax string.
* If ANY of the given permission strings matches, access is granted.
*
* @return string[]
*/
public function getPermissions(): array;
}

View File

@@ -0,0 +1,83 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Type;
use App\Entity\Project;
use App\Entity\Team;
use App\Entity\User;
use App\Repository\ProjectRepository;
use App\Security\CurrentUser;
class UserTeamProjects extends SimpleWidget implements AuthorizedWidget
{
/**
* @var ProjectRepository
*/
private $repository;
public function __construct(CurrentUser $user, ProjectRepository $repository)
{
$this->setId('UserTeamProjects');
$this->setTitle('label.my_team_projects');
$this->setOptions([
'user' => $user->getUser(),
'id' => '',
]);
$this->repository = $repository;
}
public function getOptions(array $options = []): array
{
$options = parent::getOptions($options);
if (empty($options['id'])) {
$options['id'] = uniqid('UserTeamProjects_');
}
return $options;
}
public function getData(array $options = [])
{
$options = $this->getOptions($options);
/** @var User $user */
$user = $options['user'];
$projects = [];
/** @var Team $team */
foreach ($user->getTeams() as $team) {
/** @var Project $project */
foreach ($team->getProjects() as $project) {
if (!$project->isVisible() || !$project->getCustomer()->isVisible()) {
continue;
}
$projects[$project->getId()] = $project;
}
}
$stats = [];
foreach ($projects as $id => $project) {
if ($project->getBudget() > 0 || $project->getTimeBudget() > 0) {
$stats[] = $this->repository->getProjectStatistics($project);
}
}
return $stats;
}
/**
* @return string[]
*/
public function getPermissions(): array
{
return ['budget_team_project', 'budget_teamlead_project', 'budget_project'];
}
}

View File

@@ -0,0 +1,54 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Widget\Type;
use App\Entity\User;
use App\Security\CurrentUser;
class UserTeams extends SimpleWidget implements AuthorizedWidget
{
public function __construct(CurrentUser $user)
{
$this->setId('UserTeams');
$this->setTitle('label.teams');
$this->setOptions([
'user' => $user->getUser(),
'id' => '',
]);
}
public function getOptions(array $options = []): array
{
$options = parent::getOptions($options);
if (empty($options['id'])) {
$options['id'] = uniqid('UserTeams_');
}
return $options;
}
public function getData(array $options = [])
{
$options = $this->getOptions($options);
/** @var User $user */
$user = $options['user'];
return $user->getTeams();
}
/**
* @return string[]
*/
public function getPermissions(): array
{
return ['view_team_member', 'view_team'];
}
}