TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
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)
 
 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)
 
 getConnectionForTableName (string $tableName)
 

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 30 of file RelationHandler.php.

Member Function Documentation

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 1637 of file RelationHandler.php.

References $GLOBALS.

Referenced by RelationHandler\writeMM().

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 1343 of file RelationHandler.php.

References RelationHandler\getWorkspaceId(), and BackendUtility\isTableWorkspaceEnabled().

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 1302 of file RelationHandler.php.

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 1223 of file RelationHandler.php.

References $fields, $GLOBALS, RelationHandler\$results, RelationHandler\getConnectionForTableName(), GeneralUtility\intExplode(), QueryHelper\stripLogicalOperatorPrefix(), and GeneralUtility\trimExplode().

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 1666 of file RelationHandler.php.

References BackendUtility\getLiveVersionIdOfRecord().

Referenced by RelationHandler\readForeignField(), RelationHandler\readList(), and RelationHandler\writeForeignField().

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 1197 of file RelationHandler.php.

getWorkspaceId ( )

Gets the current workspace id.

Returns
int

Definition at line 223 of file RelationHandler.php.

References $GLOBALS, and RelationHandler\$workspaceId.

Referenced by RelationHandler\convertItemArray(), RelationHandler\processDeletePlaceholder(), and RelationHandler\purgeItemArray().

static 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 1622 of file RelationHandler.php.

References MathUtility\canBeInterpretedAsInteger().

isPurged ( )

Whether item array has been purged in this instance.

Returns
bool

Definition at line 246 of file RelationHandler.php.

References RelationHandler\$purged.

processDeletePlaceholder ( )

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

Returns
bool Whether items have been purged

Definition at line 1417 of file RelationHandler.php.

References RelationHandler\getWorkspaceId(), and RelationHandler\purgeItemArrayHandler().

purgeDeletePlaceholder (   $tableName,
array  $ids 
)
protected

Purges ids that have a delete placeholder

Parameters
string$tableName
array$ids
Returns
array

Definition at line 1555 of file RelationHandler.php.

References Enumeration\cast(), VersionState\DELETE_PLACEHOLDER, and RelationHandler\getConnectionForTableName().

purgeItemArray (   $workspaceId = null)
Parameters
NULL | int$workspaceId
Returns
bool Whether items have been purged

Definition at line 1391 of file RelationHandler.php.

References RelationHandler\$workspaceId, RelationHandler\getWorkspaceId(), and RelationHandler\purgeItemArrayHandler().

Referenced by RelationHandler\start().

purgeItemArrayHandler (   $purgeCallback)
protected

Handles a purge callback on $this->itemArray

Parameters
callable$purgeCallback
Returns
bool Whether items have been purged

Definition at line 1432 of file RelationHandler.php.

References BackendUtility\isTableWorkspaceEnabled(), and RelationHandler\removeFromItemArray().

Referenced by RelationHandler\processDeletePlaceholder(), and RelationHandler\purgeItemArray().

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 1508 of file RelationHandler.php.

References RelationHandler\getConnectionForTableName().

purgeVersionedIds (   $tableName,
array  $ids 
)
protected

Purges ids that are versioned.

Parameters
string$tableName
array$ids
Returns
array

Definition at line 1462 of file RelationHandler.php.

References RelationHandler\getConnectionForTableName().

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 909 of file RelationHandler.php.

References $GLOBALS, RelationHandler\$undeleteRecord, RelationHandler\getConnectionForTableName(), RelationHandler\getLiveDefaultId(), BackendUtility\isTableWorkspaceEnabled(), GeneralUtility\makeInstance(), and QueryHelper\parseOrderBy().

Referenced by RelationHandler\start().

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 390 of file RelationHandler.php.

References RelationHandler\$firstTable, $GLOBALS, MathUtility\canBeInterpretedAsInteger(), RelationHandler\getLiveDefaultId(), BackendUtility\isTableWorkspaceEnabled(), and GeneralUtility\trimExplode().

Referenced by RelationHandler\start().

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 524 of file RelationHandler.php.

References RelationHandler\$firstTable, RelationHandler\$MM_oppositeTable, RelationHandler\getConnectionForTableName(), and QueryHelper\stripLogicalOperatorPrefix().

Referenced by RelationHandler\start().

readyForInterface ( )

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

Returns
string

Definition at line 1277 of file RelationHandler.php.

References $GLOBALS, and BackendUtility\getRecordTitle().

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 855 of file RelationHandler.php.

References RelationHandler\$MM_isMultiTableRelationship, RelationHandler\getConnectionForTableName(), and QueryHelper\stripLogicalOperatorPrefix().

removeFromItemArray (   $tableName,
  $id 
)
protected

Definition at line 1603 of file RelationHandler.php.

Referenced by RelationHandler\purgeItemArrayHandler().

setFetchAllFields (   $allFields)

Sets $fetchAllFields

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

Definition at line 351 of file RelationHandler.php.

setUpdateReferenceIndex (   $updateReferenceIndex)

Sets whether the reference index shall be updated.

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

Definition at line 362 of file RelationHandler.php.

References RelationHandler\$updateReferenceIndex.

setUseLiveParentIds (   $useLiveParentIds)
Parameters
bool$useLiveParentIds

Definition at line 370 of file RelationHandler.php.

References RelationHandler\$useLiveParentIds.

setUseLiveReferenceIds (   $useLiveReferenceIds)
Parameters
bool$useLiveReferenceIds

Definition at line 378 of file RelationHandler.php.

References RelationHandler\$useLiveReferenceIds.

setWorkspaceId (   $workspaceId)

Sets the current workspace id.

Parameters
int$workspaceId

Definition at line 236 of file RelationHandler.php.

References RelationHandler\$workspaceId.

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 472 of file RelationHandler.php.

References RelationHandler\getConnectionForTableName(), GeneralUtility\intExplode(), and QueryHelper\parseOrderBy().

Referenced by RelationHandler\start().

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 262 of file RelationHandler.php.

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

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 1048 of file RelationHandler.php.

References RelationHandler\$currentTable, $fields, $GLOBALS, MathUtility\canBeInterpretedAsInteger(), Enumeration\cast(), RelationHandler\getConnectionForTableName(), RelationHandler\getLiveDefaultId(), BackendUtility\getRecord(), BackendUtility\isTableWorkspaceEnabled(), VersionState\NEW_PLACEHOLDER_VERSION, and QueryHelper\parseOrderBy().

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 611 of file RelationHandler.php.

References RelationHandler\$additionalWhere, RelationHandler\$currentTable, RelationHandler\$firstTable, RelationHandler\$MM_insert_fields, RelationHandler\completeOppositeUsageValues(), RelationHandler\getConnectionForTableName(), and QueryHelper\stripLogicalOperatorPrefix().

Member Data Documentation

$additionalWhere = []

Definition at line 71 of file RelationHandler.php.

Referenced by RelationHandler\writeMM().

$checkIfDeleted = true

Definition at line 78 of file RelationHandler.php.

$dbPaths = []

Definition at line 83 of file RelationHandler.php.

$fetchAllFields = false
protected

Definition at line 37 of file RelationHandler.php.

$firstTable = ''
$itemArray = []

Definition at line 59 of file RelationHandler.php.

$MM_hasUidField

Definition at line 163 of file RelationHandler.php.

$MM_insert_fields = []

Definition at line 170 of file RelationHandler.php.

Referenced by RelationHandler\writeMM().

$MM_is_foreign = false

Definition at line 105 of file RelationHandler.php.

$MM_isMultiTableRelationship = ''

Definition at line 133 of file RelationHandler.php.

Referenced by RelationHandler\remapMM().

$MM_match_fields = []

Definition at line 156 of file RelationHandler.php.

Referenced by RelationHandler\start().

$MM_oppositeField = ''

Definition at line 112 of file RelationHandler.php.

Referenced by RelationHandler\start().

$MM_oppositeFieldConf = ''

Definition at line 126 of file RelationHandler.php.

$MM_oppositeTable = ''

Definition at line 119 of file RelationHandler.php.

Referenced by RelationHandler\readMM(), and RelationHandler\start().

$MM_oppositeUsage
protected

Definition at line 184 of file RelationHandler.php.

$MM_table_where = ''

Definition at line 177 of file RelationHandler.php.

$nonTableArray = []

Definition at line 66 of file RelationHandler.php.

$purged = false
protected

Definition at line 209 of file RelationHandler.php.

Referenced by RelationHandler\isPurged().

$registerNonTableValues = false

Definition at line 44 of file RelationHandler.php.

$results = []

Definition at line 216 of file RelationHandler.php.

Referenced by RelationHandler\getFromDB().

$secondTable = ''

Definition at line 97 of file RelationHandler.php.

$tableArray = []

Definition at line 52 of file RelationHandler.php.

$undeleteRecord

Definition at line 148 of file RelationHandler.php.

Referenced by RelationHandler\readForeignField().

$updateReferenceIndex = true
protected

Definition at line 189 of file RelationHandler.php.

Referenced by RelationHandler\setUpdateReferenceIndex().

$useLiveParentIds = true
protected

Definition at line 194 of file RelationHandler.php.

Referenced by RelationHandler\setUseLiveParentIds().

$useLiveReferenceIds = true
protected

Definition at line 199 of file RelationHandler.php.

Referenced by RelationHandler\setUseLiveReferenceIds().