Code Duplication    Length = 29-30 lines in 3 locations

main/newscorm/learnpath.class.php 3 locations

@@ 5193-5222 (lines=30) @@
5190
     * Updates the "prevent_reinit" value that enables control on reinitialising items on second view
5191
     * @return	boolean	True if prevent_reinit has been set to 'on', false otherwise (or 1 or 0 in this case)
5192
     */
5193
    public function update_reinit()
5194
    {
5195
        $course_id = api_get_course_int_id();
5196
        if ($this->debug > 0) {
5197
            error_log('New LP - In learnpath::update_reinit()', 0);
5198
        }
5199
        $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
5200
        $sql = "SELECT * FROM $lp_table
5201
                WHERE c_id = ".$course_id." AND id = " . $this->get_id();
5202
        $res = Database::query($sql);
5203
        if (Database :: num_rows($res) > 0) {
5204
            $row = Database :: fetch_array($res);
5205
            $force = $row['prevent_reinit'];
5206
            if ($force == 1) {
5207
                $force = 0;
5208
            } elseif ($force == 0) {
5209
                $force = 1;
5210
            }
5211
            $sql = "UPDATE $lp_table SET prevent_reinit = $force
5212
                    WHERE c_id = ".$course_id." AND id = " . $this->get_id();
5213
            Database::query($sql);
5214
            $this->prevent_reinit = $force;
5215
            return $force;
5216
        } else {
5217
            if ($this->debug > 2) {
5218
                error_log('New LP - Problem in update_reinit() - could not find LP ' . $this->get_id() . ' in DB', 0);
5219
            }
5220
        }
5221
        return -1;
5222
    }
5223
5224
    /**
5225
     * Determine the attempt_mode thanks to prevent_reinit and seriousgame_mode db flag
@@ 5331-5359 (lines=29) @@
5328
     * @return boolean true if seriousgame_mode has been set to 1, false otherwise
5329
     * @author ndiechburg <[email protected]>
5330
     **/
5331
    public function set_seriousgame_mode()
5332
    {
5333
        $course_id = api_get_course_int_id();
5334
        if ($this->debug > 0) {
5335
            error_log('New LP - In learnpath::set_seriousgame_mode()', 0);
5336
        }
5337
        $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
5338
        $sql = "SELECT * FROM $lp_table WHERE c_id = ".$course_id." AND id = " . $this->get_id();
5339
        $res = Database::query($sql);
5340
        if (Database :: num_rows($res) > 0) {
5341
            $row = Database :: fetch_array($res);
5342
            $force = $row['seriousgame_mode'];
5343
            if ($force == 1) {
5344
                $force = 0;
5345
            } elseif ($force == 0) {
5346
                $force = 1;
5347
            }
5348
            $sql = "UPDATE $lp_table SET seriousgame_mode = $force
5349
			        WHERE c_id = ".$course_id." AND id = " . $this->get_id();
5350
            Database::query($sql);
5351
            $this->seriousgame_mode = $force;
5352
            return $force;
5353
        } else {
5354
            if ($this->debug > 2) {
5355
                error_log('New LP - Problem in set_seriousgame_mode() - could not find LP ' . $this->get_id() . ' in DB', 0);
5356
            }
5357
        }
5358
        return -1;
5359
    }
5360
5361
    /**
5362
     * Updates the "scorm_debug" value that shows or hide the debug window
@@ 5365-5394 (lines=30) @@
5362
     * Updates the "scorm_debug" value that shows or hide the debug window
5363
     * @return	boolean	True if scorm_debug has been set to 'on', false otherwise (or 1 or 0 in this case)
5364
     */
5365
    public function update_scorm_debug()
5366
    {
5367
        $course_id = api_get_course_int_id();
5368
        if ($this->debug > 0) {
5369
            error_log('New LP - In learnpath::update_scorm_debug()', 0);
5370
        }
5371
        $lp_table = Database :: get_course_table(TABLE_LP_MAIN);
5372
        $sql = "SELECT * FROM $lp_table
5373
                WHERE c_id = ".$course_id." AND id = " . $this->get_id();
5374
        $res = Database::query($sql);
5375
        if (Database :: num_rows($res) > 0) {
5376
            $row = Database :: fetch_array($res);
5377
            $force = $row['debug'];
5378
            if ($force == 1) {
5379
                $force = 0;
5380
            } elseif ($force == 0) {
5381
                $force = 1;
5382
            }
5383
            $sql = "UPDATE $lp_table SET debug = $force
5384
                    WHERE c_id = ".$course_id." AND id = " . $this->get_id();
5385
            $res = Database::query($sql);
5386
            $this->scorm_debug = $force;
5387
            return $force;
5388
        } else {
5389
            if ($this->debug > 2) {
5390
                error_log('New LP - Problem in update_scorm_debug() - could not find LP ' . $this->get_id() . ' in DB', 0);
5391
            }
5392
        }
5393
        return -1;
5394
    }
5395
5396
    /**
5397
     * Function that makes a call to the function sort_tree_array and create_tree_array