Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
defined('MOODLE_INTERNAL') || die();
-
 
18
 
-
 
19
global $CFG;
17
defined('MOODLE_INTERNAL') || die();
20
require_once($CFG->libdir . '/gradelib.php');
18
 
21
 
19
/**
22
/**
20
 * assign module data generator class
23
 * assign module data generator class
21
 *
24
 *
Línea 31... Línea 34...
31
     *
34
     *
32
     * @param array|stdClass|null $record
35
     * @param array|stdClass|null $record
33
     * @param array|null $options
36
     * @param array|null $options
34
     * @return stdClass
37
     * @return stdClass
35
     */
38
     */
36
    public function create_instance($record = null, array $options = null) {
39
    public function create_instance($record = null, ?array $options = null) {
37
        $record = (object)(array)$record;
40
        $record = (object)(array)$record;
Línea 38... Línea 41...
38
 
41
 
39
        $defaultsettings = array(
42
        $defaultsettings = [
40
            'alwaysshowdescription'             => 1,
43
            'alwaysshowdescription'             => 1,
41
            'submissiondrafts'                  => 1,
44
            'submissiondrafts'                  => 1,
42
            'requiresubmissionstatement'        => 0,
45
            'requiresubmissionstatement'        => 0,
43
            'sendnotifications'                 => 0,
46
            'sendnotifications'                 => 0,
Línea 50... Línea 53...
50
            'gradingduedate'                    => 0,
53
            'gradingduedate'                    => 0,
51
            'teamsubmission'                    => 0,
54
            'teamsubmission'                    => 0,
52
            'requireallteammemberssubmit'       => 0,
55
            'requireallteammemberssubmit'       => 0,
53
            'teamsubmissiongroupingid'          => 0,
56
            'teamsubmissiongroupingid'          => 0,
54
            'blindmarking'                      => 0,
57
            'blindmarking'                      => 0,
55
            'attemptreopenmethod'               => 'none',
58
            'attemptreopenmethod'               => 'untilpass',
56
            'maxattempts'                       => -1,
59
            'maxattempts'                       => 1,
57
            'markingworkflow'                   => 0,
60
            'markingworkflow'                   => 0,
58
            'markingallocation'                 => 0,
61
            'markingallocation'                 => 0,
59
            'markinganonymous'                  => 0,
62
            'markinganonymous'                  => 0,
60
            'activityformat'                    => 0,
63
            'activityformat'                    => 0,
61
            'timelimit'                         => 0,
64
            'timelimit'                         => 0,
62
            'submissionattachments'             => 0,
65
            'submissionattachments'             => 0,
63
        );
66
        ];
Línea 64... Línea 67...
64
 
67
 
65
        if (property_exists($record, 'teamsubmissiongroupingid')) {
68
        if (property_exists($record, 'teamsubmissiongroupingid')) {
66
            $record->teamsubmissiongroupingid = $this->get_grouping_id($record->teamsubmissiongroupingid);
69
            $record->teamsubmissiongroupingid = $this->get_grouping_id($record->teamsubmissiongroupingid);
Línea -... Línea 70...
-
 
70
        }
-
 
71
 
-
 
72
        if (property_exists($record, 'gradetype')) {
-
 
73
            if ((int)$record->gradetype === GRADE_TYPE_SCALE && property_exists($record, 'gradescale')) {
-
 
74
                // Get the scale id and apply it.
-
 
75
                $defaultsettings['grade[modgrade_type]'] = GRADE_TYPE_SCALE;
-
 
76
                $defaultsettings['grade[modgrade_scale]'] = $record->gradescale;
-
 
77
                $defaultsettings['grade'] = -$record->gradescale;
-
 
78
            } else if ((int)$record->gradetype === GRADE_TYPE_NONE) {
-
 
79
                $defaultsettings['grade[modgrade_type]'] = GRADE_TYPE_NONE;
-
 
80
                $defaultsettings['grade'] = 0;
-
 
81
            }
67
        }
82
        }
68
 
83
 
69
        foreach ($defaultsettings as $name => $value) {
84
        foreach ($defaultsettings as $name => $value) {
70
            if (!isset($record->{$name})) {
85
            if (!isset($record->{$name})) {
71
                $record->{$name} = $value;
86
                $record->{$name} = $value;
Línea 76... Línea 91...
76
    }
91
    }
Línea 77... Línea 92...
77
 
92
 
78
    /**
93
    /**
79
     * Create an assignment submission.
94
     * Create an assignment submission.
80
     *
95
     *
-
 
96
     * @param array $data with keys userid, cmid and
-
 
97
     *      then data for each assignsubmission plugin used.
81
     * @param array $data
98
     *      For backwards compatibility, you can pass cmid as 'assignid' but that generates a warning.
82
     */
99
     */
83
    public function create_submission(array $data): void {
100
    public function create_submission(array $data): void {
Línea -... Línea 101...
-
 
101
        global $USER;
-
 
102
 
-
 
103
        if (array_key_exists('assignid', $data)) {
-
 
104
            debugging(
-
 
105
                'The cmid passed to create_submission should have array key cmid, not assignid.',
-
 
106
                DEBUG_DEVELOPER,
-
 
107
            );
-
 
108
            $data['cmid'] = $data['assignid'];
-
 
109
            unset($data['assignid']);
84
        global $USER;
110
        }
85
 
111
 
86
        $currentuser = $USER;
112
        $currentuser = $USER;
Línea 87... Línea 113...
87
        $user = \core_user::get_user($data['userid']);
113
        $user = \core_user::get_user($data['userid']);
88
        $this->set_user($user);
114
        $this->set_user($user);
89
 
115
 
Línea 90... Línea 116...
90
        $submission = (object) [
116
        $submission = (object) [
91
            'userid' => $user->id,
117
            'userid' => $user->id,
92
        ];
118
        ];
Línea 93... Línea 119...
93
 
119
 
94
        [$course, $cm] = get_course_and_cm_from_cmid($data['assignid'], 'assign');
120
        [$course, $cm] = get_course_and_cm_from_cmid($data['cmid'], 'assign');
Línea 101... Línea 127...
101
                $plugingenerator = $this->datagenerator->get_plugin_generator("assignsubmission_{$pluginname}");
127
                $plugingenerator = $this->datagenerator->get_plugin_generator("assignsubmission_{$pluginname}");
102
                $plugingenerator->add_submission_data($submission, $assign, $data);
128
                $plugingenerator->add_submission_data($submission, $assign, $data);
103
            }
129
            }
104
        }
130
        }
Línea -... Línea 131...
-
 
131
 
-
 
132
        if (isset($data['status'])) {
-
 
133
            $submission->status = $data['status'];
-
 
134
        }
105
 
135
 
Línea 106... Línea 136...
106
        $assign->save_submission((object) $submission, $notices);
136
        $assign->save_submission($submission, $notices);
107
 
137
 
Línea 108... Línea 138...
108
        $this->set_user($currentuser);
138
        $this->set_user($currentuser);
-
 
139
    }
-
 
140
 
-
 
141
    /**
-
 
142
     * Create an assignment extension.
-
 
143
     *
-
 
144
     * @param array $data must have keys cmid, userid, extensionduedate.
-
 
145
     */
-
 
146
    public function create_extension(array $data): void {
-
 
147
        $user = \core_user::get_user($data['userid'], '*', MUST_EXIST);
-
 
148
 
-
 
149
        [$course, $cm] = get_course_and_cm_from_cmid($data['cmid'], 'assign');
-
 
150
        $context = context_module::instance($cm->id);
-
 
151
        $assign = new assign($context, $cm, $course);
-
 
152
 
-
 
153
        if (!$assign->save_user_extension($user->id, $data['extensionduedate'] ?: null)) {
-
 
154
            throw new \core\exception\coding_exception('The requested extension could not be created.');
-
 
155
        }
109
    }
156
    }
110
 
157
 
111
    /**
158
    /**
112
     * Gets the grouping id from it's idnumber.
159
     * Gets the grouping id from it's idnumber.
113
     *
160
     *
Línea 118... Línea 165...
118
    protected function get_grouping_id(string $idnumber): int {
165
    protected function get_grouping_id(string $idnumber): int {
119
        global $DB;
166
        global $DB;
Línea 120... Línea 167...
120
 
167
 
121
        // Do not fetch grouping ID for empty grouping idnumber.
168
        // Do not fetch grouping ID for empty grouping idnumber.
122
        if (empty($idnumber)) {
169
        if (empty($idnumber)) {
123
            return null;
170
            throw new \core\exception\coding_exception('idnumber cannot be empty');
Línea 124... Línea 171...
124
        }
171
        }
125
 
172
 
126
        if (!$id = $DB->get_field('groupings', 'id', ['idnumber' => $idnumber])) {
173
        if (!$id = $DB->get_field('groupings', 'id', ['idnumber' => $idnumber])) {