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

📄 scorm_classes.php

📁 完美的在线教育系统
💻 PHP
📖 第 1 页 / 共 2 页
字号:
<?php // $Id: scorm_classes.php,v 1.2 2006/07/06 18:50:49 moosh Exp $if ( count( get_included_files() ) == 1 ) die( '---' );/** * @copyright (c) 2007 Dokeos * @copyright (c) 2001-2006 Universite catholique de Louvain (UCL) * * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE * * @author Claro Team <cvs@claroline.net> * @author Yannick Warnier <yannick.warnier@dokeos.com> */require_once(api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/question.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/answer.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/unique_answer.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/multiple_answer.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/fill_blanks.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/freeanswer.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/hotspot.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/matching.class.php');require_once(api_get_path(SYS_CODE_PATH).'exercice/hotspot.class.php');// answer typesdefine('UNIQUE_ANSWER',		1);define('MCUA',				1);define('TF',				1);define('MULTIPLE_ANSWER',	2);define('MCMA',				2);define('FILL_IN_BLANKS',	3);define('FIB',				3);define('MATCHING',			4);define('FREE_ANSWER', 		5);define('HOTSPOT',			6);/** * The ScormQuestion class is a gateway to getting the answers exported  * (the question is just an HTML text, while the answers are the most important). * It is important to note that the SCORM export process is done in two parts. * First, the HTML part (which is the presentation), and second the JavaScript * part (the process). * The two bits are separate to allow for a one-big-javascript and a one-big-html * files to be built. Each export function thus returns an array of HTML+JS */class ScormQuestion extends Question{	/**	 * Include the correct answer class and create answer	 */	function setAnswer()	{		switch($this->type)		{			case MCUA :				$this->answer = new ScormAnswerMultipleChoice($this->id, false);                $this->answer->questionJSId = $this->js_id;				break; 			case MCMA :				$this->answer = new ScormAnswerMultipleChoice($this->id, true);	                $this->answer->questionJSId = $this->js_id;				break;			case TF :				$this->answer = new ScormAnswerTrueFalse($this->id);                 $this->answer->questionJSId = $this->js_id;				break;			case FIB :				$this->answer = new ScormAnswerFillInBlanks($this->id);                 $this->answer->questionJSId = $this->js_id;				break;			case MATCHING :				$this->answer = new ScormAnswerMatching($this->id);                 $this->answer->questionJSId = $this->js_id;				break;			case FREE_ANSWER :				$this->answer = new ScormAnswerFree($this->id);                 $this->answer->questionJSId = $this->js_id;				break;			case HOTSPOT:				$this->answer = new ScormAnswerHotspot($this->id);                 $this->answer->questionJSId = $this->js_id;				break;			default :				$this->answer = null;                $this->answer->questionJSId = $this->js_id;				break;		}		return true;	}		function export()	{		$html = $this->getQuestionHTML();		$js   = $this->getQuestionJS();				if( is_object($this->answer) )		{			list($js2,$html2) = $this->answer->export();			$js .= $js2;			$html .= $html2;		}		return array($js,$html);			}    function createAnswersForm($form)    {    	return true;    }    function processAnswersCreation($form)    {    	return true;    }    /**     * Returns an HTML-formatted question     */    function getQuestionHTML()    {    	$title			= $this->selectTitle();		$description	= $this->selectDescription();		$cols = 2;		$s='<tr>' .			'<td colspan="'.$cols.'" id="question_'.$this->id.'_title" valign="middle" style="background-color:#d6d6d6;">' . "\n" .		   	api_parse_tex($title).		   	'</td>' . "\n" .		   	'</tr>' . "\n" .		   	'<tr>' . "\n" .		   	'<td valign="top" colspan="'.$cols.'">' . "\n" .		   	'<i>'.api_parse_tex($description).'</i>' . "\n" .		   	'</td>' . "\n" .		   	'</tr>' . "\n";		return $s;    }    /**     * Return the JavaScript code bound to the question     */    function getQuestionJS()    {    	//$id = $this->id;    	$w = $this->selectWeighting();    	$s = 'questions.push('.$this->js_id.');'."\n";    	if($this->type == FREE_ANSWER or $this->type == HOTSPOT)    	{ //put the max score to 0 to avoid discounting the points of    	  //non-exported quiz types in the SCORM    		$w=0;    	}    	$s .= 'questions_score_max['.$this->js_id.'] = '.$w.";\n";    	return $s;    }}/** * This class handles the export to SCORM of a multiple choice question * (be it single answer or multiple answers) */class ScormAnswerMultipleChoice extends Answer{	/**	 * Return HTML code for possible answers     */	function export()	{		$html = '';    	$js   = '';    	$html = '<tr><td colspan="2"><table width="100%">' . "\n";		$type = $this->getQuestionType();		$jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n";		$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n";        if ($type == MCMA)        {        	//$questionTypeLang = get_lang('MultipleChoiceMultipleAnswers');        	$id = 1;        	$jstmp = '';        	$jstmpc = '';			foreach( $this->answer as $i => $answer )			{				$identifier = 'question_'.$this->questionJSId.'_multiple_'.$i;				$html .=			    		'<tr>' . "\n" 				.	'<td align="center" width="5%">' . "\n"		    	.	'<input name="'.$identifier.'" id="'.$identifier.'" value="'.$i.'" type="checkbox" />' . "\n"		    	.	'</td>' . "\n"		    	.	'<td width="95%">' . "\n"		    	.	'<label for="'.$identifier.'">' . $this->answer[$i] . '</label>' . "\n"		    	.	'</td>' . "\n"		    	.	'</tr>' . "\n\n";		    	$jstmp .= $i.',';		    	if($this->correct[$i])		    	{		    		$jstmpc .= $i.',';		    	}		    	$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$i].";\n";		    	$id++;			}			$js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp,0,-1).');'."\n";	    	$js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.substr($jstmpc,0,-1).');'."\n";	    	$js .= 'questions_types['.$this->questionJSId.'] = \'mcma\';'."\n";	    	$js .= $jstmpw;        }        else        {        	//$questionTypeLang = get_lang('MultipleChoiceUniqueAnswer');        	$id = 1;        	$jstmp = '';        	$jstmpc = '';			foreach( $this->answer as $i => $answer )			{				        	$identifier = 'question_'.$this->questionJSId.'_unique_'.$i;				$html .=			    		'<tr>' . "\n" 				.	'<td align="center" width="5%">' . "\n"		    	.	'<input name="'.$identifier.'" id="'.$identifier.'" value="'.$i.'" type="radio"/>' . "\n"		    	.	'</td>' . "\n"		    	.	'<td width="95%">' . "\n"		    	.	'<label for="'.$identifier.'">' . $this->answer[$i] . '</label>' . "\n"		    	.	'</td>' . "\n"		    	.	'</tr>' . "\n\n";		    	$jstmp .= $i.',';		    	if($this->correct[$i])		    	{		    		$jstmpc .= $i;		    	}		    	$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$this->weighting[$i].";\n";		    	$id++;			}			$js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp,0,-1).');'."\n";	    	$js .= 'questions_answers_correct['.$this->questionJSId.'] = '.$jstmpc.';'."\n";	    	$js .= 'questions_types['.$this->questionJSId.'] = \'mcua\';'."\n";			$js .= $jstmpw;        }		$html .= '</table></td></tr>' . "\n";        return array($js,$html);    }}/** * This class handles the SCORM export of true/false questions */class ScormAnswerTrueFalse extends Answer{	/**     * Return the XML flow for the possible answers.      * That's one <response_lid>, containing several <flow_label>     *     * @author Amand Tihon <amand@alrj.org>     */    function export()    {    	$js = '';    	$html = '<tr><td colspan="2"><table width="100%">';		$identifier = 'question_'.$this->questionJSId.'_tf';		$identifier_true  = $identifier.'_true';		$identifier_false = $identifier.'_false';		$html .=	    		'<tr>' . "\n" 		.	'<td align="center" width="5%">' . "\n"    	.	'<input name="'.$identifier_true.'" id="'.$identifier_true.'" value="'.$this->trueGrade.'" type="radio" '		.		'/>' . "\n"    	.	'</td>' . "\n"    	.	'<td width="95%">' . "\n"    	.	'<label for="'.$identifier_true.'">' . get_lang('True') . '</label>' . "\n"    	.	'</td>' . "\n"    	.	'</tr>' . "\n\n";    	$html .=			'<tr>' . "\n" 		.	'<td align="center" width="5%">' . "\n"		.	'<input name="'.$identifier_false.'" id="'.$identifier_false.'" value="'.$this->falseGrade.'" type="radio" '		.		'/>' . "\n"		.	'</td>' . "\n"		.	'<td width="95%">' . "\n"		.	'<label for="'.$identifier_false.'">' . get_lang('False') . '</label>' . "\n"		.	'</td>' . "\n"		.	'</tr>' . "\n\n";		$html .= '</table></td></tr>' . "\n";		$js .= 'questions_answers['.$this->questionJSId.'] = new Array(\'true\',\'false\');'."\n";    	$js .= 'questions_types['.$this->questionJSId.'] = \'tf\';'."\n";		if($this->response == 'TRUE')		{	    	$js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array(\'true\');'."\n";		}		else		{	    	$js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array(\'false\');'."\n";		}		$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n";		$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n";    	$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][1] = '.$this->weighting[1].";\n";    	$js .= $jstmpw;        return array($js,$html);    }}/** * This class handles the SCORM export of fill-in-the-blanks questions */class ScormAnswerFillInBlanks extends Answer {	/**     * Export the text with missing words.     *     * As a side effect, it stores two lists in the class :     * the missing words and their respective weightings.     */    function export()    {    	global $charset;    	$js = '';    	$html = '<tr><td colspan="2"><table width="100%">' . "\n";		// get all enclosed answers		$blankList = array();		// build replacement 		$replacementList = array();		foreach( $this->answer as $i => $answer )		{			$blankList[] = '['.$answer.']';		}		$answerCount = count($blankList);		// splits text and weightings that are joined with the character '::'		list($answer,$weight)=explode('::',$answer);		$weights = explode(',',$weight);		// because [] is parsed here we follow this procedure:		// 1. find everything between the [ and ] tags		$i=1;		$jstmp = '';		$jstmpc = '';		$jstmpw = 'questions_answers_ponderation['.$this->questionJSId.'] = new Array();'."\n";		$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.'][0] = 0;'."\n";		$startlocations=strpos($answer,'[');		$endlocations=strpos($answer,']');		while($startlocations !== false && $endlocations !== false)		{			$texstring=substr($answer,$startlocations,($endlocations-$startlocations)+1);			$answer = substr_replace($answer,'<input type="text" name="question_'.$this->questionJSId.'_fib_'.$i.'" id="question_'.$this->questionJSId.'_fib_'.$i.'" size="10" value="" />',$startlocations,($endlocations-$startlocations)+1);			$jstmp .= $i.',';			$jstmpc .= "'".htmlentities(substr($texstring,1,-1),ENT_QUOTES,$charset)."',";				    	$jstmpw .= 'questions_answers_ponderation['.$this->questionJSId.']['.$i.'] = '.$weights[$i-1].";\n";			$i++;			$startlocations=strpos($answer,'[');			$endlocations=strpos($answer,']');		}		$html .= 	'<tr>' . "\n" 				.	'<td>' . "\n"		    	.	$answer  . "\n"	    		.	'</td>' . "\n"	    		.	'</tr>' . "\n";		$html .= '</table></td></tr>' . "\n";		$js .= 'questions_answers['.$this->questionJSId.'] = new Array('.substr($jstmp,0,-1).');'."\n";    	$js .= 'questions_answers_correct['.$this->questionJSId.'] = new Array('.substr($jstmpc,0,-1).');'."\n";    	$js .= 'questions_types['.$this->questionJSId.'] = \'fib\';'."\n";    	$js .= $jstmpw;        return array($js,$html);    }    }/** * This class handles the SCORM export of matching questions */class ScormAnswerMatching extends Answer{

⌨️ 快捷键说明

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