Code Duplication    Length = 17-21 lines in 3 locations

main/exercise/TestCategory.php 1 location

@@ 1002-1018 (lines=17) @@
999
     *
1000
     * @return int is id of test category
1001
     */
1002
    public static function get_category_id_for_title($title, $courseId = 0)
1003
    {
1004
        $out_res = 0;
1005
        if (empty($courseId)) {
1006
            $courseId = api_get_course_int_id();
1007
        }
1008
        $courseId = intval($courseId);
1009
        $tbl_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
1010
        $sql = "SELECT id FROM $tbl_cat
1011
                WHERE c_id = $courseId AND title = '".Database::escape_string($title)."'";
1012
        $res = Database::query($sql);
1013
        if (Database::num_rows($res) > 0) {
1014
            $data = Database::fetch_array($res);
1015
            $out_res = $data['id'];
1016
        }
1017
        return $out_res;
1018
    }
1019
1020
    /**
1021
     * Add a relation between question and category in table c_quiz_question_rel_category

main/forum/forumfunction.inc.php 2 locations

@@ 5369-5389 (lines=21) @@
5366
 * @author Jhon Hinojosa <[email protected]>,
5367
 * @version octubre 2008, dokeos 1.8
5368
 */
5369
function count_number_of_post_in_thread($thread_id)
5370
{
5371
    $table_posts = Database :: get_course_table(TABLE_FORUM_POST);
5372
    $course_id = api_get_course_int_id();
5373
    if (empty($course_id)) {
5374
        return 0;
5375
    }
5376
    $sql = "SELECT count(*) count FROM $table_posts
5377
            WHERE 
5378
                c_id = $course_id AND 
5379
                thread_id='".intval($thread_id)."' ";
5380
    $result = Database::query($sql);
5381
5382
    $count = 0;
5383
    if (Database::num_rows($result) > 0) {
5384
        $row = Database::fetch_array($result);
5385
        $count = $row['count'];
5386
    }
5387
5388
    return $count;
5389
}
5390
5391
/**
5392
 * This function counts the number of post inside a thread user
@@ 5398-5415 (lines=18) @@
5395
 *
5396
 * @return  int the number of post inside a thread user
5397
 */
5398
function count_number_of_post_for_user_thread($thread_id, $user_id)
5399
{
5400
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
5401
    $course_id = api_get_course_int_id();
5402
    $sql = "SELECT count(iid) as count 
5403
            FROM $table_posts
5404
            WHERE c_id = $course_id AND
5405
                  thread_id=".intval($thread_id)." AND
5406
                  poster_id = ".intval($user_id)." AND visible = 1 ";
5407
    $result = Database::query($sql);
5408
    $count = 0;
5409
    if (Database::num_rows($result) > 0) {
5410
        $count = Database::fetch_array($result);
5411
        $count = $count['count'];
5412
    }
5413
5414
    return $count;
5415
}
5416
5417
/**
5418
 * This function counts the number of user register in course