TYPO3 CMS  TYPO3_7-6
ContentController.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 {
26  protected $contentRepository;
27 
31  protected $defaultViewObjectName = \TYPO3\CMS\Extbase\Mvc\View\JsonView::class;
32 
37  protected $dataMapFactory;
38 
42  public function listAction()
43  {
44  $content = $this->contentRepository->findAll();
45  $value[$this->getRuntimeIdentifier()] = $this->getStructure($content);
46  // this is required so we don't try to json_encode content of the image
47  $this->view->setConfiguration(['value' => [
48  '_descendAll' => [
49  '_descendAll' => [
50  '_descendAll' => [
51  '_descendAll' => [
52  '_descendAll' => [
53  '_exclude' => ['contents']
54  ]
55  ]
56  ]
57  ]
58  ]
59  ]]);
60  $this->view->assign('value', $value);
61  }
62 
68  public function processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)
69  {
70  try {
71  parent::processRequest($request, $response);
72  } catch (\TYPO3\CMS\Extbase\Property\Exception $exception) {
73  throw new \RuntimeException(
74  $this->getRuntimeIdentifier() . ': ' . $exception->getMessage() . ' (' . $exception->getCode() . ')',
75  1476122223
76  );
77  }
78  }
79 
84  protected function getStructure($iterator)
85  {
86  $structure = [];
87 
88  if (!$iterator instanceof \Iterator) {
89  $iterator = [$iterator];
90  }
91 
92  foreach ($iterator as $entity) {
93  $dataMap = $this->dataMapFactory->buildDataMap(get_class($entity));
94  $tableName = $dataMap->getTableName();
95  $identifier = $tableName . ':' . $entity->getUid();
97 
98  $structureItem = [];
99  foreach ($properties as $propertyName => $propertyValue) {
100  $columnMap = $dataMap->getColumnMap($propertyName);
101  if ($columnMap !== null) {
102  $propertyName = $columnMap->getColumnName();
103  }
104  if ($propertyValue instanceof \Iterator) {
105  $structureItem[$propertyName] = $this->getStructure($propertyValue);
106  } else {
107  $structureItem[$propertyName] = $propertyValue;
108  }
109  }
110  //let's flatten the structure and put file reference properties level up, so we can use StructureHasRecordConstraint
111  if ($entity instanceof \TYPO3\CMS\Extbase\Domain\Model\FileReference
112  && isset($structureItem['originalResource'])
113  && $structureItem['originalResource'] instanceof \TYPO3\CMS\Core\Resource\FileReference
114  ) {
115  $structureItem = $structureItem['originalResource']->getProperties();
116  }
117  $structure[$identifier] = $structureItem;
118  }
119 
120  return $structure;
121  }
122 
126  protected function getRuntimeIdentifier()
127  {
128  $arguments = [];
129  foreach ($this->request->getArguments() as $argumentName => $argumentValue) {
130  $arguments[] = $argumentName . '=' . $argumentValue;
131  }
132  return $this->request->getControllerActionName() . '(' . implode(', ', $arguments) . ')';
133  }
134 }
processRequest(\TYPO3\CMS\Extbase\Mvc\RequestInterface $request, \TYPO3\CMS\Extbase\Mvc\ResponseInterface $response)