All pastes #609759 Raw Edit

Stuff

public text v1 · immutable
·published 2007-07-09 01:51 UTC
rendered paste body
<?

/* News
 * 
 * Description:
 * News
 *  
 */
 
class Get_Started_Take_The_Test_Quiz
{
	function build($module_id, $request, $calendar = NULL)
	{
		global $main;

		$file = $main->cfg['dir'] . "/www/files_dir/" . $main->cfg['usr'] . "/xml/quiz.xml";
		$xml = $main->xml->connect($file);
		
		$content 			=& $xml[0]['children'][0];
		$ipod 				=& $xml[0]['children'][1];
		$introduction 	=& $xml[0]['children'][2];
		
		$questions = array(
			'verbal'				=>		array(
				'count'					=>	count($xml[0]['children'][3]['children']),
				'items'					=>&	$xml[0]['children'][3]['children'],
			),
			'numerical'		=>		array(
				'count'					=>	count($xml[0]['children'][4]['children']),
				'items'					=>&	$xml[0]['children'][4]['children'],
			),
			'abstract'			=>		array(
				'count'					=>	count($xml[0]['children'][5]['children']),
				'items'					=>&	$xml[0]['children'][5]['children'],
			),
			'general'			=>		array(
				'count'					=>	count($xml[0]['children'][6]['children']),
				'items'					=>&	$xml[0]['children'][6]['children'],
			),
		);
		
		$results 			=&	 $xml[0]['children'][7];
		
		$quiz = array();
		
		if (!$request['step'])
		{
			$quiz['content']		=		array(
				'text'			=>&			$content,
				'ipod'		=>&			$ipod
			);
			
			$_SESSION['questions'] = array(
			
			);
		}
		elseif ($request['step'] <= 10)
		{
			$type = "verbal";
		}
		elseif ($request['step'] <= 17)
		{
			$type = "numerical";
		}
		elseif ($request['step'] <= 24)
		{
			$type = "abstract";
		}
		elseif ($request['step'] <= 29)
		{
			$type = "general";
		}
		else
		{
			$quiz['content']		=		array(
				'text'			=>&			$content,
				'ipod'		=>&			$ipod
			);			
		}
		
		
		if (
			$request['step'] > 0
			&&
			$request['step'] <= 29
		)
		{
			$question = $this->get_question($type, $questions[$type]);
		
			$quiz['content']		=		array(
				'question'			=>&			$question
			);	
		}
			
		$main->core->debug->dump($quiz);
		
		return array(
			'id'			=>		$module_id,
			'content'		=>&	$quiz
		);

	}
	
	function get_question($type, $questions)
	{
		global $main, $_SESSION;
		
		do 
		{
			$random_question = rand(1, $questions['count']);	
		} 
		while ($_SESSION['questions'][$type]['taken'][$random_question]);
				
		$_SESSION['questions'][$type]['taken'][$random_question] = array(
		);
		
		return array(
			'number'		=>		$random_question,
			'item'			=>		$questions['items'][($random_question - 1)]
		);
	}
	
}

?>