Code Duplication    Length = 17-21 lines in 3 locations

main/exercise/TestCategory.php 1 location

@@ 1034-1050 (lines=17) @@
1031
     *
1032
     * @return int is id of test category
1033
     */
1034
    public static function get_category_id_for_title($title, $courseId = 0)
1035
    {
1036
        $out_res = 0;
1037
        if (empty($courseId)) {
1038
            $courseId = api_get_course_int_id();
1039
        }
1040
        $courseId = intval($courseId);
1041
        $tbl_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
1042
        $sql = "SELECT id FROM $tbl_cat
1043
                WHERE c_id = $courseId AND title = '".Database::escape_string($title)."'";
1044
        $res = Database::query($sql);
1045
        if (Database::num_rows($res) > 0) {
1046
            $data = Database::fetch_array($res);
1047
            $out_res = $data['id'];
1048
        }
1049
        return $out_res;
1050
    }
1051
1052
    /**
1053
     * Add a relation between question and category in table c_quiz_question_rel_category

main/forum/forumfunction.inc.php 2 locations

@@ 5274-5294 (lines=21) @@
5271
 * @author Jhon Hinojosa <[email protected]>,
5272
 * @version octubre 2008, dokeos 1.8
5273
 */
5274
function count_number_of_post_in_thread($thread_id)
5275
{
5276
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
5277
    $course_id = api_get_course_int_id();
5278
    if (empty($course_id)) {
5279
        return 0;
5280
    }
5281
    $sql = "SELECT count(*) count FROM $table_posts
5282
            WHERE 
5283
                c_id = $course_id AND 
5284
                thread_id='".intval($thread_id)."' ";
5285
    $result = Database::query($sql);
5286
5287
    $count = 0;
5288
    if (Database::num_rows($result) > 0) {
5289
        $row = Database::fetch_array($result);
5290
        $count = $row['count'];
5291
    }
5292
5293
    return $count;
5294
}
5295
5296
/**
5297
 * This function counts the number of post inside a thread user
@@ 5303-5320 (lines=18) @@
5300
 *
5301
 * @return  int the number of post inside a thread user
5302
 */
5303
function count_number_of_post_for_user_thread($thread_id, $user_id)
5304
{
5305
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
5306
    $course_id = api_get_course_int_id();
5307
    $sql = "SELECT count(iid) as count 
5308
            FROM $table_posts
5309
            WHERE c_id = $course_id AND
5310
                  thread_id=".intval($thread_id)." AND
5311
                  poster_id = ".intval($user_id)." AND visible = 1 ";
5312
    $result = Database::query($sql);
5313
    $count = 0;
5314
    if (Database::num_rows($result) > 0) {
5315
        $count = Database::fetch_array($result);
5316
        $count = $count['count'];
5317
    }
5318
5319
    return $count;
5320
}
5321
5322
/**
5323
 * This function counts the number of user register in course