public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $response = $qa->get_last_qt_data();
     $o = html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $o .= html_writer::start_tag('div', array('id' => 'ablock_' . $question->id, 'class' => 'ablock'));
     $o .= $this->construct_ablock_select($qa, $options);
     $o .= html_writer::end_tag('div');
     if ($this->can_use_drag_and_drop()) {
         $o .= html_writer::tag('div', '', array('class' => 'clearer'));
     }
     if ($qa->get_state() == question_state::$invalid) {
         $o .= html_writer::nonempty_tag('div', $question->get_validation_error($response), array('class' => 'validationerror'));
     }
     if ($this->can_use_drag_and_drop()) {
         $initparams = new stdClass();
         $initparams->qid = $question->id;
         $initparams->stemscount = count($question->get_stem_order());
         $initparams->ablockcontent = $this->construct_ablock_dragable($qa, $options);
         $initparams->readonly = $options->readonly;
         $initparams = json_encode($initparams);
         $js = "YAHOO.util.Event.onDOMReady(function(){M.order.Init({$initparams});});";
         $o .= html_writer::script($js);
     }
     return $o;
 }
Exemple #2
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $response = $qa->get_last_qt_data();
     $o = html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $o .= html_writer::start_tag('div', array('id' => 'ablock_' . $question->id, 'class' => 'ablock'));
     $o .= $this->construct_ablock_select($qa, $options);
     $o .= html_writer::end_tag('div');
     if ($this->can_use_drag_and_drop()) {
         $o .= html_writer::tag('div', '', array('class' => 'clearer'));
     }
     if ($qa->get_state() == question_state::$invalid) {
         $o .= html_writer::nonempty_tag('div', $question->get_validation_error($response), array('class' => 'validationerror'));
     }
     if ($this->can_use_drag_and_drop()) {
         $initparams = new stdClass();
         $initparams->qid = $question->id;
         $initparams->stemscount = count($question->get_stem_order());
         $initparams->ablockcontent = $this->construct_ablock_dragable($qa, $options);
         $initparams->readonly = $options->readonly;
         global $PAGE;
         $PAGE->requires->js_init_call('M.order.Init', array($initparams), FALSE, array('name' => 'order', 'fullpath' => '/question/type/order/order.js', 'requires' => array('yui2-yahoo', 'yui2-event', 'yui2-dom', 'yui2-dragdrop', 'yui2-animation')));
     }
     return $o;
 }
 public function manual_comment(question_attempt $qa, question_display_options $options)
 {
     if ($options->manualcomment != question_display_options::EDITABLE) {
         return '';
     }
     $question = $qa->get_question();
     return html_writer::nonempty_tag('div', $question->format_text($question->graderinfo, $question->graderinfo, $qa, 'qtype_poodllrecording', 'graderinfo', $question->id), array('class' => 'graderinfo'));
 }
Exemple #4
0
 public function feedback(question_attempt $qa, question_display_options $options)
 {
     // If the latest answer was invalid, display an informative message.
     if ($qa->get_state() == question_state::$invalid) {
         return html_writer::nonempty_tag('div', $this->disregarded_info(), array('class' => 'gradingdetails'));
     }
     // Otherwise get the details.
     return $this->render_adaptive_marks($qa->get_behaviour()->get_adaptive_marks(), $options);
 }
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     global $CFG, $PAGE;
     $question = $qa->get_question();
     $questiontext = $question->format_questiontext($qa);
     $uniqid = uniqid();
     $myanswerid = "my_answer" . $uniqid;
     $correctanswerid = "correct_answer" . $uniqid;
     $marvinjsconfig = get_config('qtype_easyomechjs_options');
     $marvinjspath = $marvinjsconfig->path;
     $protocol = (empty($_SERVER['HTTPS']) or $_SERVER['HTTPS'] == 'off') ? 'http://' : 'https://';
     $PAGE->requires->js(new moodle_url($protocol . $_SERVER['HTTP_HOST'] . $marvinjspath . '/gui/lib/promise-0.1.1.min.js'));
     $PAGE->requires->js(new moodle_url($protocol . $_SERVER['HTTP_HOST'] . $marvinjspath . '/js/marvinjslauncher.js'));
     $result = html_writer::tag('div', $questiontext, array('class' => 'qtext'));
     if ($options->readonly) {
         $result .= html_writer::tag('input', '', array('id' => 'myresponse' . $uniqid, 'type' => 'button', 'value' => 'My Response'));
         $result .= html_writer::tag('input', '', array('id' => 'corresponse' . $uniqid, 'type' => 'button', 'value' => 'Correct Answer'));
         $this->page->requires->js_init_call('M.qtype_easyomechjs.showmyresponse', array($CFG->version, $uniqid));
         $this->page->requires->js_init_call('M.qtype_easyomechjs.showcorresponse', array($CFG->version, $uniqid));
     }
     $toreplaceid = 'applet' . $uniqid;
     $toreplace = html_writer::tag('div', get_string('enablejavaandjavascript', 'qtype_easyomechjs'), array('id' => $toreplaceid, 'class' => 'easyomechjs resizable'));
     $answerlabel = html_writer::tag('span', get_string('answer', 'qtype_easyomechjs', ''), array('class' => 'answerlabel'));
     $result .= html_writer::tag('div', $answerlabel . $toreplace, array('class' => 'ablock'));
     if ($qa->get_state() == question_state::$invalid) {
         $lastresponse = $this->get_last_response($qa);
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($lastresponse), array('class' => 'validationerror'));
     }
     if (!$options->readonly) {
         $question = $qa->get_question();
         $answertemp = $question->get_correct_response();
         $currentanswer = $qa->get_last_qt_var('answer');
         if ($currentanswer != null) {
             $strippedxml = $currentanswer;
         } else {
             $strippedxml = $this->remove_xml_tags($answertemp['answer'], 'MEFlow');
         }
         $strippedanswerid = "stripped_answer" . $uniqid;
         $result .= html_writer::tag('textarea', $strippedxml, array('id' => $strippedanswerid, 'style' => 'display:none;', 'name' => $strippedanswerid));
     }
     if ($options->readonly) {
         $currentanswer = $qa->get_last_qt_var('answer');
         $strippedanswerid = "stripped_answer" . $uniqid;
         $result .= html_writer::tag('textarea', $currentanswer, array('id' => $strippedanswerid, 'style' => 'display:none;', 'name' => $strippedanswerid));
         $answertemp = $question->get_correct_response();
         // Buttons to show correct and user answers - yeah its a hack!
         $result .= html_writer::tag('textarea', $qa->get_last_qt_var('answer'), array('id' => $myanswerid, 'name' => $myanswerid, 'style' => 'display:none;'));
         $result .= html_writer::tag('textarea', $answertemp['answer'], array('id' => $correctanswerid, 'name' => $correctanswerid, 'style' => 'display:none;'));
     }
     $result .= html_writer::tag('div', $this->hidden_fields($qa), array('class' => 'inputcontrol'));
     $this->require_js($toreplaceid, $qa, $options->readonly, $options->correctness, $uniqid);
     return $result;
 }
 /**
  * Generate the HTML required for a ddmatch question
  *
  * @param $qa question_attempt The question attempt
  * @param $options question_display_options The options for display
  */
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     // We use the question quite a lot so store a reference to it once.
     $question = $qa->get_question();
     // Put together the basic question text and answer block.
     $output = '';
     $output .= $this->construct_questiontext($question->format_questiontext($qa));
     $output .= $this->construct_answerblock($qa, $question, $options);
     $this->page->requires->string_for_js('draganswerhere', 'qtype_ddmatch');
     $this->page->requires->yui_module('moodle-qtype_ddmatch-dragdrop', 'M.qtype.ddmatch.init_dragdrop', array(array('questionid' => $qa->get_slot(), 'readonly' => $options->readonly)));
     if ($qa->get_state() === question_state::$invalid) {
         $response = $qa->get_last_qt_data();
         $output .= html_writer::nonempty_tag('div', $question->get_validation_error($response), array('class' => 'validationerror'));
     }
     return $output;
 }
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $currentanswer = $qa->get_last_qt_var('answer');
     $inputname = $qa->get_qt_field_name('answer');
     $inputattributes = array('type' => 'text', 'name' => $inputname, 'value' => $currentanswer, 'id' => $inputname, 'size' => 80, 'style' => 'display:none', 'spellcheck' => 'true');
     if ($options->readonly) {
         $inputattributes['readonly'] = 'readonly';
     }
     $feedbackimg = '';
     if ($options->correctness) {
         $answer = $question->get_matching_answer(array('answer' => $currentanswer));
         if ($answer) {
             $fraction = $answer->fraction;
         } else {
             $fraction = 0;
         }
         $inputattributes['class'] = $this->feedback_class($fraction);
         $feedbackimg = $this->feedback_image($fraction);
     }
     $questiontext = $question->format_questiontext($qa);
     $placeholder = false;
     if (preg_match('/_____+/', $questiontext, $matches)) {
         $placeholder = $matches[0];
         $inputattributes['size'] = round(strlen($placeholder) * 1.1);
     }
     $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg;
     if ($placeholder) {
         $inputinplace = html_writer::tag('label', get_string('answer'), array('for' => $inputattributes['id'], 'class' => 'accesshide'));
         $inputinplace .= $input;
         $questiontext = substr_replace($questiontext, $inputinplace, strpos($questiontext, $placeholder), strlen($placeholder));
     }
     $result = html_writer::tag('div', $questiontext, array('class' => 'qtext'));
     if (!$placeholder) {
         $result .= html_writer::start_tag('div', array('class' => 'ablock'));
         $result .= html_writer::tag('label', get_string('answer', 'qtype_shortanswer', html_writer::tag('span', $input, array('class' => 'answer'))), array('for' => $inputattributes['id']));
         $result .= html_writer::end_tag('div');
     }
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error(array('answer' => $currentanswer)), array('class' => 'validationerror'));
     }
     $formatted = " <link href=\"../../jquery-spellchecker-demo-master/js/lib/redactor/redactor.css\" rel=\"stylesheet\" />\n    <link href=\"../../jquery-spellchecker-demo-master/css/bootstrap.min.css\" rel=\"stylesheet\">\n    <link href=\"../../jquery-spellchecker-demo-master/css/jquery.spellchecker.css\" rel=\"stylesheet\" />\n    <link href=\"../../jquery-spellchecker-demo-master/css/demos.css\" rel=\"stylesheet\" />\n   \n\n<style>\n@import url('//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css');\n \n.warning {margin: 10px 0px; padding:12px;}\n.warning {color: #9F6000; background-color: #FEEFB3; font-weight:normal;}\n.warning i, {margin:10px 22px; font-size:2em;vertical-align:middle;}\n</style>\n\n \n    <style type=\"text/css\">\n    .redactor_toolbar li a.redactor_btn_spellchecker {\n      background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHtSURBVDjLY/j//z8DJZiBKgY49drM9J3idhLEtu+xjvea4nLNqsVspnWr2S6QmF6+Zol2ltpq5QSlmcpxijMxDABp9pjkuMuu28rIpsMi3rLZFKzIus38mm6OuqRxpf41nC5w7rOJd+i1ngnUXGLTbj7Tsskk3rbL8ppZreEu7Ry1mWpJSvHK8Uoz0TWK5U/nYIg8y8rgPsl+l12P1WqgbTPdJtk/AtoWb1CkBdagnqyyWilawVM/Rw/FBQyx540ZGm/eYIg8P43BdYLdSZiEcYXeTJB/TaoNroH8q5OldVIhXE5SKUqhXSNRfZdKvPKVkOrED+L9d/8wN998w+B4XIL40I48K8FQf/O6+7In/7mbb35hsD2qjBKNDLU3ExjKb7pi1Rx61ke89+6fwBVP/jPXXn/HYHlYGiMdMJTe1JJc/PgHQ/X1xQyplznBYuFnmRiiz062nPfof8DSJ/8ZSq8/ZzA9KIEzIQE1Vvuuf/6fufv2M4bgsz4MxVdPui8Cal4C1Jx/+RGDPqpmTANiz7MAvXI+bO2L/5ZzHvzP2Pjif8DCx/8ZMi/fY9DcL0FUUmbwPKkg3Hr7T+WOV//95j/8z5B6/jaD6l4JkvIC0J9FTtPu/2dIPn+PQXG3BFmZiUFzbweDLH7NVMmNAOGld33BRiNUAAAAAElFTkSuQmCC) !important;\n      background-repeat: no-repeat;\n      background-position: center center;\n    }\n    </style>\n\n    <script type=\"text/javascript\">\n      var _gaq = _gaq || [];\n      _gaq.push(['_setAccount', 'UA-1636725-34']);\n      _gaq.push(['_trackPageview']);\n      (function() {\n        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;\n        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';\n        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);\n\n      })();\n    </script>\n\n\n  \n\n      \n   \n\n    <div class=\"container\" id=\"spellarea\" style=\"width: 100%;\">\n \n\n      <div class=\"row-fluid\">\n          \n\n          <div class=\"tab-content\">\n\n<div class=\"warning\"> <i class=\"fa fa-warning\"></i> (Cheque a grafia correta das palavras)</div>\n\n            <div class=\"tab-pane active\" id=\"demo\">\n          <textarea id=\"text-area\" class=\"textarea\" style=\"width:90%\" rows=\"10\">\n           <p id='answer'> Suua Resposta </p>\n          </textarea>\n  </script> \n\n\n\n          </div>\n          <div class=\"tab-pane\" id=\"usage\">\n\n        <p>Include the neccessary files:</p>\n        <pre class=\"prettyprint linenums\">\n&lt;link rel=\"stylesheet\" href=\"redactor/redactor.css\" /&gt;\n&lt;link rel=\"stylesheet\" href=\"jquery.spellchecker.css\" /&gt;\n\n&lt;script src=\"../../jquery-spellchecker-demo-master/js/jquery-1.8.2.min.js\"&gt;&lt;/script&gt;\n&lt;script src=\"../../jquery-spellchecker-demo-master/js/jquery.spellchecker.js\"&gt;&lt;/script&gt;\n&lt;script src=\"../../redactor/redactor.min.js\"&gt;&lt;/script&gt;</pre>\n <p>Add the following CSS:</p>\n        <pre class=\"prettyprint linenums lang-css\">\n.redactor_toolbar li a.redactor_btn_spellchecker {\n  background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAAHtSURBVDjLY/j//z8DJZiBKgY49drM9J3idhLEtu+xjvea4nLNqsVspnWr2S6QmF6+Zol2ltpq5QSlmcpxijMxDABp9pjkuMuu28rIpsMi3rLZFKzIus38mm6OuqRxpf41nC5w7rOJd+i1ngnUXGLTbj7Tsskk3rbL8ppZreEu7Ry1mWpJSvHK8Uoz0TWK5U/nYIg8y8rgPsl+l12P1WqgbTPdJtk/AtoWb1CkBdagnqyyWilawVM/Rw/FBQyx540ZGm/eYIg8P43BdYLdSZiEcYXeTJB/TaoNroH8q5OldVIhXE5SKUqhXSNRfZdKvPKVkOrED+L9d/8wN998w+B4XIL40I48K8FQf/O6+7In/7mbb35hsD2qjBKNDLU3ExjKb7pi1Rx61ke89+6fwBVP/jPXXn/HYHlYGiMdMJTe1JJc/PgHQ/X1xQyplznBYuFnmRiiz062nPfof8DSJ/8ZSq8/ZzA9KIEzIQE1Vvuuf/6fufv2M4bgsz4MxVdPui8Cal4C1Jx/+RGDPqpmTANiz7MAvXI+bO2L/5ZzHvzP2Pjif8DCx/8ZMi/fY9DcL0FUUmbwPKkg3Hr7T+WOV//95j/8z5B6/jaD6l4JkvIC0J9FTtPu/2dIPn+PQXG3BFmZiUFzbweDLH7NVMmNAOGld33BRiNUAAAAAElFTkSuQmCC) !important;\n  background-repeat: no-repeat;\n  background-position: center center;\n}</pre>\n<p>Create the spellchecker plugin and init the Reactor editor:</p>\n\n        <pre class=\"prettyprint linenums\">\n</pre>\n      </div></div></div>\n\n    </div> <!-- /container -->\n\n    <script src=\"../../jquery-spellchecker-demo-master/js/lib/jquery/jquery-1.8.2.min.js\"></script>\n    <script src=\"../../jquery-spellchecker-demo-master/js/lib/redactor/redactor.min.js\"></script>\n    <script src=\"../../jquery-spellchecker-demo-master/js/lib/bootstrap/bootstrap.min.js\"></script>\n    <script src=\"../../jquery-spellchecker-demo-master/js/lib/prettyprint/prettyprint.js\"></script>\n    <script src=\"../../jquery-spellchecker-demo-master/js/jquery.spellchecker.js\"></script>\n\n    <script>\n(function() {\n   var update = function(){\n        try{\n         var answer = document.getElementById(\"answer\").innerHTML.trim();\n\n//      document.getElementById(\"answer\").innerHTML = ' ' +answer;\n//      answer = document.getElementById(\"answer\").innerHTML.trim();\n\n\nvar is_chrome = window.chrome;\nconsole.log(is_chrome);\n \n    if (typeof is_chrome != 'undefined'){\n        //document.getElementById(\"answer\").innerHTML = \" - \";\ndocument.getElementById(\"answer\").innerHTML = ' ' +answer;\nanswer = document.getElementById(\"answer\").innerHTML.trim();\n        }\n\n        var tmp = document.createElement(\"DIV\");\n       tmp.innerHTML = answer;\n         answer = tmp.textContent || tmp.innerText || \"\";\n\n         document.getElementById(\"" . $inputname . "\").value = answer.trim();\n         console.log( answer +\"- \"+answer.length );//document.getElementById(\"" . $inputname . "\").value);\n        \n        } catch (e) {}}\n\n  if ( \$('input[name=\"" . $inputname . "\"]').is('[readonly]') ) {\n         document.getElementById(\"" . $inputname . "\").style.display = \"block\";\n        //window.alert('ok');\n         document.getElementById(\"spellarea\").style.display = \"none\";\n    };\n\n\n\n  if (typeof window.RedactorPlugins === 'undefined') window.RedactorPlugins = {};\n   \n  window.RedactorPlugins.spellchecker = {\n    init: function() {\n      \n      this.addBtn('spellchecker', 'Checar grafia das palavras!', function(obj) {\n       \n        obj.toggle();\n      });\n    },\n    create: function() {\n        //window.alert(document.getElementById(\"text-area\").value);\n      this.spellchecker = new \$.SpellChecker(this.\$editor, {\n\n        lang: 'pt-br',\n        parser: 'html',\n        webservice: {\n          path: \"../webservices/php/SpellChecker.php\",\n          driver: 'pspell'\n        },\n        suggestBox: {\n          position: 'below'\n        }\n      });\n\n    // var answer = document.getElementById(\"answer\").innerHTML;\n        // document.getElementById(\"" . $inputname . "\").value = answer;\n        // console.log( document.getElementById(\"" . $inputname . "\").value);\n        update();\n\n      // Bind spellchecker handler functions\n      this.spellchecker.on('check.success', function() {\n        alert('Sem erros de escrita!');\n      });\n    },\n    toggle: function() {\n      if (!this.spellchecker) {\n        this.setBtnActive('spellchecker');\n        this.create();\n        this.spellchecker.check();\n      } else {\n        this.setBtnInactive('spellchecker');\n        this.spellchecker.destroy();\n        this.spellchecker = null;\n      }\n        //var answer = document.getElementById(\"answer\").innerHTML;\n        //document.getElementById(\"" . $inputname . "\").value = answer;\n        //console.log( document.getElementById(\"" . $inputname . "\").value);\n\n        update();\n        var classname = document.getElementsByClassName(\"words\");\n        var myFunction = function() {\n                setTimeout(function(){\n        update();\n        //var answer = document.getElementById(\"answer\").innerHTML;\n        //document.getElementById(\"" . $inputname . "\").value = answer;\n        //console.log( document.getElementById(\"" . $inputname . "\").value);\n        }, 1000);\n   \n        };\n\n    for(var i=0;i<classname.length;i++){\n        classname[i].addEventListener('click',  myFunction, false);\n    }\n\n   }\n  };\n   \n\n// Init redactor\n  \$('.textarea').redactor({ \n    plugins: ['spellchecker'],\n    blurCallback: function(e)\n    {\n        //var answer = document.getElementById(\"answer\").innerHTML;\n        //console.log(answer);\n        //show();\n        \n \n         //document.getElementById(\"" . $inputname . "\").value = answer;\n        \n        //console.log( document.getElementById(\"" . $inputname . "\").value);\n    },\n    keyupCallback: function(x)\n    {\n        //var answer = document.getElementById(\"answer\").innerHTML;\n        //console.log(answer);\n        //show();\n        \n        update();\n         //document.getElementById(\"" . $inputname . "\").value = answer;\n        \n        //console.log( document.getElementById(\"" . $inputname . "\").value);\n        }\n\n  });\n\n})();\n\n\n\$('.redactor_btn_formatting').remove();\n\$('.redactor_separator').remove();\n\$('.redactor_btn_bold').remove();\n\$('.redactor_btn_italic').remove();\n\$('.redactor_btn_html').remove();\n\$('.redactor_btn_image').remove();\n\$('.redactor_btn_table').remove();\n\$('.redactor_btn_link').remove();\n\$('.redactor_btn_fontcolor').remove();\n\$('.redactor_btn_backcolor').remove();\n\$('.redactor_btn_alignment').remove();\n\$('.redactor_btn_horizontalrule').remove();\n\$('.redactor_btn_deleted').remove();\n\$('.redactor_btn_unorderedlist').remove();\n\$('.redactor_btn_video').remove();\n\$('.redactor_btn_orderedlist').remove();\n\$('.redactor_btn_outdent').remove();\n\$('.redactor_btn_indent').remove();\n \n\n\n\n\n       \n    </script>\n  ";
     $result .= $formatted;
     return $result;
 }
Exemple #8
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $questiontext = '';
     foreach ($question->textfragments as $i => $fragment) {
         if ($i > 0) {
             $questiontext .= $this->embedded_element($qa, $i, $options);
         }
         $questiontext .= $fragment;
     }
     $result = '';
     $result .= html_writer::tag('div', $question->format_text($questiontext, $question->questiontextformat, $qa, 'question', 'questiontext', $question->id), array('class' => $this->qtext_classname(), 'id' => $this->qtext_id($qa)));
     $result .= $this->post_qtext_elements($qa, $options);
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($qa->get_last_qt_data()), array('class' => 'validationerror'));
     }
     return $result;
 }
Exemple #9
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $stemorder = $question->get_stem_order();
     $response = $qa->get_last_qt_data();
     $choices = $this->format_choices($question);
     $result = '';
     $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $result .= html_writer::start_tag('div', array('class' => 'ablock'));
     $result .= html_writer::start_tag('table', array('class' => 'answer'));
     $result .= html_writer::start_tag('tbody');
     $parity = 0;
     $i = 1;
     foreach ($stemorder as $key => $stemid) {
         $result .= html_writer::start_tag('tr', array('class' => 'r' . $parity));
         $fieldname = 'sub' . $key;
         $result .= html_writer::tag('td', $this->format_stem_text($qa, $stemid), array('class' => 'text'));
         $classes = 'control';
         $feedbackimage = '';
         if (array_key_exists($fieldname, $response)) {
             $selected = $response[$fieldname];
         } else {
             $selected = 0;
         }
         $fraction = (int) ($selected && $selected == $question->get_right_choice_for($stemid));
         if ($options->correctness && $selected) {
             $classes .= ' ' . $this->feedback_class($fraction);
             $feedbackimage = $this->feedback_image($fraction);
         }
         $result .= html_writer::tag('td', html_writer::label(get_string('answer', 'qtype_match', $i), 'menu' . $qa->get_qt_field_name('sub' . $key), false, array('class' => 'accesshide')) . html_writer::select($choices, $qa->get_qt_field_name('sub' . $key), $selected, array('0' => 'choose'), array('disabled' => $options->readonly)) . ' ' . $feedbackimage, array('class' => $classes));
         $result .= html_writer::end_tag('tr');
         $parity = 1 - $parity;
         $i++;
     }
     $result .= html_writer::end_tag('tbody');
     $result .= html_writer::end_tag('table');
     $result .= html_writer::end_tag('div');
     // Closes <div class="ablock">.
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($response), array('class' => 'validationerror'));
     }
     return $result;
 }
Exemple #10
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $currentanswer = $qa->get_last_qt_var('answer');
     $inputname = $qa->get_qt_field_name('answer');
     $inputattributes = array('type' => 'text', 'name' => $inputname, 'value' => $currentanswer, 'id' => $inputname, 'size' => 80);
     if ($options->readonly) {
         $inputattributes['readonly'] = 'readonly';
     }
     $feedbackimg = '';
     if ($options->correctness) {
         $answer = $question->get_matching_answer(array('answer' => $currentanswer));
         if ($answer) {
             $fraction = $answer->fraction;
         } else {
             $fraction = 0;
         }
         $inputattributes['class'] = $this->feedback_class($fraction);
         $feedbackimg = $this->feedback_image($fraction);
     }
     $questiontext = $question->format_questiontext($qa);
     $placeholder = false;
     if (preg_match('/_____+/', $questiontext, $matches)) {
         $placeholder = $matches[0];
         $inputattributes['size'] = round(strlen($placeholder) * 1.1);
     }
     $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg;
     if ($placeholder) {
         $inputinplace = html_writer::tag('label', get_string('answer'), array('for' => $inputattributes['id'], 'class' => 'accesshide'));
         $inputinplace .= $input;
         $questiontext = substr_replace($questiontext, $inputinplace, strpos($questiontext, $placeholder), strlen($placeholder));
     }
     $result = html_writer::tag('div', $questiontext, array('class' => 'qtext'));
     if (!$placeholder) {
         $result .= html_writer::start_tag('div', array('class' => 'ablock'));
         $result .= html_writer::tag('label', get_string('answer', 'qtype_shortanswer', html_writer::tag('span', $input, array('class' => 'answer'))), array('for' => $inputattributes['id']));
         $result .= html_writer::end_tag('div');
     }
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error(array('answer' => $currentanswer)), array('class' => 'validationerror'));
     }
     return $result;
 }
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $currentanswer = array();
     $inputattributes = array();
     $input = array();
     $questiontext = $question->format_questiontext($qa);
     $result = html_writer::tag('div', $questiontext, array('class' => 'qtext'));
     $result .= html_writer::start_tag('div', array('class' => 'ablock'));
     $parameters = explode(',', $question->parameters);
     $result .= html_writer::start_tag('table');
     $result .= html_writer::start_tag('tbody');
     foreach ($parameters as $parameter) {
         $parameter = trim($parameter);
         if (preg_match('/^(\\w+).*(\\[[^]]+\\])$/', $parameter, $matches)) {
             $parameter_name = $matches[1];
             $unity = $matches[2];
         } else {
             $parameter_name = $parameter;
             $unity = '';
         }
         $inputname['param_' . $parameter_name] = $qa->get_qt_field_name('answer_' . $parameter_name);
         $currentanswer['param_' . $parameter_name] = $qa->get_last_qt_var('answer_' . $parameter_name);
         $inputattributes['param_' . $parameter_name] = array('type' => 'text', 'name' => $inputname['param_' . $parameter_name], 'value' => s($currentanswer['param_' . $parameter_name]), 'id' => $inputname['param_' . $parameter_name], 'size' => 20);
         if ($options->readonly) {
             $inputattributes['param_' . $parameter_name]['readonly'] = 'readonly';
         }
         $input['param_' . $parameter_name] = html_writer::empty_tag('input', $inputattributes['param_' . $parameter_name]);
         $result .= html_writer::start_tag('tr');
         $result .= html_writer::tag('td', $parameter . ' : ', array('class' => 'paramname'));
         $result .= html_writer::tag('td', $input['param_' . $parameter_name], array('class' => 'answer'));
         $result .= html_writer::end_tag('tr');
     }
     $result .= html_writer::end_tag('tbody');
     $result .= html_writer::end_tag('table');
     $result .= html_writer::end_tag('div');
     $result .= html_writer::tag('div', '', array('class' => 'clearer'));
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error(array('answer' => $currentanswer)), array('class' => 'validationerror'));
     }
     return $result;
 }
Exemple #12
0
 /**
  * Generate the display of the formulation part of the question. This is the
  * area that contains the question text, and the controls for students to
  * input their answers. Some question types also embed bits of feedback, for
  * example ticks and crosses, in this area.
  *
  * @param question_attempt $qa the question attempt to display.
  * @param question_display_options $options controls what should and should not be displayed.
  * @return string HTML fragment.
  */
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     global $CFG, $PAGE;
     $question = $qa->get_question();
     $qtext = $question->format_questiontext($qa);
     $testcases = $question->testcases;
     $examples = array_filter($testcases, function ($tc) {
         return $tc->useasexample;
     });
     if (count($examples) > 0) {
         $qtext .= html_writer::tag('p', 'For example:', array('class' => 'for-example-para'));
         $qtext .= html_writer::start_tag('div', array('class' => 'coderunner-examples'));
         $qtext .= $this->format_examples($examples);
         $qtext .= html_writer::end_tag('div');
     }
     $qtext .= html_writer::start_tag('div', array('class' => 'prompt'));
     $answerprompt = get_string("answer", "quiz") . ': ';
     $qtext .= $answerprompt;
     $qtext .= html_writer::end_tag('div');
     $responsefieldname = $qa->get_qt_field_name('answer');
     $responsefieldid = 'id_' . $responsefieldname;
     $rows = isset($question->answerboxlines) ? $question->answerboxlines : 18;
     $cols = isset($question->answerboxcolumns) ? $question->answerboxcolumns : 100;
     $taattributes = array('class' => 'coderunner-answer edit_code', 'name' => $responsefieldname, 'id' => $responsefieldid, 'cols' => $cols, 'spellcheck' => 'false', 'rows' => $rows);
     if ($options->readonly) {
         $taattributes['readonly'] = 'readonly';
     }
     $currentanswer = $qa->get_last_qt_var('answer');
     $currentrating = $qa->get_last_qt_var('rating', 0);
     $qtext .= html_writer::tag('textarea', s($currentanswer), $taattributes);
     if ($qa->get_state() == question_state::$invalid) {
         $qtext .= html_writer::nonempty_tag('div', $question->get_validation_error(array('answer' => $currentanswer)), array('class' => 'validationerror'));
     }
     // Initialise any program-editing JavaScript.
     // Thanks to Ulrich Dangel for incorporating the Ace code editor.
     $PAGE->requires->js_init_call('M.qtype_coderunner.initQuestionTA', array($responsefieldid));
     load_ace_if_required($question, $responsefieldid, constants::USER_LANGUAGE);
     return $qtext;
 }
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     global $PAGE;
     $question = $qa->get_question();
     if ($question->answerdisplay == "dragdrop") {
         $PAGE->requires->js('/question/type/gapfill/jquery/jquery-1.4.2.js');
         $PAGE->requires->js('/question/type/gapfill/jquery/ui/jquery.ui.core.min.js');
         $PAGE->requires->js('/question/type/gapfill/jquery/ui/jquery.ui.widget.min.js');
         $PAGE->requires->js('/question/type/gapfill/jquery/ui/jquery.ui.mouse.min.js');
         $PAGE->requires->js('/question/type/gapfill/jquery/ui/jquery.ui.draggable.min.js');
         $PAGE->requires->js('/question/type/gapfill/jquery/ui/jquery.ui.droppable.min.js');
         $PAGE->requires->js('/question/type/gapfill/dragdrop.js');
     }
     $answers = $qa->get_step(0)->get_qt_var('_allanswers');
     $output = '';
     if ($question->answerdisplay == "dragdrop") {
         $ddclass = " draggable answers ";
         $answers = $this->get_answers('dragdrop', $answers);
         foreach ($answers as $value) {
             $output .= '<span class="' . $ddclass . '">' . $value . "</span>&nbsp";
         }
         $output .= "</br></br>";
     }
     $marked_gaps = $question->get_marked_gaps($qa, $options);
     foreach ($question->textfragments as $place => $fragment) {
         if ($place > 0) {
             $output .= $this->embedded_element($qa, $place, $options, $marked_gaps);
         }
         /* format the non entry field parts of the question text, this will also
            ensure images get displayed */
         $output .= $question->format_text($fragment, $question->questiontextformat, $qa, 'question', 'questiontext', $question->id);
     }
     print "<br/>";
     if ($qa->get_state() == question_state::$invalid) {
         $output .= html_writer::nonempty_tag('div', $question->get_validation_error(array('answer' => $output)), array('class' => 'validationerror'));
     }
     return $output;
 }
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     global $CFG, $PAGE;
     $question = $qa->get_question();
     $questiontext = $question->format_questiontext($qa);
     $placeholder = false;
     if (preg_match('/_____+/', $questiontext, $matches)) {
         $placeholder = $matches[0];
     }
     $toreplaceid = 'applet' . $qa->get_slot();
     $toreplace = html_writer::tag('span', get_string('enablejavascript', 'qtype_jme'), array('id' => $toreplaceid));
     if ($placeholder) {
         $toreplace = html_writer::tag('span', get_string('enablejavascript', 'qtype_jme'), array('class' => 'ablock'));
         $questiontext = substr_replace($questiontext, $toreplace, strpos($questiontext, $placeholder), strlen($placeholder));
     }
     $result = html_writer::tag('div', $questiontext, array('class' => 'qtext'));
     if (!$placeholder) {
         $answerlabel = html_writer::tag('span', get_string('answer', 'qtype_jme', ''), array('class' => 'answerlabel'));
         $result .= html_writer::tag('div', $answerlabel . $toreplace, array('class' => 'ablock'));
     }
     if ($qa->get_state() == question_state::$invalid) {
         $lastresponse = $this->get_last_response($qa);
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($lastresponse), array('class' => 'validationerror'));
     }
     if ($options->readonly) {
         $currentanswer = $qa->get_last_qt_var('answer');
         if (!$currentanswer) {
             $currentanswer = '';
         }
         $result .= html_writer::tag('div', get_string('youranswer', 'qtype_jme', $currentanswer), array('class' => 'qtext'));
     }
     $result .= html_writer::tag('div', $this->hidden_fields($qa), array('class' => 'inputcontrol'));
     $this->require_js($toreplaceid, $qa, $options->readonly, $options->correctness);
     // Include JSME loader script as an html tag.
     $jsmescript = $CFG->wwwroot . '/question/type/jme/jsme/jsme.nocache.js';
     $result .= html_writer::tag('script', '', array('src' => $jsmescript));
     return $result;
 }
 /**
  * Display the interface for messaging options
  *
  * @param   mixed   $processors         array of objects containing message processors
  * @param   mixed   $providers          array of objects containing message providers
  * @param   mixed   $preferences        array of objects containing current preferences
  * @param   mixed   $defaultpreferences array of objects containing site default preferences
  * @return  string                      The text to render
  */
 public function manage_messagingoptions($processors, $providers, $preferences, $defaultpreferences)
 {
     // Filter out enabled, available system_configured and user_configured processors only.
     $readyprocessors = array_filter($processors, create_function('$a', 'return $a->enabled && $a->configured && $a->object->is_user_configured();'));
     // Start the form.  We're not using mform here because of our special formatting needs ...
     $output = html_writer::start_tag('form', array('method' => 'post', 'class' => 'mform'));
     $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()));
     /// Settings table...
     $output .= html_writer::start_tag('fieldset', array('id' => 'providers', 'class' => 'clearfix'));
     $output .= html_writer::nonempty_tag('legend', get_string('providers_config', 'message'), array('class' => 'ftoggler'));
     // Display the messging options table
     $table = new html_table();
     $table->attributes['class'] = 'generaltable';
     $table->data = array();
     $table->head = array('');
     foreach ($readyprocessors as $processor) {
         $table->head[] = get_string('pluginname', 'message_' . $processor->name);
     }
     $number_procs = count($processors);
     // Populate the table with rows
     foreach ($providers as $provider) {
         $preferencebase = $provider->component . '_' . $provider->name;
         $headerrow = new html_table_row();
         $providername = get_string('messageprovider:' . $provider->name, $provider->component);
         $providercell = new html_table_cell($providername);
         $providercell->header = true;
         $providercell->colspan = $number_procs + 1;
         $providercell->attributes['class'] = 'c0';
         $headerrow->cells = array($providercell);
         $table->data[] = $headerrow;
         foreach (array('loggedin', 'loggedoff') as $state) {
             $optionrow = new html_table_row();
             $optionname = new html_table_cell(get_string($state . 'description', 'message'));
             $optionname->attributes['class'] = 'c0';
             $optionrow->cells = array($optionname);
             foreach ($readyprocessors as $processor) {
                 // determine the default setting
                 $permitted = MESSAGE_DEFAULT_PERMITTED;
                 $defaultpreference = $processor->name . '_provider_' . $preferencebase . '_permitted';
                 if (isset($defaultpreferences->{$defaultpreference})) {
                     $permitted = $defaultpreferences->{$defaultpreference};
                 }
                 // If settings are disallowed, just display the message that
                 // the setting is not permitted, if not use user settings or
                 // force them.
                 if ($permitted == 'disallowed') {
                     if ($state == 'loggedoff') {
                         // skip if we are rendering the second line
                         continue;
                     }
                     $cellcontent = html_writer::nonempty_tag('div', get_string('notpermitted', 'message'), array('class' => 'dimmed_text'));
                     $optioncell = new html_table_cell($cellcontent);
                     $optioncell->rowspan = 2;
                     $optioncell->attributes['class'] = 'disallowed';
                 } else {
                     // determine user preferences and use then unless we force
                     // the preferences.
                     $disabled = array();
                     if ($permitted == 'forced') {
                         $checked = true;
                         $disabled['disabled'] = 1;
                     } else {
                         $checked = false;
                         // See if hser has touched this preference
                         if (isset($preferences->{$preferencebase . '_' . $state})) {
                             // User have some preferneces for this state in the database, use them
                             $checked = isset($preferences->{$preferencebase . '_' . $state}[$processor->name]);
                         } else {
                             // User has not set this preference yet, using site default preferences set by admin
                             $defaultpreference = 'message_provider_' . $preferencebase . '_' . $state;
                             if (isset($defaultpreferences->{$defaultpreference})) {
                                 $checked = (int) in_array($processor->name, explode(',', $defaultpreferences->{$defaultpreference}));
                             }
                         }
                     }
                     $elementname = $preferencebase . '_' . $state . '[' . $processor->name . ']';
                     // prepare language bits
                     $processorname = get_string('pluginname', 'message_' . $processor->name);
                     $statename = get_string($state, 'message');
                     $labelparams = array('provider' => $providername, 'processor' => $processorname, 'state' => $statename);
                     $label = get_string('sendingviawhen', 'message', $labelparams);
                     $cellcontent = html_writer::label($label, $elementname, true, array('class' => 'accesshide'));
                     $cellcontent .= html_writer::checkbox($elementname, 1, $checked, '', array_merge(array('id' => $elementname), $disabled));
                     $optioncell = new html_table_cell($cellcontent);
                     $optioncell->attributes['class'] = 'mdl-align';
                 }
                 $optionrow->cells[] = $optioncell;
             }
             $table->data[] = $optionrow;
         }
     }
     $output .= html_writer::start_tag('div');
     $output .= html_writer::table($table);
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('fieldset');
     foreach ($processors as $processor) {
         if (($processorconfigform = $processor->object->config_form($preferences)) && $processor->enabled) {
             $output .= html_writer::start_tag('fieldset', array('id' => 'messageprocessor_' . $processor->name, 'class' => 'clearfix'));
             $output .= html_writer::nonempty_tag('legend', get_string('pluginname', 'message_' . $processor->name), array('class' => 'ftoggler'));
             $output .= html_writer::start_tag('div');
             $output .= $processorconfigform;
             $output .= html_writer::end_tag('div');
             $output .= html_writer::end_tag('fieldset');
         }
     }
     $output .= html_writer::start_tag('fieldset', array('id' => 'messageprocessor_general', 'class' => 'clearfix'));
     $output .= html_writer::nonempty_tag('legend', get_string('generalsettings', 'admin'), array('class' => 'ftoggler'));
     $output .= html_writer::start_tag('div');
     $output .= get_string('blocknoncontacts', 'message') . ': ';
     $output .= html_writer::checkbox('blocknoncontacts', 1, $preferences->blocknoncontacts, '');
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('fieldset');
     $output .= html_writer::start_tag('div', array('class' => 'mdl-align'));
     $output .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('updatemyprofile'), 'class' => 'form-submit'));
     $output .= html_writer::end_tag('div');
     $output .= html_writer::end_tag('form');
     return $output;
 }
function mahara_footer()
{
    global $CFG;
    if ($CFG->current_app->hasPrivilege('Student')) {
        $institution = $CFG->current_app->getCurrentUser()->getInstitution();
    }
    if (!$institution) {
        $institution = $CFG->current_app->getInstitution();
    }
    $footer_links = $institution->selectFromMhrTable('config', 'field', 'footerlinks', true);
    $wwwroot = $institution->getAppUrl(false);
    $content = html_writer::start_tag('div', array('id' => 'footer-wrap'));
    $content .= '<div id="footernavleft"><a href="' . $CFG->current_app->getSupportUrl() . '" target="_blank">Technical Support</a></div>';
    $content .= html_writer::start_tag('div', array('id' => 'footernav'));
    if ($pos = strpos($footer_links->value, 'termsandconditions')) {
        $content .= html_writer::nonempty_tag('a', 'Terms and Conditions', array('href' => "{$wwwroot}/terms.php"));
        $content .= html_writer::end_tag('a');
        $content .= "|";
    }
    if ($pos = strpos($footer_links->value, 'privacystatement')) {
        $content .= html_writer::nonempty_tag('a', 'Privacy Statement', array('href' => "{$wwwroot}/privacy.php"));
        $content .= html_writer::end_tag('a');
        $content .= "|";
    }
    if ($pos = strpos($footer_links->value, 'about')) {
        $content .= html_writer::nonempty_tag('a', 'About', array('href' => "{$wwwroot}/about.php"));
        $content .= html_writer::end_tag('a');
        $content .= "|";
    }
    if ($pos = strpos($footer_links->value, 'contactus')) {
        $content .= html_writer::nonempty_tag('a', 'Contact Us', array('href' => "{$wwwroot}/contact.php"));
        $content .= html_writer::end_tag('a');
    }
    $content .= html_writer::end_tag('div');
    $content .= html_writer::start_tag('div', array('id' => 'poweredby'));
    $content .= html_writer::start_tag('a', array('href' => "http://globalclassroom.us"));
    $content .= html_writer::start_tag('img', array('src' => 'https://s3.amazonaws.com/static.globalclassroom.us/marketing/Stratus/poweredby_blk-trans.png', 'alt' => 'powered by global classroom'));
    $content .= html_writer::end_tag('img');
    $content .= html_writer::end_tag('a');
    $content .= html_writer::end_tag('div');
    $content .= html_writer::end_tag('div');
    return $content;
}
 public function extra_help(question_attempt $qa, question_display_options $options)
 {
     return html_writer::nonempty_tag('div', $qa->get_behaviour()->get_extra_help_if_requested($options->markdp));
 }
Exemple #18
0
/**
 * Print the message history between two users
 * @param object $user1 the current user
 * @param object $user2 the other user
 * @param string $search search terms to highlight
 * @param int $messagelimit maximum number of messages to return
 * @param string $messagehistorylink the html for the message history link or false
 * @param bool $viewingnewmessages are we currently viewing new messages?
 */
function message_print_message_history($user1,$user2,$search='',$messagelimit=0, $messagehistorylink=false, $viewingnewmessages=false) {
    global $CFG, $OUTPUT;

    echo $OUTPUT->box_start('center');
    echo html_writer::start_tag('table', array('cellpadding' => '10', 'class' => 'message_user_pictures'));
    echo html_writer::start_tag('tr');

    echo html_writer::start_tag('td', array('align' => 'center', 'id' => 'user1'));
    echo $OUTPUT->user_picture($user1, array('size' => 100, 'courseid' => SITEID));
    echo html_writer::tag('div', fullname($user1), array('class' => 'heading'));
    echo html_writer::end_tag('td');

    echo html_writer::start_tag('td', array('align' => 'center'));
    echo html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/left'), 'alt' => get_string('from')));
    echo html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('t/right'), 'alt' => get_string('to')));
    echo html_writer::end_tag('td');

    echo html_writer::start_tag('td', array('align' => 'center', 'id' => 'user2'));
    echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID));
    echo html_writer::tag('div', fullname($user2), array('class' => 'heading'));

    if (isset($user2->iscontact) && isset($user2->isblocked)) {
        $incontactlist = $user2->iscontact;
        $isblocked = $user2->isblocked;

        $script = null;
        $text = true;
        $icon = false;

        $strcontact = message_get_contact_add_remove_link($incontactlist, $isblocked, $user2, $script, $text, $icon);
        $strblock   = message_get_contact_block_link($incontactlist, $isblocked, $user2, $script, $text, $icon);
        $useractionlinks = $strcontact.'&nbsp;|'.$strblock;

        echo html_writer::tag('div', $useractionlinks, array('class' => 'useractionlinks'));
    }

    echo html_writer::end_tag('td');
    echo html_writer::end_tag('tr');
    echo html_writer::end_tag('table');
    echo $OUTPUT->box_end();

    if (!empty($messagehistorylink)) {
        echo $messagehistorylink;
    }

    /// Get all the messages and print them
    if ($messages = message_get_history($user1, $user2, $messagelimit, $viewingnewmessages)) {
        $tablecontents = '';

        $current = new stdClass();
        $current->mday = '';
        $current->month = '';
        $current->year = '';
        $messagedate = get_string('strftimetime');
        $blockdate   = get_string('strftimedaydate');
        foreach ($messages as $message) {
            if ($message->notification) {
                $notificationclass = ' notification';
            } else {
                $notificationclass = null;
            }
            $date = usergetdate($message->timecreated);
            if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) {
                $current->mday = $date['mday'];
                $current->month = $date['month'];
                $current->year = $date['year'];

                $datestring = html_writer::empty_tag('a', array('name' => $date['year'].$date['mon'].$date['mday']));
                $tablecontents .= html_writer::tag('div', $datestring, array('class' => 'mdl-align heading'));

                $tablecontents .= $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'mdl-align');
            }

            $formatted_message = $side = null;
            if ($message->useridfrom == $user1->id) {
                $formatted_message = message_format_message($message, $messagedate, $search, 'me');
                $side = 'left';
            } else {
                $formatted_message = message_format_message($message, $messagedate, $search, 'other');
                $side = 'right';
            }
            $tablecontents .= html_writer::tag('div', $formatted_message, array('class' => "mdl-left $side $notificationclass"));
        }

        echo html_writer::nonempty_tag('div', $tablecontents, array('class' => 'mdl-left messagehistory'));
    } else {
        echo html_writer::nonempty_tag('div', '('.get_string('nomessagesfound', 'message').')', array('class' => 'mdl-align messagehistory'));
    }
}
Exemple #19
0
    public function subquestion(question_attempt $qa, question_display_options $options,
            $index, question_graded_automatically $subq) {

        $fieldprefix = 'sub' . $index . '_';
        $fieldname = $fieldprefix . 'answer';
        $response = $qa->get_last_qt_var($fieldname);

        $inputattributes = array(
            'type' => 'radio',
            'name' => $qa->get_qt_field_name($fieldname),
        );
        if ($options->readonly) {
            $inputattributes['disabled'] = 'disabled';
        }

        $result = $this->all_choices_wrapper_start();
        $fraction = null;
        foreach ($subq->get_order($qa) as $value => $ansid) {
            $ans = $subq->answers[$ansid];

            $inputattributes['value'] = $value;
            $inputattributes['id'] = $inputattributes['name'] . $value;

            $isselected = $subq->is_choice_selected($response, $value);
            if ($isselected) {
                $inputattributes['checked'] = 'checked';
                $fraction = $ans->fraction;
            } else {
                unset($inputattributes['checked']);
            }

            $class = 'r' . ($value % 2);
            if ($options->correctness && $isselected) {
                $feedbackimg = $this->feedback_image($ans->fraction);
                $class .= ' ' . $this->feedback_class($ans->fraction);
            } else {
                $feedbackimg = '';
            }

            $result .= $this->choice_wrapper_start($class);
            $result .= html_writer::empty_tag('input', $inputattributes);
            $result .= html_writer::tag('label', $subq->format_text($ans->answer,
                    $ans->answerformat, $qa, 'question', 'answer', $ansid),
                    array('for' => $inputattributes['id']));
            $result .= $feedbackimg;

            if ($options->feedback && $isselected && trim($ans->feedback)) {
                $result .= html_writer::tag('div',
                        $subq->format_text($ans->feedback, $ans->feedbackformat,
                                $qa, 'question', 'answerfeedback', $ansid),
                        array('class' => 'specificfeedback'));
            }

            $result .= $this->choice_wrapper_end();
        }

        $result .= $this->all_choices_wrapper_end();

        $feedback = array();
        if ($options->feedback && $options->marks >= question_display_options::MARK_AND_MAX &&
                $subq->maxmark > 0) {
            $a = new stdClass();
            $a->mark = format_float($fraction * $subq->maxmark, $options->markdp);
            $a->max =  format_float($subq->maxmark, $options->markdp);

            $feedback[] = html_writer::tag('div', get_string('markoutofmax', 'question', $a));
        }

        if ($options->rightanswer) {
            foreach ($subq->answers as $ans) {
                if (question_state::graded_state_for_fraction($ans->fraction) ==
                        question_state::$gradedright) {
                    $feedback[] = get_string('correctansweris', 'qtype_multichoice',
                            $subq->format_text($ans->answer, $ans->answerformat,
                                    $qa, 'question', 'answer', $ansid));
                    break;
                }
            }
        }

        $result .= html_writer::nonempty_tag('div', implode('<br />', $feedback), array('class' => 'outcome'));

        return $result;
    }
Exemple #20
0
 /**
  * Displayed where there might normally be a review link, to explain why the
  * review is not available at this time.
  * @param string $message optional message explaining why the review is not possible.
  * @return string HTML to output.
  */
 public function no_review_message($message) {
     return html_writer::nonempty_tag('span', $message,
             array('class' => 'noreviewmessage'));
 }
Exemple #21
0
/**
 * Print the message history between two users
 *
 * @param object $user1 the current user
 * @param object $user2 the other user
 * @param string $search search terms to highlight
 * @param int $messagelimit maximum number of messages to return
 * @param string $messagehistorylink the html for the message history link or false
 * @param bool $viewingnewmessages are we currently viewing new messages?
 */
function message_print_message_history($user1, $user2 ,$search = '', $messagelimit = 0, $messagehistorylink = false, $viewingnewmessages = false, $showactionlinks = true) {
    global $OUTPUT, $PAGE;

    $PAGE->requires->yui_module(
        array('moodle-core_message-toolbox'),
        'M.core_message.toolbox.deletemsg.init',
        array(array())
    );

    echo $OUTPUT->box_start('center', 'message_user_pictures');
    echo $OUTPUT->box_start('user');
    echo $OUTPUT->box_start('generalbox', 'user1');
    echo $OUTPUT->user_picture($user1, array('size' => 100, 'courseid' => SITEID));
    echo html_writer::tag('div', fullname($user1), array('class' => 'heading'));
    echo $OUTPUT->box_end();
    echo $OUTPUT->box_end();

    $imgattr = array('src' => $OUTPUT->pix_url('i/twoway'), 'alt' => '', 'width' => 16, 'height' => 16);
    echo $OUTPUT->box(html_writer::empty_tag('img', $imgattr), 'between');

    echo $OUTPUT->box_start('user');
    echo $OUTPUT->box_start('generalbox', 'user2');
    // Show user picture with link is real user else without link.
    if (core_user::is_real_user($user2->id)) {
        echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID));
    } else {
        echo $OUTPUT->user_picture($user2, array('size' => 100, 'courseid' => SITEID, 'link' => false));
    }
    echo html_writer::tag('div', fullname($user2), array('class' => 'heading'));

    if ($showactionlinks && isset($user2->iscontact) && isset($user2->isblocked)) {

        $script = null;
        $text = true;
        $icon = false;

        $strcontact = message_get_contact_add_remove_link($user2->iscontact, $user2->isblocked, $user2, $script, $text, $icon);
        $strblock   = message_get_contact_block_link($user2->iscontact, $user2->isblocked, $user2, $script, $text, $icon);
        $useractionlinks = $strcontact.'&nbsp;|&nbsp;'.$strblock;

        echo html_writer::tag('div', $useractionlinks, array('class' => 'useractionlinks'));
    }
    echo $OUTPUT->box_end();
    echo $OUTPUT->box_end();
    echo $OUTPUT->box_end();

    if (!empty($messagehistorylink)) {
        echo $messagehistorylink;
    }

    /// Get all the messages and print them
    if ($messages = message_get_history($user1, $user2, $messagelimit, $viewingnewmessages)) {
        $tablecontents = '';

        $current = new stdClass();
        $current->mday = '';
        $current->month = '';
        $current->year = '';
        $messagedate = get_string('strftimetime');
        $blockdate   = get_string('strftimedaydate');
        $messagenumber = 0;
        foreach ($messages as $message) {
            $messagenumber++;
            if ($message->notification) {
                $notificationclass = ' notification';
            } else {
                $notificationclass = null;
            }
            $date = usergetdate($message->timecreated);
            if ($current->mday != $date['mday'] | $current->month != $date['month'] | $current->year != $date['year']) {
                $current->mday = $date['mday'];
                $current->month = $date['month'];
                $current->year = $date['year'];

                $datestring = html_writer::empty_tag('a', array('name' => $date['year'].$date['mon'].$date['mday']));
                $tablecontents .= html_writer::tag('div', $datestring, array('class' => 'mdl-align heading'));

                $tablecontents .= $OUTPUT->heading(userdate($message->timecreated, $blockdate), 4, 'mdl-align');
            }

            if ($message->useridfrom == $user1->id) {
                $formatted_message = message_format_message($message, $messagedate, $search, 'me');
                $side = 'left';
            } else {
                $formatted_message = message_format_message($message, $messagedate, $search, 'other');
                $side = 'right';
            }

            // Check if it is a read message or not.
            if (isset($message->timeread)) {
                $type = 'message_read';
            } else {
                $type = 'message';
            }

            if (message_can_delete_message($message, $user1->id)) {
                $usergroup = optional_param('usergroup', MESSAGE_VIEW_UNREAD_MESSAGES, PARAM_ALPHANUMEXT);
                $viewing = optional_param('viewing', $usergroup, PARAM_ALPHANUMEXT);
                $deleteurl = new moodle_url('/message/index.php', array('user1' => $user1->id, 'user2' => $user2->id,
                    'viewing' => $viewing, 'deletemessageid' => $message->id, 'deletemessagetype' => $type,
                    'sesskey' => sesskey()));

                $deleteicon = $OUTPUT->action_icon($deleteurl, new pix_icon('t/delete', get_string('delete')));
                $deleteicon = html_writer::tag('div', $deleteicon, array('class' => 'deleteicon accesshide'));
                $formatted_message .= $deleteicon;
            }

            $tablecontents .= html_writer::tag('div', $formatted_message, array('class' => "mdl-left messagecontent
                $side $notificationclass", 'id' => 'message_' . $messagenumber));
        }

        echo html_writer::nonempty_tag('div', $tablecontents, array('class' => 'mdl-left messagehistory'));
    } else {
        echo html_writer::nonempty_tag('div', '('.get_string('nomessagesfound', 'message').')', array('class' => 'mdl-align messagehistory'));
    }
}
Exemple #22
0
 protected function hint(question_attempt $qa, question_hint $hint)
 {
     $output = '';
     $question = $qa->get_question();
     $response = $qa->get_last_qt_data();
     if ($hint->statewhichincorrect) {
         $wrongdrags = $question->get_wrong_drags($response);
         $wrongparts = array();
         foreach ($wrongdrags as $wrongdrag) {
             $wrongparts[] = html_writer::nonempty_tag('span', $wrongdrag, array('class' => 'wrongpart'));
         }
         $output .= html_writer::nonempty_tag('div', get_string('followingarewrong', 'qtype_ddmarker', join(', ', $wrongparts)), array('class' => 'wrongparts'));
     }
     $output .= parent::hint($qa, $hint);
     return $output;
 }
Exemple #23
0
    public function formulation_and_controls(question_attempt $qa,
            question_display_options $options) {

        $question = $qa->get_question();
        $currentanswer = $qa->get_last_qt_var('answer');
        if ($question->unitdisplay == qtype_numerical::UNITSELECT) {
            $selectedunit = $qa->get_last_qt_var('unit');
        } else {
            $selectedunit = null;
        }

        $inputname = $qa->get_qt_field_name('answer');
        $inputattributes = array(
            'type' => 'text',
            'name' => $inputname,
            'value' => $currentanswer,
            'id' => $inputname,
            'size' => 80,
        );

        if ($options->readonly) {
            $inputattributes['readonly'] = 'readonly';
        }

        $feedbackimg = '';
        if ($options->correctness) {
            list($value, $unit) = $question->ap->apply_units($currentanswer, $selectedunit);
            $answer = $question->get_matching_answer($value);
            if ($answer) {
                $fraction = $question->apply_unit_penalty($answer->fraction, $unit);
            } else {
                $fraction = 0;
            }
            $inputattributes['class'] = $this->feedback_class($fraction);
            $feedbackimg = $this->feedback_image($fraction);
        }

        $questiontext = $question->format_questiontext($qa);
        $placeholder = false;
        if (preg_match('/_____+/', $questiontext, $matches)) {
            $placeholder = $matches[0];
            $inputattributes['size'] = round(strlen($placeholder) * 1.1);
        }

        $input = html_writer::empty_tag('input', $inputattributes) . $feedbackimg;

        if ($question->unitdisplay == qtype_numerical::UNITSELECT) {
            $unitselect = html_writer::select($question->ap->get_unit_options(),
                    $qa->get_qt_field_name('unit'), $selectedunit, array(''=>'choosedots'),
                    array('disabled' => $options->readonly));
            if ($question->ap->are_units_before()) {
                $input = $unitselect . ' ' . $input;
            } else {
                $input = $input . ' ' . $unitselect;
            }
        }

        if ($placeholder) {
            $questiontext = substr_replace($questiontext, $input,
                    strpos($questiontext, $placeholder), strlen($placeholder));
        }

        $result = html_writer::tag('div', $questiontext, array('class' => 'qtext'));

        if (!$placeholder) {
            $result .= html_writer::start_tag('div', array('class' => 'ablock'));
            $result .= get_string('answer', 'qtype_shortanswer',
                    html_writer::tag('div', $input, array('class' => 'answer')));
            $result .= html_writer::end_tag('div');
        }

        if ($qa->get_state() == question_state::$invalid) {
            $result .= html_writer::nonempty_tag('div',
                    $question->get_validation_error(array('answer' => $currentanswer)),
                    array('class' => 'validationerror'));
        }

        return $result;
    }
 public static function impl_formulation_and_controls(qtype_multichoice_renderer_base $renderer, question_attempt $qa, question_display_options $options)
 {
     global $CFG, $PAGE, $OUTPUT;
     // get the current question
     $question = $qa->get_question();
     // get the response
     $response = $question->get_response($qa);
     // answer prefix
     $answer_input_name = $qa->get_qt_field_name('answer');
     // set the ID of the OmeroImageViewer
     $omero_frame_id = self::to_unique_identifier($qa, "omero-image-viewer");
     // set the ID the ModalImagePanel
     $modal_image_panel_id = $omero_frame_id . "-" . qtype_omerocommon_renderer_helper::MODAL_VIEWER_ELEMENT_ID;
     // set the name of the feedback image class
     $feedback_image_class = $omero_frame_id . "-feedbackimage";
     // ID of the question answer container
     $question_answer_container = self::to_unique_identifier($qa, "omero-interactive-question-container");
     // the OMERO image URL
     $omero_image_url = $question->omeroimageurl;
     // extract the omero server
     $OMERO_SERVER = get_config('omero', 'omero_restendpoint');
     // parse the URL to get the image ID and its related params
     $matches = array();
     $pattern = '/\\/([0123456789]+)(\\?.*)?/';
     if (preg_match($pattern, $omero_image_url, $matches)) {
         $omero_image = $matches[1];
         $omero_image_params = count($matches) === 3 ? $matches[2] : "";
     }
     // check
     $multi_correct_answer = $question instanceof qtype_omerointeractive_multi_question;
     $no_max_markers = 0;
     $answer_shape_map = array();
     $shape_grade_map = new stdClass();
     $available_shapes = array();
     $shape_groups = array();
     foreach ($question->get_order($qa) as $ans_idx => $ansid) {
         $ans = $question->answers[$ansid];
         $value = $ans->answer;
         $shape_group = array_map("intval", explode(",", $ans->answer));
         $shape_group_cardinality = count($shape_group);
         // update the max number of markers allowed
         if ($ans->fraction > 0 && !empty($value)) {
             $no_max_markers += $shape_group_cardinality;
         }
         // compute the shape grade
         $shape_group_fraction = 0;
         if ($shape_group_cardinality > 0) {
             $shape_group_fraction = $multi_correct_answer ? $ans->fraction / $shape_group_cardinality : $ans->fraction;
         }
         foreach ($shape_group as $shape_id) {
             $shape_grade_map->{$shape_id} = $shape_group_fraction;
             array_push($available_shapes, $shape_id);
             $answer_shape_map[$shape_id] = $ans;
         }
         array_push($shape_groups, array("shapes" => $shape_group, "shape_grade" => $shape_group_fraction));
     }
     // Fix the max number of markers
     if (!$multi_correct_answer) {
         $no_max_markers = 1;
     }
     $answer_order = "";
     $answer_options = array();
     $feedbackimages = array();
     foreach ($ans->feedbackimages as $image_id => $image) {
         array_push($feedbackimages, $image_id);
     }
     $feedbackimages_html = "";
     if (count($ans->feedbackimages) > 0) {
         $feedbackimages_html = '<div style="display: block; float: right;">[ ' . get_string("see", "qtype_omerocommon") . " ";
         $current_language = current_language();
         foreach ($ans->feedbackimages as $image) {
             $feedbackimages_html .= '<span class="' . $feedback_image_class . '" imageid="' . $image->id . '"' . ' imagename="' . $image->name . '"' . ' imagedescription="' . $image->description_locale_map->{$current_language} . '"' . ' imagelock="' . $image->lock . '"' . ' imageproperties="' . htmlspecialchars(json_encode($image->properties)) . '"' . ' visiblerois="' . implode(",", $image->visiblerois) . '"' . ' focusablerois="' . implode(",", $image->focusablerois) . '"' . '>' . '<i class="glyphicon glyphicon-book" style="margin-left: 2px; margin-right: 5px;"></i>' . '"' . $image->name . '"</span>';
         }
         $feedbackimages_html .= ' ]</div>';
     }
     $feedbackimg = array();
     $classes = array();
     // Show correct/wrong markers
     if ($options->correctness) {
         foreach ($response->markers as $index => $marker) {
             $shape = $response->shapes[$index];
             $isselected = true;
             $hidden = '';
             $answer_options_attributes = array();
             $marker_correction = $hidden;
             $marker_correction .= html_writer::empty_tag('li', $answer_options_attributes);
             $marker_correction_text = get_string("marker", "qtype_omerointeractive") . " " . html_writer::tag("i", " ", array("class" => "glyphicon glyphicon-map-marker roi-shape-info", "roi-shape-id" => $marker->shape_id)) . " ";
             if ($shape !== "none") {
                 $marker_correction_text .= get_string("your_marker_inside", "qtype_omerointeractive") . " " . html_writer::tag("i", " ", array("class" => "glyphicon glyphicon-map-marker roi-shape-info", "roi-shape-id" => $shape->shape_id)) . " [" . $shape->shape_id . "] ";
             } else {
                 $marker_correction_text .= get_string("your_marker_outside", "qtype_omerointeractive");
             }
             $marker_correction_text .= '<span class="pull-right">' . $renderer->feedback_image($renderer->is_right_marker($shape_grade_map, $response, $index)) . html_writer::tag("i", " ", array("class" => "glyphicon glyphicon-eye-open roi-shape-visibility", "roi-shape-id" => $marker->shape_id, "style" => "margin-right: 5px")) . '</span>';
             if ($shape !== "none" && !empty(strip_tags($answer_shape_map[$shape->shape_id]->feedback))) {
                 $shape_answer = $answer_shape_map[$shape->shape_id];
                 $marker_correction_text .= html_writer::tag("div", html_writer::tag("i", " ", array("class" => "pull-left glyphicon glyphicon-record", "style" => "margin-right: 5px")) . format_text($shape_answer->feedback) . $feedbackimages_html, array("class" => "outcome", "style" => "padding: 20px 30px 20px;"));
             }
             $marker_correction .= html_writer::tag('label', $marker_correction_text);
             $answer_options[] = $marker_correction;
             $class = 'r' . $value % 2;
             $answer_options_attributes['checked'] = 'checked';
             $feedback_class = $renderer->feedback_image($renderer->is_right_marker($shape_grade_map, $response, $index));
             $feedbackimg[] = $renderer->feedback_image($renderer->is_right_marker($shape_grade_map, $response, $index));
             $class .= ' ' . $renderer->feedback_class($renderer->is_right_marker($shape_grade_map, $response, $index));
             $classes[] = $class;
         }
     }
     foreach ($question->get_order($qa) as $value => $ansid) {
         $ans = $question->answers[$ansid];
         $answer_order .= $ans->answer;
         $answer_options_attributes['name'] = $renderer->get_input_name($qa, $value);
         $answer_options_attributes['value'] = $renderer->get_input_value($value);
         $answer_options_attributes['id'] = $renderer->get_input_id($qa, $value);
         $hidden = '';
         if (!$options->readonly && $renderer->get_input_type() == 'checkbox') {
             $hidden .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $answer_options_attributes['name'], 'value' => 0));
         }
     }
     /**
      * Render the question
      */
     $result = '';
     // add the ModalImagePanel template
     $result .= qtype_omerocommon_renderer_helper::modal_viewer(true, true, true, $modal_image_panel_id);
     // main question_answer_container
     $result .= html_writer::start_tag('div', array('id' => $question_answer_container, 'class' => 'ablock'));
     // question text
     $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     // viewer of the question image
     $result .= '<div class="image-viewer-with-controls-container">';
     $result .= '<!-- TOOLBAR -->
             <div class="btn-group interactive-player-toolbar pull-right" style="margin-left: 5px;" data-toggle="buttons" aria-pressed="false" autocomplete="true">
                 <a href="#" id="' . self::to_unique_identifier($qa, self::IMAGE_CLEAR_MARKER_CTRL) . '" class="btn btn-default disabled" aria-label="Left Align">
                     <i class="glyphicon glyphicon-remove"></i> ' . get_string('clear_markers', 'qtype_omerointeractive') . '</a>
             </div>
             <div class="btn-group interactive-player-toolbar pull-right" data-toggle="buttons" aria-pressed="false" autocomplete="off">
                 <a href="#" id="' . self::to_unique_identifier($qa, self::IMAGE_ADD_MARKER_CTRL) . '" class="btn btn-default disabled"  aria-label="Left Align">
                     <i class="glyphicon glyphicon-plus"></i> ' . get_string('add_marker', 'qtype_omerointeractive') . '</a>
                 <a href="#" id="' . self::to_unique_identifier($qa, self::IMAGE_EDIT_MARKER_CTRL) . '" class="btn btn-default disabled" aria-label="Left Align">
                     <i class="glyphicon glyphicon-edit"></i> ' . get_string('edit_marker', 'qtype_omerointeractive') . '</a>
             </div>';
     $result .= '<div id="' . self::to_unique_identifier($qa, "graphics_container") . '" class="image-viewer-container" style="position: relative;" >
         <div id="' . self::to_unique_identifier($qa, self::IMAGE_VIEWER_CONTAINER) . '" style="position: absolute; width: 100%; height: 500px; margin: auto; z-index: 0;"></div>
         <canvas id="' . self::to_unique_identifier($qa, 'annotations_canvas') . '" style="position: absolute; width: 100%; height: 500px; margin: auto; z-index: 1;"></canvas>
         <div id="' . self::to_unique_identifier($qa, self::IMAGE_VIEWER_CONTAINER) . '-loading-dialog" class="image-viewer-loading-dialog"></div>
     </div>';
     $image_properties = null;
     $image_properties = json_decode($question->omeroimageproperties);
     $result .= '<div class="image_position_button">' . '<span class="sm">' . ($question->omeroimageproperties ? '<b>(x,y):</b> ' . $image_properties->center->x . ", " . $image_properties->center->y . '<i class="restore-image-center-btn glyphicon glyphicon-screenshot" style="margin-left: 10px;"></i>' : "") . '</span></div>';
     if (!empty($question->focusablerois)) {
         $result .= '<div id="' . self::to_unique_identifier($qa, self::FOCUS_AREAS_CONTAINER) . '" ' . ' class="focus_areas_container">' . '<span class="focus-areas-text">* ' . get_string("focusareas", "qtype_omerointeractive") . '</span> ' . '</div>';
     }
     $result .= '<div id="' . self::to_unique_identifier($qa, self::MARKER_REMOVERS_CONTAINER) . '" ' . ' class="remove_marker_button_group">' . '<span class="yourmarkers-text">* ' . get_string("yourmarkers", "qtype_omerointeractive") . '</span> ' . '</div>';
     $result .= '</div>';
     $answer_input_name = $qa->get_qt_field_name('answer');
     $answer_options_attributes = array('type' => $renderer->get_input_type(), 'name' => $answer_input_name);
     if ($options->readonly) {
         $answer_options_attributes['disabled'] = 'disabled';
     }
     if ($options->correctness && count($response->markers) > 0) {
         $result .= html_writer::start_tag('div', array('class' => 'question-summary hidden'));
         $result .= html_writer::tag('div', count($response->markers) === 1 ? get_string("notice_your_answer", "qtype_omerocommon") : get_string("notice_your_answers", "qtype_omerocommon"), array("class" => "answer-summary-fixed-text"));
         $result .= html_writer::start_tag('ul', array('class' => 'answer'));
         foreach ($answer_options as $key => $answer_option) {
             $result .= html_writer::tag('div', $answer_option, array('class' => $classes[$key])) . "\n";
         }
         $result .= html_writer::end_tag('ul');
         // Answer.
         $result .= html_writer::end_tag('div');
         // Answer.
     }
     $result .= html_writer::tag('div', '', array('id' => $question_answer_container . '-invalidator-panel', 'class' => "invalidator-panel"));
     $result .= html_writer::end_tag('div');
     // Ablock.
     // support for dialog message
     $result .= html_writer::tag('div', '
      <div class="modal fade" id="modal-frame-' . $omero_frame_id . '" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
           <div class="modal-dialog" role="document">
             <div class="modal-content">
               <div class="modal-header">
                 <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                 <h4 class="modal-title text-warning" id="modal-frame-label-' . $omero_frame_id . '">
                     <i class="glyphicon glyphicon-warning-sign"></i> ' . get_string('validate_warning', 'qtype_omerocommon') . '</h4>
               </div>
               <div class="modal-body text-left">
                 <span id="modal-frame-text-' . $omero_frame_id . '"></span>
               </div>
               <div class="modal-footer text-center">
                 <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
               </div>
           </div>
      </div>');
     $player_config = array("image_id" => $omero_image, "image_properties" => json_decode($question->omeroimageproperties), "image_frame_id" => $omero_frame_id, "image_annotations_canvas_id" => self::to_unique_identifier($qa, "annotations_canvas"), "modal_image_panel_id" => $modal_image_panel_id, "feedback_image_class" => $feedback_image_class, "image_server" => $OMERO_SERVER, "image_viewer_container" => self::to_unique_identifier($qa, self::IMAGE_VIEWER_CONTAINER), "image_navigation_locked" => (bool) $question->omeroimagelocked, "viewer_model_server" => $CFG->omero_image_server, "qname" => $question->name, "question_answer_container" => $question_answer_container, "enable_add_makers_ctrl_id" => self::to_unique_identifier($qa, self::IMAGE_ADD_MARKER_CTRL), "enable_edit_markers_ctrl_id" => self::to_unique_identifier($qa, self::IMAGE_EDIT_MARKER_CTRL), "remove_marker_ctrl_id" => self::to_unique_identifier($qa, self::IMAGE_DEL_MARKER_CTRL), "clear_marker_ctrl_id" => self::to_unique_identifier($qa, self::IMAGE_CLEAR_MARKER_CTRL), "marker_removers_container" => self::to_unique_identifier($qa, self::MARKER_REMOVERS_CONTAINER), "focus_areas_container" => self::to_unique_identifier($qa, self::FOCUS_AREAS_CONTAINER), "answer_input_name" => $answer_input_name, "available_shapes" => $available_shapes, "shape_groups" => $shape_groups, "visible_rois" => empty($question->visiblerois) ? [] : explode(",", $question->visiblerois), "focusable_rois" => empty($question->focusablerois) ? [] : explode(",", $question->focusablerois), "correction_mode" => (bool) $options->correctness, "response" => $response, "answers" => $response, "answer_fraction" => $shape_grade_map, "max_markers" => $no_max_markers);
     $player_config_element_id = self::to_unique_identifier($qa, "viewer-config");
     $result .= html_writer::empty_tag("input", array("id" => $player_config_element_id, "type" => "hidden", "value" => json_encode($player_config)));
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($qa->get_last_qt_data()), array('class' => 'validationerror'));
     }
     $result .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => "answer_input_name", 'value' => $answer_input_name));
     global $PAGE;
     $PAGE->requires->string_for_js('marker', 'qtype_omerointeractive');
     $PAGE->requires->js_call_amd("qtype_omerointeractive/question-player-interactive", "start", array($player_config_element_id));
     return $result;
 }
Exemple #25
0
 /**
  * Generate the display of the outcome part of the question. This is the
  * area that contains the various forms of feedback.
  *
  * @param question_attempt $qa the question attempt to display.
  * @param qbehaviour_renderer $behaviouroutput the renderer to output the behaviour
  *      specific parts.
  * @param qtype_renderer $qtoutput the renderer to output the question type
  *      specific parts.
  * @param question_display_options $options controls what should and should not be displayed.
  * @return HTML fragment.
  */
 protected function outcome(question_attempt $qa, qbehaviour_renderer $behaviouroutput, qtype_renderer $qtoutput, question_display_options $options)
 {
     $output = '';
     $output .= html_writer::nonempty_tag('div', $qtoutput->feedback($qa, $options), array('class' => 'feedback'));
     $output .= html_writer::nonempty_tag('div', $behaviouroutput->feedback($qa, $options), array('class' => 'im-feedback'));
     return $output;
 }
Exemple #26
0
 public function formulation_and_controls(question_attempt $qa, question_display_options $options)
 {
     $question = $qa->get_question();
     $response = $qa->get_last_qt_var('answer', '');
     $inputname = $qa->get_qt_field_name('answer');
     $trueattributes = array('type' => 'radio', 'name' => $inputname, 'value' => 1, 'id' => $inputname . 'true');
     $falseattributes = array('type' => 'radio', 'name' => $inputname, 'value' => 0, 'id' => $inputname . 'false');
     if ($options->readonly) {
         $trueattributes['disabled'] = 'disabled';
         $falseattributes['disabled'] = 'disabled';
     }
     // Work out which radio button to select (if any).
     $truechecked = false;
     $falsechecked = false;
     $responsearray = array();
     if ($response) {
         $trueattributes['checked'] = 'checked';
         $truechecked = true;
         $responsearray = array('answer' => 1);
     } else {
         if ($response !== '') {
             $falseattributes['checked'] = 'checked';
             $falsechecked = true;
             $responsearray = array('answer' => 1);
         }
     }
     // Work out visual feedback for answer correctness.
     $trueclass = '';
     $falseclass = '';
     $truefeedbackimg = '';
     $falsefeedbackimg = '';
     if ($options->correctness) {
         if ($truechecked) {
             $trueclass = ' ' . $this->feedback_class((int) $question->rightanswer);
             $truefeedbackimg = $this->feedback_image((int) $question->rightanswer);
         } else {
             if ($falsechecked) {
                 $falseclass = ' ' . $this->feedback_class((int) (!$question->rightanswer));
                 $falsefeedbackimg = $this->feedback_image((int) (!$question->rightanswer));
             }
         }
     }
     $radiotrue = html_writer::empty_tag('input', $trueattributes) . html_writer::tag('label', get_string('true', 'qtype_truefalse'), array('for' => $trueattributes['id']));
     $radiofalse = html_writer::empty_tag('input', $falseattributes) . html_writer::tag('label', get_string('false', 'qtype_truefalse'), array('for' => $falseattributes['id']));
     $result = '';
     $result .= html_writer::tag('div', $question->format_questiontext($qa), array('class' => 'qtext'));
     $result .= html_writer::start_tag('div', array('class' => 'ablock'));
     $result .= html_writer::tag('div', get_string('selectone', 'qtype_truefalse'), array('class' => 'prompt'));
     $result .= html_writer::start_tag('div', array('class' => 'answer'));
     $result .= html_writer::tag('div', $radiotrue . ' ' . $truefeedbackimg, array('class' => 'r0' . $trueclass));
     $result .= html_writer::tag('div', $radiofalse . ' ' . $falsefeedbackimg, array('class' => 'r1' . $falseclass));
     $result .= html_writer::end_tag('div');
     // Answer.
     $result .= html_writer::end_tag('div');
     // Ablock.
     if ($qa->get_state() == question_state::$invalid) {
         $result .= html_writer::nonempty_tag('div', $question->get_validation_error($responsearray), array('class' => 'validationerror'));
     }
     return $result;
 }
Exemple #27
0
    public function formulation_and_controls(question_attempt $qa,
            question_display_options $options) {

        $question = $qa->get_question();
        $response = $question->get_response($qa);

        $inputname = $qa->get_qt_field_name('answer');
        $inputattributes = array(
            'type' => $this->get_input_type(),
            'name' => $inputname,
        );

        if ($options->readonly) {
            $inputattributes['disabled'] = 'disabled';
        }

        $radiobuttons = array();
        $feedbackimg = array();
        $feedback = array();
        $classes = array();
        foreach ($question->get_order($qa) as $value => $ansid) {
            $ans = $question->answers[$ansid];
            $inputattributes['name'] = $this->get_input_name($qa, $value);
            $inputattributes['value'] = $this->get_input_value($value);
            $inputattributes['id'] = $this->get_input_id($qa, $value);
            $isselected = $question->is_choice_selected($response, $value);
            if ($isselected) {
                $inputattributes['checked'] = 'checked';
            } else {
                unset($inputattributes['checked']);
            }
            $hidden = '';
            if (!$options->readonly && $this->get_input_type() == 'checkbox') {
                $hidden = html_writer::empty_tag('input', array(
                    'type' => 'hidden',
                    'name' => $inputattributes['name'],
                    'value' => 0,
                ));
            }
            $radiobuttons[] = $hidden . html_writer::empty_tag('input', $inputattributes) .
                    html_writer::tag('label',
                        $this->number_in_style($value, $question->answernumbering) .
                        $question->make_html_inline($question->format_text(
                                $ans->answer, $ans->answerformat,
                                $qa, 'question', 'answer', $ansid)),
                    array('for' => $inputattributes['id'], 'class' => 'm-l-1'));

            // Param $options->suppresschoicefeedback is a hack specific to the
            // oumultiresponse question type. It would be good to refactor to
            // avoid refering to it here.
            if ($options->feedback && empty($options->suppresschoicefeedback) &&
                    $isselected && trim($ans->feedback)) {
                $feedback[] = html_writer::tag('div',
                        $question->make_html_inline($question->format_text(
                                $ans->feedback, $ans->feedbackformat,
                                $qa, 'question', 'answerfeedback', $ansid)),
                        array('class' => 'specificfeedback'));
            } else {
                $feedback[] = '';
            }
            $class = 'r' . ($value % 2);
            if ($options->correctness && $isselected) {
                $feedbackimg[] = $this->feedback_image($this->is_right($ans));
                $class .= ' ' . $this->feedback_class($this->is_right($ans));
            } else {
                $feedbackimg[] = '';
            }
            $classes[] = $class;
        }

        $result = '';
        $result .= html_writer::tag('div', $question->format_questiontext($qa),
                array('class' => 'qtext'));

        $result .= html_writer::start_tag('div', array('class' => 'ablock'));
        $result .= html_writer::tag('div', $this->prompt(), array('class' => 'prompt'));

        $result .= html_writer::start_tag('div', array('class' => 'answer'));
        foreach ($radiobuttons as $key => $radio) {
            $result .= html_writer::tag('div', $radio . ' ' . $feedbackimg[$key] . $feedback[$key],
                    array('class' => $classes[$key])) . "\n";
        }
        $result .= html_writer::end_tag('div'); // Answer.

        $result .= html_writer::end_tag('div'); // Ablock.

        if ($qa->get_state() == question_state::$invalid) {
            $result .= html_writer::nonempty_tag('div',
                    $question->get_validation_error($qa->get_last_qt_data()),
                    array('class' => 'validationerror'));
        }

        return $result;
    }
Exemple #28
0
$num = count($letters) + 3;
//if were viewing the letters
if (!$edit) {
    $data = array();
    $max = 100;
    foreach ($letters as $boundary => $letter) {
        $line = array();
        $line[] = format_float($max, 2) . ' %';
        $line[] = format_float($boundary, 2) . ' %';
        $line[] = format_string($letter);
        $data[] = $line;
        $max = $boundary - 0.01;
    }
    print_grade_page_head($COURSE->id, 'letter', 'view', get_string('gradeletters', 'grades'));
    $stredit = get_string('editgradeletters', 'grades');
    $editlink = html_writer::nonempty_tag('div', html_writer::link($returnurl . $editparam, $stredit), array('class' => 'mdl-align'));
    echo $editlink;
    $table = new html_table();
    $table->head = array(get_string('max', 'grades'), get_string('min', 'grades'), get_string('letter', 'grades'));
    $table->size = array('30%', '30%', '40%');
    $table->align = array('left', 'left', 'left');
    $table->width = '30%';
    $table->data = $data;
    $table->tablealign = 'center';
    echo html_writer::table($table);
    echo $editlink;
} else {
    //else we're editing
    require_once 'edit_form.php';
    $data = new stdClass();
    $data->id = $context->id;
 public function test_nonempty_tag_zero_string()
 {
     $this->assertSame('<div class="score">0</div>', html_writer::nonempty_tag('div', '0', array('class' => 'score')));
 }
Exemple #30
0
 protected function navigation_node(navigation_node $node, $attrs = array())
 {
     global $CFG, $PAGE;
     static $mainsubnav;
     static $coursessubnav;
     $items = $node->children;
     $hidecourses = property_exists($PAGE->theme->settings, 'coursesloggedinonly') && $PAGE->theme->settings->coursesloggedinonly && !isloggedin();
     // exit if empty, we don't want an empty ul element
     if ($items->count() == 0) {
         return '';
     }
     // array of nested li elements
     $lis = array();
     foreach ($items as $item) {
         if (!$item->display) {
             continue;
         }
         if ($item->key === 'courses' && $hidecourses) {
             continue;
         }
         // Skip pointless "Current course" node, go straight to its last (sole) child
         if ($item->key === 'currentcourse') {
             $item = $item->children->last();
         }
         $isbranch = $item->children->count() > 0 || $item->nodetype == navigation_node::NODETYPE_BRANCH || property_exists($item, 'isexpandable') && $item->isexpandable;
         $hasicon = !$isbranch && $item->icon instanceof renderable;
         if ($isbranch) {
             $item->hideicon = true;
         }
         if ($item->action instanceof action_link && $hasicon && !$item->hideicon && strip_tags($item->action->text) == $item->action->text) {
             // Icon hasn't already been rendered - render it now.
             $item->action->text = $this->output->render($item->icon) . $item->action->text;
         }
         $content = $this->output->render($item);
         if ($isbranch && $item->children->count() == 0) {
             $expanded = false;
             // Navigation block does this via AJAX - we'll merge it in directly instead
             if (!empty($CFG->navshowallcourses) && $item->key === 'courses') {
                 if (!$coursessubnav) {
                     // Prepare dummy page for subnav initialisation
                     $dummypage = new krystle_dummy_page();
                     $dummypage->set_context($PAGE->context);
                     $dummypage->set_url($PAGE->url);
                     $coursessubnav = new krystle_expand_navigation($dummypage, $item->type, $item->key);
                     $expanded = true;
                 }
                 $subnav = $coursessubnav;
             } else {
                 if (!$mainsubnav) {
                     // Prepare dummy page for subnav initialisation
                     $dummypage = new krystle_dummy_page();
                     $dummypage->set_context($PAGE->context);
                     $dummypage->set_url($PAGE->url);
                     $mainsubnav = new krystle_expand_navigation($dummypage, $item->type, $item->key);
                     $expanded = true;
                 }
                 $subnav = $mainsubnav;
             }
             $branch = $subnav->find($item->key, $item->type);
             if ($branch === false) {
                 if (!$expanded) {
                     // re-use subnav so we don't have to reinitialise everything
                     $subnav->expand($item->type, $item->key);
                 }
                 if (!isloggedin() || isguestuser()) {
                     $subnav->set_expansion_limit(navigation_node::TYPE_COURSE);
                 }
                 $branch = $subnav->find($item->key, $item->type);
             }
             if ($branch !== false) {
                 $content .= $this->navigation_node($branch);
             }
         } else {
             $content .= $this->navigation_node($item);
         }
         if ($isbranch && !(is_string($item->action) || empty($item->action))) {
             $content = html_writer::tag('li', $content, array('class' => 'clickable-with-children'));
         } else {
             $content = html_writer::tag('li', $content);
         }
         $lis[] = $content;
     }
     if (count($lis)) {
         return html_writer::nonempty_tag('ul', implode("\n", $lis), $attrs);
     } else {
         return '';
     }
 }