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