/** * @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) { //error_log("updating instance".$wwassignment->id); //checking mappings $wwclient = new wwassignment_client(); $wwcoursename = _wwassignment_mapped_course($wwassignment->course, 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); _wwassignment_create_events($wwsetname, $wwassignment, $wwsetdata['open_date'], $wwsetdata['due_date']); return $returnid; }
function wwassignment_refresh_events($courseid = 0) { // error_log('wwassignment_refresh_events called --not yet defined'); global $DB; // 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 wwassignment event in the site is checked, else // only wwassignment events belonging to the course specified are checked. // This function is used, in its new format, by restore_refresh_events() and by the cron function // // find wwassignment instances associated with this course or all wwassignment modules $courses = array(); # create array of courses if ($courseid) { if (!($wwassignments = $DB->get_records("wwassignment", array("course" => $courseid)))) { return true; } else { $courses[$courseid] = array(); // collect wwassignments for this course array_push($courses[$courseid], $wwassignments); } } else { if (!($wwassignments = $DB->get_records("wwassignment"))) { return true; } else { foreach ($wwassignments as $ww) { // collect wwassignments for each course // error_log("course id ".$ww->course); if (!$courses[$ww->course]) { $courses[$ww->course] = array(); } array_push($courses[$ww->course], $ww); // push wwassignment onto an exisiting one } } } // $courses now holds a list of courses with wwassignment modules $moduleid = _wwassignment_cmid(); $cids = array_keys($courses); # collect course ids // error_log("cids".print_r($cids, true)); $wwclient = new wwassignment_client(); foreach ($cids as $cid) { // connect to WeBWorK $wwcoursename = _wwassignment_mapped_course($cid, false); $wwassignment->webwork_course = $wwcoursename; if ($wwcoursename == -1) { // error_log("Can't connect course $cid to webwork"); break; } // retrieve wwassignments associated with this course foreach ($courses[$cid] as $wwassignment) { //checking mappings $wwsetname = $wwassignment->webwork_set; // error_log("updating events for $wwcoursename $wwsetname"); //get data from WeBWorK $wwsetdata = $wwclient->get_assignment_data($wwcoursename, $wwsetname, false); $wwassignment->grade = $wwclient->get_max_grade($wwcoursename, $wwsetname, false); $wwassignment->timemodified = time(); $returnid = $DB->update_record('wwassignment', $wwassignment); // update event //this part won't work because these items implicitly require the course. _wwassignment_delete_events($wwassignment->id); _wwassignment_create_events($wwassignment, $wwsetdata); } } return true; }
function _wwassignment_refresh_event($wwassignment) { global $DB; $cid = $wwassignment->course; $wwcoursename = _wwassignment_mapped_course($cid, false); if ($wwcoursename == -1) { error_log("Can't connect course {$cid} to webwork"); return false; } $wwclient = new wwassignment_client(); $wwsetname = $wwassignment->webwork_set; error_log("updating events for {$wwcoursename} {$wwsetname}"); //get data from WeBWorK $wwsetdata = $wwclient->get_assignment_data($wwcoursename, $wwsetname, false); $wwassignment->grade = $wwclient->get_max_grade($wwcoursename, $wwsetname, false); $wwassignment->timemodified = time(); $returnid = $DB->update_record('wwassignment', $wwassignment); // update event _wwassignment_delete_events($wwassignment->id); _wwassignment_create_events($wwassignment, $wwsetdata); return true; }