/** * Function that automatic creates answers (and save it to database) for cloze question type * ADA_ERASE_TEST_SIMPLICITY version * * @global db $dh * * @param int $question_id * @param array $data question data * @param array $test test record * * @see QuestionClozeTest::createClozeAnswers */ public static function createEraseClozeAnswers($question_id, $data, $test) { $dh = $GLOBALS['dh']; QuestionClozeTest::createClozeAnswers($question_id, $data, $test); require_once MODULES_TEST_PATH . '/include/nodeTest.class.inc.php'; $questionObj = nodeTest::readNode($question_id); //the next function computes cloze orders with span orders and returns it $nuovi_ordini = $questionObj->getClozeOrders(); //save new computed orders for each answer $res = $dh->test_getNodesByParent($questionObj->id_nodo); if (!empty($res)) { foreach ($res as $v) { $v['ordine'] = $nuovi_ordini[$v['ordine']]; $dh->test_updateNode($v['id_nodo'], array('ordine' => $v['ordine'])); } } //change original orders with new ones inside question text $testo = $questionObj->testo; foreach ($nuovi_ordini as $k => $v) { $testo = str_replace('<cloze title="' . $k . '">', '<clozeTMP title="' . $v . '">', $testo); } $testo = str_replace('<clozeTMP', '<cloze', $testo); $dh->test_updateNode($questionObj->id_nodo, array('testo' => $testo)); }
/** * function used to save question * * @global db $dh * * @param array $data question data to be saved in database * @param int $question_id question node id * * @return node id in case of successful insert or boolean */ protected function saveQuestion($data, $question_id = null) { $dh = $GLOBALS['dh']; $data['testo'] = preg_replace(array('#<p[^>]*>#', '#</p>#'), array('', '<br />'), $data['testo']); if (is_null($question_id)) { $question_res = $dh->test_addNode($data); $question_id = $question_res; } else { $question_res = $dh->test_updateNode($question_id, $data); } if ($data['tipo'][1] == ADA_CLOZE_TEST_TYPE && $question_res) { require_once MODULES_TEST_PATH . '/include/question.class.inc.php'; require_once MODULES_TEST_PATH . '/include/questionCloze.class.inc.php'; if ($data['tipo'][3] == ADA_ERASE_TEST_SIMPLICITY) { require_once MODULES_TEST_PATH . '/include/questionEraseCloze.class.inc.php'; QuestionEraseClozeTest::createEraseClozeAnswers($question_id, $data, $this->test); } else { if ($data['tipo'][3] == ADA_SLOT_TEST_SIMPLICITY) { require_once MODULES_TEST_PATH . '/include/questionSlotCloze.class.inc.php'; QuestionSlotClozeTest::createSlotClozeAnswers($question_id, $data, $this->test); } else { if ($data['tipo'][3] == ADA_MULTIPLE_TEST_SIMPLICITY) { require_once MODULES_TEST_PATH . '/include/questionMultipleCloze.class.inc.php'; QuestionMultipleClozeTest::createMultipleClozeAnswers($question_id, $data, $this->test); } else { QuestionClozeTest::createClozeAnswers($question_id, $data, $this->test); } } } } return $question_res; }