TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
DefaultAvatarProvider.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Backend\Backend\Avatar;
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  */
21 
26 {
34  public function getImage(array $backendUser, $size)
35  {
36  $fileUid = $this->getAvatarFileUid($backendUser['uid']);
37 
38  // Get file object
39  try {
40  $file = ResourceFactory::getInstance()->getFileObject($fileUid);
41  $processedImage = $file->process(
43  ['width' => $size . 'c', 'height' => $size . 'c']
44  );
45 
47  Image::class,
48  $processedImage->getPublicUrl(),
49  $processedImage->getProperty('width'),
50  $processedImage->getProperty('height')
51  );
52  } catch (FileDoesNotExistException $e) {
53  // No image found
54  $image = null;
55  }
56 
57  return $image;
58  }
59 
66  protected function getAvatarFileUid($beUserId)
67  {
68  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
69  $file = $queryBuilder
70  ->select('uid_local')
71  ->from('sys_file_reference')
72  ->where(
73  $queryBuilder->expr()->eq(
74  'tablenames',
75  $queryBuilder->createNamedParameter('be_users', \PDO::PARAM_STR)
76  ),
77  $queryBuilder->expr()->eq(
78  'fieldname',
79  $queryBuilder->createNamedParameter('avatar', \PDO::PARAM_STR)
80  ),
81  $queryBuilder->expr()->eq(
82  'table_local',
83  $queryBuilder->createNamedParameter('sys_file', \PDO::PARAM_STR)
84  ),
85  $queryBuilder->expr()->eq(
86  'uid_foreign',
87  $queryBuilder->createNamedParameter($beUserId, \PDO::PARAM_INT)
88  )
89  )
90  ->execute()
91  ->fetchColumn();
92 
93  return (int)$file;
94  }
95 }
static makeInstance($className,...$constructorArguments)