public function __construct($data, $question, $case_sensitive = false, $modifiable = true) { $dh = $GLOBALS['dh']; $this->question = $question; $this->case_sensitive = $case_sensitive; $this->ordine = array(); $this->answers = array(); $this->modifiable = $modifiable; require_once MODULES_TEST_PATH . '/include/nodeTest.class.inc.php'; $this->questionObj = nodeTest::readNode($this->question); $res = $dh->test_getNodesByParent($this->questionObj->id_nodo); foreach ($res as $k => $v) { $this->questionObj->addChild(nodeTest::readNode($v, $this->questionObj)); } $tmp = array(); foreach ($data as $k => $v) { $tmp[$v['ordine']][] = $v; } parent::__construct($tmp); }
/** * 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 that executes answer logic (add / mod) * * @global db $dh * * @return string */ protected function action() { $dh = $GLOBALS['dh']; $tmp = $dh->test_getNodesByParent($this->question['id_nodo']); $risposte = array(); if (!empty($tmp)) { foreach ($tmp as $k => $v) { $risposte[] = array('other_answer' => $v['tipo'][1], 'answer' => $v['testo'], 'value' => $v['correttezza'], 'case_sensitive' => $v['tipo'][2], 'record' => $v['id_nodo'], 'ordine' => $v['ordine']); } } $case_sensitive = false; $open_cloze = array(ADA_NORMAL_TEST_SIMPLICITY, ADA_MEDIUM_TEST_SIMPLICITY); if ($this->question['tipo'][1] == ADA_OPEN_AUTOMATIC_TEST_TYPE || $this->question['tipo'][1] == ADA_CLOZE_TEST_TYPE && in_array($this->question['tipo'][3], $open_cloze)) { $case_sensitive = true; } $open_answer = false; if (in_array($this->question['tipo'][1], array(ADA_STANDARD_TEST_TYPE, ADA_MULTIPLE_CHECK_TEST_TYPE))) { $open_answer = true; } $form = $this->instantiateObject($risposte, $this->question, $case_sensitive, $open_answer); if ($_POST) { //hack to capture ajax calls from ADA_CLOZE_TEST_TYPE -> ADA_MULTIPLE_TEST_SIMPLICITY if ($this->question['tipo'][3] == ADA_MULTIPLE_TEST_SIMPLICITY) { require_once MODULES_TEST_PATH . '/include/nodeTest.class.inc.php'; $questionObj = nodeTest::readNode($this->question['id_nodo']); $questionObj->updateAnswerTable($_POST[QuestionMultipleClozeTest::postVariable]); } if ($form->isValid()) { //crea nuove risposte con i dati del form $post = array(); foreach ($_POST['answer'] as $k => $v) { $post[] = array('answer' => $_POST['answer'][$k], 'value' => intval($_POST['value'][$k]), 'case_sensitive' => $_POST['case_sensitive'][$k] == 1 ? true : false, 'other_answer' => $_POST['other_answer'][$k] == 1 ? true : false, 'record' => $_POST['record'][$k], 'ordine' => $_POST['ordine'][$k]); } $result = true; $tipo = ADA_LEAF_ANSWER . ADA_NO_OPEN_TEST_ANSWER . ADA_CASE_SENSITIVE_TEST . '000'; foreach ($post as $k => $v) { $t = $tipo; $t[1] = $v['other_answer'] ? ADA_OPEN_TEST_ANSWER : ADA_NO_OPEN_TEST_ANSWER; $t[2] = $v['case_sensitive'] ? ADA_CASE_INSENSITIVE_TEST : ADA_CASE_SENSITIVE_TEST; $data = array('id_corso' => $this->test['id_corso'], 'id_utente' => $_SESSION['sess_id_user'], 'id_istanza' => $this->test['id_istanza'], 'nome' => $v['answer'], 'testo' => Node::prepareInternalLinkMediaForDatabase($v['answer']), 'correttezza' => $v['value'], 'tipo' => $t, 'id_nodo_parent' => $this->question['id_nodo'], 'id_nodo_radice' => $this->test['id_nodo'], 'ordine' => $v['ordine'] ? $v['ordine'] : $k + 1); if (intval($v['record']) > 0) { $res = $dh->test_updateNode(intval($v['record']), $data); } else { $res = $dh->test_addNode($data); } if (AMATestDataHandler::isError($res)) { $result = false; $html = translateFN('Errore durante la creazione delle risposte'); break; } unset($data); } if ($result) { $get_topic = isset($_GET['topic']) ? '&topic=' . $_GET['topic'] : ''; if ($_POST['return'] == 'here') { redirect(MODULES_TEST_HTTP . '/edit_answers.php?id_question=' . $this->question['id_nodo'] . $get_topic); } else { redirect(MODULES_TEST_HTTP . '/index.php?id_test=' . $this->test['id_nodo'] . $get_topic . '#liQuestion' . $this->question['id_nodo']); } } } } else { $html = $form->getHtml(); $div = CDOMElement::create('div', 'id:insertImage,class:hide'); $div->setAttribute('title', translateFN('Inserisci Immagine')); $div->setAttribute('style', 'text-align:right;'); $labelUrl = CDOMElement::create('label', 'for:inputUrl'); $labelUrl->addChild(new CText(translateFN('Url') . ':')); $inputUrl = CDOMElement::create('text', 'id:inputUrl'); $div->addChild($labelUrl); $div->addChild($inputUrl); $div->addChild(new CText('<br />')); $labelTitle = CDOMElement::create('label', 'for:inputTitle'); $labelTitle->addChild(new CText(translateFN('Titolo') . ':')); $inputTitle = CDOMElement::create('text', 'id:inputTitle'); $div->addChild($labelTitle); $div->addChild($inputTitle); $div->addChild(new CText('<br />')); $labelRadio = CDOMElement::create('label'); $labelRadio->addChild(new CText(translateFN('Permetti zoom') . ':')); $labelYes = CDOMElement::create('label', 'for:radioPopupYes'); $labelYes->addChild(new CText(translateFN('Si'))); $labelNo = CDOMElement::create('label', 'for:radioPopupNo'); $labelNo->addChild(new CText(translateFN('No'))); $radioYes = CDOMElement::create('radio', 'id:radioPopupYes,name:radioPopup'); $radioYes->setAttribute('checked', ''); $radioNo = CDOMElement::create('radio', 'id:radioPopupNo,name:radioPopup'); $div->addChild($labelRadio); $div->addChild($radioYes); $div->addChild($labelYes); $div->addChild($radioNo); $div->addChild($labelNo); $div->addChild(new CText('<br />')); $labelWidth = CDOMElement::create('label', 'for:inputWidth'); $labelWidth->addChild(new CText(translateFN('Larghezza') . ':')); $inputWidth = CDOMElement::create('text', 'id:inputWidth,size:4,value:75'); $labelHeight = CDOMElement::create('label', 'for:inputHeight'); $labelHeight->addChild(new CText(translateFN('Altezza') . ':')); $inputHeight = CDOMElement::create('text', 'id:inputHeight,size:4,value:75'); $div->addChild($labelWidth); $div->addChild($inputWidth); $div->addChild($labelHeight); $div->addChild($inputHeight); $html .= $div->getHtml(); } return $html; }