Code Duplication    Length = 15-16 lines in 2 locations

main/newscorm/learnpath.class.php 2 locations

@@ 3949-3963 (lines=15) @@
3946
        $num = Database :: num_rows($res);
3947
        // First check the order is correct, globally (might be wrong because
3948
        // of versions < 1.8.4)
3949
        if ($num > 0) {
3950
            $i = 1;
3951
            while ($row = Database :: fetch_array($res)) {
3952
                if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
3953
                    $need_fix = true;
3954
                    $sql_u = "UPDATE $lp_table SET display_order = $i
3955
                              WHERE c_id = ".$course_id." AND id = " . $row['id'];
3956
                    Database::query($sql_u);
3957
                }
3958
                $row['display_order'] = $i;
3959
                $lps[$row['id']] = $row;
3960
                $lp_order[$i] = $row['id'];
3961
                $i++;
3962
            }
3963
        }
3964
        if ($num > 1) { // If there's only one element, no need to sort.
3965
            $order = $lps[$lp_id]['display_order'];
3966
            if ($order > 1) { // If it's the first element, no need to move up.
@@ 3998-4013 (lines=16) @@
3995
        $max = 0;
3996
        // First check the order is correct, globally (might be wrong because
3997
        // of versions < 1.8.4).
3998
        if ($num > 0) {
3999
            $i = 1;
4000
            while ($row = Database :: fetch_array($res)) {
4001
                $max = $i;
4002
                if ($row['display_order'] != $i) { // If we find a gap in the order, we need to fix it.
4003
                    $need_fix = true;
4004
                    $sql_u = "UPDATE $lp_table SET display_order = $i
4005
                              WHERE c_id = ".$course_id." AND id = " . $row['id'];
4006
                    Database::query($sql_u);
4007
                }
4008
                $row['display_order'] = $i;
4009
                $lps[$row['id']] = $row;
4010
                $lp_order[$i] = $row['id'];
4011
                $i++;
4012
            }
4013
        }
4014
        if ($num > 1) { // If there's only one element, no need to sort.
4015
            $order = $lps[$lp_id]['display_order'];
4016
            if ($order < $max) { // If it's the first element, no need to move up.