⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 report.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php  // $Id: report.php,v 1.7.4.3 2008/03/06 07:34:04 gbateson Exp $/// Overview report just displays a big table of all the attemptsclass hotpot_report extends hotpot_default_report {	function display(&$hotpot, &$cm, &$course, &$users, &$attempts, &$questions, &$options) {		global $CFG;		// create the tables		$tables = array();		$this->create_responses_table($hotpot, $course, $users, $attempts, $questions, $options, $tables);		$this->create_analysis_table($users, $attempts, $questions, $options, $tables);		// print report		$this->print_report($course, $hotpot, $tables, $options);		return true;	}	function create_responses_table(&$hotpot, &$course, &$users, &$attempts, &$questions, &$options, &$tables) {		global $CFG;		$is_html = ($options['reportformat']=='htm');		// shortcuts for font tags		$br = $is_html ? "<br />\n" : "\n";		$blank = $is_html ? '&nbsp;' : "";		$font_end   = $is_html ? '</font>' : '';		$font_red   = $is_html ? '<font color="red">'   : '';		$font_blue  = $is_html ? '<font color="blue">'  : '';		$font_brown = $is_html ? '<font color="brown">' : '';		$font_green = $is_html ? '<font color="green">' : '';		$font_small = $is_html ? '<font size="-2">' : '';		$nobr_start = $is_html ? '<nobr>'  : '';		$nobr_end   = $is_html ? '</nobr>' : '';		// is review allowed? (do this once here, to save time later)		$allow_review = ($is_html && (has_capability('mod/hotpot:viewreport',get_context_instance(CONTEXT_COURSE, $course->id)) || $hotpot->review));		// assume penalties column is NOT required		$show_penalties = false;		// initialize $table		unset($table);		$table->border = 1;		$table->width = '100%';		// initialize legend, if necessary		if (!empty($options['reportshowlegend'])) {			$table->legend = array();		}		// headings for name, attempt number, score/grade and penalties		$table->head = array(			get_string("name"),			hotpot_grade_heading($hotpot, $options),			get_string('attempt', 'quiz'),		);		$table->align = array('left', 'center', 'center');		$table->size = array(150, 80, 10);		$table->wrap = array(0, 0, 0);		$table->fontsize = array(0, 0, 0);		// question headings		$this->add_question_headings($questions, $table, 'left', 0, false, 2);		// penalties (not always needed) and raw score		array_push($table->head,			get_string('penalties', 'hotpot'),			get_string('score', 'quiz')		);		array_push($table->align, 'center', 'center');		array_push($table->size, 50, 50);		array_push($table->wrap, 0, 0);		array_push($table->fontsize, 0, 0);		// message strings		$strnoresponse = get_string('noresponse', 'quiz');		// array to map columns onto question ids ($col => $id)		$questionids = array_keys($questions);		// add details of users' responses		foreach ($users as $user) {			// shortcut to user info held in first attempt record			$u = &$user->attempts[0];			if (function_exists("fullname")) {				$name = fullname($u);			} else {				$name = "$u->firstname $u->lastname";			}			if ($is_html) {				$name = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$u->userid.'&amp;course='.$course->id.'">'.$name.'</a>';			}			$grade = isset($user->grade) ? $user->grade : $blank;			foreach ($user->attempts as $attempt) {				$attemptnumber = $attempt->attempt;				if ($allow_review) {					$attemptnumber = ' <a href="review.php?hp='.$hotpot->id.'&amp;attempt='.$attempt->id.'">'.$attemptnumber.'</a>';				}				$cells = array ($name, $grade, $attemptnumber);				// $name and $grade are only printed on first line per user				$name = $blank;				$grade = $blank;				$start_col = count($cells);				foreach ($questionids as $col => $id) {					$cells[$start_col + $col] = "$font_brown($strnoresponse)$font_end";				}				if (isset($attempt->penalties)) {					$show_penalties = true;					$penalties = $attempt->penalties;				} else {					$penalties = $blank;				}				array_push($cells, $penalties, hotpot_format_score($attempt));				// get responses to questions in this attempt				foreach ($attempt->responses as $response) {					// check this question id is OK (should be)					$col = array_search($response->question, $questionids);					if (is_numeric($col)) {						// correct						if ($value = hotpot_strings($response->correct)) {							$this->set_legend($table, $col, $value, $questions[$response->question]);						} else {							$value = "($strnoresponse)";						}						$cell = $font_red.$value.$font_end;						// wrong						if ($value = hotpot_strings($response->wrong)) {							if (isset($table->legend)) {								$values = array();								foreach (explode(',', $value) as $v) {									$this->set_legend($table, $col, $v, $questions[$response->question]);									$values[] = $v;								}								$value = implode(',', $values);							}							$cell .= $br.$font_blue.$value.$font_end;						}						// ignored						if ($value = hotpot_strings($response->ignored)) {							if (isset($table->legend)) {								$values = array();								foreach (explode(',', $value) as $v) {									$this->set_legend($table, $col, $v, $questions[$response->question]);									$values[] = $v;								}								$value = implode(',', $values);							}							$cell .= $br.$font_brown.$value.$font_end;						}						// numeric						if (is_numeric($response->score)) {							if (empty($table->caption)) {								$table->caption = get_string('indivresp', 'quiz');								if ($is_html) {									$table->caption .= helpbutton('responsestable', $table->caption, 'hotpot', true, false, '', true);								}							}							$hints = empty($response->hints) ? 0 : $response->hints;							$clues = empty($response->clues) ? 0 : $response->clues;							$checks = empty($response->checks) ? 0 : $response->checks;							$numeric = $response->score.'% '.$blank.' ('.$hints.','.$clues.','.$checks.')';							$cell .= $br.$nobr_start.$font_green.$numeric.$font_end.$nobr_end;						}						$cells[$start_col + $col] = $cell;					}				}				$table->data[] = $cells;			}			// insert 'tabledivider' between users			$table->data[] = 'hr';		} // end foreach $users		// remove final 'hr' from data rows		array_pop($table->data);		if (!$show_penalties) {			$col = 3 + count($questionids);			$this->remove_column($table, $col);		}		$tables[] = &$table;	}	function create_analysis_table(&$users, &$attempts, &$questions, &$options, &$tables) {		$is_html = ($options['reportformat']=='htm');		// the fields we are interested in, in the order we want them		$fields = array('correct', 'wrong', 'ignored', 'hints', 'clues', 'checks', 'weighting');		$string_fields = array('correct', 'wrong', 'ignored');		$q = array(); // statistics about the $q(uestions)		$f = array(); // statistics about the $f(ields)		////////////////////////////////////////////		// compile the statistics about the questions		////////////////////////////////////////////		foreach ($questions as $id=>$question) {			// extract scores for attempts at this question			$scores = array();			foreach ($question->attempts as $attempt) {				$scores[] = $attempt->score;			}			// sort scores values (in ascending order)			asort($scores);			// get the borderline high and low scores			$count = count($scores);			switch ($count) {				case 0:					$lo_score = 0;					$hi_score = 0;					break;				case 1:					$lo_score = 0;					$hi_score = $scores[0];					break;				default:					$lo_score = $scores[round($count*1/3)];					$hi_score = $scores[round($count*2/3)];					break;			}			// get statistics for each attempt which includes this question			foreach ($question->attempts as $attempt) {				$is_hi_score = ($attempt->score >= $hi_score);				$is_lo_score = ($attempt->score <  $lo_score);				// reference to the response to the current question				$response = &$attempt->responses[$id];				// update statistics for fields in this response				foreach($fields as $field) {					if (!isset($q[$id])) {						$q[$id] = array();					}					if (!isset($f[$field])) {						$f[$field] = array('count' => 0);					}					if (!isset($q[$id][$field])) {						$q[$id][$field] = array('count' => 0);					}					$values = explode(',', $response->$field);					$values = array_unique($values);					foreach($values as $value) {						// $value should be an integer (string_id or count)						if (is_numeric($value)) {							$f[$field]['count']++;							if (!isset($q[$id][$field][$value])) {								$q[$id][$field][$value] = 0;							}							$q[$id][$field]['count']++;							$q[$id][$field][$value]++;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -