TYPO3 CMS  TYPO3_8-7
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 
40  // Get file object
41  try {
42  $file = ResourceFactory::getInstance()->getFileObject($fileUid);
43  $processedImage = $file->process(
45  ['width' => $size . 'c', 'height' => $size . 'c']
46  );
47 
49  Image::class,
50  $processedImage->getPublicUrl(),
51  $processedImage->getProperty('width'),
52  $processedImage->getProperty('height')
53  );
54  } catch (FileDoesNotExistException $e) {
55  // No image found
56  $image = null;
57  }
58 
59  return $image;
60  }
61 
68  protected function getAvatarFileUid($backendUserId)
69  {
70  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
71  $fileUid = $queryBuilder
72  ->select('uid_local')
73  ->from('sys_file_reference')
74  ->where(
75  $queryBuilder->expr()->eq(
76  'tablenames',
77  $queryBuilder->createNamedParameter('be_users', \PDO::PARAM_STR)
78  ),
79  $queryBuilder->expr()->eq(
80  'fieldname',
81  $queryBuilder->createNamedParameter('avatar', \PDO::PARAM_STR)
82  ),
83  $queryBuilder->expr()->eq(
84  'table_local',
85  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
86  ),
87  $queryBuilder->expr()->eq(
88  'uid_foreign',
89  $queryBuilder->createNamedParameter((int)$backendUserId, \PDO::PARAM_INT)
90  )
91  )
92  ->execute()
93  ->fetchColumn();
94 
95  return (int)$fileUid;
96  }
97 }
static makeInstance($className,... $constructorArguments)