TYPO3 CMS  TYPO3_7-6
CategoryCollection.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 
24 {
35  public static function create(array $collectionRecord, $fillItems = false)
36  {
38  $collection = GeneralUtility::makeInstance(__CLASS__,
39  $collectionRecord['table_name'],
40  $collectionRecord['field_name']
41  );
42  $collection->fromArray($collectionRecord);
43  if ($fillItems) {
44  $collection->loadContents();
45  }
46  return $collection;
47  }
48 
63  public static function load($id, $fillItems = false, $tableName = '', $fieldName = '')
64  {
65  $collectionRecord = self::getDatabaseConnection()->exec_SELECTgetSingleRow(
66  '*',
67  static::$storageTableName,
68  'uid = ' . (int)$id . self::getTypoScriptFrontendController()->sys_page->enableFields(static::$storageTableName)
69  );
70  $collectionRecord['table_name'] = $tableName;
71  $collectionRecord['field_name'] = $fieldName;
72  return self::create($collectionRecord, $fillItems);
73  }
74 
85  protected function getCollectedRecords()
86  {
87  $db = self::getDatabaseConnection();
88 
89  $relatedRecords = [];
90  // Assemble where clause
91  $where = 'AND ' . self::$storageTableName . '.uid = ' . (int)$this->getIdentifier();
92  // Add condition on tablenames fields
93  $where .= ' AND sys_category_record_mm.tablenames = ' . $db->fullQuoteStr(
94  $this->getItemTableName(),
95  'sys_category_record_mm'
96  );
97  // Add condition on fieldname field
98  $where .= ' AND sys_category_record_mm.fieldname = ' . $db->fullQuoteStr(
99  $this->getRelationFieldName(),
100  'sys_category_record_mm'
101  );
102  // Add enable fields for item table
103  $tsfe = self::getTypoScriptFrontendController();
104  $where .= $tsfe->sys_page->enableFields($this->getItemTableName());
105  // If language handling is defined for item table, add language condition
106  if (isset($GLOBALS['TCA'][$this->getItemTableName()]['ctrl']['languageField'])) {
107  // Consider default or "all" language
108  $languageField = $this->getItemTableName() . '.' . $GLOBALS['TCA'][$this->getItemTableName()]['ctrl']['languageField'];
109  $languageCondition = $languageField . ' IN (0, -1)';
110  // If not in default language, also consider items in current language with no original
111  if ($tsfe->sys_language_content > 0) {
112  $languageCondition .= '
113  OR (' . $languageField . ' = ' . (int)$tsfe->sys_language_content . '
114  AND ' . $this->getItemTableName() . '.' .
115  $GLOBALS['TCA'][$this->getItemTableName()]['ctrl']['transOrigPointerField'] . ' = 0)
116  ';
117  }
118  $where .= ' AND (' . $languageCondition . ')';
119  }
120  // Get the related records from the database
121  $resource = $db->exec_SELECT_mm_query(
122  $this->getItemTableName() . '.*',
123  self::$storageTableName,
124  'sys_category_record_mm',
125  $this->getItemTableName(),
126  $where
127  );
128 
129  if ($resource) {
130  while ($record = $db->sql_fetch_assoc($resource)) {
131  // Overlay the record for workspaces
132  $tsfe->sys_page->versionOL(
133  $this->getItemTableName(),
134  $record
135  );
136  // Overlay the record for translations
137  if (is_array($record) && $tsfe->sys_language_contentOL) {
138  if ($this->getItemTableName() === 'pages') {
139  $record = $tsfe->sys_page->getPageOverlay($record);
140  } else {
141  $record = $tsfe->sys_page->getRecordOverlay(
142  $this->getItemTableName(),
143  $record,
144  $tsfe->sys_language_content,
145  $tsfe->sys_language_contentOL
146  );
147  }
148  }
149  // Record may have been unset during the overlay process
150  if (is_array($record)) {
151  $relatedRecords[] = $record;
152  }
153  }
154  $db->sql_free_result($resource);
155  }
156  return $relatedRecords;
157  }
158 
164  protected static function getTypoScriptFrontendController()
165  {
166  return $GLOBALS['TSFE'];
167  }
168 
174  protected static function getDatabaseConnection()
175  {
176  return $GLOBALS['TYPO3_DB'];
177  }
178 }
static load($id, $fillItems=false, $tableName='', $fieldName='')
static create(array $collectionRecord, $fillItems=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']