From: pkiddie <pk...@us...> - 2005-10-20 10:32:41
|
Update of /cvsroot/stack/stack-1-0/scripts/rqp/moodle_16_rqp/quiz/questiontypes/rqp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23804/scripts/rqp/moodle_16_rqp/quiz/questiontypes/rqp Modified Files: editquestion.php lib.php options.php Log Message: Commented the lib.php file extensively Fixed bug where importing code implied 0 was empty, when in fact this is not always true! Index: editquestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/moodle_16_rqp/quiz/questiontypes/rqp/editquestion.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** editquestion.php 5 Oct 2005 11:43:44 -0000 1.2 --- editquestion.php 20 Oct 2005 10:32:25 -0000 1.3 *************** *** 5,12 **** $strbacktoquiz = get_string("backtoquiz", "quiz"); $struseroptions = get_string("userOptions", "quiz"); - - //Here we must decide whether to display the RQP servers authoring form, or use the generic one - //If current selected server has authoring in serverProperties=false, then use rqp.html - //Otherwise we use HTML from rendering function if (empty($question->id)) { //Authoring a new question --- 5,8 ---- *************** *** 35,45 **** else { ! ! //If desired server can author ! if ($server->properties & RQP_SERVER_AUTHORING) { //Set up render variables ! $render['source'] = $question->options->source; ! $render['options'] = array ( 'admin' => '' , 'teacher' => '', 'user' => '', --- 31,41 ---- else { ! //Here we must decide whether to display the RQP servers authoring form, or use the generic one ! //If current selected server has an authoring form available, use that, otherwise use rqp.html ! if ($server->properties & RQP_SERVER_AUTHORING) { //If server can author questions //Set up render variables ! $render['source'] = $question->options->source; //Get any existing source ! $render['options'] = array ( 'admin' => '' , //No options to set 'teacher' => '', 'user' => '', *************** *** 49,53 **** if (!empty($SESSION->persistent_data)) { ! $render['persistentData']= $SESSION->options->persistent_data; //not used in authoring } --- 45,49 ---- if (!empty($SESSION->persistent_data)) { ! $render['persistentData']= $SESSION->options->persistent_data; //not used in authoring } *************** *** 56,71 **** $render['directives'] = array('edit'); ! ! $render['mimetypes'] = array('text/html');; ! $render['namePrefix'] = $type->name; //STACK $render['itemBase'] = ''; $render['resourceBase'] = $CFG->dataroot . '/moddata/quiz/rqp/resource/'; $render['tempfileBase'] = $CFG->dataroot . '/moddata/quiz/rqp/temp/'; ! //Check presence of form fields which are to be processed if (empty($form)) { $render['inputData']=array(); } else { $render['inputData']=quiz_rqp_parse_input($form,$render['namePrefix']); --- 52,67 ---- $render['directives'] = array('edit'); ! $render['mimetypes'] = array('text/html'); //Default to text/html ! $render['namePrefix'] = $type->name; //Prefix with name of server type $render['itemBase'] = ''; $render['resourceBase'] = $CFG->dataroot . '/moddata/quiz/rqp/resource/'; $render['tempfileBase'] = $CFG->dataroot . '/moddata/quiz/rqp/temp/'; ! //Are there any form fields to be processed? if (empty($form)) { $render['inputData']=array(); } + //Send each form fields as item in key/val array via render else { $render['inputData']=quiz_rqp_parse_input($form,$render['namePrefix']); *************** *** 103,112 **** } ! if ("complete"!=$response['outcomeVars']['completion']) { $QUIZ_QTYPES[$question->qtype]->print_replacement_options($question, $course, $contextquiz); $QUIZ_QTYPES[$question->qtype]->print_question_form_end($question); } ! //if server has indicated the session has come to a close else { echo '<tr valign="top"> --- 99,108 ---- } ! if ("complete"!=$response['outcomeVars']['completion']) { //Check status of completion variable $QUIZ_QTYPES[$question->qtype]->print_replacement_options($question, $course, $contextquiz); $QUIZ_QTYPES[$question->qtype]->print_question_form_end($question); } ! //If server has indicated authoring session has come to a close else { echo '<tr valign="top"> Index: options.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/moodle_16_rqp/quiz/questiontypes/rqp/options.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** options.php 5 Oct 2005 11:43:44 -0000 1.2 --- options.php 20 Oct 2005 10:32:25 -0000 1.3 *************** *** 1,3 **** ! <?php /* This page is responsible for the setting of options */ require_once('../../../../config.php'); --- 1,3 ---- ! <?php // $Id$ /* This page is responsible for the setting of options */ require_once('../../../../config.php'); Index: lib.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/moodle_16_rqp/quiz/questiontypes/rqp/lib.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** lib.php 5 Oct 2005 11:43:44 -0000 1.2 --- lib.php 20 Oct 2005 10:32:25 -0000 1.3 *************** *** 11,15 **** */ ! define('RQP_SERVER_RENDERING', 1); define('RQP_SERVER_IMPLICITCLONING', 2); define('RQP_SERVER_EXPLICITCLONING', 4); --- 11,15 ---- */ ! define('RQP_SERVER_RENDERING', 1); //Define server property flags define('RQP_SERVER_IMPLICITCLONING', 2); define('RQP_SERVER_EXPLICITCLONING', 4); *************** *** 18,27 **** define('RQP_SERVER_TEACHEROPTIONS', 32); define('RQP_SERVER_USEROPTIONS', 64); ! ! //Define RQP version <TODO>: Should this be in the client ! define ('RQP_VER','1.0'); ! ! //This global array holds an ordered, up to date list of all RQP types ! $rqpTypes = array(); /** --- 18,23 ---- define('RQP_SERVER_TEACHEROPTIONS', 32); define('RQP_SERVER_USEROPTIONS', 64); ! define ('RQP_VER','1.0'); //Define RQP version <TODO>: Should this be in the client ! $rqpTypes = array(); //This global array holds an ordered, up to date list of all RQP types /** *************** *** 53,57 **** } ! //For a specified type, retrieve the administrators options function quiz_rqp_get_admin_options($typeid) { --- 49,60 ---- } ! /** ! * For a specified question type, retrieve the administrator options set within the ! * RQP question type web form. ! * ! * @param int $typeid the RQP question type id ! * @return mixed false if no administrator options set for that type, ! * otherwise a server specific options string ! */ function quiz_rqp_get_admin_options($typeid) { *************** *** 63,67 **** } ! //For a specified user and RQP server type, retrieve the user options function quiz_rqp_get_user_options($userid, $typeid) { if (!$userOptions = get_record('quiz_rqp_user_options', 'userid', $userid, 'typeid', $typeid)) { --- 66,78 ---- } ! /** ! * For a specified question type and user id, retrieve any options the user has set within the ! * user options accessible whenever that type remotely renders. ! * ! * @param int $typeid the RQP question type id ! * @param int $userid the user id ! * @return mixed false if no user options set for that type/user combination, ! * otherwise a server specific options string ! */ function quiz_rqp_get_user_options($userid, $typeid) { if (!$userOptions = get_record('quiz_rqp_user_options', 'userid', $userid, 'typeid', $typeid)) { *************** *** 72,76 **** } ! //For a specified quiz and RQP server type, retrieve the quiz options (part of the teacher options) function quiz_rqp_get_quiz_options($quizid, $typeid) { if (!$quizOptions = get_record('quiz_rqp_quiz_options', 'quizid', $quizid, 'typeid', $typeid)) { --- 83,94 ---- } ! /** ! * For a specified question type and quiz id, retrieve any options the teacher has set at the quiz level ! * ! * @param int $typeid the RQP question type id ! * @param int $quizid the quiz id ! * @return mixed false if no user options set for that type within the current quiz, ! * otherwise a server specific options string ! */ function quiz_rqp_get_quiz_options($quizid, $typeid) { if (!$quizOptions = get_record('quiz_rqp_quiz_options', 'quizid', $quizid, 'typeid', $typeid)) { *************** *** 81,85 **** } ! //For a specified course and RQP server type, retrieve the course options (part of the teacher options) function quiz_rqp_get_course_options($courseid, $typeid) { if (!$courseOptions = get_record('quiz_rqp_course_options', 'courseid', $courseid, 'typeid', $typeid)) { --- 99,111 ---- } ! /** ! * For a specified question type and course id, retrieve any options the teacher has set globally within ! * the current course. ! * ! * @param int $typeid the RQP question type id ! * @param int $courseid the course id ! * @return mixed false if no course options set for that type/course combination, ! * otherwise a server specific options string ! */ function quiz_rqp_get_course_options($courseid, $typeid) { if (!$courseOptions = get_record('quiz_rqp_course_options', 'courseid', $courseid, 'typeid', $typeid)) { *************** *** 90,98 **** } ! //For a specified course, quiz and RQP server type, retrieve the teachers options (quiz options, if they exist ! //override the course options ! //TODO: Some options manipulation here, as course options and quiz options under umbrella of 'teacher' options. ! //These options strings are RQP server specific, in STACK's case each option represented in as a value in an array ! //So this is the functionality atm function quiz_rqp_get_teacher_options($quizid, $courseid, $typeid) { --- 116,129 ---- } ! /** ! * For a specified question type and quiz and course id, retrieve any teacher options set ! * In this case quiz options override those set at the course level. ! * ! * @param int $typeid the RQP question type id ! * @param int $quizid the quiz id ! * @param int $courseid the course id ! * @return mixed false if no teahcer options set at either quiz/course level ! * otherwise a server specific options string ! */ function quiz_rqp_get_teacher_options($quizid, $courseid, $typeid) { *************** *** 103,108 **** } ! return $teacherOptions; //false if no quiz/course options found for RQP type ! //otherwise serialsied options string } --- 134,138 ---- } ! return $teacherOptions; } *************** *** 111,124 **** * optionType can be one of userOptions, teacherOptions, adminOptions */ function quiz_rqp_optionsDialog($optionType, $type="", $course="", $user="", $quiz="") { global $CFG; ! //Echo javascript to open an optionsDialog with specified parameters $jsOpenOptions = '<script language="javascript" type="text/javascript">'; $jsOpenOptions .= 'javascript:'; $jsOpenOptions .= "window.open('".s($CFG->wwwroot)."/mod/quiz/questiontypes/rqp/options.php?optionstype=$optionType&typeid=$type&courseid=$course&userid=$user&quizid=$quiz','optionspopup', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=1,scrollbars=yes')"; - $jsOpenOptions .= '</script>'; --- 141,167 ---- * optionType can be one of userOptions, teacherOptions, adminOptions */ + + /** + * Create an options popup dialog, passing the required parameters to the options.php script. + * + * Not all parameters are required for each 'optionType', i.e. if optionType=adminOptions, + * $type should only be set + * + * @param string $optionType one of 'userOptions','teacherOptions','adminOptions' + * @param int $type the RQP question type id + * @param int $course the course id + * @param int $user the user id + * @param int $quiz the quiz id + * @return void + */ function quiz_rqp_optionsDialog($optionType, $type="", $course="", $user="", $quiz="") { global $CFG; ! //Echo javascript to open an optionsDialog popup with specified parameters $jsOpenOptions = '<script language="javascript" type="text/javascript">'; $jsOpenOptions .= 'javascript:'; $jsOpenOptions .= "window.open('".s($CFG->wwwroot)."/mod/quiz/questiontypes/rqp/options.php?optionstype=$optionType&typeid=$type&courseid=$course&userid=$user&quizid=$quiz','optionspopup', 'left=20,top=20,width=500,height=500,toolbar=0,resizable=1,scrollbars=yes')"; $jsOpenOptions .= '</script>'; *************** *** 126,131 **** } ! //Get a list of RQP question types from the quiz_rqp_types table and return to calling function ! //Used in course/quiz level options, to set the options for a particular RQP question type function quiz_rqp_get_types() { --- 169,180 ---- } ! /** ! * Get a list of RQP question types from the quiz_rqp_types table and return these. This ! * representation of RQP question types is required for course/quiz level options drop down ! * box ! * ! * @param void ! * @return array $rqpQuestionTypes ! */ function quiz_rqp_get_types() { *************** *** 264,267 **** --- 313,322 ---- } + /** + * Prints a server information table to calling web form, based on the $serverInfo return parameters + * + * @param object $serverInfo return parameters from a server information call (also serverInfo db return params) + * @return void + */ function quiz_rqp_print_serverinfo($serverinfo) { $info->align = array('right', 'left'); *************** *** 273,281 **** } ! //Used in types.php to ensure that the server can be communicated to, before sending web service request function quiz_rqp_check_server($url, $serverid=0) { $timeLimit = 20; ! if ($serverid!=0) { $server = get_record('quiz_rqp_servers', 'id', $serverid); $urldata = parse_url($server->url); --- 328,346 ---- } ! /** ! * Ensures the specified server can be communicated to, before sending any web service requests. ! * ! * Accepts either an URL or the particular serverid, which can then be referenced to an URL. Attempt to open ! * a socket. To an unreachable host, this will fail. The '@' signs before fsockopen quieten the function. ! * ! * @param string $url The URL of the server to check communications with ! * @param int $serverid The id of the server to retrieve the URL for ! * @return bool True if a connection could be established, false otherwise ! */ function quiz_rqp_check_server($url, $serverid=0) { $timeLimit = 20; ! //$serverid=0 is EMPTY ! if (empty($serverid)) { $server = get_record('quiz_rqp_servers', 'id', $serverid); $urldata = parse_url($server->url); *************** *** 305,312 **** } } function quiz_rqp_initialise() { global $rqpTypes; ! //Go through each type and each server, adding [] -> [type] -> [serverid],[url] to $rqpType array if ($types = get_records('quiz_rqp_types')) { --- 370,388 ---- } } + + /** + * Manages a list of all RQP question types by manipulation of the $rqpTypes global array. + * + * Iterates through each question type, adding each server from the rqp_servers db within that type to an array. + * Enables us to prioritise particular servers of particular types. This is useful where a server is not + * responding, in which case, it moves to the bottom of the list of servers for that particular type. + * + * @param void + * @return void + */ function quiz_rqp_initialise() { global $rqpTypes; ! //Go through each type and each server, adding [type] -> [serverid] to $rqpType array if ($types = get_records('quiz_rqp_types')) { *************** *** 324,329 **** } ! //Will be called by the types.php function, if a server is added/removed ! //Check that this type exists within $rqpTypes, if not, add it and the new server function quiz_rqp_add_server($typeid, $serverid) { global $rqpTypes; --- 400,409 ---- } ! /** ! * Adds a server to the $rqpTypes global array, where the user has added one via the types.php web form. ! * ! * @param void ! * @return void ! */ function quiz_rqp_add_server($typeid, $serverid) { global $rqpTypes; *************** *** 332,340 **** } ! //This function called by types.php function if a server is removed ! //In this case, check if there are any other servers of a type, if not remove that type function quiz_rqp_remove_server($typeid, $serverid) { global $rqpTypes; if(array_key_exists($typeid, $rqpTypes)) { $servers = $rqpTypes[$typeid]; --- 412,429 ---- } ! /** ! * Removes a server from the $rqpTypes global array, where the user has requested to remove ! * via the types.php web form. ! * ! * Iterates through the $rqpTypes[$typeid] global array, removing the $serverid entry. ! * ! * @param int $typeid RQP question type id ! * @param int $serverid Server id ! * @return void ! */ function quiz_rqp_remove_server($typeid, $serverid) { global $rqpTypes; + //Check type exists if(array_key_exists($typeid, $rqpTypes)) { $servers = $rqpTypes[$typeid]; *************** *** 342,345 **** --- 431,435 ---- for ($i=0;$i<count($servers);$i++) { + //Match a server entry if($servers[$i]==$serverid) { //We have found our match, now remove it *************** *** 350,354 **** } ! //Count the nunber of $servers left if(count($servers)==0) { array_delete($rqpTypes, $typeid); --- 440,444 ---- } ! //Count the nunber of $servers left and remove the type if there are 0 if(count($servers)==0) { array_delete($rqpTypes, $typeid); *************** *** 362,366 **** } ! //Removes an item indexed by a $item key. Then re-orders function array_delete($array, $item) { if (isset($array[$item])) --- 452,464 ---- } ! /** ! * Removes an item from an array and then re-orders the array ! * ! * Iterates through the $rqpTypes[$typeid] global array, removing the $serverid entry. ! * ! * @param array $array Array of servers ! * @param string $item Server key to remove ! * @return array The re-ordered array. ! */ function array_delete($array, $item) { if (isset($array[$item])) *************** *** 368,375 **** return array_merge($array); - } ! //Responsible for initialising server list and keeping up to date, with servers that work the best up the top! function quiz_rqp_get_server($typeid) { global $rqpTypes; --- 466,479 ---- return array_merge($array); } ! /** ! * Retrieve a server of a particular question type to perform the render operation ! * ! * Initialises the $rqpTypes global array which stores a preferentially ordered list of servers and respective type ! * ! * @param int $typeid The type of server to get. ! * @return mixed A $server object, otherwise false if no servers could be communicated with ! */ function quiz_rqp_get_server($typeid) { global $rqpTypes; *************** *** 377,381 **** $timeLimit = 20; ! if (empty($rqpTypes)) { quiz_rqp_initialise(); } --- 481,485 ---- $timeLimit = 20; ! if (empty($rqpTypes)) { //First run, so initialise the $rqpTypes array quiz_rqp_initialise(); } *************** *** 393,397 **** $urldata['port']=80; } ! $sock = fsockopen($urldata['host'],$urldata['port'], $errno, $errmsg, $timeLimit); --- 497,502 ---- $urldata['port']=80; } ! ! //Check we can communicate with particular server $sock = fsockopen($urldata['host'],$urldata['port'], $errno, $errmsg, $timeLimit); *************** *** 410,414 **** } ! //No connection could be established, keep iterating else if (!$sock) { $server=false; --- 515,519 ---- } ! //No connection could be established, keep iterating through list of servers till one found else if (!$sock) { $server=false; *************** *** 430,485 **** return $server; //either false or an actual server! } - - - //Returns a server url given a specified type, by randomly selecting a server - //<TODO>Need to keep a single list of servers, possibly within session variable, check with Gustav - //takes rqpType as a global array - function quiz_rqp_get_server_old($typeid) { - global $rqpTypes; - - $timeLimit = 20; //default time limit before timeout for particular server - - //Initialise list of servers within $rqpTypes, which will be managed by this function - if (empty($rqpTypes)) { - quiz_rqp_initialise(); - } - - if (!$servers = get_records('quiz_rqp_servers', 'typeid', $typeid)) - { - return false; - } - - shuffle($servers); //put servers in a random order - - foreach ($servers as $server) { - //go through each of them and try to communicate with server till successful - $urldata = parse_url($server->url); - if(!array_key_exists('port', $urldata)) { - $urldata['port']=80; - } - - $sock = fsockopen($urldata['host'],$urldata['port'], $errno, $errmsg, $timeLimit); - - stream_set_timeout($sock, 2); - stream_set_blocking($sock, false); - - //If connection established - if ($sock) { - fclose($sock); - - //push this server up to the top of the new list - break; - } - - //No connection could be established - //Keep iterating - //<TODO> What do we do with this dead server - else if (!$sock) { - $server=false; - fclose($sock); - } - } - - return $server; //either false or an actual server! - } ?> --- 535,537 ---- |