Bug #19042 » 8872_sortrow2.diff
t3lib/class.t3lib_tcemain.php (working copy) | ||
---|---|---|
// The $pid_value is now the numerical pid at this point
|
||
if ($OK) {
|
||
$sortRow = $TCA[$table]['ctrl']['sortby'];
|
||
$sortPosition = $incomingFieldArray[$sortRow] === 'last' ? 'last' : 'first';
|
||
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);
|
||
$fieldArray[$sortRow] = $this->getSortNumber($table, 0, $pid_value, $sortPosition);
|
||
}
|
||
$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 string define position, 'first' return sorting as first element, 'last' returns sorting as last element
|
||
* @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, $position='first') {
|
||
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
|
||
$res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow.',pid,uid', $table, 'pid='.intval($pid).$this->deleteClause($table), '', $sortRow . ($position === 'last' ? ' DESC' : ' ASC'), '1'); // Fetches the first record under this pid
|
||
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);
|
||
return $this->sortIntervals; // First sorting number after resorting
|
||
if ($position === 'last') {
|
||
return $row[$sortRow] + $this->sortIntervals;
|
||
} else {
|
||
return floor($row[$sortRow]/2); // Sorting number between current top element and zero
|
||
if ($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
|
||
}
|
||
}
|
||
} else { // No pages, so we choose the default value as sorting-number
|
||
return $this->sortIntervals; // First sorting number if no elements.
|