Project

General

Profile

Bug #19042 » 0008872_v3.patch

Administrator Admin, 2008-07-01 20:41

View differences:

t3lib/class.t3lib_tcemain.php (Arbeitskopie)
$sortRow = $TCA[$table]['ctrl']['sortby'];
if ($pid_value>=0) { // Points to a page on which to insert the element, possibly in the top of the page
if ($sortRow) { // If this table is sorted we better find the top sorting number
$fieldArray[$sortRow] = $this->getSortNumber($table,0,$pid_value);
// Determine whether the new record shall be inserted as the last element in the table:
$insertAsLast = false;
if (isset($incomingFieldArray['_INSERTAS'])) {
if ($incomingFieldArray['_INSERTAS'] == 'last') {
$insertAsLast = true;
}
} elseif (isset($TCA[$table]['ctrl']['insertAsLast']) && $TCA[$table]['ctrl']['insertAsLast']) {
$insertAsLast = true;
}
$fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value, $insertAsLast);
}
$fieldArray['pid'] = $pid_value; // The numerical pid is inserted in the data array
} else { // points to another record before ifself
......
* @param string Table name
* @param integer Uid of record to find sorting number for. May be zero in case of new.
* @param integer Positioning PID, either >=0 (pointing to page in which case we find sorting number for first record in page) or <0 (pointing to record in which case to find next sorting number after this record)
* @param boolean Defines whether the record should be inserted as last one of the table (sets sorting number accordant) - default: false
* @return mixed Returns integer if PID is >=0, otherwise an array with PID and sorting number. Possibly false in case of error.
*/
function getSortNumber($table,$uid,$pid) {
function getSortNumber($table, $uid, $pid, $insertAsLast=false) {
global $TCA;
if ($TCA[$table] && $TCA[$table]['ctrl']['sortby']) {
$sortRow = $TCA[$table]['ctrl']['sortby'];
if ($pid>=0) { // Sorting number is in the top
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow.',pid,uid', $table, 'pid='.intval($pid).$this->deleteClause($table), '', $sortRow.' ASC', '1'); // Fetches the first record under this pid
// Fetches the first/last record under this pid:
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
$sortRow . ',pid,uid',
$table,
'pid=' . intval($pid) . $this->deleteClause($table),
'',
$sortRow . ($insertAsLast ? ' DESC' : ' ASC'),
'1'
);
if ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { // There was an element
if ($row['uid']==$uid) { // The top record was the record it self, so we return its current sortnumber
return $row[$sortRow];
}
if ($row[$sortRow] < 1) { // If the pages sortingnumber < 1 we must resort the records under this pid
$this->resorting($table,$pid,$sortRow,0);
if ($insertAsLast) {
return $row[$sortRow] + $this->sortIntervals;
} elseif ($row[$sortRow] < 1) { // If the pages sortingnumber < 1 we must resort the records under this pid
$this->resorting($table, $pid, $sortRow, 0);
return $this->sortIntervals; // First sorting number after resorting
} else {
return floor($row[$sortRow]/2); // Sorting number between current top element and zero
(3-3/3)