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; }
$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") { $totalpoints = $wwclient->get_max_grade($wwcoursename, $wwsetname, false); $table->data[] = array($wwassignment->section, $link, $wwassignment->description, strftime("%c", $wwsetinfo['open_date']), strftime("%c", $wwsetinfo['due_date']), $totalpoints); } 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
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; }
/** * @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; }