Exemple #1
0
    # this allows guests to view webwork (signed in as user guest)
    #FIXME  -- replace this with a method that uses the automatic guest sign in on webwork.
    // 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}", "{$wwassignmentid}", _wwassignment_cmid());
/// 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);
Exemple #2
0
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;
}