From: Mike G. v. a. <we...@ma...> - 2008-01-24 04:03:45
|
Log Message: ----------- Fixed posting of events to calendar. For now only due date is posted -- that is probably all that is needed Calendar is not updated until something triggers wwassign's update subroutine The cron job will trigger this if nothing else does. Currently webwork cannot trigger the update directly. Modified Files: -------------- wwmoodle/wwassignment3/moodle/mod/wwassignment: lib.php locallib.php Revision Data ------------- Index: lib.php =================================================================== RCS file: /webwork/cvs/system/wwmoodle/wwassignment3/moodle/mod/wwassignment/lib.php,v retrieving revision 1.2 retrieving revision 1.3 diff -Lwwassignment3/moodle/mod/wwassignment/lib.php -Lwwassignment3/moodle/mod/wwassignment/lib.php -u -r1.2 -r1.3 --- wwassignment3/moodle/mod/wwassignment/lib.php +++ wwassignment3/moodle/mod/wwassignment/lib.php @@ -1,5 +1,7 @@ <?php +require_once("locallib.php"); + //////////////////////////////////////////////////////////////// //Functions that are called by the Moodle System //////////////////////////////////////////////////////////////// @@ -28,7 +30,7 @@ $returnid = insert_record('wwassignment',$wwassignment); //Creating events - _wwassignment_create_events($wwsetname,$wwassignment->id,$wwsetdata['open_date'],$wwsetdata['due_date']); + _wwassignment_create_events($wwsetname,$wwassignment,$wwsetdata['open_date'],$wwsetdata['due_date']); return $returnid; } @@ -39,11 +41,10 @@ * @return integer The result of the update_record function. */ function wwassignment_update_instance($wwassignment) { - global $COURSE; - + //error_log("updating instance".$wwassignment->id); //checking mappings $wwclient = new wwassignment_client(); - $wwcoursename = _wwassignment_mapped_course($COURSE->id,false); + $wwcoursename = _wwassignment_mapped_course($wwassignment->course,false); $wwsetname = $wwassignment->webwork_set; //get data from WeBWorK @@ -52,8 +53,8 @@ $returnid = update_record('wwassignment',$wwassignment); - _wwassignment_delete_events($wwassignment->id); - _wwassignment_create_events($wwsetname,$wwassignment->id,$wwsetdata['open_date'],$wwsetdata['due_date']); + _wwassignment_delete_events($wwassignment); + _wwassignment_create_events($wwsetname,$wwassignment,$wwsetdata['open_date'],$wwsetdata['due_date']); return $returnid; } @@ -177,10 +178,46 @@ * @desc Function that is run by the cron job. This makes sure that all data is pushed to webwork. */ function wwassignment_cron() { + // refresh wwassignment events in all courses. + wwassignment_refresh_events(); + //error_log("cron: update instance has been called"); //FIXME: Add a call that updates all events with dates (in case people forgot to push) return true; } +/** + * Make sure up-to-date events are created for all assignment instances + * + * This standard function will check all instances of this module + * and make sure there are up-to-date events created for each of them. + * If courseid = 0, then every assignment event in the site is checked, else + * only assignment events belonging to the course specified are checked. + * This function is used, in its new format, by restore_refresh_events() + * + * @param $courseid int optional If zero then all assignments for all courses are covered + * @return boolean Always returns true + */ + +function wwassignment_refresh_events($courseid = 0) { + + if ($courseid == 0) { + if (! $wwassignments = get_records("wwassignment")) { + return true; + } + } else { + if (! $wwassignments = get_records("wwassignment", "course", $courseid)) { + return true; + } + } + $moduleid = get_field('modules', 'id', 'name', 'wwassignment'); + //error_log("assignments ". count($wwassignments)); + foreach($wwassignments as $key => $wwassignment) { + //error_log("updating events for ".$wwassignment->id); + wwassignment_update_instance($wwassignment); + + } + return true; +} /** @@ -188,17 +225,14 @@ * @param string $wwassignmentid The Moodle wwassignment ID. * @return array An array of course users (IDs). */ -/*function wwassignment_get_participants($wwassignmentid) { +/* +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.4 retrieving revision 1.5 diff -Lwwassignment3/moodle/mod/wwassignment/locallib.php -Lwwassignment3/moodle/mod/wwassignment/locallib.php -u -r1.4 -r1.5 --- wwassignment3/moodle/mod/wwassignment/locallib.php +++ wwassignment3/moodle/mod/wwassignment/locallib.php @@ -2,7 +2,7 @@ require_once("$CFG->libdir/soap/nusoap.php"); -define(WWASSIGNMENT_DEBUG,0); +DEFINE('WWASSIGNMENT_DEBUG',0); ////////////////////////////////////////////////////////////////// //EVENT CREATION AND DELETION @@ -16,37 +16,39 @@ * @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) { +function _wwassignment_create_events($wwsetname,$wwassignment,$opendate,$duedate) { global $COURSE; unset($event); $event->name = $wwsetname; $event->description = 'WeBWorK Set Event'; - $event->courseid = $COURSE->id; + $event->courseid = $wwassignment->course; $event->groupid = 0; $event->userid = 0; $event->format = 1; $event->modulename = 'wwassignment'; - $event->instance = $wwassignmentid; + $event->instance = $wwassignment->id; $event->visible = 1; - $openevent = $event; + // FIXME -- this doesn't create a new object we'll just handle the due date for now + // what you want is $openevent = clone $event this makes a shallow copy of the object + //$openevent = $event; + // FIXME -- it's likely that only the due date needs to be posted. once that is sure, clean this up. $dueevent = $event; - $openevent->name .= ' is Open.'; - $openevent->eventtype = 'open'; - $openevent->timestart = $opendate; - $openevent->timeduration = $duedate - $opendate; + //$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; - - + // error_log("adding a due event"); $result = 0; - if(!add_event($openevent)) { - $result = -1; - } + //if(!add_event($openevent)) { + // $result = -1; + //} if(!add_event($dueevent)) { $result = -1; } @@ -59,9 +61,11 @@ * @param $wwassignmentid integer The wwassignment ID. * @return integer 0 on success */ -function _wwassignment_delete_events($wwassignmentid) { +function _wwassignment_delete_events($wwassignment) { + $wwassignmentid = $wwassignment->id; if ($events = get_records_select('event', "modulename = 'wwassignment' and instance = '$wwassignmentid'")) { foreach($events as $event) { + // error_log("deleting event ".$event->id); delete_event($event->id); } } @@ -492,7 +496,41 @@ 'password' => $userdata->password))); return 1; } - + /** NOT yet ready!!!!!!!!! + * @desc Updates data for 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 update_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 + # do get_user first to get current status then update this?? + $this->handler('put_user',array('courseName' => $webworkcourse, 'record' => array( + //'user_id' => $userdata->username, // can't update this + 'first_name' => $userdata->firstname, + 'last_name' => $userdata->lastname, + 'email_address' => $userdata->email, + 'student_id' => $studentid, + //'status' => 'C', //can you update this from moodle? + 'section' => '', + 'recitation' => '', + 'comment' => 'moodle updated 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. |