Fix: broken feature if the table has no field fk_parent_line

This commit is contained in:
Regis Houssin 2013-03-22 19:21:46 +01:00
parent ed690885d3
commit 34bfdb1846

View File

@ -1012,13 +1012,13 @@ abstract class CommonObject
/** /**
* Save a new position (field rang) for details lines. * Save a new position (field rang) for details lines.
* You can choose to set position for lines with already a position or lines without any position defined. * You can choose to set position for lines with already a position or lines without any position defined.
* Call this function only for table that contains a field fk_parent_line.
* *
* @param boolean $renum true to renum all already ordered lines, false to renum only not already ordered lines. * @param boolean $renum true to renum all already ordered lines, false to renum only not already ordered lines.
* @param string $rowidorder ASC or DESC * @param string $rowidorder ASC or DESC
* @param boolean $fk_parent_line Table with fk_parent_line field or not
* @return void * @return void
*/ */
function line_order($renum=false, $rowidorder='ASC') function line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
{ {
if (! $this->table_element_line) if (! $this->table_element_line)
{ {
@ -1055,6 +1055,7 @@ abstract class CommonObject
// We first search all lines that are parent lines (for multilevel details lines) // We first search all lines that are parent lines (for multilevel details lines)
$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line; $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$this->table_element_line;
$sql.= ' WHERE '.$this->fk_element.' = '.$this->id; $sql.= ' WHERE '.$this->fk_element.' = '.$this->id;
if ($fk_parent_line)
$sql.= ' AND fk_parent_line IS NULL'; $sql.= ' AND fk_parent_line IS NULL';
$sql.= ' ORDER BY rang ASC, rowid '.$rowidorder; $sql.= ' ORDER BY rang ASC, rowid '.$rowidorder;
@ -1131,11 +1132,12 @@ abstract class CommonObject
* Update a line to have a lower rank * Update a line to have a lower rank
* *
* @param int $rowid Id of line * @param int $rowid Id of line
* @param boolean $fk_parent_line Table with fk_parent_line field or not
* @return void * @return void
*/ */
function line_up($rowid) function line_up($rowid, $fk_parent_line=true)
{ {
$this->line_order(); $this->line_order(false, 'ASC', $fk_parent_line);
// Get rang of line // Get rang of line
$rang = $this->getRangOfLine($rowid); $rang = $this->getRangOfLine($rowid);
@ -1148,11 +1150,12 @@ abstract class CommonObject
* Update a line to have a higher rank * Update a line to have a higher rank
* *
* @param int $rowid Id of line * @param int $rowid Id of line
* @param boolean $fk_parent_line Table with fk_parent_line field or not
* @return void * @return void
*/ */
function line_down($rowid) function line_down($rowid, $fk_parent_line=true)
{ {
$this->line_order(); $this->line_order(false, 'ASC', $fk_parent_line);
// Get rang of line // Get rang of line
$rang = $this->getRangOfLine($rowid); $rang = $this->getRangOfLine($rowid);