/** * Writes remapped foreign field (IRRE). * * @param t3lib_loadDBGroup $dbAnalysis Instance that holds the sorting order of child records * @param array $configuration The TCA field configuration * @param integer $parentId The uid of the parent record * @return void */ public function writeRemappedForeignField(t3lib_loadDBGroup $dbAnalysis, array $configuration, $parentId) { foreach ($dbAnalysis->itemArray as &$item) { if (isset($this->remappedIds[$item['table']][$item['id']])) { $item['id'] = $this->remappedIds[$item['table']][$item['id']]; } } $dbAnalysis->writeForeignField($configuration, $parentId); }
/** * Write the sorting values to a foreign_table, that has a foreign_field (uid of the parent record) * * @param array $conf: TCA configuration for current field * @param integer $parentUid: The uid of the parent record * @param boolean $updateToUid: Whether to update the foreign field with the $parentUid (on Copy) * @param boolean $skipSorting: Do not update the sorting columns, this could happen for imported values * @return void */ function writeForeignField($conf, $parentUid, $updateToUid = 0, $skipSorting = false) { $c = 0; $foreign_table = $conf['foreign_table']; $foreign_field = $conf['foreign_field']; $symmetric_field = $conf['symmetric_field']; $foreign_table_field = $conf['foreign_table_field']; // if there are table items and we have a proper $parentUid if (t3lib_div::testInt($parentUid) && count($this->tableArray)) { // if updateToUid is not a positive integer, set it to '0', so it will be ignored if (!(t3lib_div::testInt($updateToUid) && $updateToUid > 0)) { $updateToUid = 0; } $fields = 'uid,' . $foreign_field . ($symmetric_field ? ',' . $symmetric_field : ''); // update all items foreach ($this->itemArray as $val) { $uid = $val['id']; $table = $val['table']; // fetch the current (not overwritten) relation record if we should handle symmetric relations if ($conf['symmetric_field']) { $row = t3lib_BEfunc::getRecord($table, $uid, $fields, '', false); $isOnSymmetricSide = t3lib_loadDBGroup::isOnSymmetricSide($parentUid, $conf, $row); } $updateValues = array(); // no update to the uid is requested, so this is the normal behaviour // just update the fields and care about sorting if (!$updateToUid) { // Always add the pointer to the parent uid if ($isOnSymmetricSide) { $updateValues[$symmetric_field] = $parentUid; } else { $updateValues[$foreign_field] = $parentUid; } // if it is configured in TCA also to store the parent table in the child record, just do it if ($foreign_table_field && $this->currentTable) { $updateValues[$foreign_table_field] = $this->currentTable; } // update sorting columns if not to be skipped if (!$skipSorting) { // get the correct sorting field if ($conf['foreign_sortby']) { // specific manual sortby for data handled by this field $sortby = $conf['foreign_sortby']; } elseif ($GLOBALS['TCA'][$foreign_table]['ctrl']['sortby']) { // manual sortby for all table records $sortby = $GLOBALS['TCA'][$foreign_table]['ctrl']['sortby']; } // strip a possible "ORDER BY" in front of the $sortby value $sortby = $GLOBALS['TYPO3_DB']->stripOrderBy($sortby); $symSortby = $conf['symmetric_sortby']; // set the sorting on the right side, it depends on who created the relation, so what uid is in the symmetric_field if ($isOnSymmetricSide && $symSortby) { $updateValues[$symSortby] = ++$c; } elseif ($sortby) { $updateValues[$sortby] = ++$c; } } // update to a foreign_field/symmetric_field pointer is requested, normally used on record copies // only update the fields, if the old uid is found somewhere - for select fields, TCEmain is doing this already! } else { if ($isOnSymmetricSide) { $updateValues[$symmetric_field] = $updateToUid; } else { $updateValues[$foreign_field] = $updateToUid; } } if (count($updateValues)) { $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . intval($uid), $updateValues); $this->updateRefIndex($table, $uid); } } } }
/** * Check, if a field should be skipped, that was defined to be handled as foreign_field or foreign_sortby of * the parent record of the "inline"-type - if so, we have to skip this field - the rendering is done via "inline" as hidden field * * @param string $table: The table name * @param string $field: The field name * @param array $row: The record row from the database * @param array $config: TCA configuration of the field * @return boolean Determines whether the field should be skipped. */ function skipField($table, $field, $row, $config) { $skipThisField = false; if ($this->getStructureDepth()) { $searchArray = array('%OR' => array('config' => array(0 => array('%AND' => array('foreign_table' => $table, '%OR' => array('%AND' => array('appearance' => array('useCombination' => true), 'foreign_selector' => $field), 'MM' => $config['MM']))), 1 => array('%AND' => array('foreign_table' => $config['foreign_table'], 'foreign_selector' => $config['foreign_field']))))); // get the parent record from structure stack $level = $this->getStructureLevel(-1); // If we have symmetric fields, check on which side we are and hide fields, that are set automatically: if (t3lib_loadDBGroup::isOnSymmetricSide($level['uid'], $level['config'], $row)) { $searchArray['%OR']['config'][0]['%AND']['%OR']['symmetric_field'] = $field; $searchArray['%OR']['config'][0]['%AND']['%OR']['symmetric_sortby'] = $field; // Hide fields, that are set automatically: } else { $searchArray['%OR']['config'][0]['%AND']['%OR']['foreign_field'] = $field; $searchArray['%OR']['config'][0]['%AND']['%OR']['foreign_sortby'] = $field; } $skipThisField = $this->compareStructureConfiguration($searchArray, true); } return $skipThisField; }