本文整理汇总了PHP中TYPO3\CMS\Core\Database\DatabaseConnection::sql_field_type方法的典型用法代码示例。如果您正苦于以下问题:PHP DatabaseConnection::sql_field_type方法的具体用法?PHP DatabaseConnection::sql_field_type怎么用?PHP DatabaseConnection::sql_field_type使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TYPO3\CMS\Core\Database\DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::sql_field_type方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: compareFieldArrayWithCurrentAndUnset
/**
* Compares the incoming field array with the current record and unsets all fields which are the same.
* Used for existing records being updated
*
* @param string $table Record table name
* @param int $id Record uid
* @param array $fieldArray Array of field=>value pairs intended to be inserted into the database. All keys with values matching exactly the current value will be unset!
* @return array Returns $fieldArray. If the returned array is empty, then the record should not be updated!
*/
public function compareFieldArrayWithCurrentAndUnset($table, $id, $fieldArray)
{
// Fetch the original record:
$res = $this->databaseConnection->exec_SELECTquery('*', $table, 'uid=' . (int) $id);
$currentRecord = $this->databaseConnection->sql_fetch_assoc($res);
// If the current record exists (which it should...), begin comparison:
if (is_array($currentRecord)) {
// Read all field types:
$c = 0;
$cRecTypes = array();
foreach ($currentRecord as $col => $val) {
$cRecTypes[$col] = $this->databaseConnection->sql_field_type($res, $c);
$c++;
}
// Free result:
$this->databaseConnection->sql_free_result($res);
// Unset the fields which are similar:
foreach ($fieldArray as $col => $val) {
$fieldConfiguration = $GLOBALS['TCA'][$table]['columns'][$col]['config'];
$isNullField = !empty($fieldConfiguration['eval']) && GeneralUtility::inList($fieldConfiguration['eval'], 'null');
// Unset fields if stored and submitted values are equal - except the current field holds MM relations.
// In general this avoids to store superfluous data which also will be visualized in the editing history.
if (!$fieldConfiguration['MM'] && $this->isSubmittedValueEqualToStoredValue($val, $currentRecord[$col], $cRecTypes[$col], $isNullField)) {
unset($fieldArray[$col]);
} else {
if (!isset($this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$col])) {
$this->historyRecords[$table . ':' . $id]['oldRecord'][$col] = $currentRecord[$col];
} elseif ($this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$col] != $this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$col]) {
$this->historyRecords[$table . ':' . $id]['oldRecord'][$col] = $this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$col];
}
if (!isset($this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$col])) {
$this->historyRecords[$table . ':' . $id]['newRecord'][$col] = $fieldArray[$col];
} elseif ($this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$col] != $this->mmHistoryRecords[$table . ':' . $id]['oldRecord'][$col]) {
$this->historyRecords[$table . ':' . $id]['newRecord'][$col] = $this->mmHistoryRecords[$table . ':' . $id]['newRecord'][$col];
}
}
}
} else {
// If the current record does not exist this is an error anyways and we just return an empty array here.
$fieldArray = array();
}
return $fieldArray;
}