‪TYPO3CMS  10.4
DefaultAvatarProvider.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
29 {
37  public function ‪getImage(array $backendUser, $size)
38  {
39  $fileUid = $this->‪getAvatarFileUid($backendUser['uid']);
40  if ($fileUid === 0) {
41  // Early return if there is no valid image file UID
42  return null;
43  }
44  // Get file object
45  try {
46  $file = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($fileUid);
47  $processedImage = $file->process(
49  ['width' => $size . 'c', 'height' => $size . 'c']
50  );
51 
52  $image = GeneralUtility::makeInstance(
53  Image::class,
54  $processedImage->getPublicUrl(),
55  $processedImage->getProperty('width'),
56  $processedImage->getProperty('height')
57  );
58  } catch (‪FileDoesNotExistException $e) {
59  // No image found
60  $image = null;
61  }
62 
63  return $image;
64  }
65 
72  protected function ‪getAvatarFileUid($backendUserId)
73  {
74  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
75  $fileUid = $queryBuilder
76  ->select('uid_local')
77  ->from('sys_file_reference')
78  ->where(
79  $queryBuilder->expr()->eq(
80  'tablenames',
81  $queryBuilder->createNamedParameter('be_users', \PDO::PARAM_STR)
82  ),
83  $queryBuilder->expr()->eq(
84  'fieldname',
85  $queryBuilder->createNamedParameter('avatar', \PDO::PARAM_STR)
86  ),
87  $queryBuilder->expr()->eq(
88  'table_local',
89  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
90  ),
91  $queryBuilder->expr()->eq(
92  'uid_foreign',
93  $queryBuilder->createNamedParameter((int)$backendUserId, \PDO::PARAM_INT)
94  )
95  )
96  ->execute()
97  ->fetchColumn();
98 
99  return (int)$fileUid;
100  }
101 }
‪TYPO3\CMS\Core\Resource\ProcessedFile\CONTEXT_IMAGECROPSCALEMASK
‪const CONTEXT_IMAGECROPSCALEMASK
Definition: ProcessedFile.php:58
‪TYPO3\CMS\Backend\Backend\Avatar\DefaultAvatarProvider\getImage
‪Image null getImage(array $backendUser, $size)
Definition: DefaultAvatarProvider.php:37
‪TYPO3\CMS\Backend\Backend\Avatar\DefaultAvatarProvider
Definition: DefaultAvatarProvider.php:29
‪TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException
Definition: FileDoesNotExistException.php:22
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:41
‪TYPO3\CMS\Core\Resource\ProcessedFile
Definition: ProcessedFile.php:44
‪TYPO3\CMS\Backend\Backend\Avatar
Definition: Avatar.php:16
‪TYPO3\CMS\Backend\Backend\Avatar\DefaultAvatarProvider\getAvatarFileUid
‪int getAvatarFileUid($backendUserId)
Definition: DefaultAvatarProvider.php:72
‪TYPO3\CMS\Backend\Backend\Avatar\AvatarProviderInterface
Definition: AvatarProviderInterface.php:22
‪TYPO3\CMS\Backend\Backend\Avatar\Image
Definition: Image.php:27
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46