TYPO3 CMS  TYPO3_7-6
RecordCollectionRepository.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 
18 
23 {
27  const TYPE_Static = 'static';
28 
34  protected $table = 'sys_collection';
35 
39  protected $typeField = 'type';
40 
44  protected $tableField = 'table_name';
45 
52  public function findByUid($uid)
53  {
54  $result = null;
55  $data = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
56  '*',
57  $this->table,
58  'uid=' . (int)$uid . BackendUtility::deleteClause($this->table)
59  );
60  if (is_array($data)) {
61  $result = $this->createDomainObject($data);
62  }
63  return $result;
64  }
65 
71  public function findAll()
72  {
73  return $this->queryMultipleRecords();
74  }
75 
82  public function findByTableName($tableName)
83  {
84  $conditions = [
85  $this->tableField . '=' . $this->getDatabaseConnection()->fullQuoteStr($tableName, $this->table)
86  ];
87  return $this->queryMultipleRecords($conditions);
88  }
89 
96  public function findByType($type)
97  {
98  $conditions = [
99  $this->typeField . '=' . $this->getDatabaseConnection()->fullQuoteStr($type, $this->table)
100  ];
101  return $this->queryMultipleRecords($conditions);
102  }
103 
111  public function findByTypeAndTableName($type, $tableName)
112  {
113  $conditions = [
114  $this->typeField . '=' . $this->getDatabaseConnection()->fullQuoteStr($type, $this->table),
115  $this->tableField . '=' . $this->getDatabaseConnection()->fullQuoteStr($tableName, $this->table)
116  ];
117  return $this->queryMultipleRecords($conditions);
118  }
119 
126  public function deleteByUid($uid)
127  {
128  $this->getDatabaseConnection()->exec_UPDATEquery($this->table, 'uid=' . (int)$uid, ['deleted' => 1, 'tstamp' => $GLOBALS['EXEC_TIME']]);
129  }
130 
137  protected function queryMultipleRecords(array $conditions = [])
138  {
139  $result = null;
140  if (!empty($conditions)) {
141  $conditionsWhereClause = implode(' AND ', $conditions);
142  } else {
143  $conditionsWhereClause = '1=1';
144  }
145  $data = $this->getDatabaseConnection()->exec_SELECTgetRows(
146  '*',
147  $this->table,
148  $conditionsWhereClause . BackendUtility::deleteClause($this->table)
149  );
150  if ($data !== null) {
151  $result = $this->createMultipleDomainObjects($data);
152  }
153  return $result;
154  }
155 
163  protected function createDomainObject(array $record)
164  {
165  switch ($record['type']) {
166  case self::TYPE_Static:
167  $collection = StaticRecordCollection::create($record);
168  break;
169  default:
170  throw new \RuntimeException('Unknown record collection type "' . $record['type'], 1328646798);
171  }
172  return $collection;
173  }
174 
181  protected function createMultipleDomainObjects(array $data)
182  {
183  $collections = [];
184  foreach ($data as $collection) {
185  $collections[] = $this->createDomainObject($collection);
186  }
187  return $collections;
188  }
189 
195  protected function getDatabaseConnection()
196  {
197  return $GLOBALS['TYPO3_DB'];
198  }
199 }
static create(array $collectionRecord, $fillItems=false)
$uid
Definition: server.php:38
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static deleteClause($table, $tableAlias='')