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