‪TYPO3CMS  9.5
StaticRecordCollection.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 
19 
24 {
33  public static function ‪create(array $collectionRecord, $fillItems = false)
34  {
36  $collection = GeneralUtility::makeInstance(
37  self::class,
38  $collectionRecord['table_name']
39  );
40  $collection->fromArray($collectionRecord);
41  if ($fillItems) {
42  $collection->loadContents();
43  }
44  return $collection;
45  }
46 
53  public function ‪__construct($tableName = null)
54  {
55  parent::__construct();
56  if (!empty($tableName)) {
57  $this->‪setItemTableName($tableName);
58  } elseif (empty($this->itemTableName)) {
59  throw new \RuntimeException(\‪TYPO3\CMS\Core\Collection\StaticRecordCollection::class . ' needs a valid itemTableName.', 1330293778);
60  }
61  }
62 
73  public function ‪loadContents()
74  {
75  $entries = $this->‪getCollectedRecords();
76  $this->‪removeAll();
77  foreach ($entries as $entry) {
78  $this->‪add($entry);
79  }
80  }
81 
90  protected function ‪getPersistableDataArray()
91  {
92  return [
93  'title' => $this->‪getTitle(),
94  'description' => $this->‪getDescription(),
95  'items' => $this->‪getItemUidList(true),
96  'type' => 'static',
97  'table_name' => $this->‪getItemTableName()
98  ];
99  }
100 
106  public function ‪add($data)
107  {
108  $this->storage->push($data);
109  }
110 
116  public function ‪addAll(‪CollectionInterface $other)
117  {
118  foreach ($other as $value) {
119  $this->‪add($value);
120  }
121  }
122 
130  public function remove($data)
131  {
132  $offset = 0;
133  foreach ($this->storage as $value) {
134  if ($value == $data) {
135  break;
136  }
137  $offset++;
138  }
139  $this->storage->offsetUnset($offset);
140  }
141 
147  public function ‪removeAll()
148  {
149  $this->storage = new \SplDoublyLinkedList();
150  }
151 
159  protected function ‪getCollectedRecords()
160  {
161  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
162  ->getQueryBuilderForTable(self::$storageTableName);
163  $queryBuilder->getRestrictions()->removeAll();
164  $statement = $queryBuilder->select($this->‪getItemTableName() . '.*')
165  ->from(self::$storageTableName)
166  ->join(
167  self::$storageTableName,
168  'sys_collection_entries',
169  'sys_collection_entries',
170  $queryBuilder->expr()->eq(
171  'sys_collection_entries.uid_local',
172  $queryBuilder->quoteIdentifier(self::$storageTableName . '.uid')
173  )
174  )
175  ->join(
176  'sys_collection_entries',
177  $this->‪getItemTableName(),
178  $this->‪getItemTableName(),
179  $queryBuilder->expr()->eq(
180  'sys_collection_entries.uid_foreign',
181  $queryBuilder->quoteIdentifier($this->getItemTableName() . '.uid')
182  )
183  )
184  ->where(
185  $queryBuilder->expr()->eq(
186  self::$storageTableName . '.uid',
187  $queryBuilder->createNamedParameter($this->getIdentifier(), \PDO::PARAM_INT)
188  )
189  )
190  ->execute();
191  $relatedRecords = [];
192  while ($record = $statement->fetch()) {
193  $relatedRecords[] = $record;
194  }
195  return $relatedRecords;
196  }
197 }
‪TYPO3\CMS\Core\Collection\StaticRecordCollection
Definition: StaticRecordCollection.php:24
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\add
‪add($data)
Definition: StaticRecordCollection.php:106
‪TYPO3\CMS\Core\Collection\AbstractRecordCollection\getTitle
‪string getTitle()
Definition: AbstractRecordCollection.php:189
‪TYPO3\CMS\Core\Collection\EditableCollectionInterface
Definition: EditableCollectionInterface.php:21
‪TYPO3
‪TYPO3\CMS\Core\Collection\AbstractRecordCollection
Definition: AbstractRecordCollection.php:33
‪TYPO3\CMS\Core\Collection\CollectionInterface
Definition: CollectionInterface.php:26
‪TYPO3\CMS\Core\Collection
Definition: AbstractRecordCollection.php:2
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\getPersistableDataArray
‪array getPersistableDataArray()
Definition: StaticRecordCollection.php:90
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\create
‪static TYPO3 CMS Core Collection StaticRecordCollection create(array $collectionRecord, $fillItems=false)
Definition: StaticRecordCollection.php:33
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\removeAll
‪removeAll()
Definition: StaticRecordCollection.php:147
‪TYPO3\CMS\Core\Collection\AbstractRecordCollection\getItemUidList
‪string getItemUidList($includeTableName=true)
Definition: AbstractRecordCollection.php:385
‪TYPO3\CMS\Core\Collection\AbstractRecordCollection\getItemTableName
‪string getItemTableName()
Definition: AbstractRecordCollection.php:239
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\__construct
‪__construct($tableName=null)
Definition: StaticRecordCollection.php:53
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\addAll
‪addAll(CollectionInterface $other)
Definition: StaticRecordCollection.php:116
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\getCollectedRecords
‪array getCollectedRecords()
Definition: StaticRecordCollection.php:159
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Collection\StaticRecordCollection\loadContents
‪loadContents()
Definition: StaticRecordCollection.php:73
‪TYPO3\CMS\Core\Collection\AbstractRecordCollection\setItemTableName
‪setItemTableName($tableName)
Definition: AbstractRecordCollection.php:249
‪TYPO3\CMS\Core\Collection\AbstractRecordCollection\getDescription
‪string getDescription()
Definition: AbstractRecordCollection.php:209