TYPO3  7.6
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  */
17 use TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException;
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  array('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  $file = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
69  'uid_local',
70  'sys_file_reference',
71  'tablenames = \'be_users\' AND fieldname = \'avatar\' AND ' .
72  'table_local = \'sys_file\' AND uid_foreign = ' . (int)$beUserId .
73  BackendUtility::BEenableFields('sys_file_reference') . BackendUtility::deleteClause('sys_file_reference')
74  );
75  return $file ? $file['uid_local'] : 0;
76  }
77 
81  protected function getDatabaseConnection()
82  {
83  return $GLOBALS['TYPO3_DB'];
84  }
85 }