forked from mgage/wwassignment
-
Notifications
You must be signed in to change notification settings - Fork 7
/
mod_form.php
84 lines (61 loc) · 3.13 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once('moodleform_mod.php');
require_once('locallib.php');
class mod_wwassignment_mod_form extends moodleform_mod
{
function definition()
{
global $COURSE, $USER;
$mform = $this->_form;
$config = get_config('wwassignment');
$this->_features->showdescription = true;
//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');
// Instead of the wwassign description, we should use the normal intro...
$this->add_intro_editor($config->requiremodintro);
$features = new stdClass;
$features->gradecat = true;
$features->groups = false;
$this->standard_coursemodule_elements($features);
$this->add_action_buttons();
return;
}
function validation($data, $files)
{
$errors = parent::validation($data, $files);
return $errors;
}
}