added avatars, show user teams in list, new team dashboard widgets (#1150)
This commit is contained in:
59
src/Twig/AvatarExtension.php
Normal file
59
src/Twig/AvatarExtension.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?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\Twig;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Utils\AvatarService;
|
||||
use Symfony\Component\Asset\Packages;
|
||||
use Twig\Extension\AbstractExtension;
|
||||
use Twig\TwigFunction;
|
||||
|
||||
class AvatarExtension extends AbstractExtension
|
||||
{
|
||||
/**
|
||||
* @var AvatarService
|
||||
*/
|
||||
private $avatar;
|
||||
/**
|
||||
* @var Packages
|
||||
*/
|
||||
private $packages;
|
||||
|
||||
public function __construct(AvatarService $avatar, Packages $packages)
|
||||
{
|
||||
$this->avatar = $avatar;
|
||||
$this->packages = $packages;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getFunctions()
|
||||
{
|
||||
return [
|
||||
new TwigFunction('avatar', [$this, 'getAvatarUrl']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getAvatarUrl(?User $profile, string $default): string
|
||||
{
|
||||
if (null === $profile) {
|
||||
return $this->packages->getUrl($default);
|
||||
}
|
||||
|
||||
$url = $this->avatar->getAvatar($profile);
|
||||
|
||||
if (null === $url) {
|
||||
return $this->packages->getUrl($default);
|
||||
}
|
||||
|
||||
return $this->packages->getUrl($url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user