TYPO3 CMS  TYPO3_7-6
TYPO3\CMS\Core\Database\RelationHandler Class Reference

Public Member Functions

 getWorkspaceId ()
 
 setWorkspaceId ($workspaceId)
 
 isPurged ()
 
 start ($itemlist, $tablelist, $MMtable='', $MMuid=0, $currentTable='', $conf=[])
 
 setFetchAllFields ($allFields)
 
 setUpdateReferenceIndex ($updateReferenceIndex)
 
 setUseLiveParentIds ($useLiveParentIds)
 
 setUseLiveReferenceIds ($useLiveReferenceIds)
 
 readList ($itemlist, array $configuration)
 
 sortList ($sortby)
 
 readMM ($tableName, $uid)
 
 writeMM ($MM_tableName, $uid, $prependTableName=false)
 
 remapMM ($MM_tableName, $uid, $newUid, $prependTableName=false)
 
 readForeignField ($uid, $conf)
 
 writeForeignField ($conf, $parentUid, $updateToUid=0, $skipSorting=false)
 
 getValueArray ($prependTableName=false)
 
 convertPosNeg ($valueArray, $fTable, $nfTable)
 
 getFromDB ()
 
 readyForInterface ()
 
 countItems ($returnAsArray=true)
 
 convertItemArray ()
 
 purgeItemArray ($workspaceId=null)
 
 processDeletePlaceholder ()
 

Static Public Member Functions

static isOnSymmetricSide ($parentUid, $parentConf, $childRec)
 

Public Attributes

 $registerNonTableValues = false
 
 $tableArray = []
 
 $itemArray = []
 
 $nonTableArray = []
 
 $additionalWhere = []
 
 $checkIfDeleted = true
 
 $dbPaths = []
 
 $firstTable = ''
 
 $secondTable = ''
 
 $MM_is_foreign = false
 
 $MM_oppositeField = ''
 
 $MM_oppositeTable = ''
 
 $MM_oppositeFieldConf = ''
 
 $MM_isMultiTableRelationship = ''
 
 $currentTable
 
 $undeleteRecord
 
 $MM_match_fields = []
 
 $MM_hasUidField
 
 $MM_insert_fields = []
 
 $MM_table_where = ''
 
 $results = []
 

Protected Member Functions

 purgeItemArrayHandler ($purgeCallback)
 
 purgeVersionedIds ($tableName, array $ids)
 
 purgeLiveVersionedIds ($tableName, array $ids)
 
 purgeDeletePlaceholder ($tableName, array $ids)
 
 removeFromItemArray ($tableName, $id)
 
 completeOppositeUsageValues ($tableName, array $referenceValues)
 
 getLiveDefaultId ($tableName, $id)
 
 getDatabaseConnection ()
 

Protected Attributes

 $fetchAllFields = false
 
 $MM_oppositeUsage
 
 $updateReferenceIndex = true
 
 $useLiveParentIds = true
 
 $useLiveReferenceIds = true
 
 $workspaceId
 
 $purged = false
 

Detailed Description

Load database groups (relations) Used to process the relations created by the TCA element types "group" and "select" for database records. Manages MM-relations as well.

Definition at line 28 of file RelationHandler.php.

Member Function Documentation

◆ completeOppositeUsageValues()

TYPO3\CMS\Core\Database\RelationHandler::completeOppositeUsageValues (   $tableName,
array  $referenceValues 
)
protected

Completes MM values to be written by values from the opposite relation. This method used MM insert field or MM match fields if defined.

Parameters
string$tableNameName of the opposite table
array$referenceValuesValues to be written
Returns
array Values to be written, possibly modified

Definition at line 1366 of file RelationHandler.php.

References $GLOBALS.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\writeMM().

◆ convertItemArray()

TYPO3\CMS\Core\Database\RelationHandler::convertItemArray ( )

Converts elements in the local item array to use version ids instead of live ids, if possible. The most common use case is, to call that prior to processing with MM relations in a workspace context. For tha special case, ids on both side of the MM relation must use version ids if available.

Returns
bool Whether items have been converted

Definition at line 1124 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getWorkspaceId(), and TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled().

◆ convertPosNeg()

TYPO3\CMS\Core\Database\RelationHandler::convertPosNeg (   $valueArray,
  $fTable,
  $nfTable 
)

Converts id numbers from negative to positive.

Parameters
array$valueArrayArray of [table]_[id] pairs.
string$fTableForeign table (the one used for positive numbers)
string$nfTableNegative foreign table
Returns
array The array with ID integer values, converted to positive for those where the table name was set but did NOT match the positive foreign table.
Deprecated:
since TYPO3 CMS 7, will be removed in TYPO3 CMS 8

Definition at line 991 of file RelationHandler.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), and TYPO3\CMS\Core\Utility\GeneralUtility\logDeprecatedFunction().

◆ countItems()

TYPO3\CMS\Core\Database\RelationHandler::countItems (   $returnAsArray = true)

Counts the items in $this->itemArray and puts this value in an array by default.

Parameters
bool$returnAsArrayWhether to put the count value in an array
Returns
mixed The plain count as integer or the same inside an array

Definition at line 1083 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getWorkspaceId(), TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), and TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

◆ getDatabaseConnection()

◆ getFromDB()

TYPO3\CMS\Core\Database\RelationHandler::getFromDB ( )

Reads all records from internal tableArray into the internal ->results array where keys are table names and for each table, records are stored with uids as their keys. If $this->fetchAllFields is false you can save a little memory since only uid,pid and a few other fields are selected.

Returns
array

Definition at line 1018 of file RelationHandler.php.

References $GLOBALS, and TYPO3\CMS\Core\Database\RelationHandler\$results.

◆ getLiveDefaultId()

TYPO3\CMS\Core\Database\RelationHandler::getLiveDefaultId (   $tableName,
  $id 
)
protected

Gets the record uid of the live default record. If already pointing to the live record, the submitted record uid is returned.

Parameters
string$tableName
int$id
Returns
int

Definition at line 1395 of file RelationHandler.php.

References TYPO3\CMS\Backend\Utility\BackendUtility\getLiveVersionIdOfRecord(), TYPO3\CMS\Core\Database\RelationHandler\getWorkspaceId(), and TYPO3\CMS\Core\Utility\GeneralUtility\makeInstance().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\readForeignField(), TYPO3\CMS\Core\Database\RelationHandler\readList(), and TYPO3\CMS\Core\Database\RelationHandler\writeForeignField().

◆ getValueArray()

TYPO3\CMS\Core\Database\RelationHandler::getValueArray (   $prependTableName = false)

After initialization you can extract an array of the elements from the object. Use this function for that.

Parameters
bool$prependTableNameIf set, then table names will ALWAYS be prepended (unless its a _NO_TABLE value)
Returns
array A numeric array.

Definition at line 964 of file RelationHandler.php.

◆ getWorkspaceId()

◆ isOnSymmetricSide()

static TYPO3\CMS\Core\Database\RelationHandler::isOnSymmetricSide (   $parentUid,
  $parentConf,
  $childRec 
)
static

Checks, if we're looking from the "other" side, the symmetric side, to a symmetric relation.

Parameters
string$parentUidThe uid of the parent record
array$parentConfThe TCA configuration of the parent field embedding the child records
array$childRecThe record row of the child record
Returns
bool Returns TRUE if looking from the symmetric ("other") side to the relation.

Definition at line 1351 of file RelationHandler.php.

References TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger().

◆ isPurged()

TYPO3\CMS\Core\Database\RelationHandler::isPurged ( )

Whether item array has been purged in this instance.

Returns
bool

Definition at line 244 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$purged.

◆ processDeletePlaceholder()

TYPO3\CMS\Core\Database\RelationHandler::processDeletePlaceholder ( )

Removes items having a delete placeholder from $this->itemArray

Returns
bool Whether items have been purged

Definition at line 1198 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getWorkspaceId(), and TYPO3\CMS\Core\Database\RelationHandler\purgeItemArrayHandler().

◆ purgeDeletePlaceholder()

TYPO3\CMS\Core\Database\RelationHandler::purgeDeletePlaceholder (   $tableName,
array  $ids 
)
protected

◆ purgeItemArray()

TYPO3\CMS\Core\Database\RelationHandler::purgeItemArray (   $workspaceId = null)

◆ purgeItemArrayHandler()

TYPO3\CMS\Core\Database\RelationHandler::purgeItemArrayHandler (   $purgeCallback)
protected

Handles a purge callback on $this->itemArray

Parameters
callable$purgeCallback
Returns
bool Whether items have been purged

Definition at line 1213 of file RelationHandler.php.

References TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), and TYPO3\CMS\Core\Database\RelationHandler\removeFromItemArray().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\processDeletePlaceholder(), and TYPO3\CMS\Core\Database\RelationHandler\purgeItemArray().

◆ purgeLiveVersionedIds()

TYPO3\CMS\Core\Database\RelationHandler::purgeLiveVersionedIds (   $tableName,
array  $ids 
)
protected

Purges ids that are live but have an accordant version.

Parameters
string$tableName
array$ids
Returns
array

Definition at line 1275 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getDatabaseConnection().

◆ purgeVersionedIds()

TYPO3\CMS\Core\Database\RelationHandler::purgeVersionedIds (   $tableName,
array  $ids 
)
protected

Purges ids that are versioned.

Parameters
string$tableName
array$ids
Returns
array

Definition at line 1243 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\getDatabaseConnection().

◆ readForeignField()

TYPO3\CMS\Core\Database\RelationHandler::readForeignField (   $uid,
  $conf 
)

Reads items from a foreign_table, that has a foreign_field (uid of the parent record) and stores the parts in the internal array itemArray and tableArray.

Parameters
int$uidThe uid of the parent record (this value is also on the foreign_table in the foreign_field)
array$confTCA configuration for current field
Returns
void

Definition at line 761 of file RelationHandler.php.

References $GLOBALS, $uid, TYPO3\CMS\Core\Database\RelationHandler\$undeleteRecord, TYPO3\CMS\Backend\Utility\BackendUtility\deleteClause(), TYPO3\CMS\Core\Database\RelationHandler\getLiveDefaultId(), TYPO3\CMS\Core\Database\RelationHandler\getWorkspaceId(), and TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ readList()

TYPO3\CMS\Core\Database\RelationHandler::readList (   $itemlist,
array  $configuration 
)

Explodes the item list and stores the parts in the internal arrays itemArray and tableArray from MM records.

Parameters
string$itemlistItem list
array$configurationParent field configuration
Returns
void

Definition at line 388 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$firstTable, $GLOBALS, TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), TYPO3\CMS\Core\Database\RelationHandler\getLiveDefaultId(), TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ readMM()

TYPO3\CMS\Core\Database\RelationHandler::readMM (   $tableName,
  $uid 
)

Reads the record tablename/id into the internal arrays itemArray and tableArray from MM records. You can call this function after start if you supply no list to start()

Parameters
string$tableNameMM Tablename
int$uidLocal UID
Returns
void

Definition at line 505 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$additionalWhere, TYPO3\CMS\Core\Database\RelationHandler\$firstTable, $GLOBALS, TYPO3\CMS\Core\Database\RelationHandler\$MM_oppositeTable, and $uid.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ readyForInterface()

TYPO3\CMS\Core\Database\RelationHandler::readyForInterface ( )

Prepare items from itemArray to be transferred to the TCEforms interface (as a comma list)

Returns
string

Definition at line 1058 of file RelationHandler.php.

References $GLOBALS, TYPO3\CMS\Core\Utility\GeneralUtility\fixed_lgd_cs(), and TYPO3\CMS\Backend\Utility\BackendUtility\getRecordTitle().

◆ remapMM()

TYPO3\CMS\Core\Database\RelationHandler::remapMM (   $MM_tableName,
  $uid,
  $newUid,
  $prependTableName = false 
)

Remaps MM table elements from one local uid to another Does NOT update the reference index for you, must be called subsequently to do that!

Parameters
string$MM_tableNameMM table name
int$uidLocal, current UID
int$newUidLocal, new UID
bool$prependTableNameIf set, then table names will always be written.
Returns
void

Definition at line 721 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$additionalWhere, $GLOBALS, TYPO3\CMS\Core\Database\RelationHandler\$MM_isMultiTableRelationship, and $uid.

◆ removeFromItemArray()

TYPO3\CMS\Core\Database\RelationHandler::removeFromItemArray (   $tableName,
  $id 
)
protected

◆ setFetchAllFields()

TYPO3\CMS\Core\Database\RelationHandler::setFetchAllFields (   $allFields)

Sets $fetchAllFields

Parameters
bool$allFieldsenables fetching of all fields in getFromDB()

Definition at line 349 of file RelationHandler.php.

◆ setUpdateReferenceIndex()

TYPO3\CMS\Core\Database\RelationHandler::setUpdateReferenceIndex (   $updateReferenceIndex)

Sets whether the reference index shall be updated.

Parameters
bool$updateReferenceIndexWhether the reference index shall be updated
Returns
void

Definition at line 360 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$updateReferenceIndex.

◆ setUseLiveParentIds()

TYPO3\CMS\Core\Database\RelationHandler::setUseLiveParentIds (   $useLiveParentIds)
Parameters
bool$useLiveParentIds

Definition at line 368 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$useLiveParentIds.

◆ setUseLiveReferenceIds()

TYPO3\CMS\Core\Database\RelationHandler::setUseLiveReferenceIds (   $useLiveReferenceIds)
Parameters
bool$useLiveReferenceIds

Definition at line 376 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$useLiveReferenceIds.

◆ setWorkspaceId()

TYPO3\CMS\Core\Database\RelationHandler::setWorkspaceId (   $workspaceId)

Sets the current workspace id.

Parameters
int$workspaceId

Definition at line 234 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$workspaceId.

◆ sortList()

TYPO3\CMS\Core\Database\RelationHandler::sortList (   $sortby)

Does a sorting on $this->itemArray depending on a default sortby field. This is only used for automatic sorting of comma separated lists. This function is only relevant for data that is stored in comma separated lists!

Parameters
string$sortbyThe default_sortby field/command (e.g. 'price DESC')
Returns
void

Definition at line 470 of file RelationHandler.php.

References $a, and $GLOBALS.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ start()

TYPO3\CMS\Core\Database\RelationHandler::start (   $itemlist,
  $tablelist,
  $MMtable = '',
  $MMuid = 0,
  $currentTable = '',
  $conf = [] 
)

Initialization of the class.

Parameters
string$itemlistList of group/select items
string$tablelistComma list of tables, first table takes priority if no table is set for an entry in the list.
string$MMtableName of a MM table.
int$MMuidLocal UID for MM lookup
string$currentTableCurrent table name
array$confTCA configuration for current field
Returns
void

Definition at line 260 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$currentTable, $GLOBALS, TYPO3\CMS\Core\Database\RelationHandler\$MM_match_fields, TYPO3\CMS\Core\Database\RelationHandler\$MM_oppositeField, TYPO3\CMS\Core\Database\RelationHandler\$MM_oppositeTable, TYPO3\CMS\Core\Database\RelationHandler\purgeItemArray(), TYPO3\CMS\Core\Database\RelationHandler\readForeignField(), TYPO3\CMS\Core\Database\RelationHandler\readList(), TYPO3\CMS\Core\Database\RelationHandler\readMM(), TYPO3\CMS\Core\Database\RelationHandler\sortList(), and TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode().

◆ writeForeignField()

TYPO3\CMS\Core\Database\RelationHandler::writeForeignField (   $conf,
  $parentUid,
  $updateToUid = 0,
  $skipSorting = false 
)

Write the sorting values to a foreign_table, that has a foreign_field (uid of the parent record)

Parameters
array$confTCA configuration for current field
int$parentUidThe uid of the parent record
int$updateToUidIf this is larger than zero it will be used as foreign UID instead of the given $parentUid (on Copy)
bool$skipSortingDo not update the sorting columns, this could happen for imported values
Returns
void

Definition at line 847 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$currentTable, $GLOBALS, $uid, TYPO3\CMS\Core\Utility\MathUtility\canBeInterpretedAsInteger(), TYPO3\CMS\Core\Type\Enumeration\cast(), TYPO3\CMS\Core\Database\RelationHandler\getLiveDefaultId(), TYPO3\CMS\Backend\Utility\BackendUtility\getRecord(), TYPO3\CMS\Backend\Utility\BackendUtility\isTableWorkspaceEnabled(), and TYPO3\CMS\Core\Versioning\VersionState\NEW_PLACEHOLDER_VERSION.

◆ writeMM()

TYPO3\CMS\Core\Database\RelationHandler::writeMM (   $MM_tableName,
  $uid,
  $prependTableName = false 
)

Writes the internal itemArray to MM table:

Parameters
string$MM_tableNameMM table name
int$uidLocal UID
bool$prependTableNameIf set, then table names will always be written.
Returns
void

Definition at line 568 of file RelationHandler.php.

References TYPO3\CMS\Core\Database\RelationHandler\$additionalWhere, TYPO3\CMS\Core\Database\RelationHandler\$currentTable, TYPO3\CMS\Core\Database\RelationHandler\$firstTable, $GLOBALS, TYPO3\CMS\Core\Database\RelationHandler\$MM_insert_fields, $uid, and TYPO3\CMS\Core\Database\RelationHandler\completeOppositeUsageValues().

Member Data Documentation

◆ $additionalWhere

TYPO3\CMS\Core\Database\RelationHandler::$additionalWhere = []

◆ $checkIfDeleted

TYPO3\CMS\Core\Database\RelationHandler::$checkIfDeleted = true

Definition at line 76 of file RelationHandler.php.

◆ $currentTable

◆ $dbPaths

TYPO3\CMS\Core\Database\RelationHandler::$dbPaths = []

Definition at line 81 of file RelationHandler.php.

◆ $fetchAllFields

TYPO3\CMS\Core\Database\RelationHandler::$fetchAllFields = false
protected

Definition at line 35 of file RelationHandler.php.

◆ $firstTable

TYPO3\CMS\Core\Database\RelationHandler::$firstTable = ''

◆ $itemArray

TYPO3\CMS\Core\Database\RelationHandler::$itemArray = []

Definition at line 57 of file RelationHandler.php.

◆ $MM_hasUidField

TYPO3\CMS\Core\Database\RelationHandler::$MM_hasUidField

Definition at line 161 of file RelationHandler.php.

◆ $MM_insert_fields

TYPO3\CMS\Core\Database\RelationHandler::$MM_insert_fields = []

◆ $MM_is_foreign

TYPO3\CMS\Core\Database\RelationHandler::$MM_is_foreign = false

Definition at line 103 of file RelationHandler.php.

◆ $MM_isMultiTableRelationship

TYPO3\CMS\Core\Database\RelationHandler::$MM_isMultiTableRelationship = ''

◆ $MM_match_fields

TYPO3\CMS\Core\Database\RelationHandler::$MM_match_fields = []

Definition at line 154 of file RelationHandler.php.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ $MM_oppositeField

TYPO3\CMS\Core\Database\RelationHandler::$MM_oppositeField = ''

Definition at line 110 of file RelationHandler.php.

Referenced by TYPO3\CMS\Core\Database\RelationHandler\start().

◆ $MM_oppositeFieldConf

TYPO3\CMS\Core\Database\RelationHandler::$MM_oppositeFieldConf = ''

Definition at line 124 of file RelationHandler.php.

◆ $MM_oppositeTable

TYPO3\CMS\Core\Database\RelationHandler::$MM_oppositeTable = ''

◆ $MM_oppositeUsage

TYPO3\CMS\Core\Database\RelationHandler::$MM_oppositeUsage
protected

Definition at line 182 of file RelationHandler.php.

◆ $MM_table_where

TYPO3\CMS\Core\Database\RelationHandler::$MM_table_where = ''

Definition at line 175 of file RelationHandler.php.

◆ $nonTableArray

TYPO3\CMS\Core\Database\RelationHandler::$nonTableArray = []

Definition at line 64 of file RelationHandler.php.

◆ $purged

TYPO3\CMS\Core\Database\RelationHandler::$purged = false
protected

◆ $registerNonTableValues

TYPO3\CMS\Core\Database\RelationHandler::$registerNonTableValues = false

Definition at line 42 of file RelationHandler.php.

◆ $results

TYPO3\CMS\Core\Database\RelationHandler::$results = []

◆ $secondTable

TYPO3\CMS\Core\Database\RelationHandler::$secondTable = ''

Definition at line 95 of file RelationHandler.php.

◆ $tableArray

TYPO3\CMS\Core\Database\RelationHandler::$tableArray = []

Definition at line 50 of file RelationHandler.php.

◆ $undeleteRecord

TYPO3\CMS\Core\Database\RelationHandler::$undeleteRecord

◆ $updateReferenceIndex

TYPO3\CMS\Core\Database\RelationHandler::$updateReferenceIndex = true
protected

◆ $useLiveParentIds

TYPO3\CMS\Core\Database\RelationHandler::$useLiveParentIds = true
protected

◆ $useLiveReferenceIds

TYPO3\CMS\Core\Database\RelationHandler::$useLiveReferenceIds = true
protected

◆ $workspaceId