Example #1
0
 function definition()
 {
     global $COURSE, $USER, $OUTPUT;
     $mform =& $this->_form;
     //Is this particular course mapped to a course in WeBWorK
     $wwclient = new wwassignment_client();
     $wwcoursename = _wwassignment_mapped_course($COURSE->id, false);
     $wwsetname = _wwassignment_mapped_set($this->_instance);
     $wwusername = $USER->username;
     //create the instructor if necessary
     $wwusername = _wwassignment_mapcreate_user($wwcoursename, $wwusername, '10');
     //login the instructor
     $wwkey = _wwassignment_login_user($wwcoursename, $wwusername);
     $wwinstructorlink = _wwassignment_link_to_instructor_auto_login($wwcoursename, $wwusername, $wwkey);
     $mform->addElement('link', 'instructor_page_link', get_string('instructor_page_link_desc', 'wwassignment'), $wwinstructorlink, get_string('instructor_page_link_name', 'wwassignment'));
     if ($wwsetname != -1) {
         //we are doing an update, since an id exists in moodle db
         $wwsetlink = _wwassignment_link_to_edit_set_auto_login($wwcoursename, $wwsetname, $wwusername, $wwkey);
         $mform->addElement('link', 'edit_set', get_string('edit_set_link_desc', 'wwassignment'), $wwsetlink, get_string('edit_set_link_name', 'wwassignment'));
         $wwsetdata = $wwclient->get_assignment_data($wwcoursename, $wwsetname, false);
         $opendate = strftime("%c", $wwsetdata['open_date']);
         $duedate = strftime("%c", $wwsetdata['due_date']);
         $mform->addElement('static', 'opendate', 'WeBWorK Set Open Date', $opendate);
         $mform->addElement('static', 'duedate', 'WeBWorK Set Due Date', $duedate);
     }
     //define the mapping
     $mform->addElement('header', 'set_initialization', get_string('set_initialization', 'wwassignment'));
     //name
     $mform->addElement('text', 'name', get_string('wwassignmentname', 'wwassignment'), array('size' => '64'));
     $mform->setType('name', PARAM_TEXT);
     $mform->addRule('name', null, 'required', null, 'client');
     //set select
     $options = $wwclient->options_set($wwcoursename, false);
     $mform->addElement('select', 'webwork_set', get_string('webwork_set', 'wwassignment'), $options);
     //	$OUTPUT->help_icon('enablenotification','assignment');
     $mform->addHelpButton('webwork_set', 'webwork_set', 'wwassignment');
     //description
     $mform->addElement('htmleditor', 'description', get_string('description', 'assignment'));
     $mform->setType('description', PARAM_RAW);
     $mform->addHelpButton('description', 'writing', 'wwassignment');
     $features = new stdClass();
     $features->gradecat = true;
     $features->groups = false;
     $this->standard_coursemodule_elements($features);
     $this->add_action_buttons();
     //$this->standard_hidden_coursemodule_elements();
     return;
 }
Example #2
0
 protected function specific_definition($mform)
 {
     // include CFG object
     global $CFG;
     // library for wwassign funcsitons
     $lib = $CFG->dirroot . '/mod/wwassignment/locallib.php';
     require_once $lib;
     // form header
     $mform->addElement('header', 'configheader', get_string('blocksettings', 'block'));
     // get courses from WeBWorK server
     $client = new wwassignment_client();
     $options = $client->options_course(true);
     // add the menu
     $mform->addElement('select', 'config_wwlink_id', get_string('select_course', 'block_wwlink'), $options);
     $mform->setType('config_wwlink_id', PARAM_RAW);
 }
Example #3
0
/**
* @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;
}
Example #4
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;
}
Example #5
0
/**
* @desc Makes sure that a user is logged in to WW.
* @param $wwcoursename string The course to login to.
* @param $wwusername string The user to login.
* @return string The users key for WW.
*/
function _wwassignment_login_user($wwcoursename, $wwusername)
{
    $wwclient = new wwassignment_client();
    return $wwclient->login_user($wwcoursename, $wwusername, false);
}
 /**
  * @desc Test Basic Communication
  */
 function test_basic_communication()
 {
     $client = new wwassignment_client();
     $response = $client->handler('hello');
     $this->assertEqual('hello world!', $response, 'Webwork Server Communication Test.');
 }
Example #7
0
$stropendate = get_string("open_date", "wwassignment");
$strduedate = get_string("due_date", "wwassignment");
$strtotalpoints = get_string("total_points", "wwassignment");
if ($course->format == "weeks") {
    $table->head = array($strweek, $strname, $strdescription, $stropendate, $strduedate, $strtotalpoints);
    $table->align = array("center", "left", "left", "left", "left");
} else {
    if ($course->format == "topics") {
        $table->head = array($strtopic, $strname, $strdescription, $stropendate, $strduedate);
        $table->align = array("center", "left", "left", "left", "left", "left", "left");
    } else {
        $table->head = array($strname, $strdescription, $stropendate, $strduedate);
        $table->align = array("left", "left", "left", "left", "left", "left");
    }
}
$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);
Example #8
0
$strdescription = get_string('description');
$stropendate = get_string("open_date", "wwassignment");
$strduedate = get_string("due_date", "wwassignment");
if ($course->format == "weeks") {
    $table->head = array($strweek, $strname, $strdescription, $strOpenDate, $strDueDate);
    $table->align = array("center", "left", "left", "left", "left");
} else {
    if ($course->format == "topics") {
        $table->head = array($strtopic, $strname, $strdescription, $strOpenDate, $strDueDate);
        $table->align = array("center", "left", "left", "left", "left", "left", "left");
    } else {
        $table->head = array($strname, $strdescription, $strOpenDate, $strDueDate);
        $table->align = array("left", "left", "left", "left", "left", "left");
    }
}
$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") {
            $table->data[] = array($wwassignment->section, $link, $wwassignment->description, strftime("%c", $wwsetinfo['open_date']), strftime("%c", $wwsetinfo['due_date']));