|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Skobkin\Bundle\PointToolsBundle\Twig; |
|
4
|
|
|
|
|
5
|
|
|
use Skobkin\Bundle\PointToolsBundle\Service\UserApi; |
|
6
|
|
|
|
|
7
|
|
|
class PointAvatarExtension extends \Twig_Extension |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* @var UserApi |
|
11
|
|
|
*/ |
|
12
|
|
|
private $userApi; |
|
13
|
|
|
|
|
14
|
12 |
|
public function __construct(UserApi $userApi) |
|
15
|
|
|
{ |
|
16
|
12 |
|
$this->userApi = $userApi; |
|
17
|
12 |
|
} |
|
18
|
|
|
|
|
19
|
6 |
|
public function getFunctions() |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
6 |
|
new \Twig_SimpleFunction('point_avatar', [$this, 'pointAvatarFunction']), |
|
23
|
6 |
|
new \Twig_SimpleFunction('point_avatar_small', [$this, 'pointAvatarSmallFunction']), |
|
24
|
6 |
|
new \Twig_SimpleFunction('point_avatar_medium', [$this, 'pointAvatarMediumFunction']), |
|
25
|
6 |
|
new \Twig_SimpleFunction('point_avatar_large', [$this, 'pointAvatarLargeFunction']), |
|
26
|
|
|
]; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function pointAvatarSmallFunction($login) |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->pointAvatarFunction($login, UserApi::AVATAR_SIZE_SMALL); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function pointAvatarMediumFunction($login) |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->pointAvatarFunction($login, UserApi::AVATAR_SIZE_MEDIUM); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
1 |
|
public function pointAvatarLargeFunction($login) |
|
40
|
|
|
{ |
|
41
|
1 |
|
return $this->pointAvatarFunction($login, UserApi::AVATAR_SIZE_LARGE); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function pointAvatarFunction($login, $size) |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->userApi->getAvatarUrlByLogin($login, $size); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
12 |
|
public function getName() |
|
50
|
|
|
{ |
|
51
|
12 |
|
return 'point_tools_avatars'; |
|
52
|
|
|
} |
|
53
|
|
|
} |