From: Matt L. v. a. <we...@ma...> - 2007-09-24 22:51:43
|
Log Message: ----------- Major Code Refactoring Modified Files: -------------- wwmoodle/wwassignment3/moodle/mod/wwassignment: index.php lib.php locallib.php version.php view.php wwmoodle/wwassignment3/moodle/mod/wwassignment/db: install.xml wwmoodle/wwassignment3/moodle/mod/wwassignment/simpletest: testwwassignment.php Revision Data ------------- Index: version.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/version.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/version.php -Lwwassignment3/moodle/mod/wwassignment/version.php -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/version.php +++ wwassignment3/moodle/mod/wwassignment/version.php @@ -0,0 +1,11 @@ +<?php +// $Id$ +///////////////////////////////////////////////////////////////////////////////// +/// Code fragment to define the version of wwassignment +/// This fragment is called by moodle_needs_upgrading() and /admin/index.php +///////////////////////////////////////////////////////////////////////////////// + +$module->version = 2007092500; // The current module version (Date: YYYYMMDDXX) +$module->cron = 0; // Period for cron to check this module (secs) + +?> \ No newline at end of file Index: index.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/index.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/index.php -Lwwassignment3/moodle/mod/wwassignment/index.php -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/index.php +++ wwassignment3/moodle/mod/wwassignment/index.php @@ -0,0 +1,95 @@ +<?php +/** +* @desc This page lists all the instances of wwassignments within a particular course. +*/ + +require_once("../../config.php"); +require_once("locallib.php"); + +//get the course ID from GET line +$id = required_param('id', PARAM_INT); + +//check this course exists +if (!$course = get_record("course", "id", $id)) { + error("Course ID is incorrect"); +} + +//force login +require_login($course->id); +add_to_log($course->id, "wwassignment", "view all", "index.php?id=$course->id", ""); + +//Get all required strings +$strwwassignments = get_string("modulenameplural", "wwassignment"); +$strwwassignment = get_string("modulename", "wwassignment"); + +//Print the header +if ($course->category) { + $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> »"; +} +print_header("$course->shortname: $strwwassignments", "$course->fullname", "$navigation $strwwassignments", "", "", true, "", navmenu($course)); + +//Get all the appropriate data +if (!$wwassignments = get_all_instances_in_course("wwassignment", $course)) { + notice("There are no $strwwassignments", "../../course/view.php?id=$course->id"); + die; +} + +//Print the list of instances (your module will probably extend this) +$timenow = time(); +$strname = get_string("name"); +$strweek = get_string("week"); +$strtopic = get_string("topic"); +$strdescription = get_string('description'); +$stropendate = get_string("open_date", "wwassignment"); +$strduedate = get_string("due_date", "wwassignment"); + +if ($course->format == "weeks") { + $table->head = array ($strweek, $strname,$strdescription, $strOpenDate, $strDueDate); + $table->align = array ("center", "left", "left", "left", "left"); +} else if ($course->format == "topics") { + $table->head = array ($strtopic, $strname,$strdescription, $strOpenDate, $strDueDate); + $table->align = array ("center", "left", "left", "left", "left", "left", "left"); +} else { + $table->head = array ($strname,$strdescription, $strOpenDate, $strDueDate); + $table->align = array ("left", "left", "left", "left", "left", "left"); +} + +$wwclient = new wwassignment_client(); +$wwcoursename = _wwassignment_mapped_course($COURSE->id,false); + +foreach ($wwassignments as $wwassignment) { + // grab specific info for this set: + if(isset($wwassignment)) { + $wwsetname = $wwassignment->webwork_set; + $wwsetinfo = $wwclient->get_assignment_data($wwcoursename,$wwsetname,false); + + if (!$wwassignment->visible) { + //Show dimmed if the mod is hidden + $link = "<a class=\"dimmed\" href=\"view.php?id=$wwassignment->coursemodule\">$wwassignment->name</a>"; + } else { + //Show normal if the mod is visible + $link = "<a href=\"view.php?id=$wwassignment->coursemodule\">$wwassignment->name</a>"; + } + if ($course->format == "weeks" or $course->format == "topics") { + $table->data[] = array ($wwassignment->section, $link, $wwassignment->description, strftime("%c", $wwsetinfo['open_date']), strftime("%c", $wwsetinfo['due_date'])); + } else { + $table->data[] = array ($link, $wwassignment->description, strftime("%c", $wwsetinfo['open_date']), strftime("%c", $wwsetinfo['due_date'])); + } + } +} + +echo "<br />"; + +print_table($table); + +/*if( isteacher($course->id) ) { + $wwusername = $USER->username; + + $wwlink = _wwassignment_link_to_instructor_auto_login($wwcoursename,$wwusername,) + print("<p style='font-size: smaller; color: #aaa; text-align: center;'><a style='color: #666;text-decoration:underline' href='".WWASSIGNMENT_WEBWORK_URL."/$course->shortname/instructor' target='_webwork_edit'>".get_string("go_to_webwork", "wwassignment")."</a></p>"); +}*/ + +/// Finish the page +print_footer($course); + +?> Index: view.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/view.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/view.php -Lwwassignment3/moodle/mod/wwassignment/view.php -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/view.php +++ wwassignment3/moodle/mod/wwassignment/view.php @@ -0,0 +1,88 @@ +<?php +/** +* @desc Prints an actual wwassignment with an iframe to WeBWorK. +*/ + +require_once("../../config.php"); +require_once("lib.php"); + +$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or +$a = optional_param('a', 0, PARAM_INT); // NEWMODULE ID + +if($id) { + if (! $cm = get_record("course_modules", "id", $id)) { + error("Course Module ID was incorrect"); + } + + if (! $course = get_record("course", "id", $cm->course)) { + error("Course is misconfigured"); + } + if (! $wwassignment = get_record("wwassignment", "id", $cm->instance)) { + error("Course module is incorrect"); + } +} else { + + if (! $wwassignment = get_record("wwassignment", "id", $a)) { + error("Course module is incorrect"); + } + if (! $course = get_record("course", "id", $wwassignment->course)) { + error("Course is misconfigured"); + } + if (! $cm = get_coursemodule_from_instance("wwassignment", $wwassignment->id, $course->id)) { + error("Course Module ID was incorrect"); + } +} + +//catch the guests +global $USER; +if($USER->username == 'guest') { + print_error('Guests cannot view WeBWorK Problem Sets'); +} + +//force login +$courseid = $course->id; +$wwassignmentid = $wwassignment->id; +require_login($courseid); + +//webwork code +$wwcoursename = _wwassignment_mapped_course($courseid,false); +$wwusername = $USER->username; +$wwsetname = $wwassignment->webwork_set; +_wwassignment_mapcreate_user($wwcoursename,$wwusername); +_wwassignment_mapcreate_user_set($wwcoursename,$wwusername,$wwsetname); +$wwkey = _wwassignment_login_user($wwcoursename,$wwusername); +$wwsetlink = _wwassignment_link_to_set_auto_login($wwcoursename,$wwsetname,$wwusername,$wwkey); + +add_to_log($course->id, "wwassignment", "view", "view.php?id=$cm->id", "$wwassignment->id"); + +/// Print the page header + +if ($course->category) { + $navigation = "<a href=\"../../course/view.php?id=$course->id\">$course->shortname</a> ->"; +} + +$strwwassignments = get_string("modulenameplural", "wwassignment"); +$strwwassignment = get_string("modulename", "wwassignment"); + +print_header("$course->shortname: $wwassignment->name", "$course->fullname", "$navigation <a href='index.php?id=$course->id'>$strwwassignments</a> -> $wwassignment->name", "", "", true, update_module_button($cm->id, $course->id, $strwwassignment), navmenu($course, $cm)); +/// Print the main part of the page + + + +// Print webwork in iframe and link to escape to have webwork in a single window +print("<p style='font-size: smaller; color: #aaa;'>" . get_string("iframeNoShow-1", "wwassignment") + . "<a href='$wwsetlink'>" . get_string("iframeNoShow-2", "wwassignment") + ."</a><p align='center'></iframe></p>\n" + ); +print("<iframe id='wwPage' src='$wwsetlink' frameborder='1' " + . "width='".$CFG->wwassignment_iframewidth."' " + . "height='".$CFG->wwassignment_iframeheight."'>" + ); + +print("<script>ww.Init(".isteacher($course->id).")</script>"); + + +/// Finish the page +print_footer($course); + +?> Index: lib.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/lib.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/lib.php -Lwwassignment3/moodle/mod/wwassignment/lib.php -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/lib.php +++ wwassignment3/moodle/mod/wwassignment/lib.php @@ -0,0 +1,204 @@ +<?php + +//////////////////////////////////////////////////////////////// +//Functions that are called by the Moodle System +//////////////////////////////////////////////////////////////// + +/** +* @desc Called when the module is installed into the Moodle System +*/ +function wwassignment_install() { +} + +/** +* @desc Creates a new Moodle assignment <-> Webwork problem set tie. +* @param $wwassignment object The data of the record to be entered in the DB. +* @return integer The ID of the new record. +*/ +function wwassignment_add_instance($wwassignment) { + global $COURSE; + + //Get data about the set from WebWorK + $wwclient = new wwassignment_client(); + $wwcoursename = _wwassignment_mapped_course($COURSE->id,false); + $wwsetname = $wwassignment->webwork_set; + $wwsetdata = $wwclient->get_assignment_data($wwcoursename,$wwsetname,false); + + //Attaching Moodle Set to WeBWorK Set + $returnid = insert_record('wwassignment',$wwassignment); + + //Creating events + _wwassignment_create_events($wwsetname,$wwassignment->id,$wwsetdata['open_date'],$wwsetdata['due_date']); + + return $returnid; +} + +/** +* @desc Updates and resynchronizes all information related to the a moodle assignment <-> webwork problem set tie. +* @param $wwassignment object The data of the record to be updated in the DB. +* @return integer The result of the update_record function. +*/ +function wwassignment_update_instance($wwassignment) { + global $COURSE; + + //checking mappings + $wwclient = new wwassignment_client(); + $wwcoursename = _wwassignment_mapped_course($COURSE->id,false); + $wwsetname = $wwassignment->webwork_set; + + //get data from WeBWorK + $wwsetdata = $wwclient->get_assignment_data($wwcoursename,$wwsetname,false); + $wwassignment->id = $wwassignment->instance; + + $returnid = update_record('wwassignment',$wwassignment); + + _wwassignment_delete_events($wwassignment->id); + _wwassignment_create_events($wwsetname,$wwassignment->id,$wwsetdata['open_date'],$wwsetdata['due_date']); + + return $returnid; +} + +/** +* @desc Deletes a tie in Moodle. Deletes nothing in webwork. +* @param integer $wwassignmentid The id of the assignment to delete. +* @return bool Delete was successful or not. +*/ +function wwassignment_delete_instance($wwassignmentid) { + + $result = true; + + #delete DB record + if (!delete_records('wwassignment', 'id',$wwassignmentid)) { + $result = false; + } + + #delete events + _wwassignment_delete_events($wwassignmentid); + + // Get the cm id to properly clean up the grade_items for this assignment + // bug 4976 + if (! $cm = get_record('modules', 'name', 'wwassignment')) { + $result = false; + } else { + if (! delete_records('grade_item', 'modid', $cm->id, 'cminstance', $wwassignment->id)) { + $result = false; + } + } + return $result; +} + +/** +* @desc Contacts webwork to find out the completion status of a problem set for all users in a course. +* @param integer $wwassignmentid The problem set +* @return object The student grades indexed by student ID. +*/ +function wwassignment_grades($wwassignmentid) { + global $COURSE; + $wwclient = new wwassignment_client(); + + $studentgrades = new stdClass; + $studentgrades->grades = array(); + $studentgrades->maxgrade = 0; + + $gradeformula = '$finalgrade += ($problem->status > 0) ? 1 : 0;'; + + $wwcoursename = _wwassignment_mapped_course($COURSE->id,false); + $wwsetname = _wwassignment_mapped_set($wwassignmentid,false); + + // enumerate over the students in the course: + $students = get_course_students($COURSE->id); + + $usernamearray = array(); + foreach($students as $student) { + array_push($usernamearray,$student->username); + } + $gradearray = $wwclient->grade_users_sets($wwcoursename,$usernamearray,$wwsetname); + $i = 0; + foreach($students as $student) { + $studentgrades->grades[$student->id] = $gradearray[$i]; + $i++; + } + $studentgrades->maxgrade = $wwclient->get_max_grade($wwcoursename,$wwsetname); + return $studentgrades; +} + + +/** +* @desc Returns a small object with summary information about a wwassignment instance. Used for user activity repots. +* @param string $course The ID of the course. +* @param string $user The ID of the user. +* @param string $wwassignment The ID of the wwassignment instance. +* @return array Representing time, info pairing. +*/ +function wwassignment_user_outline($course, $user, $mod, $wwassignment) { + $aLogs = get_logs("l.userid=$user AND l.course=$course AND l.cmid={$wwassignment->id}"); + if( count($aLogs) > 0 ) { + $return->time = $aLogs[0]->time; + $return->info = $aLogs[0]->info; + } + return $return; +} + +/** +* @desc Prints a detailed representation of what a user has done with a instance of this module. +* @param string $course The ID of the course. +* @param string $user The ID of the user. +* @param string $wwassignment The ID of the wwassignment instance. +* @return array Representing time, info pairing. +*/ +function wwassignment_user_complete($course, $user, $mod, $wwassignment) { + return true; +} + + + +function wwassignment_delete_course() { +} + +function wwassignment_process_options() { +} + +function wwassignment_reset_course_form() { +} + +function wwassignment_delete_userdata() { + +} + +/** +* @desc Finds recent activity that has occured in wwassignment activities. +*/ +function wwassignment_print_recent_activity($course, $isteacher, $timestart) { + global $CFG; + return false; // True if anything was printed, otherwise false +} + +/** +* @desc Function that is run by the cron job. This makes sure that all data is pushed to webwork. +*/ +function wwassignment_cron() { + //FIXME: Add a call that updates all events with dates (in case people forgot to push) + return true; +} + + + +/** +* @desc Finds all the participants in the course +* @param string $wwassignmentid The Moodle wwassignment ID. +* @return array An array of course users (IDs). +*/ +/*function wwassignment_get_participants($wwassignmentid) { + $wwassignment = get_record('wwassignment', 'id', $wwassignmentid); + if(!isset($wwassignment)) { + return array(); + } + return get_course_users($wwassignment->course); +} + +function wwassignment_refresh_events($courseid = 0) { + error_log('wwassignment_refresh_events called'); + return true; +}*/ + +?> \ No newline at end of file Index: locallib.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/locallib.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/locallib.php -Lwwassignment3/moodle/mod/wwassignment/locallib.php -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/locallib.php +++ wwassignment3/moodle/mod/wwassignment/locallib.php @@ -0,0 +1,502 @@ +<?php + +require_once("$CFG->libdir/soap/nusoap.php"); + +////////////////////////////////////////////////////////////////// +//EVENT CREATION AND DELETION +////////////////////////////////////////////////////////////////// + +/** +* @desc Creates the corresponding events for a wwassignment. +* @param $wwsetname string The name of the set. +* @param $wwassignmentid string The ID of the wwassignment record. +* @param $opendate integer The UNIX timestamp of the open date. +* @param $duedate integer The UNIX timestamp of the due date. +* @return integer 0 on success. -1 on error. +*/ +function _wwassignment_create_events($wwsetname,$wwassignmentid,$opendate,$duedate) { + unset($event); + $event->name = $wwsetname; + $openevent->description = ''; + $event->courseid = $COURSE->id; + $event->groupid = 0; + $event->userid = 0; + $event->modulename = 'wwassignment'; + $event->instance = $wwassignmentid; + + $openevent = $event; + $dueevent = $event; + + $openevent->name .= ' is Open.'; + $openevent->eventtype = 'open'; + $openevent->timestart = $opendate; + $openevent->timeduration = $duedate - $opendate; + + $dueevent->name .= ' is Due.'; + $dueevent->eventtype = 'due'; + $dueevent->timestart = $duedate; + $dueevent->timeduration = 1; + + $result = 0; + if(!add_event($openevent)) { + $result = -1; + } + if(!add_event($dueevent)) { + $result = -1; + } + return $result; +} + + +/** +* @desc Deletes all events relating to the wwassignment passed in. +* @param $wwassignmentid integer The wwassignment ID. +* @return integer 0 on success +*/ +function _wwassignment_delete_events($wwassignmentid) { + if ($events = get_records_select('event', "modulename = 'wwassignment' and instance = '$wwassignmentid'")) { + foreach($events as $event) { + delete_event($event->id); + } + } + return 0; +} + +////////////////////////////////////////////////////////////////// +//Functions that ensure creation of WeBWorK Data +////////////////////////////////////////////////////////////////// + +/** +* @desc Checks whether a user exists in a WW course. If it doesnt creates the user using the currently logged in one. +* @param $wwcoursename string The WW course. +* @param $username string The username to check. +* @param $permission string The permission the user needs if created. +* @return string the new username. +*/ +function _wwassignment_mapcreate_user($wwcoursename,$username,$permission = '0') { + $wwclient = new wwassignment_client(); + $exists = $wwclient->mapped_user($wwcoursename,$username); + if($exists == -1) { + global $USER; + $tempuser = $USER; + $newusername = $wwclient->create_user($wwcoursename,$tempuser,$permission); + return $newusername; + } + return $username; +} + +/** +* @desc Checks whether a set exists for a user in a WW course. If it doesnt autocreates. +* @param $wwcoursename string The WW course. +* @param $wwusername string The WW user. +* @param $wwsetname string The WW set. +* @return integer 0. +*/ +function _wwassignment_mapcreate_user_set($wwcoursename,$wwusername,$wwsetname) { + $wwclient = new wwassignment_client(); + $exists = $wwclient->mapped_user_set($wwcoursename,$wwusername,$wwsetname); + if($exists == -1) { + $wwclient->create_user_set($wwcoursename,$wwusername,$wwsetname); + } + return 0; +} + +/** +* @desc Makes sure that a user is logged in to WW. +* @param $wwcoursename string The course to login to. +* @param $wwusername string The user to login. +* @return string The users key for WW. +*/ +function _wwassignment_login_user($wwcoursename,$wwusername) { + $wwclient = new wwassignment_client(); + return $wwclient->login_user($wwcoursename,$wwusername,false); +} + +//////////////////////////////////////////////////////////////// +//functions that check mapping existance in the local db +//////////////////////////////////////////////////////////////// + +/** +* @desc Finds the webwork course name from a moodle course id. +* @param integer $courseid Moodle Course ID. +* @param integer $silent whether to trigger an error message. +* @return string the name of the webwork course on success and -1 on failure. +*/ +function _wwassignment_mapped_course($courseid,$silent = true) { + $wwassignmentbridge = get_record('wwassignment_bridge','course', $courseid); + if((isset($wwassignmentbridge)) && (isset($wwassignmentbridge->webwork_course))) { + return $wwassignmentbridge->webwork_course; + } + if(!$silent) { + print_error(get_string('webwork_course_map_failure','wwassignment')); + } + return -1; +} + +/** +* @desc Finds the webwork set name from a wwassignment id. +* @param integer $wwassignmentid Moodle wwassignment ID. +* @param integer $silent whether to trigger an error message. +* @return string the name of the webwork set on success and -1 on failure. +*/ +function _wwassignment_mapped_set($wwassignmentid,$silent = true) { + $wwassignment = get_record('wwassignment','id',$wwassignmentid); + if((isset($wwassignment)) && (isset($wwassignment->webwork_set))) { + return $wwassignment->webwork_set; + } + if(!$silent) { + print_error(get_string('webwork_set_map_failure','wwassignment')); + } + return -1; +} + +//////////////////////////////////////////////////////////////// +//functions that create links to the webwork site. +//////////////////////////////////////////////////////////////// + +/** +* @desc Returns URL link to a webwork course logging the user in. +* @param string $webworkcourse The webwork course. +* @param string $webworkset The webwork set. +* @param string $webworkuser The webwork user. +* @param string $key The key used to login the user. +* @return URL. +*/ +function _wwassignment_link_to_edit_set_auto_login($webworkcourse,$webworkset,$username,$key) { + return _wwassignment_link_to_course($webworkcourse) . "instructor/sets/$webworkset/?effectiveUser=$username&user=$username&key=$key"; +} + + +/** +* @desc Returns URL link to a webwork course logging the user in. +* @param string $webworkcourse The webwork course. +* @param string $webworkuser The webwork user. +* @param string $key The key used to login the user. +* @return URL. +*/ +function _wwassignment_link_to_instructor_auto_login($webworkcourse,$username,$key) { + return _wwassignment_link_to_course($webworkcourse) . "instructor/?effectiveUser=$username&user=$username&key=$key"; +} + +/** +* @desc Returns the URL link to a webwork course and a particular set logged in. +* @param string $webworkcourse The webwork course. +* @param string $webworkset The webwork set. +* @param string $webworkuser The webwork user. +* @param string $key The key used to login the user. +* @return URL. +*/ +function _wwassignment_link_to_set_auto_login($webworkcourse,$webworkset,$webworkuser,$key) { + return _wwassignment_link_to_set($webworkcourse,$webworkset) . "?effectiveUser=$webworkuser&user=$webworkuser&key=$key"; +} + +/** +* @desc Returns the URL link to a webwork course and a particular set. +* @param string $webworkcourse The webwork course. +* @param string $webworkset The webwork set. +* @return URL. +*/ +function _wwassignment_link_to_set($webworkcourse,$webworkset) { + return _wwassignment_link_to_course($webworkcourse) . "$webworkset/"; +} + +/** +* @desc Returns the URL link to a webwork course. +* @param string $webworkcourse The webwork course. +* @return URL. +*/ +function _wwassignment_link_to_course($webworkcourse) { + return WWASSIGNMENT_WEBWORK_URL."/$webworkcourse/"; +} + + +/////////////////////////////////////////////////////////////// +//wwassignment client class +/////////////////////////////////////////////////////////////// + +/** +* @desc This singleton class acts as the gateway for all communication from the Moodle Client to the WeBWorK SOAP Server. It encapsulates an instance of a SoapClient. +*/ +class wwassignment_client { + var $client; + var $defaultparams; + var $datacache; + var $mappingcache; + /** + * @desc Constructs a singleton webwork_client. + */ + function wwassignment_client() + { + // static associative array containing the real objects, key is classname + static $instances=array(); + // get classname + $class = get_class($this); + if (!array_key_exists($class, $instances)) { + // does not yet exist, save in array + $this->client = new soap_client(WWASSIGNMENT_WEBWORK_WSDL,'wsdl'); + $err = $this->client->getError(); + if ($err) { + print_error(get_string('construction_error','wwassignment')."<BR>$err"); + } + $this->defaultparams = array(); + $this->defaultparams['authenKey'] = WWASSIGNMENT_WEBWORK_KEY; + $this->datacache = array(); + $this->mappingcache = array(); + $instances[$class] = $this; + + } + foreach (get_class_vars($class) as $var => $value) { + $this->$var =& $instances[$class]->$var; + } + } + /** + *@desc Calls a SOAP function and passes (authenkey,course) automatically in the parameter list. + *@param string $functioncall The function to call + *@param array $params The parameters to the function. + *@param integer $override=false whether to override the default parameters that are passed to the soap function (authenKey). + *@return Result of the soap function. + */ + function handler($functioncall,$params=array(),$override=false) { + if(!is_array($params)) { + $params = array($params); + } + if(!$override) { + $params = array_merge($this->defaultparams,$params); + } + $result = $this->client->call($functioncall,$params); + //$result = call_user_func_array(array(&$this->client,$functioncall),$params); + if($err = $this->client->getError()) { + //print_error(get_string("rpc_fault","wwassignment') . " " . $functioncall. " ". $err); + print_error(get_string('rpc_error','wwassignment')."<BR>$err<BR><BR>Response:<BR>".$this->client->response ); + } + return $result; + } + + /** + * @desc Checks whether a user is in a webwork course. + * @param string $webworkcourse The webwork course name. + * @param string $webworkuser The webwork user name. + * @param integer $silent whether to trigger an error message + * @return string Returns the webwork user on success and -1 on failure. + */ + function mapped_user($webworkcourse,$webworkuser,$silent = true) { + if(isset($this->mappingcache[$webworkcourse]['user'][$webworkuser])) { + return $this->mappingcache[$webworkcourse]['user'][$webworkuser]; + } + $record = $this->handler('get_user',array('courseName' => $webworkcourse,'userID' => $webworkuser)); + if($record != -1) { + $this->mappingcache[$webworkcourse]['user'][$webworkuser] = $webworkuser; + return $webworkuser; + } + if(!$silent) { + print_error(get_string('webwork_user_map_failure',"wwassignment")); + } + return -1; + } + + /** + * @desc Checks whether a user has his own copy of a set built in a webwork course. + * @param string $webworkcourse The webwork course name. + * @param string $webworkuser The webwork user name. + * @param string $webworkset The webwork set name. + * @param integer $silent whether to trigger an error message + * @return integer Returns 1 on success and -1 on failure. + */ + function mapped_user_set($webworkcourse,$webworkuser,$webworkset,$silent = true) { + if(isset($this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset])) { + return $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset]; + } + $record = $this->handler('get_user_set',array('courseName' => $webworkcourse,'userID' => $webworkuser,'setID' => $webworkset)); + if($record != -1) { + $this->mappingcache[$webworkcourse]['user_set'][$webworkuser][$webworkset] = 1; + return 1; + } + + if(!$silent) { + print_error(get_string('webwork_user_set_map_failure','wwassignment')); + } + return -1; + } + + /** + * @desc Gets the record of the global set for a webwork course and set name. + * @param string $webworkcourse The webwork course name. + * @param string $webworkset The webwork set name. + * @param integer $silent whether to trigger an error message + * @return array Returns set information on success or -1 on failure. + */ + function get_assignment_data($webworkcourse,$webworkset,$silent = true) { + $record = $this->handler('get_global_set',array('courseName' => $webworkcourse, 'setID' => $webworkset)); + if(isset($record)) { + $setinfo = array(); + $setinfo['open_date'] = $record['open_date']; + $setinfo['due_date'] = $record['due_date']; + $setinfo['set_id'] = $record['set_id']; + $setinfo['name'] = $record['set_id']; + return $setinfo; + } + if(!$silent) { + print_error(get_string('webwork_set_map_failure','wwassignment')); + } + return -1; + + } + + /** + * @desc Gets all the user problems for a specfic course, user and set. + * @param string $webworkcourse The webwork course name. + * @param string $webworkuser The webwork users name. + * @param string $webworkset The webwork set name. + * @param integer $silent whether to trigger an error message + * @return array Returns an array of problems on success or -1 on failure. + */ + function get_user_problems($webworkcourse,$webworkuser,$webworkset,$silent = true) { + $record = $this->handler('get_all_user_problems',array('courseName' => $webworkcourse,'userID' => $webworkuser,'setID' => $webworkset)); + if(isset($record)) { + return $record; + } + if(!$silent) { + print_error(get_string('webwork_user_set_map_failure','wwassignment')); + } + return -1; + } + + /** + * @desc Calculates the max grade on a set by counting the number of problems in the set. + * @param string $webworkcourse The webwork course name. + * @param string $webworkset The webwork set name. + * @param integer $silent whether to trigger an error message + * @return integer The max grade on success or -1 on failure. + */ + function get_max_grade($webworkcourse,$webworkset,$silent = true) { + $record = $this->handler('list_global_problems',array('courseName' => $webworkcourse,'setID' => $webworkset)); + if(isset($record)) { + return count($record); + } + if(!$silent) { + print_error(get_string('webwork_set_map_failure','wwassignment')); + } + return -1; + + } + /** + * @desc Forces a login of a user into a course. + * @param string $webworkcourse The webwork course name. + * @param string $webworkuser The webwork users name. + * @param integer $silent whether to trigger an error message + * @return string The webwork key for URL on success or -1 on failure. + */ + function login_user($webworkcourse,$webworkuser,$silent = true) { + $key = $this->handler('login_user',array('courseName' => $webworkcourse,'userID' => $webworkuser)); + if(isset($key)) { + return $key; + } + if(!$silent) { + print_error(get_string('webwork_user_map_failure','wwassignment')); + } + return -1; + } + + /** + * @desc Retrieves a list of sets from a webwork course and converts it into form options format. + * @param string $webworkcourse The webwork course name. + * @param integer $silent whether to trigger an error message + * @return array The form options. + */ + function options_set($webworkcourse,$silent = true) { + $setlist = $this->handler('list_global_sets',array('courseName' => $webworkcourse)); + if(isset($setlist)) { + $setoptions = array(); + foreach($setlist as $setid) { + + $setoptions[$setid] = $setid; + } + return $setoptions; + } + if(!$silent) { + print_error(get_string('webwork_course_map_failure','wwassignment')); + } + return -1; + } + + /** + * @desc Retrieves a list of courses from a webwork course and converts it into form options format. + * @param integer $silent whether to trigger an error message + * @return array The form options. + */ + function options_course($silent = true) { + $courselist = $this->handler('list_courses'); + sort($courselist); + if(isset($courselist)) { + $courseoptions = array(); + foreach($courselist as $course) { + $courseoptions[$course] = $course; + } + return $courseoptions; + } + if(!$silent) { + print_error(get_string('webwork_course_list_map_failure','wwassignment')); + } + return -1; + + } + + /** + * @desc Creates a user in the WeBWorK course. + * @param string $webworkcourse The webwork course name. + * @param array $userdata The user data to use in creation. + * @param string $permission The permissions of the new user, defaults to 0. + * @return Returns 1 on success. + */ + function create_user($webworkcourse,&$userdata,$permission='0') { + $studentid = $userid; + # FIXME: find permission for this user and set permissions appropriately in webwork + # FIXME: find the group(s) that this person is a member of + # FIXME: I have used the following scheme: gage_SEC use groups ending like this to determine sections in webwork + # FIXME: use ordinary groups taName to correspond to recitation sections in WeBWorK + # + # FIXME: make it so an update_user function is called whenever the user data in moodle is changed + # FIXME: so if a student switches groups this is reflected in WeBWorK + $this->handler('add_user',array('courseName' => $webworkcourse, 'record' => array( + 'user_id' => $userdata->username, + 'first_name' => $userdata->firstname, + 'last_name' => $userdata->lastname, + 'email_address' => $userdata->email, + 'student_id' => $studentid, + 'status' => 'C', + 'section' => '', + 'recitation' => '', + 'comment' => 'moodle created user'))); + $this->handler('add_permission',array('courseName' => $webworkcourse,'record' => array( + 'user_id' => $userdata->username, + 'permission' => $permission))); + $this->handler('add_password',array('courseName' => $webworkcourse,'record' => array( + 'user_id' => $userdata->username, + 'password' => $userdata->password))); + return 1; + } + + /** + * @desc Creates a user set in WeBWorK + * @param string $webworkcourse The webwork course name. + * @param string $webworkuser The webwork user name. + * @param string $webworkset The webwork set name. + * @return Returns 1 on success. + */ + function create_user_set($webworkcourse,$webworkuser,$webworkset) { + $this->handler('assign_set_to_user',array('courseName' => $webworkcourse,'userID' => $webworkuser, 'setID' => $webworkset)); + return 1; + } + + /** + * @desc Finds grades of many users for one set. + * @param string $webworkcourse The webwork course name. + * @param array $webworkusers A list of webwork users + * @param string $webworkset The webwork set name + * @return array Returns an array of grades + */ + function grade_users_sets($webworkcourse,$webworkusers,$webworkset) { + return $this->handler('grade_users_sets',array('courseName' => $webworkcourse, 'userIDs' => $webworkusers, 'setID' => $webworkset)); + } +}; +?> \ No newline at end of file Index: install.xml =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/db/install.xml,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/db/install.xml -Lwwassignment3/moodle/mod/wwassignment/db/install.xml -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/db/install.xml +++ wwassignment3/moodle/mod/wwassignment/db/install.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8" ?> +<XMLDB PATH="mod/wwassignment/db" VERSION="20070620" COMMENT="XMLDB file for Moodle mod/wwassignment" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"> + <TABLES> + <TABLE NAME="wwassignment" COMMENT="" NEXT="wwassignment_bridge"> + <FIELDS> + <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/> + <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="name"/> + <FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="course" NEXT="description"/> + <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="webwork_set"/> + <FIELD NAME="webwork_set" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" DEFAULT="undefined" PREVIOUS="description"/> + + </FIELDS> + <KEYS> + <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for data"/> + </KEYS> + </TABLE> + <TABLE NAME="wwassignment_bridge" COMMENT="" PREVIOUS="wwassignment"> + <FIELDS> + <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="course"/> + <FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="webwork_course"/> + + <FIELD NAME="webwork_course" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="course"/> + </FIELDS> + <KEYS> + <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for data"/> + </KEYS> + </TABLE> + </TABLES> + <STATEMENTS> + </STATEMENTS> + +</XMLDB> \ No newline at end of file Index: testwwassignment.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/simpletest/testwwassignment.php,v retrieving revision 1.1 retrieving revision 1.2 diff -Lwwassignment3/moodle/mod/wwassignment/simpletest/testwwassignment.php -Lwwassignment3/moodle/mod/wwassignment/simpletest/testwwassignment.php -u -r1.1 -r1.2 --- wwassignment3/moodle/mod/wwassignment/simpletest/testwwassignment.php +++ wwassignment3/moodle/mod/wwassignment/simpletest/testwwassignment.php @@ -0,0 +1,48 @@ +<?php +require_once(dirname(__FILE__) . '/../../config.php'); + +global $CFG; + +require_once($CFG->libdir . '/simpletestlib.php'); +require_once($CFG->dirroot . '/mod/wwassignment/locallib.php'); + +class wwassignment_test extends UnitTestCase { + + function setUp() { + } + + function tearDown() { + } + + /** + * @desc Test Module Name. + */ + function test_name() { + $this->assertEqual($this->qtype->name(),'webwork','Module Test'); + } + + /** + * @desc Test WSDL Path is set. + */ + function test_wsdl_path() { + $this->assertNotEqual(WWQUESTION_WSDL,'ENTER YOUR WSDL PATH HERE','WSDL Path Test'); + } + + /** + * @desc Test Webwork Path + */ + function test_webwork_path() { + } + + /** + * @desc Test Basic Communication + */ + function test_basic_communication() { + $client = new wwassignment_client(); + $response = $client->handler('hello'); + $this->assertEqual('hello world!',$response,'Webwork Server Communication Test.'); + } +} + +?> + |