‪TYPO3CMS  ‪main
FileCollectionRepository.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 
25 
30 {
34  protected ‪$table = 'sys_file_collection';
35 
39  protected ‪$typeField = 'type';
40 
48  public function ‪findByUid(‪$uid)
49  {
50  $object = null;
51  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
52 
53  if ($this->‪getEnvironmentMode() === 'FE') {
54  $queryBuilder->setRestrictions(GeneralUtility::makeInstance(FrontendRestrictionContainer::class));
55  } else {
56  $queryBuilder->getRestrictions()
57  ->removeAll()
58  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
59  }
60 
61  $data = $queryBuilder->select('*')
62  ->from($this->table)
63  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(‪$uid, ‪Connection::PARAM_INT)))
64  ->executeQuery()
65  ->fetchAssociative();
66  if (is_array($data)) {
67  $object = $this->‪createDomainObject($data);
68  }
69  if ($object === null) {
70  throw new ‪ResourceDoesNotExistException('Could not find row with uid "' . ‪$uid . '" in table "' . $this->table . '"', 1314354066);
71  }
72  return $object;
73  }
74 
81  public function ‪findByType($type)
82  {
83  $expressionBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
84  ->getQueryBuilderForTable($this->table)
85  ->expr();
86 
87  return $this->‪queryMultipleRecords([
88  $expressionBuilder->eq($this->typeField, $expressionBuilder->literal((string)$type)),
89  ]);
90  }
91 
98  protected function ‪queryMultipleRecords(array $conditions = [])
99  {
100  $result = null;
101 
102  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($this->table);
103  $queryBuilder->getRestrictions()
104  ->removeAll()
105  ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
106 
107  $queryBuilder->select('*')
108  ->from($this->table);
109 
110  if (!empty($conditions)) {
111  $queryBuilder->where(...$conditions);
112  }
113 
114  $data = $queryBuilder->executeQuery()->fetchAllAssociative();
115  if (!empty($data)) {
116  $result = $this->‪createMultipleDomainObjects($data);
117  }
118 
119  return $result;
120  }
121 
128  protected function ‪createMultipleDomainObjects(array $data)
129  {
130  $collections = [];
131  foreach ($data as $collection) {
132  $collections[] = $this->‪createDomainObject($collection);
133  }
134  return $collections;
135  }
136 
141  protected function ‪getEnvironmentMode(): string
142  {
143  return (‪$GLOBALS['TSFE'] ?? null) instanceof ‪TypoScriptFrontendController ? 'FE' : 'BE';
144  }
145 
153  protected function ‪createDomainObject(array ‪$record)
154  {
155  return $this->‪getFileFactory()->‪createCollectionObject($record);
156  }
157 
163  protected function ‪getFileFactory()
164  {
165  return GeneralUtility::makeInstance(ResourceFactory::class);
166  }
167 
173  public function ‪findAll()
174  {
175  return $this->‪queryMultipleRecords();
176  }
177 }
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\findAll
‪Collection AbstractFileCollection[] null findAll()
Definition: FileCollectionRepository.php:171
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\createMultipleDomainObjects
‪TYPO3 CMS Core Collection AbstractRecordCollection[] createMultipleDomainObjects(array $data)
Definition: FileCollectionRepository.php:126
‪TYPO3\CMS\Core\Resource\FileCollectionRepository
Definition: FileCollectionRepository.php:30
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\$typeField
‪string $typeField
Definition: FileCollectionRepository.php:37
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Core\Resource\Collection\AbstractFileCollection
Definition: AbstractFileCollection.php:28
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\getFileFactory
‪ResourceFactory getFileFactory()
Definition: FileCollectionRepository.php:161
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\createDomainObject
‪Collection AbstractFileCollection createDomainObject(array $record)
Definition: FileCollectionRepository.php:151
‪TYPO3\CMS\Core\Resource\ResourceFactory\createCollectionObject
‪CollectionInterface< File > createCollectionObject(array $collectionData)
Definition: ResourceFactory.php:158
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\$table
‪string $table
Definition: FileCollectionRepository.php:33
‪TYPO3\CMS\Core\Resource\ResourceFactory
Definition: ResourceFactory.php:42
‪TYPO3\CMS\Core\Resource\Exception\ResourceDoesNotExistException
Definition: ResourceDoesNotExistException.php:23
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\queryMultipleRecords
‪Collection AbstractFileCollection[] null queryMultipleRecords(array $conditions=[])
Definition: FileCollectionRepository.php:96
‪TYPO3\CMS\Core\Resource
Definition: generateMimeTypes.php:52
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
Definition: TypoScriptFrontendController.php:58
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction
Definition: DeletedRestriction.php:28
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\findByType
‪Collection AbstractFileCollection[] null findByType($type)
Definition: FileCollectionRepository.php:79
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\getEnvironmentMode
‪getEnvironmentMode()
Definition: FileCollectionRepository.php:139
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Resource\FileCollectionRepository\findByUid
‪Collection AbstractFileCollection null findByUid($uid)
Definition: FileCollectionRepository.php:46
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:30