Code Duplication    Length = 17-19 lines in 2 locations

main/exercice/TestCategory.php 2 locations

@@ 254-272 (lines=19) @@
251
     *
252
     * @return int
253
     */
254
	public static function getCategoryForQuestion($questionId, $courseId ="")
255
    {
256
		$result = 0;
257
        if (empty($courseId) || $courseId == "") {
258
            $courseId = api_get_course_int_id();
259
        }
260
		$table = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY);
261
        $questionId = intval($questionId);
262
		$sql = "SELECT category_id
263
		        FROM $table
264
		        WHERE question_id = $questionId AND c_id = $courseId";
265
		$res = Database::query($sql);
266
		if (Database::num_rows($res) > 0) {
267
            $data = Database::fetch_array($res);
268
			$result = $data['category_id'];
269
		}
270
271
		return $result;
272
	}
273
274
	/**
275
	 * true if question id has a category
@@ 997-1013 (lines=17) @@
994
     *
995
     * @return int is id of test category
996
     */
997
    public static function get_category_id_for_title($title, $courseId = 0)
998
    {
999
        $out_res = 0;
1000
        if (empty($courseId)) {
1001
            $courseId = api_get_course_int_id();
1002
        }
1003
        $courseId = intval($courseId);
1004
        $tbl_cat = Database::get_course_table(TABLE_QUIZ_QUESTION_CATEGORY);
1005
        $sql = "SELECT id FROM $tbl_cat
1006
                WHERE c_id = $courseId AND title = '".Database::escape_string($title)."'";
1007
        $res = Database::query($sql);
1008
        if (Database::num_rows($res) > 0) {
1009
            $data = Database::fetch_array($res);
1010
            $out_res = $data['id'];
1011
        }
1012
        return $out_res;
1013
    }
1014
1015
    /**
1016
     * Add a relation between question and category in table c_quiz_question_rel_category