ÿØÿà JFIF    ÿÛ „  ( %!1"%)+...383-7(-.+  -%%--------+------------/----------------------------ÿÀ  ¶" ÿÄ     ÿÄ @    !1AQaq‘¡"±ÁÑð2’BRráS‚ñ3b¢CT²Ò #cÿÄ    ÿÄ '   1!AQ2a"‘±#ÿÚ   ? ò(/p‘—–¢·,M|¯G»R£üešT. ôŸEoCFñ‡ 4ÔkåóxR|µÁ¨ÓDà!Ç´µ˜‡p ÍQ‹§!þž^õWsŒy  åÁ§$á«%ºq˜™JyyË0y«^Ϗ -3ÃÏËÈ£Æ\P’ä„s&•‹Üs üô'àWt¹pñCp$bÚF`·7.^)¾!)ÒÙ˜–ÅÏš^h¾ø³·ìe±ŒaeÖ—Í,e=B}Jéߦ$$½—šÙÜCC¯¶è8β–Åkèwx LÉngT±æ¹£Ócœ¿Í/©Éÿ ‰ÚCÒ­mq;Tt¶–}0"zÖPcd1š­¤tˆ„ÐÓâqú[™öUCŠ2޿د­É(¸ßúçšmW,Ò ºf‹Ån™ÄLêÁ8üÁkÁ€L¥ÍuJ1œôrÂSŒÓöt!7EUíïb)AËi¬â-ÙHk8òÁiXYwÅ)O^"ÇØriÛô{»wRUKÙÏÚlÓ¬€‚’שT ] ªb—ÊîKC^×M“xùäñz¬zJ× {4[¹M'IÆeH1LCWÕ]œûº WDæà°OÅ‚¹c²ÞuA–rL`HšpCez‡V’— Ž‚Ë„–ñ­'µR0ÕÖ=À:±G»C\nÆÉ5*¢ †3šhQ4ýÒi$Õ1"Ü]¢p-q3zcQ$ªö¨¥æf›‘»´ÝÚHá„e²JÇ–iÊ:·à¬Øc5Åk»Laª*wi [0Ówk ¦a¦0Õ²ÅÅ‚T¸’³q:Æ<¹ú Ò˜Æ}2VE•Ѐp¡Ô3Úº …h³^LJºçì¥Ánó|˜ÖˆÎˆ+« ¦dø‘Mº–d\ªDðÛ„Ì×LÝ——Ð9Ç|•FèçVm™¨€™3õS–9Äå¢<̉Ìm¢±`·º˜&Z²ž Ë®D«¶»6™‰©­HÈ Àá«h­i³04æ’hxœi3ï¨(ÓL·†‹¶ËpŒ ƒÜÒ? :õdsÀ –3æÓ·Üjâ¬9—]8n¼&]I F£¼…ì–—Œ0v°LǐÅfÛ2TÖ’aµ˜N@ÖBSÏ^à´4-±°b×nÈÈœÆD=KdŒø…ÄÈK,›ÖR§fjü$^ÔÎ!„6^ s:Üun\ôkCÞò÷<—Lúl Í›G¹ÀPá¼Nc¡šÒ…ÙWͳœ±vÊáЄ×9‹P‰cEØ‘™›µŸP<×g1 º©Ø¬wiÁ^l5× I/';Ë+´Z‡ÓÄFÕp[Èð’ HÄ ó 9¬Dl4“é±Ï”V=^Hð;žLädÉa‚°Ë,#/Ž~²BÔÛ QãñQtIeórVB,ÏÂf‹4#Μc‹É3ZIÖ Œ¢¥·üxa‡Ãçè„jŠ[5 Ä!U?,3žÎ×…ðdÓ÷háŠA‰ìÄ4÷ÃÜZÃE{‰®+W\ZÍE[‰»µk»MÝ­`¢©†˜ÃV‹-f¢¡†¢a«eŠ%«Y¨©q%jâd,Ôq`) ¤¦…šˆ ¦E>0Ùb²t–Ÿ  ÷jsςҒKÈcø(é›;k(’#ôŒQ ™C> õ³M9óºÆµ¤çâ;uÀ)5>RÔ¸fÓ~Ȧ—’-$fe«"FâUˆÊwµPÏu w+"åÉó¨6s™Û9(À¨ù©hE°½†n`m~“@©›p!Vkhµ Á1šbEqqÊ@ºèl›2 –Yã%‘‚hÛ{a¶‡ÅÞM²¬çL34®Çl]®‹ŽØŒm'RÜe35æöˆ­Á­ cP9šeÁköo´L³Ì=p8]”‡B¶,šº|ɏdzXˆØk*ÇÚ{#ñ‰pã(€¶‡9ý'šÜ³½¯kƒ†Â’ëSOƒ•Å®H6+a¢µˆ‹Y¨b˜b+XˆÖ!°u!¢"µˆˆn2ˆ Å0Ä`Å Ô®c(ÓÜGº•Ä»Œ âWî%q.áÐÄ÷î%umÍ£+ÜQ,Vn¦-GphU¸¢X­&,Gt ·K¢ÅÅ·¥RÄÊÉbKn N­R2g$VµÕó Qr#–ÓZUÏð0ÎtÙÀœz ëöo“Îk¯n„T°"SÞ+³/…€½"ižãO%Í%&Δâ‘ËØ´IˆÓ°Ë‰ÞM3.™yçÁzit›`4C`k¢¼á!álÄï sÂ[×!¤l¾æo"ƒIÔ'@ªu)3›ô®“@Z à¾] üœ'‡4¸PÞkÁ-qÄH‰ÓÍBd´ÿ —¹°ÄA&ÊUC„öz‚‚RæŠtf¬>˜ÑidšEçÑL÷áý¡V±h§­c¿¥¨ƒ@g¼…Ýö^ÞËc.ž„æ“I[ ª+·zÐÒÚ,½Ð»¶€C›7jk$๖€Ž¾ÅÙpp¶ÍþéΤ ½ØÎŒq ñpæžÅ¥#Øâ49ÃÂK^MYV“,¶Éz_òæ:…;Õ«¦I3âJ£¤û5$7Èxün\â]Êe¯(Ÿ&Ž‹¶2<6Ćf× æ¢ƱqWı[(ÙÂŽç‚T7¨@ÈÉÍß‚ïÙ"&3TYlGށ†)†#5ŠA©^T2ÆÁ†)©†©†¤yGXÁ†©"†)©¼ÅV WS†#©]R–r‹q5ÕbâWþBh¯u+ªÅÄ×ü„nÑ^êkªÁj‰jeœWˆÕÕ`µDµ2Ì+Ä µDµµ5Ô{¤Þ0RF’H÷AÛ<ÊÁ§ ƈæ0Ñ£ê4 öÚµ[¬/1²€â<-¬šö²r×0o×w ´xÐÒË„ g01¬„åEM蛇Ã\6µE›‘fÙO k÷CºnÓ1`iîÒ² áÂ!ÑLÄÿ ³¬\õ*:M=Ç»c‹2[‰ØsÕLò\ŒK L^™üÄN\¶#» Ç\……ßïIœÉ$¸ÎñÍ®ÔHÇ Ûí/´>Li”„†g^$ 7NÍÑÑ2M2ªNg=k½Ð}Ÿl6‡ —JWˆ”ÞéT·+µ¦üÂFè¢Vs6ýÆ4»2+2IÝ9ô9®ÇGÙÇ1+Ä8;*Õ§ž½D*îÑWÚçá3Ma¤·ˆ¥t}š²Ü…Q+Æüµ8HíS”üxGéÁˆ¦Ël„éÈ 5 µÄƒ6äÜ(kIš¯S†fÖ&¸®×v|Äyˆ*禌Éù@7-®Ä[]ÎÖ¿ê`º…=:…žJVnݳvðÖKE¼‚ »mà ÷f®:Ë ™–4rð¡4` ܹçž~‹C=œ…¾Ïj|VDtK.ƒ"9 Ï ­–éXá³6WÒïIL-Ї Ç home/smkb8269/public_html/lms.smk-almanshuriyah.sch.id/mod/lesson/pagetypes/shortanswer.php000064400000054350152267163240026053 0ustar00. /** * Short answer * * @package mod_lesson * @copyright 2009 Sam Hemelryk * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later **/ defined('MOODLE_INTERNAL') || die(); /** Short answer question type */ define("LESSON_PAGE_SHORTANSWER", "1"); class lesson_page_type_shortanswer extends lesson_page { protected $type = lesson_page::TYPE_QUESTION; protected $typeidstring = 'shortanswer'; protected $typeid = LESSON_PAGE_SHORTANSWER; protected $string = null; public function get_typeid() { return $this->typeid; } public function get_typestring() { if ($this->string===null) { $this->string = get_string($this->typeidstring, 'lesson'); } return $this->string; } public function get_idstring() { return $this->typeidstring; } public function display($renderer, $attempt) { global $USER, $CFG, $PAGE; $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents(), 'lessonid'=>$this->lesson->id)); $data = new stdClass; $data->id = $PAGE->cm->id; $data->pageid = $this->properties->id; if (isset($USER->modattempts[$this->lesson->id])) { $data->answer = s($attempt->useranswer); } $mform->set_data($data); // Trigger an event question viewed. $eventparams = array( 'context' => context_module::instance($PAGE->cm->id), 'objectid' => $this->properties->id, 'other' => array( 'pagetype' => $this->get_typestring() ) ); $event = \mod_lesson\event\question_viewed::create($eventparams); $event->trigger(); return $mform->display(); } /** * Creates answers for this page type. * * @param object $properties The answer properties. */ public function create_answers($properties) { if (isset($properties->enableotheranswers) && $properties->enableotheranswers) { $properties->response_editor = array_values($properties->response_editor); $properties->jumpto = array_values($properties->jumpto); $properties->score = array_values($properties->score); $wrongresponse = end($properties->response_editor); $wrongkey = key($properties->response_editor); $properties->answer_editor[$wrongkey] = LESSON_OTHER_ANSWERS; } parent::create_answers($properties); } /** * Update the answers for this page type. * * @param object $properties The answer properties. * @param context $context The context for this module. * @param int $maxbytes The maximum bytes for any uploades. */ public function update($properties, $context = null, $maxbytes = null) { if ($properties->enableotheranswers) { $properties->response_editor = array_values($properties->response_editor); $properties->jumpto = array_values($properties->jumpto); $properties->score = array_values($properties->score); $wrongresponse = end($properties->response_editor); $wrongkey = key($properties->response_editor); $properties->answer_editor[$wrongkey] = LESSON_OTHER_ANSWERS; } parent::update($properties, $context, $maxbytes); } public function check_answer() { global $CFG; $result = parent::check_answer(); $mform = new lesson_display_answer_form_shortanswer($CFG->wwwroot.'/mod/lesson/continue.php', array('contents'=>$this->get_contents())); $data = $mform->get_data(); require_sesskey(); $studentanswer = trim($data->answer); if ($studentanswer === '') { $result->noanswer = true; return $result; } $i=0; $answers = $this->get_answers(); foreach ($answers as $answer) { $answer = parent::rewrite_answers_urls($answer, false); $i++; // Applying PARAM_TEXT as it is applied to the answer submitted by the user. $expectedanswer = clean_param($answer->answer, PARAM_TEXT); $ismatch = false; $markit = false; $useregexp = ($this->qoption); if ($useregexp) { //we are using 'normal analysis', which ignores case $ignorecase = ''; if (substr($expectedanswer, -2) == '/i') { $expectedanswer = substr($expectedanswer, 0, -2); $ignorecase = 'i'; } } else { $expectedanswer = str_replace('*', '%@@%@@%', $expectedanswer); $expectedanswer = preg_quote($expectedanswer, '/'); $expectedanswer = str_replace('%@@%@@%', '.*', $expectedanswer); } // see if user typed in any of the correct answers if ((!$this->lesson->custom && $this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) or ($this->lesson->custom && $answer->score > 0) ) { if (!$useregexp) { // we are using 'normal analysis', which ignores case if (preg_match('/^'.$expectedanswer.'$/i',$studentanswer)) { $ismatch = true; } } else { if (preg_match('/^'.$expectedanswer.'$/'.$ignorecase,$studentanswer)) { $ismatch = true; } } if ($ismatch == true) { $result->correctanswer = true; } } else { if (!$useregexp) { //we are using 'normal analysis' // see if user typed in any of the wrong answers; don't worry about case if (preg_match('/^'.$expectedanswer.'$/i',$studentanswer)) { $ismatch = true; } } else { // we are using regular expressions analysis $startcode = substr($expectedanswer,0,2); switch ($startcode){ //1- check for absence of required string in $studentanswer (coded by initial '--') case "--": $expectedanswer = substr($expectedanswer,2); if (!preg_match('/^'.$expectedanswer.'$/'.$ignorecase,$studentanswer)) { $ismatch = true; } break; //2- check for code for marking wrong strings (coded by initial '++') case "++": $expectedanswer=substr($expectedanswer,2); $markit = true; //check for one or several matches if (preg_match_all('/'.$expectedanswer.'/'.$ignorecase,$studentanswer, $matches)) { $ismatch = true; $nb = count($matches[0]); $original = array(); $marked = array(); $fontStart = ''; $fontEnd = ''; for ($i = 0; $i < $nb; $i++) { array_push($original,$matches[0][$i]); array_push($marked,$fontStart.$matches[0][$i].$fontEnd); } $studentanswer = str_replace($original, $marked, $studentanswer); } break; //3- check for wrong answers belonging neither to -- nor to ++ categories default: if (preg_match('/^'.$expectedanswer.'$/'.$ignorecase,$studentanswer, $matches)) { $ismatch = true; } break; } $result->correctanswer = false; } } if ($ismatch) { $result->newpageid = $answer->jumpto; $options = new stdClass(); $options->para = false; $options->noclean = true; $result->response = format_text($answer->response, $answer->responseformat, $options); $result->answerid = $answer->id; break; // quit answer analysis immediately after a match has been found } } // We could check here to see if we have a wrong answer jump to use. if ($result->answerid == 0) { // Use the all other answers jump details if it is set up. $lastanswer = end($answers); // Double check that this is the @#wronganswer#@ answer. if (strpos($lastanswer->answer, LESSON_OTHER_ANSWERS) !== false) { $otheranswers = end($answers); $result->newpageid = $otheranswers->jumpto; $options = new stdClass(); $options->para = false; $result->response = format_text($otheranswers->response, $otheranswers->responseformat, $options); // Does this also need to do the jumpto_is_correct? if ($this->lesson->custom) { $result->correctanswer = ($otheranswers->score > 0); } $result->answerid = $otheranswers->id; } } $result->userresponse = $studentanswer; //clean student answer as it goes to output. $result->studentanswer = s($studentanswer); return $result; } public function option_description_string() { if ($this->properties->qoption) { return " - ".get_string("casesensitive", "lesson"); } return parent::option_description_string(); } public function display_answers(html_table $table) { $answers = $this->get_answers(); $options = new stdClass; $options->noclean = true; $options->para = false; $i = 1; foreach ($answers as $answer) { $answer = parent::rewrite_answers_urls($answer, false); $cells = array(); if ($this->lesson->custom && $answer->score > 0) { // if the score is > 0, then it is correct $cells[] = ':'; } else if ($this->lesson->custom) { $cells[] = ':'; } else if ($this->lesson->jumpto_is_correct($this->properties->id, $answer->jumpto)) { // underline correct answers $cells[] = '' . get_string('answer', 'lesson') . ' ' . $i . ':' . "\n"; } else { $cells[] = ':'; } $cells[] = format_text($answer->answer, $answer->answerformat, $options); $table->data[] = new html_table_row($cells); $cells = array(); $cells[] = ':'; $cells[] = format_text($answer->response, $answer->responseformat, $options); $table->data[] = new html_table_row($cells); $cells = array(); $cells[] = ':'; $cells[] = $answer->score; $table->data[] = new html_table_row($cells); $cells = array(); $cells[] = ':'; $cells[] = $this->get_jump_name($answer->jumpto); $table->data[] = new html_table_row($cells); if ($i === 1){ $table->data[count($table->data)-1]->cells[0]->style = 'width:20%;'; } $i++; } return $table; } public function stats(array &$pagestats, $tries) { $temp = $this->lesson->get_last_attempt($tries); if (isset($pagestats[$temp->pageid][$temp->useranswer])) { $pagestats[$temp->pageid][$temp->useranswer]++; } else { $pagestats[$temp->pageid][$temp->useranswer] = 1; } if (isset($pagestats[$temp->pageid]["total"])) { $pagestats[$temp->pageid]["total"]++; } else { $pagestats[$temp->pageid]["total"] = 1; } return true; } public function report_answers($answerpage, $answerdata, $useranswer, $pagestats, &$i, &$n) { global $PAGE; $answers = $this->get_answers(); $formattextdefoptions = new stdClass; $formattextdefoptions->para = false; //I'll use it widely in this page foreach ($answers as $answer) { $answer = parent::rewrite_answers_urls($answer, false); if ($useranswer == null && $i == 0) { // I have the $i == 0 because it is easier to blast through it all at once. if (isset($pagestats[$this->properties->id])) { $stats = $pagestats[$this->properties->id]; $total = $stats["total"]; unset($stats["total"]); foreach ($stats as $valentered => $ntimes) { $data = ''; $percent = $ntimes / $total * 100; $percent = round($percent, 2); $percent .= "% ".get_string("enteredthis", "lesson"); $answerdata->answers[] = array($data, $percent); } } else { $answerdata->answers[] = array(get_string("nooneansweredthisquestion", "lesson"), " "); } $i++; } else if ($useranswer != null && ($answer->id == $useranswer->answerid || $answer == end($answers))) { // get in here when what the user entered is not one of the answers $data = ''; if (isset($pagestats[$this->properties->id][$useranswer->useranswer])) { $percent = $pagestats[$this->properties->id][$useranswer->useranswer] / $pagestats[$this->properties->id]["total"] * 100; $percent = round($percent, 2); $percent .= "% ".get_string("enteredthis", "lesson"); } else { $percent = get_string("nooneenteredthis", "lesson"); } $answerdata->answers[] = array($data, $percent); if ($answer->id == $useranswer->answerid) { if ($answer->response == null) { if ($useranswer->correct) { $answerdata->response = get_string("thatsthecorrectanswer", "lesson"); } else { $answerdata->response = get_string("thatsthewronganswer", "lesson"); } } else { $answerdata->response = $answer->response; } if ($this->lesson->custom) { $answerdata->score = get_string("pointsearned", "lesson").": ".$answer->score; } elseif ($useranswer->correct) { $answerdata->score = get_string("receivedcredit", "lesson"); } else { $answerdata->score = get_string("didnotreceivecredit", "lesson"); } // We have found the correct answer, do not process any more answers. $answerpage->answerdata = $answerdata; break; } else { $answerdata->response = get_string("thatsthewronganswer", "lesson"); if ($this->lesson->custom) { $answerdata->score = get_string("pointsearned", "lesson").": 0"; } else { $answerdata->score = get_string("didnotreceivecredit", "lesson"); } } } $answerpage->answerdata = $answerdata; } return $answerpage; } /** * Make updates to the form data if required. In this case to put the all other answer data into the write section of the form. * * @param stdClass $data The form data to update. * @return stdClass The updated fom data. */ public function update_form_data(stdClass $data): stdClass { $answercount = count($this->get_answers()); // Check for other answer entry. $lastanswer = $data->{'answer_editor[' . ($answercount - 1) . ']'}; if (strpos($lastanswer, LESSON_OTHER_ANSWERS) !== false) { $data->{'answer_editor[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'answer_editor[' . ($answercount - 1) . ']'}; $data->{'response_editor[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'response_editor[' . ($answercount - 1) . ']'}; $data->{'jumpto[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'jumpto[' . ($answercount - 1) . ']'}; $data->{'score[' . ($this->lesson->maxanswers + 1) . ']'} = $data->{'score[' . ($answercount - 1) . ']'}; $data->enableotheranswers = true; // Unset the old values. unset($data->{'answer_editor[' . ($answercount - 1) . ']'}); unset($data->{'response_editor[' . ($answercount - 1) . ']'}); unset($data->{'jumpto[' . ($answercount - 1) . ']'}); unset($data->{'score[' . ($answercount - 1) . ']'}); } return $data; } } class lesson_add_page_form_shortanswer extends lesson_add_page_form_base { public $qtype = 'shortanswer'; public $qtypestring = 'shortanswer'; protected $answerformat = ''; protected $responseformat = LESSON_ANSWER_HTML; public function custom_definition() { $this->_form->addElement('checkbox', 'qoption', get_string('options', 'lesson'), get_string('casesensitive', 'lesson')); //oh my, this is a regex option! $this->_form->setDefault('qoption', 0); $this->_form->addHelpButton('qoption', 'casesensitive', 'lesson'); $answercount = $this->_customdata['lesson']->maxanswers; for ($i = 0; $i < $answercount; $i++) { $this->_form->addElement('header', 'answertitle'.$i, get_string('answer').' '.($i+1)); // Only first answer is required. $this->add_answer($i, null, ($i < 1)); $this->add_response($i); $this->add_jumpto($i, null, ($i == 0 ? LESSON_NEXTPAGE : LESSON_THISPAGE)); $this->add_score($i, null, ($i===0)?1:0); } // Other answer jump. $this->_form->addElement('header', 'wronganswer', get_string('allotheranswers', 'lesson')); $newcount = $answercount + 1; $this->_form->addElement('advcheckbox', 'enableotheranswers', get_string('enabled', 'lesson')); $this->add_response($newcount); $this->add_jumpto($newcount, get_string('allotheranswersjump', 'lesson'), LESSON_NEXTPAGE); $this->add_score($newcount, get_string('allotheranswersscore', 'lesson'), 0); } } class lesson_display_answer_form_shortanswer extends moodleform { public function definition() { global $OUTPUT, $USER; $mform = $this->_form; $contents = $this->_customdata['contents']; $hasattempt = false; $attrs = array('size'=>'50', 'maxlength'=>'200'); if (isset($this->_customdata['lessonid'])) { $lessonid = $this->_customdata['lessonid']; if (isset($USER->modattempts[$lessonid]->useranswer)) { $attrs['readonly'] = 'readonly'; $hasattempt = true; } } $placeholder = false; if (preg_match('/_____+/', $contents, $matches)) { $placeholder = $matches[0]; $contentsparts = explode( $placeholder, $contents, 2); $attrs['size'] = round(strlen($placeholder) * 1.1); } // Disable shortforms. $mform->setDisableShortforms(); $mform->addElement('header', 'pageheader'); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); $mform->addElement('hidden', 'pageid'); $mform->setType('pageid', PARAM_INT); if ($placeholder) { $contentsgroup = array(); $contentsgroup[] = $mform->createElement('static', '', '', $contentsparts[0]); $contentsgroup[] = $mform->createElement('text', 'answer', '', $attrs); $contentsgroup[] = $mform->createElement('static', '', '', $contentsparts[1]); $mform->addGroup($contentsgroup, '', '', '', false); } else { $mform->addElement('html', $OUTPUT->container($contents, 'contents')); $mform->addElement('text', 'answer', get_string('youranswer', 'lesson'), $attrs); } $mform->setType('answer', PARAM_TEXT); if ($hasattempt) { $this->add_action_buttons(null, get_string("nextpage", "lesson")); } else { $this->add_action_buttons(null, get_string("submit", "lesson")); } } }