Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 23... Línea 23...
23
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
23
 * @copyright 2012 NetSpot {@link http://www.netspot.com.au}
24
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
25
 */
26
defined('MOODLE_INTERNAL') || die();
26
defined('MOODLE_INTERNAL') || die();
Línea 27... Línea -...
27
 
-
 
28
require_once(__DIR__ . '/deprecatedlib.php');
-
 
29
 
27
 
30
/**
28
/**
31
 * Adds an assignment instance
29
 * Adds an assignment instance
32
 *
30
 *
33
 * This is done by calling the add_instance() method of the assignment type class
31
 * This is done by calling the add_instance() method of the assignment type class
34
 * @param stdClass $data
32
 * @param stdClass $data
35
 * @param mod_assign_mod_form $form
33
 * @param mod_assign_mod_form $form
36
 * @return int The instance id of the new assignment
34
 * @return int The instance id of the new assignment
37
 */
35
 */
38
function assign_add_instance(stdClass $data, mod_assign_mod_form $form = null) {
36
function assign_add_instance(stdClass $data, ?mod_assign_mod_form $form = null) {
39
    global $CFG;
37
    global $CFG;
Línea 40... Línea 38...
40
    require_once($CFG->dirroot . '/mod/assign/locallib.php');
38
    require_once($CFG->dirroot . '/mod/assign/locallib.php');
41
 
39
 
Línea 68... Línea 66...
68
 */
66
 */
69
function assign_reset_userdata($data) {
67
function assign_reset_userdata($data) {
70
    global $CFG, $DB;
68
    global $CFG, $DB;
71
    require_once($CFG->dirroot . '/mod/assign/locallib.php');
69
    require_once($CFG->dirroot . '/mod/assign/locallib.php');
Línea 72... Línea 70...
72
 
70
 
73
    $status = array();
71
    $status = [];
74
    $params = array('courseid'=>$data->courseid);
72
    $params = ['courseid' => $data->courseid];
75
    $sql = "SELECT a.id FROM {assign} a WHERE a.course=:courseid";
73
    $sql = "SELECT a.id FROM {assign} a WHERE a.course=:courseid";
76
    $course = $DB->get_record('course', array('id'=>$data->courseid), '*', MUST_EXIST);
74
    $course = $DB->get_record('course', ['id' => $data->courseid], '*', MUST_EXIST);
77
    if ($assigns = $DB->get_records_sql($sql, $params)) {
75
    if ($assigns = $DB->get_records_sql($sql, $params)) {
78
        foreach ($assigns as $assign) {
76
        foreach ($assigns as $assign) {
-
 
77
            $cm = get_coursemodule_from_instance(
79
            $cm = get_coursemodule_from_instance('assign',
78
                'assign',
80
                                                 $assign->id,
79
                $assign->id,
81
                                                 $data->courseid,
80
                $data->courseid,
82
                                                 false,
81
                false,
-
 
82
                MUST_EXIST,
83
                                                 MUST_EXIST);
83
            );
84
            $context = context_module::instance($cm->id);
84
            $context = context_module::instance($cm->id);
85
            $assignment = new assign($context, $cm, $course);
85
            $assignment = new assign($context, $cm, $course);
86
            $status = array_merge($status, $assignment->reset_userdata($data));
86
            $status = array_merge($status, $assignment->reset_userdata($data));
87
        }
87
        }
-
 
88
    }
88
    }
89
 
89
    return $status;
90
    return $status;
Línea 90... Línea 91...
90
}
91
}
91
 
92
 
Línea 202... Línea 203...
202
 * whether the course reset functionality affects the assignment.
203
 * whether the course reset functionality affects the assignment.
203
 * @param MoodleQuickForm $mform form passed by reference
204
 * @param MoodleQuickForm $mform form passed by reference
204
 */
205
 */
205
function assign_reset_course_form_definition(&$mform) {
206
function assign_reset_course_form_definition(&$mform) {
206
    $mform->addElement('header', 'assignheader', get_string('modulenameplural', 'assign'));
207
    $mform->addElement('header', 'assignheader', get_string('modulenameplural', 'assign'));
-
 
208
    $mform->addElement('static', 'assigndelete', get_string('delete'));
207
    $name = get_string('deleteallsubmissions', 'assign');
209
    $name = get_string('deleteallsubmissions', 'assign');
208
    $mform->addElement('advcheckbox', 'reset_assign_submissions', $name);
210
    $mform->addElement('advcheckbox', 'reset_assign_submissions', $name);
209
    $mform->addElement('advcheckbox', 'reset_assign_user_overrides',
211
    $mform->addElement('advcheckbox', 'reset_assign_user_overrides',
210
        get_string('removealluseroverrides', 'assign'));
212
        get_string('removealluseroverrides', 'assign'));
211
    $mform->addElement('advcheckbox', 'reset_assign_group_overrides',
213
    $mform->addElement('advcheckbox', 'reset_assign_group_overrides',
Línea 378... Línea 380...
378
            return true;
380
            return true;
379
        case FEATURE_COMPLETION_HAS_RULES:
381
        case FEATURE_COMPLETION_HAS_RULES:
380
            return true;
382
            return true;
381
        case FEATURE_GRADE_HAS_GRADE:
383
        case FEATURE_GRADE_HAS_GRADE:
382
            return true;
384
            return true;
-
 
385
        case FEATURE_GRADE_HAS_PENALTY:
-
 
386
            return true;
383
        case FEATURE_GRADE_OUTCOMES:
387
        case FEATURE_GRADE_OUTCOMES:
384
            return true;
388
            return true;
385
        case FEATURE_BACKUP_MOODLE2:
389
        case FEATURE_BACKUP_MOODLE2:
386
            return true;
390
            return true;
387
        case FEATURE_SHOW_DESCRIPTION:
391
        case FEATURE_SHOW_DESCRIPTION:
Línea 406... Línea 410...
406
 * @param settings_navigation $settings
410
 * @param settings_navigation $settings
407
 * @param navigation_node $navref
411
 * @param navigation_node $navref
408
 * @return void
412
 * @return void
409
 */
413
 */
410
function assign_extend_settings_navigation(settings_navigation $settings, navigation_node $navref) {
414
function assign_extend_settings_navigation(settings_navigation $settings, navigation_node $navref) {
411
    global $DB;
415
    global $DB, $CFG;
-
 
416
 
-
 
417
    require_once($CFG->dirroot . '/mod/assign/locallib.php');
Línea 412... Línea 418...
412
 
418
 
413
    // We want to add these new nodes after the Edit settings node, and before the
419
    // We want to add these new nodes after the Edit settings node, and before the
414
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
420
    // Locally assigned roles node. Of course, both of those are controlled by capabilities.
415
    $keys = $navref->get_children_key_list();
421
    $keys = $navref->get_children_key_list();
Línea 451... Línea 457...
451
            $url = new moodle_url('/mod/assign/view.php', $urlparams);
457
            $url = new moodle_url('/mod/assign/view.php', $urlparams);
452
            $linkname = get_string('revealidentities', 'assign');
458
            $linkname = get_string('revealidentities', 'assign');
453
            $node = $navref->add($linkname, $url, navigation_node::TYPE_SETTING);
459
            $node = $navref->add($linkname, $url, navigation_node::TYPE_SETTING);
454
        }
460
        }
455
    }
461
    }
-
 
462
 
-
 
463
    $assign = new assign($context, null, null);
-
 
464
    // If the current user can view grades, include the 'Submissions' navigation node.
-
 
465
    if ($assign->can_view_grades()) {
-
 
466
        $url = new moodle_url('/mod/assign/view.php', ['id' => $settings->get_page()->cm->id, 'action' => 'grading']);
-
 
467
        $navref->add(
-
 
468
            text: get_string('gradeitem:submissions', 'assign'),
-
 
469
            action: $url,
-
 
470
            type: navigation_node::TYPE_SETTING,
-
 
471
            key: 'mod_assign_submissions'
-
 
472
        );
-
 
473
    }
-
 
474
 
-
 
475
    // Allow changing grade penalty settings at course module level, on assignment module.
-
 
476
    // Other modules can choose to allow this change or not.
-
 
477
    if (\mod_assign\penalty\helper::is_penalty_enabled($cm->instance)) {
-
 
478
        \core_grades\penalty_manager::extend_navigation_module($settings, $navref);
-
 
479
    }
456
}
480
}
Línea 457... Línea 481...
457
 
481
 
458
/**
482
/**
459
 * Add a get_coursemodule_info function in case any assignment type wants to add 'extra' information
483
 * Add a get_coursemodule_info function in case any assignment type wants to add 'extra' information
Línea 939... Línea 963...
939
 
963
 
940
    echo '</td></tr></table>';
964
    echo '</td></tr></table>';
Línea 941... Línea 965...
941
}
965
}
942
 
966
 
943
/**
967
/**
944
 * Checks if scale is being used by any instance of assignment
968
 * Checks if scale is being used by any instance of assignment or is the default scale used for assignments.
945
 *
969
 *
946
 * This is used to find out if scale used anywhere
970
 * This is used to find out if scale used anywhere
947
 * @param int $scaleid
971
 * @param int $scaleid
948
 * @return boolean True if the scale is used by any assignment
972
 * @return boolean True if the scale is used by any assignment or is the default scale used for assignments.
949
 */
973
 */
Línea -... Línea 974...
-
 
974
function assign_scale_used_anywhere($scaleid) {
950
function assign_scale_used_anywhere($scaleid) {
975
    global $DB;
951
    global $DB;
-
 
952
 
-
 
953
    if ($scaleid and $DB->record_exists('assign', array('grade'=>-$scaleid))) {
976
 
954
        return true;
977
    return $scaleid && (
955
    } else {
978
        $DB->record_exists('assign', ['grade' => -(int)$scaleid]) ||
Línea 956... Línea 979...
956
        return false;
979
        (int)get_config('mod_assign', 'defaultgradescale') === (int)$scaleid
957
    }
980
    );
958
}
981
}
Línea 1044... Línea 1067...
1044
    if ($grades  === 'reset') {
1067
    if ($grades  === 'reset') {
1045
        $params['reset'] = true;
1068
        $params['reset'] = true;
1046
        $grades = null;
1069
        $grades = null;
1047
    }
1070
    }
Línea 1048... Línea 1071...
1048
 
1071
 
1049
    return grade_update('mod/assign',
1072
    $result = grade_update('mod/assign',
1050
                        $assign->courseid,
1073
                        $assign->courseid,
1051
                        'mod',
1074
                        'mod',
1052
                        'assign',
1075
                        'assign',
1053
                        $assign->id,
1076
                        $assign->id,
1054
                        0,
1077
                        0,
1055
                        $grades,
1078
                        $grades,
-
 
1079
                        $params);
-
 
1080
 
-
 
1081
    // Get lists of users whose grades are updated.
-
 
1082
    $userids = [];
-
 
1083
    if (is_array($grades)) {
-
 
1084
        // The $grades is array/object of grade(s).
-
 
1085
        // We are checking if it is single user (array with simple values such as userid and rawgrade).
-
 
1086
        // Or it is array of grade objects, for multiple users.
-
 
1087
        if (isset($grades['userid']) && isset($grades['rawgrade'])) {
-
 
1088
            // Single user grade update.
-
 
1089
            $userids = [$grades['userid']];
-
 
1090
        } else {
-
 
1091
            // Multiple user grade update.
-
 
1092
            foreach ($grades as $grade) {
-
 
1093
                if (is_object($grade) && isset($grade->userid) && isset($grade->rawgrade)) {
-
 
1094
                    $userids[] = $grade->userid;
-
 
1095
                }
-
 
1096
            }
-
 
1097
        }
-
 
1098
    }
-
 
1099
    // Apply penalty to each user.
-
 
1100
    foreach ($userids as $userid) {
-
 
1101
        \mod_assign\penalty\helper::apply_penalty_to_user($assign->id, $userid);
-
 
1102
    }
-
 
1103
 
1056
                        $params);
1104
    return $result;
Línea 1057... Línea 1105...
1057
}
1105
}
1058
 
1106
 
1059
/**
1107
/**
Línea 1826... Línea 1874...
1826
            return get_string('requiresaction', 'calendar', $modulename);
1874
            return get_string('requiresaction', 'calendar', $modulename);
1827
    }
1875
    }
Línea 1828... Línea 1876...
1828
 
1876
 
1829
    return get_string($identifier, 'assign', $modulename);
1877
    return get_string($identifier, 'assign', $modulename);
-
 
1878
}
-
 
1879
 
-
 
1880
/**
-
 
1881
 * Allow the support for SMS in assignment.
-
 
1882
 *
-
 
1883
 * @return bool
-
 
1884
 */
-
 
1885
function mod_assign_supports_sms_notifications(): bool {
-
 
1886
    // At the moment, assignment supports sms notifications.
-
 
1887
    return true;