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

@@ 5250-5270 (lines=21) @@
5247
 * @author Jhon Hinojosa <[email protected]>,
5248
 * @version octubre 2008, dokeos 1.8
5249
 */
5250
function count_number_of_post_in_thread($thread_id)
5251
{
5252
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
5253
    $course_id = api_get_course_int_id();
5254
    if (empty($course_id)) {
5255
        return 0;
5256
    }
5257
    $sql = "SELECT count(*) count FROM $table_posts
5258
            WHERE 
5259
                c_id = $course_id AND 
5260
                thread_id='".intval($thread_id)."' ";
5261
    $result = Database::query($sql);
5262
5263
    $count = 0;
5264
    if (Database::num_rows($result) > 0) {
5265
        $row = Database::fetch_array($result);
5266
        $count = $row['count'];
5267
    }
5268
5269
    return $count;
5270
}
5271
5272
/**
5273
 * This function counts the number of post inside a thread user
@@ 5279-5296 (lines=18) @@
5276
 *
5277
 * @return  int the number of post inside a thread user
5278
 */
5279
function count_number_of_post_for_user_thread($thread_id, $user_id)
5280
{
5281
    $table_posts = Database::get_course_table(TABLE_FORUM_POST);
5282
    $course_id = api_get_course_int_id();
5283
    $sql = "SELECT count(iid) as count 
5284
            FROM $table_posts
5285
            WHERE c_id = $course_id AND
5286
                  thread_id=".intval($thread_id)." AND
5287
                  poster_id = ".intval($user_id)." AND visible = 1 ";
5288
    $result = Database::query($sql);
5289
    $count = 0;
5290
    if (Database::num_rows($result) > 0) {
5291
        $count = Database::fetch_array($result);
5292
        $count = $count['count'];
5293
    }
5294
5295
    return $count;
5296
}
5297
5298
/**
5299
 * This function counts the number of user register in course