TYPO3 CMS  TYPO3_7-6
AbstractRepository.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 
21 {
25  protected $table = '';
26 
30  protected $factory;
31 
35  protected $typeField = '';
36 
40  protected $type = '';
41 
45  public function __construct()
46  {
47  $this->factory = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
48  }
49 
57  public function add($object)
58  {
59  }
60 
68  public function remove($object)
69  {
70  }
71 
80  public function replace($existingObject, $newObject)
81  {
82  }
83 
90  public function update($modifiedObject)
91  {
92  }
93 
100  public function getAddedObjects()
101  {
102  }
103 
110  public function getRemovedObjects()
111  {
112  }
113 
120  public function findAll()
121  {
122  $itemList = [];
123  $whereClause = '1=1';
124  if ($this->type != '') {
125  $whereClause .= ' AND ' . $this->typeField . ' = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($this->type, $this->table) . ' ';
126  }
127  $whereClause .= $this->getWhereClauseForEnabledFields();
128  $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', $this->table, $whereClause);
129  while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
130  $itemList[] = $this->createDomainObject($row);
131  }
132  $GLOBALS['TYPO3_DB']->sql_free_result($res);
133  return $itemList;
134  }
135 
143  abstract protected function createDomainObject(array $databaseRow);
144 
151  public function countAll()
152  {
153  }
154 
162  public function removeAll()
163  {
164  }
165 
176  public function findByUid($uid)
177  {
178  if (!\TYPO3\CMS\Core\Utility\MathUtility::canBeInterpretedAsInteger($uid)) {
179  throw new \InvalidArgumentException('The UID has to be an integer. UID given: "' . $uid . '"', 1316779798);
180  }
181  $row = $GLOBALS['TYPO3_DB']->exec_SELECTgetSingleRow('*', $this->table, 'uid=' . (int)$uid . $this->getWhereClauseForEnabledFields());
182  if (empty($row) || !is_array($row)) {
183  throw new \RuntimeException('Could not find row with UID "' . $uid . '" in table "' . $this->table . '"', 1314354065);
184  }
185  return $this->createDomainObject($row);
186  }
187 
194  protected function getWhereClauseForEnabledFields()
195  {
196  if ($this->getEnvironmentMode() === 'FE' && $GLOBALS['TSFE']->sys_page) {
197  // frontend context
198  $whereClause = $GLOBALS['TSFE']->sys_page->enableFields($this->table);
199  $whereClause .= $GLOBALS['TSFE']->sys_page->deleteClause($this->table);
200  } else {
201  // backend context
203  $whereClause .= \TYPO3\CMS\Backend\Utility\BackendUtility::deleteClause($this->table);
204  }
205  return $whereClause;
206  }
207 
222  public function setDefaultOrderings(array $defaultOrderings)
223  {
224  throw new \BadMethodCallException('Repository does not support the setDefaultOrderings() method.', 1313185906);
225  }
226 
236  public function setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)
237  {
238  throw new \BadMethodCallException('Repository does not support the setDefaultQuerySettings() method.', 1313185907);
239  }
240 
248  public function createQuery()
249  {
250  throw new \BadMethodCallException('Repository does not support the createQuery() method.', 1313185908);
251  }
252 
260  public function findByIdentifier($identifier)
261  {
262  return $this->findByUid($identifier);
263  }
264 
274  public function __call($method, $arguments)
275  {
276  throw new \BadMethodCallException('Repository method "' . $method . '" is not implemented.', 1378918410);
277  }
278 
285  public function getEntityClassName()
286  {
287  return $this->objectType;
288  }
289 
296  protected function getEnvironmentMode()
297  {
298  return TYPO3_MODE;
299  }
300 
304  protected function getDatabaseConnection()
305  {
306  return $GLOBALS['TYPO3_DB'];
307  }
308 }
static BEenableFields($table, $inv=false)
$uid
Definition: server.php:38
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
setDefaultQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $defaultQuerySettings)
static deleteClause($table, $tableAlias='')