123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- <?php
- /* For license terms, see /license.txt */
- /**
- * Functions.
- *
- * @package chamilo.plugin.test2pdf
- */
- $letters = [
- 'a',
- 'b',
- 'c',
- 'd',
- 'e',
- 'f',
- 'g',
- 'h',
- 'i',
- 'j',
- 'k',
- 'l',
- 'm',
- 'n',
- 'o',
- 'p',
- 'q',
- 'r',
- 's',
- 't',
- 'u',
- 'v',
- 'w',
- 'x',
- 'y',
- 'z',
- ];
- /**
- * List exercises.
- *
- * @param int $courseId Course ID
- * @param int $sessionId Session ID
- *
- * @throws Exception
- *
- * @return array Results (list of exercise details)
- */
- function showExerciseCourse($courseId, $sessionId = 0)
- {
- $tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $tableLpItem = Database::get_course_table(TABLE_LP_ITEM);
- $courseId = (int) $courseId;
- $sessionId = (int) $sessionId;
- $conditionSession = api_get_session_condition($sessionId, true, true, 'a.session_id');
- $sql = "SELECT a.*
- FROM $tableQuiz a
- LEFT JOIN $tableLpItem b ON a.iid = b.path AND a.c_id = b.c_id
- WHERE a.c_id = $courseId
- AND (a.active = 1 OR (item_type = 'quiz' AND b.c_id = $courseId))
- $conditionSession
- ORDER BY a.title ASC;";
- $res = Database::query($sql);
- $aux = [];
- while ($row = Database::fetch_assoc($res)) {
- $aux[] = $row;
- }
- return $aux;
- }
- /**
- * List quiz details.
- *
- * @throws Exception
- *
- * @return array Results (list of quiz details)
- */
- function getInfoQuiz($courseId, $id)
- {
- $courseId = (int) $courseId;
- $id = (int) $id;
- $tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $sql = "SELECT * FROM $tableQuiz WHERE c_id = $courseId AND iid = $id";
- $res = Database::query($sql);
- $row = Database::fetch_assoc($res);
- return $row;
- }
- /**
- * List question_id.
- *
- * @throws Exception
- *
- * @return array Results (list question ID)
- */
- function getQuestionsFromCourse($courseId, $quizId, $sessionId = 0)
- {
- $courseId = (int) $courseId;
- $quizId = (int) $quizId;
- $sessionId = (int) $sessionId;
- $tableQuizQuestion = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION);
- $tableQuiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $conditionSession = api_get_session_condition($sessionId, true, true, 'q.session_id');
- $sql = "SELECT a.question_id AS question_id
- FROM $tableQuizQuestion a
- INNER JOIN $tableQuestion b ON a.question_id = b.iid
- INNER JOIN $tableQuiz q ON q.iid = a.exercice_id
- WHERE a.c_id = $courseId AND b.c_id = a.c_id AND a.exercice_id = $quizId
- AND (b.type IN (1, 2, 9, 10, 11, 12, 14))
- $conditionSession
- ORDER BY question_order ASC;";
- $res = Database::query($sql);
- $aux = [];
- while ($row = Database::fetch_assoc($res)) {
- $aux[] = $row['question_id'];
- }
- return $aux;
- }
- /**
- * List question details.
- *
- * @throws Exception
- *
- * @return array Results (list of question details)
- */
- function getInfoQuestion($courseId, $id)
- {
- $courseId = (int) $courseId;
- $id = (int) $id;
- $tableQuestion = Database::get_course_table(TABLE_QUIZ_QUESTION);
- $sql = "SELECT * FROM $tableQuestion
- WHERE c_id = $courseId
- AND iid = $id
- AND (type IN (1, 2, 9, 10, 11, 12, 14))";
- $res = Database::query($sql);
- $row = Database::fetch_assoc($res);
- return $row;
- }
- /**
- * List answer details.
- *
- * @throws Exception
- *
- * @return array Results (list of answer by question_id)
- */
- function getAnswers($courseId, $id)
- {
- $courseId = (int) $courseId;
- $id = (int) $id;
- $tableQuizAnswer = Database::get_course_table(TABLE_QUIZ_ANSWER);
- $sql = "SELECT * FROM $tableQuizAnswer
- WHERE c_id = $courseId AND question_id = $id
- ORDER BY position ASC;";
- $res = Database::query($sql);
- $aux = [];
- while ($row = Database::fetch_assoc($res)) {
- $aux[] = $row;
- }
- return $aux;
- }
- /**
- * Remove all html tag.
- *
- * @param string $string The string to be stripped of HTML
- *
- * @return string clean of html tag
- */
- function removeHtml($string)
- {
- $txt = str_replace("<html>", "", $string);
- $txt = str_replace("<head>", "", $txt);
- $txt = str_replace("<title>", "", $txt);
- $txt = str_replace("</title>", "", $txt);
- $txt = str_replace("</head>", "", $txt);
- $txt = str_replace("<body>", "", $txt);
- $txt = str_replace("</body>", "", $txt);
- $txt = str_replace("</html>", "", $txt);
- $txt = strip_tags($txt);
- $txt = str_replace(chr(13).chr(10), "", $txt);
- $txt = str_replace(" ", " ", $txt);
- $txt = str_replace("Á", "Á", $txt);
- $txt = str_replace("á", "á", $txt);
- $txt = str_replace("É", "É", $txt);
- $txt = str_replace("é", "é", $txt);
- $txt = str_replace("Í", "Í", $txt);
- $txt = str_replace("í", "í", $txt);
- $txt = str_replace("Ó", "Ó", $txt);
- $txt = str_replace("ó", "ó", $txt);
- $txt = str_replace("Ú", "Ú", $txt);
- $txt = str_replace("ú", "ú", $txt);
- $txt = str_replace("Ñ", "Ñ", $txt);
- $txt = str_replace("ñ", "ñ", $txt);
- $txt = str_replace("à", "à", $txt);
- $txt = str_replace("À", "À", $txt);
- $txt = str_replace("¡", "¡", $txt);
- $txt = str_replace("·", "·", $txt);
- $txt = str_replace("Ç", "Ç", $txt);
- $txt = str_replace("ç", "ç", $txt);
- $txt = str_replace(""", '"', $txt);
- $txt = str_replace("ª", 'ª', $txt);
- $txt = str_replace("º", 'º', $txt);
- $txt = str_replace("&", '&', $txt);
- $txt = str_replace("•", '•', $txt);
- $txt = str_replace("¿", '¿', $txt);
- $txt = str_replace("€", 'EUR', $txt);
- $txt = str_replace("ü", 'ü', $txt);
- $txt = str_replace("Ü", 'Ü', $txt);
- $txt = str_replace("¨", '¨', $txt);
- return $txt;
- }
- /**
- * Remove all html tag.
- *
- * @param string $string The string to be stripped of accents
- *
- * @return string clean of html tag
- */
- function removeQuotes($string)
- {
- $txt = str_replace(" ", " ", $string);
- $txt = str_replace("Á", "Á", $txt);
- $txt = str_replace("á", "á", $txt);
- $txt = str_replace("É", "É", $txt);
- $txt = str_replace("é", "é", $txt);
- $txt = str_replace("Í", "Í", $txt);
- $txt = str_replace("í", "í", $txt);
- $txt = str_replace("Ó", "Ó", $txt);
- $txt = str_replace("ó", "ó", $txt);
- $txt = str_replace("Ú", "Ú", $txt);
- $txt = str_replace("ú", "ú", $txt);
- $txt = str_replace("Ñ", "Ñ", $txt);
- $txt = str_replace("ñ", "ñ", $txt);
- $txt = str_replace(""", '"', $txt);
- $txt = str_replace("ª", 'ª', $txt);
- $txt = str_replace("º", 'º', $txt);
- $txt = str_replace("&", '&', $txt);
- $txt = str_replace("•", '•', $txt);
- $txt = str_replace("¿ &", '¿', $txt);
- $txt = str_replace("à", "à", $txt);
- $txt = str_replace("À", "À", $txt);
- $txt = str_replace("¡", "¡", $txt);
- $txt = str_replace("·", "·", $txt);
- $txt = str_replace("Ç", "Ç", $txt);
- $txt = str_replace("ç", "ç", $txt);
- $txt = str_replace("€", 'EUR', $txt);
- $txt = str_replace("ü", 'ü', $txt);
- $txt = str_replace("Ü", 'Ü', $txt);
- $txt = str_replace("uml;", '¨', $txt);
- return $txt;
- }
|