Code Duplication    Length = 29-30 lines in 3 locations

main/lp/learnpath.class.php 3 locations

@@ 5405-5434 (lines=30) @@
5402
     * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
5403
     * @return	boolean	True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
5404
     */
5405
    public function update_reinit()
5406
    {
5407
        $course_id = api_get_course_int_id();
5408
        if ($this->debug > 0) {
5409
            error_log('New LP - In learnpath::update_reinit()', 0);
5410
        }
5411
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
5412
        $sql = "SELECT * FROM $lp_table
5413
                WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5414
        $res = Database::query($sql);
5415
        if (Database::num_rows($res) > 0) {
5416
            $row = Database::fetch_array($res);
5417
            $force = $row['prevent_reinit'];
5418
            if ($force == 1) {
5419
                $force = 0;
5420
            } elseif ($force == 0) {
5421
                $force = 1;
5422
            }
5423
            $sql = "UPDATE $lp_table SET prevent_reinit = $force
5424
                    WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5425
            Database::query($sql);
5426
            $this->prevent_reinit = $force;
5427
            return $force;
5428
        } else {
5429
            if ($this->debug > 2) {
5430
                error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB', 0);
5431
            }
5432
        }
5433
        return -1;
5434
    }
5435
5436
    /**
5437
     * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag
@@ 5543-5571 (lines=29) @@
5540
     * @return boolean true if seriousgame_mode has been set to 1, false otherwise
5541
     * @author ndiechburg <[email protected]>
5542
     **/
5543
    public function set_seriousgame_mode()
5544
    {
5545
        $course_id = api_get_course_int_id();
5546
        if ($this->debug > 0) {
5547
            error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
5548
        }
5549
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
5550
        $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5551
        $res = Database::query($sql);
5552
        if (Database::num_rows($res) > 0) {
5553
            $row = Database::fetch_array($res);
5554
            $force = $row['seriousgame_mode'];
5555
            if ($force == 1) {
5556
                $force = 0;
5557
            } elseif ($force == 0) {
5558
                $force = 1;
5559
            }
5560
            $sql = "UPDATE $lp_table SET seriousgame_mode = $force
5561
			        WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5562
            Database::query($sql);
5563
            $this->seriousgame_mode = $force;
5564
            return $force;
5565
        } else {
5566
            if ($this->debug > 2) {
5567
                error_log('New LP - Problem in set_seriousgame_mode() - could not find LP '.$this->get_id().' in DB', 0);
5568
            }
5569
        }
5570
        return -1;
5571
    }
5572
5573
    /**
5574
     * Updates the "scorm_debug" value that shows or hide the debug window
@@ 5577-5606 (lines=30) @@
5574
     * Updates the "scorm_debug" value that shows or hide the debug window
5575
     * @return	boolean	True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
5576
     */
5577
    public function update_scorm_debug()
5578
    {
5579
        $course_id = api_get_course_int_id();
5580
        if ($this->debug > 0) {
5581
            error_log('New LP - In learnpath::update_scorm_debug()', 0);
5582
        }
5583
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
5584
        $sql = "SELECT * FROM $lp_table
5585
                WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5586
        $res = Database::query($sql);
5587
        if (Database::num_rows($res) > 0) {
5588
            $row = Database::fetch_array($res);
5589
            $force = $row['debug'];
5590
            if ($force == 1) {
5591
                $force = 0;
5592
            } elseif ($force == 0) {
5593
                $force = 1;
5594
            }
5595
            $sql = "UPDATE $lp_table SET debug = $force
5596
                    WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5597
            Database::query($sql);
5598
            $this->scorm_debug = $force;
5599
            return $force;
5600
        } else {
5601
            if ($this->debug > 2) {
5602
                error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB', 0);
5603
            }
5604
        }
5605
        return -1;
5606
    }
5607
5608
    /**
5609
     * Function that makes a call to the function sort_tree_array and create_tree_array