TYPO3 CMS  TYPO3_6-2
Collector.php
Go to the documentation of this file.
1 <?php
3 
21 
25  protected $tableFields;
26 
30  protected $structure = array();
31 
35  protected $structurePaths = array();
36 
40  protected $records = array();
41 
45  public $cObj;
46 
47  public function addRecordData($content, array $configuration = NULL) {
48  $recordIdentifier = $this->cObj->currentRecord;
49  list($tableName) = explode(':', $recordIdentifier);
50  $currentWatcherValue = $this->getCurrentWatcherValue();
51  $position = strpos($currentWatcherValue, '/' . $recordIdentifier);
52 
53  $recordData = $this->filterFields($tableName, $this->cObj->data);
54  $this->records[$recordIdentifier] = $recordData;
55 
56  if ($currentWatcherValue === $recordIdentifier) {
57  $this->structure[$recordIdentifier] = $recordData;
58  $this->structurePaths[$recordIdentifier] = array(array());
59  } elseif(!empty($position)) {
60  $levelIdentifier = substr($currentWatcherValue, 0, $position);
61  $this->addToStructure($levelIdentifier, $recordIdentifier, $recordData);
62  }
63  }
64 
65  public function addFileData($content, array $configuration = NULL) {
66  $currentFile = $this->cObj->getCurrentFile();
67 
68  if ($currentFile instanceof \TYPO3\CMS\Core\Resource\File) {
69  $tableName = 'sys_file';
70  } elseif ($currentFile instanceof \TYPO3\CMS\Core\Resource\FileReference) {
71  $tableName = 'sys_file_reference';
72  } else {
73  return;
74  }
75 
76  $recordData = $this->filterFields($tableName, $currentFile->getProperties());
77  $recordIdentifier = $tableName . ':' . $currentFile->getUid();
78  $this->records[$recordIdentifier] = $recordData;
79 
80  $currentWatcherValue = $this->getCurrentWatcherValue();
81  $levelIdentifier = rtrim($currentWatcherValue, '/');
82  $this->addToStructure($levelIdentifier, $recordIdentifier, $recordData);
83  }
84 
90  protected function filterFields($tableName, array $recordData) {
91  $recordData = array_intersect_key(
92  $recordData,
93  array_flip($this->getTableFields($tableName))
94  );
95  return $recordData;
96  }
97 
98  protected function addToStructure($levelIdentifier, $recordIdentifier, array $recordData) {
99  $steps = explode('/', $levelIdentifier);
100  $structurePaths = array();
102 
103  foreach ($steps as $step) {
104  list($identifier, $fieldName) = explode('.', $step);
105  $structurePaths[] = $identifier;
106  $structurePaths[] = $fieldName;
107  if (!isset($structure[$identifier])) {
108  return;
109  }
110  $structure = &$structure[$identifier];
111  if (!isset($structure[$fieldName]) || !is_array($structure[$fieldName])) {
112  $structure[$fieldName] = array();
113  }
114  $structure = &$structure[$fieldName];
115  }
116 
117  $structure[$recordIdentifier] = $recordData;
118  $this->structurePaths[$recordIdentifier][] = $structurePaths;
119  }
120 
126  public function attachSection($content, array $configuration = NULL) {
127  $section = array(
128  'structure' => $this->structure,
129  'structurePaths' => $this->structurePaths,
130  'records' => $this->records,
131  );
132 
133  $as = (!empty($configuration['as']) ? $configuration['as'] : NULL);
134  $this->getRenderer()->addSection($section, $as);
135  }
136 
141  protected function getTableFields($tableName) {
142  if (!isset($this->tableFields) && !empty($this->getFrontendController()->tmpl->setup['config.']['watcher.']['tableFields.'])) {
143  $this->tableFields = $this->getFrontendController()->tmpl->setup['config.']['watcher.']['tableFields.'];
144  foreach ($this->tableFields as &$fieldList) {
145  $fieldList = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $fieldList, TRUE);
146  }
147  unset($fieldList);
148  }
149 
150  return (!empty($this->tableFields[$tableName]) ? $this->tableFields[$tableName] : array());
151  }
152 
156  protected function getCurrentWatcherValue() {
157  $watcherValue = NULL;
158  if (isset($this->getFrontendController()->register['watcher'])) {
159  $watcherValue = $this->getFrontendController()->register['watcher'];
160  }
161  return $watcherValue;
162  }
163 
167  protected function getRenderer() {
168  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
169  'TYPO3\\CMS\\Core\\Tests\\Functional\\Framework\\Frontend\\Renderer'
170  );
171  }
172 
176  protected function getFrontendController() {
177  return $GLOBALS['TSFE'];
178  }
179 
180 }
addFileData($content, array $configuration=NULL)
Definition: Collector.php:65
attachSection($content, array $configuration=NULL)
Definition: Collector.php:126
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
addToStructure($levelIdentifier, $recordIdentifier, array $recordData)
Definition: Collector.php:98
addRecordData($content, array $configuration=NULL)
Definition: Collector.php:47
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]