Code Duplication    Length = 29-30 lines in 3 locations

main/lp/learnpath.class.php 3 locations

@@ 5357-5386 (lines=30) @@
5354
     * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
5355
     * @return	boolean	True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
5356
     */
5357
    public function update_reinit()
5358
    {
5359
        $course_id = api_get_course_int_id();
5360
        if ($this->debug > 0) {
5361
            error_log('New LP - In learnpath::update_reinit()', 0);
5362
        }
5363
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
5364
        $sql = "SELECT * FROM $lp_table
5365
                WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5366
        $res = Database::query($sql);
5367
        if (Database::num_rows($res) > 0) {
5368
            $row = Database::fetch_array($res);
5369
            $force = $row['prevent_reinit'];
5370
            if ($force == 1) {
5371
                $force = 0;
5372
            } elseif ($force == 0) {
5373
                $force = 1;
5374
            }
5375
            $sql = "UPDATE $lp_table SET prevent_reinit = $force
5376
                    WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5377
            Database::query($sql);
5378
            $this->prevent_reinit = $force;
5379
            return $force;
5380
        } else {
5381
            if ($this->debug > 2) {
5382
                error_log('New LP - Problem in update_reinit() - could not find LP '.$this->get_id().' in DB', 0);
5383
            }
5384
        }
5385
        return -1;
5386
    }
5387
5388
    /**
5389
     * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag
@@ 5495-5523 (lines=29) @@
5492
     * @return boolean true if seriousgame_mode has been set to 1, false otherwise
5493
     * @author ndiechburg <[email protected]>
5494
     **/
5495
    public function set_seriousgame_mode()
5496
    {
5497
        $course_id = api_get_course_int_id();
5498
        if ($this->debug > 0) {
5499
            error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
5500
        }
5501
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
5502
        $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5503
        $res = Database::query($sql);
5504
        if (Database::num_rows($res) > 0) {
5505
            $row = Database::fetch_array($res);
5506
            $force = $row['seriousgame_mode'];
5507
            if ($force == 1) {
5508
                $force = 0;
5509
            } elseif ($force == 0) {
5510
                $force = 1;
5511
            }
5512
            $sql = "UPDATE $lp_table SET seriousgame_mode = $force
5513
			        WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5514
            Database::query($sql);
5515
            $this->seriousgame_mode = $force;
5516
            return $force;
5517
        } else {
5518
            if ($this->debug > 2) {
5519
                error_log('New LP - Problem in set_seriousgame_mode() - could not find LP '.$this->get_id().' in DB', 0);
5520
            }
5521
        }
5522
        return -1;
5523
    }
5524
5525
    /**
5526
     * Updates the "scorm_debug" value that shows or hide the debug window
@@ 5529-5558 (lines=30) @@
5526
     * Updates the "scorm_debug" value that shows or hide the debug window
5527
     * @return	boolean	True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
5528
     */
5529
    public function update_scorm_debug()
5530
    {
5531
        $course_id = api_get_course_int_id();
5532
        if ($this->debug > 0) {
5533
            error_log('New LP - In learnpath::update_scorm_debug()', 0);
5534
        }
5535
        $lp_table = Database::get_course_table(TABLE_LP_MAIN);
5536
        $sql = "SELECT * FROM $lp_table
5537
                WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5538
        $res = Database::query($sql);
5539
        if (Database::num_rows($res) > 0) {
5540
            $row = Database::fetch_array($res);
5541
            $force = $row['debug'];
5542
            if ($force == 1) {
5543
                $force = 0;
5544
            } elseif ($force == 0) {
5545
                $force = 1;
5546
            }
5547
            $sql = "UPDATE $lp_table SET debug = $force
5548
                    WHERE c_id = ".$course_id." AND id = ".$this->get_id();
5549
            Database::query($sql);
5550
            $this->scorm_debug = $force;
5551
            return $force;
5552
        } else {
5553
            if ($this->debug > 2) {
5554
                error_log('New LP - Problem in update_scorm_debug() - could not find LP '.$this->get_id().' in DB', 0);
5555
            }
5556
        }
5557
        return -1;
5558
    }
5559
5560
    /**
5561
     * Function that makes a call to the function sort_tree_array and create_tree_array