/** * @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; }
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; }