Code Duplication    Length = 25-33 lines in 2 locations

main/inc/lib/groupmanager.lib.php 1 location

@@ 1366-1390 (lines=25) @@
1363
     * @param int $user_id
1364
     * @return int The number of groups the user is subscribed in.
1365
     */
1366
    public static function user_in_number_of_groups($user_id, $cat_id = null)
1367
    {
1368
        $table_group_user = Database::get_course_table(TABLE_GROUP_USER);
1369
        $table_group = Database::get_course_table(TABLE_GROUP);
1370
        $user_id = intval($user_id);
1371
        $cat_id = intval($cat_id);
1372
1373
        $course_id = api_get_course_int_id();
1374
        $cat_condition = '';
1375
        if (!empty($cat_id)) {
1376
            $cat_condition = " AND g.category_id =  $cat_id ";
1377
        }
1378
1379
        $sql = "SELECT  COUNT(*) AS number_of_groups
1380
                FROM $table_group_user gu, $table_group g
1381
                WHERE
1382
                    gu.c_id = $course_id AND
1383
                    g.c_id = $course_id AND
1384
                    gu.user_id = $user_id AND
1385
                    g.iid = gu.group_id  
1386
                    $cat_condition";
1387
        $result = Database::query($sql);
1388
        $db_object = Database::fetch_object($result);
1389
1390
        return $db_object->number_of_groups;
1391
    }
1392
1393
    /**

main/inc/lib/exercise.lib.php 1 location

@@ 3541-3573 (lines=33) @@
3538
     * @param int $session_id
3539
     * @return int
3540
     */
3541
    public static function get_number_students_finish_exercise(
3542
        $exercise_id,
3543
        $course_code,
3544
        $session_id
3545
    ) {
3546
        $track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
3547
        $track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
3548
3549
        $exercise_id = intval($exercise_id);
3550
        $course_code = Database::escape_string($course_code);
3551
        $session_id = intval($session_id);
3552
3553
        $sql = "SELECT DISTINCT exe_user_id
3554
                FROM $track_exercises e
3555
                INNER JOIN $track_attempt a 
3556
                ON (a.exe_id = e.exe_id)
3557
                WHERE
3558
                    exe_exo_id 	 = $exercise_id AND
3559
                    course_code  = '$course_code' AND
3560
                    e.session_id = $session_id AND
3561
                    status = ''";
3562
        $result = Database::query($sql);
3563
        $return = 0;
3564
        if ($result) {
3565
            $return = Database::num_rows($result);
3566
3567
        }
3568
        return $return;
3569
    }
3570
3571
    /**
3572
     * @param string $in_name is the name and the id of the <select>
3573
     * @param string $in_default default value for option
3574
     * @param string $in_onchange
3575
     * @return string the html code of the <select>
3576
     */