Beispiel #1
0
 protected function content()
 {
     //nome
     if (!empty($this->data['nome'])) {
         $defaultValue = $this->data['nome'];
     } else {
         $defaultValue = '';
     }
     $this->addTextInput('nome', translateFN('Nome (visualizzato nella breadcrumb)') . ':')->setRequired()->setValidator(FormValidator::NOT_EMPTY_STRING_VALIDATOR)->withData($defaultValue);
     //titolo
     $this->addTextInput('titolo', translateFN('Titolo') . ':')->setRequired()->setValidator(FormValidator::NOT_EMPTY_STRING_VALIDATOR)->withData($this->data['titolo']);
     //descrizione
     $this->addTextarea('testo', translateFN('Descrizione') . ':')->withData(Node::prepareInternalLinkMediaForEditor($this->data['testo']));
     //consegna (message showed on test / survey ending)
     if (!empty($this->data['nome'])) {
         $defaultValue = Node::prepareInternalLinkMediaForEditor($this->data['consegna']);
     } else {
         $defaultValue = translateFN('Dati inviati correttamente.');
     }
     $this->addTextarea('consegna', translateFN('Messaggio finale') . ':')->withData($defaultValue);
     //return
     $options = array(ADA_NO_TEST_RETURN => translateFN('Non mostrare link'), ADA_NEXT_NODE_TEST_RETURN => translateFN('Mostra link al nodo successivo del corso'), ADA_INDEX_TEST_RETURN => translateFN('Mostra link all\'indice del corso'), ADA_COURSE_INDEX_TEST_RETURN => translateFN('Mostra link all\'elenco dei corsi'));
     if (isset($this->data['return'])) {
         $defaultValue = $this->data['return'];
     } else {
         $defaultValue = ADA_NO_TEST_RETURN;
     }
     $this->addSelect('return', translateFN('Link di ritorno') . ':', $options, $defaultValue);
     //ripetibile
     $radios = array(ADA_YES_TEST_REPETEABLE => translateFN('Si'), ADA_NO_TEST_REPETEABLE => translateFN('No'));
     if (isset($this->data['ripetibile'])) {
         $defaultValue = $this->data['ripetibile'];
     } else {
         $defaultValue = ADA_YES_TEST_REPETEABLE;
     }
     $this->addRadios('ripetibile', translateFN('Ripetibile dall\'utente') . ':', $radios, $defaultValue);
     //suddivisione in sessioni
     $radios = array(ADA_SEQUENCE_TEST_MODE => translateFN('Si'), ADA_ONEPAGE_TEST_MODE => translateFN('No'));
     if (isset($this->data['suddivisione'])) {
         $defaultValue = $this->data['suddivisione'];
     } else {
         $defaultValue = ADA_ONEPAGE_TEST_MODE;
     }
     $this->addRadios('suddivisione', translateFN('Suddividi per sessioni') . ':', $radios, $defaultValue);
     //feedback
     $options = array(ADA_CORRECT_TEST_INTERACTION => translateFN('Correzioni risposte e risposta corretta'), ADA_RATING_TEST_INTERACTION => translateFN('Correzioni risposte, punteggio ottenuto e risposta corretta'), ADA_FEEDBACK_TEST_INTERACTION => translateFN('Correzioni risposte'), ADA_BLIND_TEST_INTERACTION => translateFN('Nessun feedback'));
     if (isset($this->data['feedback'])) {
         $defaultValue = $this->data['feedback'];
     } else {
         $defaultValue = ADA_RATING_TEST_INTERACTION;
     }
     $this->addSelect('feedback', translateFN('Feedback all\'utente') . ':', $options, $defaultValue);
     //livello minimo
     if (isset($this->data['min_level'])) {
         $defaultValue = $this->data['min_level'];
     } else {
         $defaultValue = 0;
     }
     $this->addTextInput('min_level', translateFN('Livello minimo per accedere al test (0 = nessun limite)') . ':')->setRequired()->setValidator(FormValidator::NON_NEGATIVE_NUMBER_VALIDATOR)->withData($defaultValue);
 }
 /**
  * Function called by render method to initialize components
  * (following business logic and with data) that will be rendered
  *
  * @see render
  */
 public function constructComponents()
 {
     if ($this->open_answer) {
         $span = CDOMElement::create('span');
         $checkbox_value = CDOMElement::create('hidden', 'name:other_answer[]');
         $checkbox_value->setAttribute('class', 'other_answer');
         $checkbox = CDOMElement::create('checkbox');
         $checkbox->setAttribute('class', 'other_answer_checkbox');
         $checkbox->setAttribute('onchange', 'change_other_answer(this);');
         if ($this->_controlData['other_answer']) {
             $checkbox_value->setAttribute('value', 1);
             $checkbox->setAttribute('checked', '');
         } else {
             $checkbox_value->setAttribute('value', 0);
         }
         $span->addChild($checkbox_value);
         $span->addChild($checkbox);
         $this->item['other_answer'] = $span;
     } else {
         $this->item['other_answer'] = null;
     }
     $this->_controlData['answer'] = Node::prepareInternalLinkMediaForEditor($this->_controlData['answer']);
     $input = CDOMElement::create('text', 'name:answer[]');
     $input->setAttribute('class', 'answer');
     $input->setAttribute('value', htmlspecialchars($this->_controlData['answer']));
     if ($this->clonable) {
         $input->setAttribute('disabled', '');
     }
     $img = CDOMElement::create('img', 'class:addImage,onclick:insertImage(this);,title:' . translateFN('Inserisci Immagine'));
     $img->setAttribute('src', 'img/img.png');
     $this->item['answer'] = CDOMElement::create('span');
     $this->item['answer']->addChild($input);
     $this->item['answer']->addChild($img);
     $this->item['value'] = CDOMElement::create('text', 'name:value[]');
     $this->item['value']->setAttribute('class', 'value');
     $this->item['value']->setAttribute('value', intval($this->_controlData['value']));
     if ($this->show_case_sensitive) {
         $span = CDOMElement::create('span');
         $checkbox_value = CDOMElement::create('hidden', 'name:case_sensitive[]');
         $checkbox_value->setAttribute('class', 'case_sensitive');
         $checkbox = CDOMElement::create('checkbox');
         $checkbox->setAttribute('class', 'case_sensitive_checkbox');
         $checkbox->setAttribute('onchange', 'change_case_sensitive(this);');
         if ($this->_controlData['case_sensitive']) {
             $checkbox_value->setAttribute('value', 1);
             $checkbox->setAttribute('checked', '');
         } else {
             $checkbox_value->setAttribute('value', 0);
         }
         $span->addChild($checkbox_value);
         $span->addChild($checkbox);
         $this->item['case_sensitive'] = $span;
     } else {
         $this->item['case_sensitive'] = null;
     }
     $this->item['record'] = CDOMElement::create('hidden', 'name:record[]');
     $this->item['record']->setAttribute('class', 'record');
     $this->item['record']->setAttribute('value', $this->_controlData['record']);
 }
    protected function common_elements()
    {
        $dh = $GLOBALS['dh'];
        $this->setName('questionForm');
        $this->addHidden('step')->withData(2);
        $injectTemplate = 'injectTemplate';
        $commento = 'commento';
        $didascalia = 'didascalia';
        $js = '
			isCloze = ' . $this->isCloze . ';
			var injectTemplate_field = "' . $injectTemplate . '";
			var commento_field = "' . $commento . '";
			var field = "' . $didascalia . '";
			var regexp = /^(?:[\\d]+|[\\w]+).*$/;
			var module_http = "' . MODULES_TEST_HTTP . '";
			document.write(\'<script type="text/javascript" src="' . MODULES_TEST_HTTP . '/js/questionFormStep2.js"><\\/script>\');';
        $this->setCustomJavascript($js);
        //forgetExerciseType
        if ($this->savedExerciseType) {
            require_once MODULES_TEST_PATH . '/include/forms/controls/forgetExerciseTypeControlTest.inc.php';
            $this->addControl(new ForgetExerciseTypeControlTest());
        }
        //parent node
        $this->parentSelect();
        //nome
        if (!empty($this->data['nome'])) {
            $defaultValue = $this->data['nome'];
        } else {
            if (!is_null($this->id_nodo_parent)) {
                $defaultValue = translateFN('domanda') . ' ';
                $res = $dh->test_getNodesByRadix($this->id_test);
                if ($dh->isError($res) || empty($res)) {
                    $defaultValue .= 1;
                } else {
                    foreach ($res as $k => $v) {
                        if ($v['tipo'][0] != ADA_GROUP_QUESTION) {
                            unset($res[$k]);
                        }
                    }
                    $defaultValue .= count($res) + 1;
                }
            } else {
                $defaultValue = '';
            }
        }
        $this->addTextInput('nome', translateFN('Nome (per uso interno)') . ':')->setRequired()->setValidator(FormValidator::NOT_EMPTY_STRING_VALIDATOR)->withData($defaultValue);
        //titolo
        $this->addTextInput('titolo', translateFN('Titolo') . ':')->withData($this->data['titolo']);
        //consegna
        $this->addTextarea('consegna', translateFN('Consegna') . ':')->withData(Node::prepareInternalLinkMediaForEditor($this->data['consegna']));
        //importazione template
        $this->addTemplateEditor($injectTemplate, translateFN('Importare un template (opzionale):'));
        //descrizione
        $this->addTextarea('testo', translateFN('Descrizione') . ':')->withData(Node::prepareInternalLinkMediaForEditor($this->data['testo']));
        //commento a fine domanda
        $options = array(ADA_NO_TEST_COMMENT => translateFN('No'), ADA_YES_TEST_COMMENT => translateFN('Si'));
        if (isset($this->data[$commento])) {
            $defaultValue = $this->data[$commento];
        } else {
            $defaultValue = ADA_NO_TEST_COMMENT;
        }
        $this->addRadios($commento, translateFN('Permetti commento a fine domanda') . ':', $options, $defaultValue);
        //didascalia commento fine domanda
        $didascalia = $this->addTextInput($didascalia, translateFN('Testo commento fine domanda') . ':')->setValidator(null)->withData($this->data[$didascalia]);
        if (isset($this->data[$commento]) && $this->data[$commento] == ADA_YES_TEST_COMMENT) {
            $didascalia->setRequired();
        }
    }
Beispiel #4
0
 /**
  * Render the object structure when the test is over
  *
  * @access protected
  *
  * @param $id_history_test the id of test instance
  * @param $return_html choose the return type
  *
  * @return an object of CDOMElement
  */
 protected function renderEndTest($id_history_test, $return_html = true)
 {
     $dh = $GLOBALS['dh'];
     if ($_SESSION['sess_id_user_type'] == AMA_TYPE_TUTOR) {
         $this->feedback = true;
         $this->rating = true;
     }
     if ($this->feedback) {
         //check if $id_history_test param is an integer and retrieve rows from database
         if (intval($id_history_test) <= 0) {
             $html = CDOMElement::create('div');
             $html->addChild(new CText(translateFN('Test non valido!')));
         } else {
             $id_history_test = intval($id_history_test);
             $givenTest = $dh->test_getHistoryTest($id_history_test);
             $givenTest = $givenTest[0];
             $givenAnswers = $dh->test_getGivenAnswers($id_history_test);
             if (AMA_DataHandler::isError($givenTest) || AMA_DataHandler::isError($givenAnswers)) {
                 $html = CDOMElement::create('div');
                 $html->addChild(new CText(translateFN('Si è verificato un errore durante il recupero delle informazioni!')));
             } else {
                 //search every question objects
                 $genericItems = $this->_children;
                 $questions = array();
                 while (!empty($genericItems)) {
                     foreach ($genericItems as $k => $child) {
                         if (!is_subclass_of($child, 'QuestionTest')) {
                             for ($i = 0; $i < $child->countChildren(); $i++) {
                                 $genericItems[] = $child->getChild($i);
                             }
                         } else {
                             $questions[] = $child;
                         }
                         unset($genericItems[$k]);
                     }
                 }
             }
             unset($genericItems);
             //assign data to objects
             if (!empty($questions)) {
                 foreach ($questions as $q) {
                     $q->setDisplay(false);
                 }
             }
             $max_score = 0;
             $score = 0;
             if (!empty($givenAnswers)) {
                 foreach ($givenAnswers as $a => $answer) {
                     if (!empty($questions)) {
                         foreach ($questions as $k => $q) {
                             if ($answer['id_nodo'] == $q->id_nodo) {
                                 $answer['risposta'] = unserialize($answer['risposta']);
                                 $q->setGivenAnswer($answer);
                                 $q->setDisplay(true);
                                 //while assigning calculate scores
                                 $score += $answer['punteggio'];
                                 $max_score += $q->getMaxScore();
                                 unset($questions[$k]);
                                 unset($givenAnswers[$a]);
                                 break;
                             }
                         }
                     }
                 }
             }
             unset($givenAnswers);
             //rendering test
             $html = $this->renderingHtml($ref, $this->feedback, $this->rating, $this->rating_answer);
             if (is_null($ref)) {
                 $ref = $html;
             }
             if (!empty($this->_children)) {
                 foreach ($this->_children as $v) {
                     $ref->addChild($v->render(false, $this->feedback, $this->rating, $this->rating_answer));
                 }
             }
             //show total Score
             if ($this->rating) {
                 $div = CDOMElement::create('div', 'id:test_score');
                 $div->setAttribute('id', 'score_test');
                 if ($_SESSION['sess_id_user_type'] != AMA_TYPE_STUDENT) {
                     $testo = translateFN('Lo studente ha totalizzato %s punti su %s');
                 } else {
                     $testo = translateFN('Hai totalizzato %s punti su %s');
                 }
                 $div->addChild(new CText(sprintf($testo, $score, $max_score)));
                 $html->addChild($div);
             }
             // prints control to set test repeatable
             if (!$this->repeatable && $_SESSION['sess_id_user_type'] == AMA_TYPE_TUTOR) {
                 $div = CDOMElement::create('div', 'id:test_controls');
                 $label = CDOMElement::create('label');
                 $label->addChild(new CText(translateFN('Permettere all\'utente di ripetere il test?')));
                 $div->addChild($label);
                 $radioSi = CDOMElement::create('radio', 'id:repeateTestYes,name:repeateTest');
                 $radioSi->setAttribute('onchange', 'toggleRepeatable(' . $id_history_test . ',true);');
                 if ($givenTest['ripetibile']) {
                     $radioSi->setAttribute('checked', '');
                 }
                 $div->addChild($radioSi);
                 $div->addChild(new CText(translateFN('Si')));
                 $radioNo = CDOMElement::create('radio', 'id:repeateTestNo,name:repeateTest');
                 $radioNo->setAttribute('onchange', 'toggleRepeatable(' . $id_history_test . ',false);');
                 if (!$givenTest['ripetibile']) {
                     $radioNo->setAttribute('checked', '');
                 }
                 $div->addChild($radioNo);
                 $div->addChild(new CText(translateFN('No')));
                 $html->addChild($div);
             }
         }
     } else {
         $html = CDOMElement::create('div');
         $html->addChild(new CText(Node::prepareInternalLinkMediaForEditor($this->consegna)));
     }
     //return link
     $return_link = null;
     switch ($this->returnLink) {
         default:
         case ADA_NO_TEST_RETURN:
             $label = null;
             $return_link = null;
             break;
         case ADA_NEXT_NODE_TEST_RETURN:
             $label = translateFN('Procedi');
             $node_obj = new Node($this->id_nodo_riferimento);
             if (!empty($node_obj->next_id)) {
                 $return_link = HTTP_ROOT_DIR . '/browsing/view.php?id_node=' . $node_obj->next_id;
             }
             break;
         case ADA_INDEX_TEST_RETURN:
             $label = translateFN('Torna all\'indice del corso');
             $return_link = HTTP_ROOT_DIR . '/browsing/main_index.php';
             break;
         case ADA_COURSE_INDEX_TEST_RETURN:
             $label = translateFN('Torna all\'elenco dei corsi');
             $return_link = HTTP_ROOT_DIR . '/browsing/user.php';
             break;
     }
     if (!is_null($return_link)) {
         $a = CDOMElement::create('a', 'href:' . $return_link);
         $a->addChild(new CText($label));
         $div = CDOMElement::create('div', 'id:return_link');
         $div->addChild($a);
         $html->addChild($div);
     }
     if ($return_html) {
         return $html->getHtml();
     } else {
         return $html;
     }
 }
Beispiel #5
0
    protected function content()
    {
        $dh = $GLOBALS['dh'];
        $this->setName('topicForm');
        $random = 'random';
        $random_number = 'random_number';
        $js = 'var random_field = "' . $random . '";
			var field = "' . $random_number . '";
			var regexp = /^[0-9]+$/;
			document.write(\'<script type="text/javascript" src="' . MODULES_TEST_HTTP . '/js/topicForm.js"><\\/script>\');';
        $this->setCustomJavascript($js);
        //parent
        $nodes = $dh->test_getNodesByParent($this->id_test, $this->id_test);
        $options = array($this->id_test => $nodes[$this->id_test]['titolo'] . ' (' . $nodes[$this->id_test]['nome'] . ')');
        foreach ($nodes as $id_nodo => $v) {
            if ($id_nodo != $this->id_test) {
                $options[$id_nodo] = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' . $v['titolo'] . ' (' . $v['nome'] . ')';
            }
        }
        if (isset($this->data['id_nodo_parent'])) {
            $defaultValue = $this->data['id_nodo_parent'];
        } else {
            if (is_null($this->id_nodo_parent)) {
                $defaultValue = $this->id_test;
            } else {
                $defaultValue = $this->id_nodo_parent;
            }
        }
        $this->addSelect('id_nodo_parent', translateFN('Aggancia a') . ':', $options, $defaultValue);
        //nome
        if (!empty($this->data['nome'])) {
            $defaultValue = $this->data['nome'];
        } else {
            if (is_null($this->id_nodo_parent)) {
                $defaultValue = translateFN('sessione') . ' ';
            } else {
                $defaultValue = translateFN('argomento') . ' ';
            }
            $res = $dh->test_getNodesByRadix($this->id_test);
            if ($dh->isError($res) || empty($res)) {
                $defaultValue .= 1;
            } else {
                foreach ($res as $k => $v) {
                    if ($v['tipo'][0] != ADA_GROUP_TOPIC) {
                        unset($res[$k]);
                    }
                }
                $defaultValue .= count($res) + 1;
            }
        }
        $this->addTextInput('nome', translateFN('Nome (per uso interno)') . ':')->setRequired()->setValidator(FormValidator::NOT_EMPTY_STRING_VALIDATOR)->withData($defaultValue);
        //titolo
        $this->addTextInput('titolo', translateFN('Titolo') . ':')->withData($this->data['titolo']);
        //descrizione
        $this->addTextarea('testo', translateFN('Descrizione') . ':')->withData(Node::prepareInternalLinkMediaForEditor($this->data['testo']));
        //durata
        if (!is_null($this->id_nodo_parent)) {
            $this->addHidden('durata')->withData(0);
        } else {
            if (isset($this->data['durata'])) {
                $defaultValue = $this->data['durata'];
            } else {
                $defaultValue = 0;
            }
            $this->addTextInput('durata', translateFN('Tempo limite (in minuti, 0 = senza limite)') . ': ')->setRequired()->setValidator(FormValidator::NON_NEGATIVE_NUMBER_VALIDATOR)->withData($defaultValue);
        }
        //random questions
        $radios = array(ADA_PICK_QUESTIONS_NORMAL => translateFN('No'), ADA_PICK_QUESTIONS_RANDOM => translateFN('Si'));
        if (isset($this->data[$random])) {
            $defaultValue = $this->data[$random];
        } else {
            $defaultValue = ADA_PICK_QUESTIONS_NORMAL;
        }
        if (is_null($this->id_nodo_parent)) {
            $randomTranslation = translateFN('Scelta casuale degli argomenti');
        } else {
            $randomTranslation = translateFN('Scelta casuale delle domande');
        }
        $this->addRadios($random, $randomTranslation . ':', $radios, $defaultValue);
        //how many random questions
        if (is_null($this->id_nodo_parent)) {
            $label = translateFN('Numero di argomenti da mostrare');
        } else {
            $label = translateFN('Numero di domande da mostrare');
        }
        $num = $this->addTextInput($random_number, $label . ':')->setValidator(FormValidator::POSITIVE_NUMBER_VALIDATOR)->withData($this->data[$random_number]);
        if (isset($this->data[$random]) && $this->data[$random] == ADA_PICK_QUESTIONS_RANDOM) {
            $num->setRequired();
        }
    }