/php/util/fix_failed_fill_in_the_blanks_questions.php
PHP | 79 lines | 49 code | 30 blank | 0 comment | 1 complexity | 6dc4a1f77b0ede1f3158ecb033cf7799 MD5 | raw file
- <?php
- namespace migration;
- use repository\RepositoryDataManager;
- use repository\content_object\fill_in_blanks_question\FillInBlanksQuestion;
- ini_set("memory_limit", "-1");
- set_time_limit(0);
- require_once dirname(__FILE__) . '/../../../common/global.inc.php';
- $dbhost = '';
- $dbuser = '';
- $dbpass = '';
- $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
- $query = "SELECT rco.*, fib.*, mir.old_id, mir.reference_table_name
- FROM `repository_content_object` as rco
- JOIN `repository_fill_in_blanks_question` AS fib on rco.id=fib.id
- JOIN migration_id_reference AS mir ON fib.id = mir.new_id
- WHERE answer_text = 'error: non-standard fill in the blanks answer [error]'";
- $dm = RepositoryDataManager :: get_instance();
- $questions = $dm->retrieve_object_set($query, FillInBlanksQuestion :: get_table_name());
- echo $questions->size() . '<br /><br />';
- while($question = $questions->next_result())
- {
- $db_name = $question->get_optional_property('reference_table_name');
- $db_name = explode('.', $db_name);
- $db_name = $db_name[0];
- $dokeos_id = $question->get_optional_property('old_id');
- mysql_select_db($db_name);
- $result = mysql_query('SELECT answer from quiz_answer
- where question_id=' . $dokeos_id);
- if (!$result) {
- die('Invalid query: ' . mysql_error());
- }
- $row = mysql_fetch_assoc($result);
- $answer_text = $row['answer'];
- $split = explode('::', $answer_text);
- $scores = explode(',', $split[1]);
- $answer_text = $split[0];
- $pattern = '/\[[^\[\]]*\]/';
- $answers = preg_match_all($pattern, $answer_text, $matches);
- foreach ($matches[0] as $i => $answer)
- {
- $score = $scores[$i] ? $scores[$i] : 0;
- $answer = (substr($answer, 1, -1));
- $new_answer = '[' . $answer . '=' . $score . ']';
- $answer_text = str_replace('[' . $answer . ']', $new_answer, $answer_text);
- }
-
- $question->set_optional_property(FillInBlanksQuestion::PROPERTY_ANSWER_TEXT, $answer_text);
- $question->update();
- }
-
- ?>