mirror of
https://github.com/moodle/moodle.git
synced 2025-04-17 06:25:33 +02:00
Merge branch 'MDL-39397_master' of git://github.com/totara/openbadges
This commit is contained in:
commit
474e0d3cd2
@ -77,12 +77,17 @@ class award_criteria_course extends award_criteria {
|
||||
$param = reset($this->params);
|
||||
|
||||
$course = $DB->get_record('course', array('id' => $param['course']));
|
||||
$str = '"' . $course->fullname . '"';
|
||||
if (isset($param['bydate'])) {
|
||||
$str .= get_string('criteria_descr_bydate', 'badges', userdate($param['bydate'], get_string('strftimedate', 'core_langconfig')));
|
||||
}
|
||||
if (isset($param['grade'])) {
|
||||
$str .= get_string('criteria_descr_grade', 'badges', $param['grade']);
|
||||
if (!$course) {
|
||||
$str = $OUTPUT->error_text(get_string('error:nosuchcourse', 'badges'));
|
||||
} else {
|
||||
$options = array('context' => context_course::instance($course->id));
|
||||
$str = html_writer::tag('b', '"' . format_string($course->fullname, true, $options) . '"');
|
||||
if (isset($param['bydate'])) {
|
||||
$str .= get_string('criteria_descr_bydate', 'badges', userdate($param['bydate'], get_string('strftimedate', 'core_langconfig')));
|
||||
}
|
||||
if (isset($param['grade'])) {
|
||||
$str .= get_string('criteria_descr_grade', 'badges', $param['grade']);
|
||||
}
|
||||
}
|
||||
return $str;
|
||||
}
|
||||
@ -92,9 +97,16 @@ class award_criteria_course extends award_criteria {
|
||||
*
|
||||
*/
|
||||
public function get_options(&$mform) {
|
||||
global $PAGE, $DB;
|
||||
$param = array_shift($this->params);
|
||||
$course = $DB->get_record('course', array('id' => $PAGE->course->id));
|
||||
global $DB;
|
||||
$param = array();
|
||||
|
||||
if ($this->id !== 0) {
|
||||
$param = reset($this->params);
|
||||
} else {
|
||||
$param['course'] = $mform->getElementValue('course');
|
||||
$mform->removeElement('course');
|
||||
}
|
||||
$course = $DB->get_record('course', array('id' => $param['course']));
|
||||
|
||||
if (!($course->enablecompletion == COMPLETION_ENABLED)) {
|
||||
$none = true;
|
||||
|
@ -99,7 +99,7 @@ class award_criteria_courseset extends award_criteria {
|
||||
$mform->addHelpButton('courses', 'addcourse', 'badges');
|
||||
|
||||
$buttonarray[] =& $mform->createElement('submit', 'submitcourse', get_string('addcourse', 'badges'));
|
||||
$buttonarray[] =& $mform->createElement('submit', 'back', get_string('cancel'));
|
||||
$buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('cancel'));
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
|
||||
$mform->addElement('hidden', 'addcourse', 'addcourse');
|
||||
@ -110,7 +110,7 @@ class award_criteria_courseset extends award_criteria {
|
||||
$mform->setType('agg', PARAM_INT);
|
||||
} else {
|
||||
$mform->addElement('static', 'nocourses', '', get_string('error:nocourses', 'badges'));
|
||||
$buttonarray[] =& $mform->createElement('submit', 'back', get_string('continue'));
|
||||
$buttonarray[] =& $mform->createElement('submit', 'cancel', get_string('continue'));
|
||||
$mform->addGroup($buttonarray, 'buttonar', '', array(' '), false);
|
||||
}
|
||||
}
|
||||
|
@ -39,11 +39,16 @@ class edit_criteria_form extends moodleform {
|
||||
$mform = $this->_form;
|
||||
$criteria = $this->_customdata['criteria'];
|
||||
$addcourse = $this->_customdata['addcourse'];
|
||||
$course = $this->_customdata['course'];
|
||||
|
||||
// Get course selector first if it's a new courseset criteria.
|
||||
if (($criteria->id == 0 || $addcourse) && $criteria->criteriatype == BADGE_CRITERIA_TYPE_COURSESET) {
|
||||
$criteria->get_courses($mform);
|
||||
} else {
|
||||
if ($criteria->id == 0 && $criteria->criteriatype == BADGE_CRITERIA_TYPE_COURSE) {
|
||||
$mform->addElement('hidden', 'course', $course);
|
||||
$mform->setType('course', PARAM_INT);
|
||||
}
|
||||
list($none, $message) = $criteria->get_options($mform);
|
||||
|
||||
if ($none) {
|
||||
|
@ -75,7 +75,7 @@ if ($edit) {
|
||||
$criteria = award_criteria::build($cparams);
|
||||
}
|
||||
|
||||
$mform = new edit_criteria_form($FULLME, array('criteria' => $criteria, 'addcourse' => $addcourse));
|
||||
$mform = new edit_criteria_form($FULLME, array('criteria' => $criteria, 'addcourse' => $addcourse, 'course' => $badge->courseid));
|
||||
|
||||
if (!empty($addcourse)) {
|
||||
if ($data = $mform->get_data()) {
|
||||
|
@ -1308,3 +1308,33 @@ function badges_user_has_backpack($userid) {
|
||||
global $DB;
|
||||
return $DB->record_exists('badge_backpack', array('userid' => $userid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles what happens to the course badges when a course is deleted.
|
||||
*
|
||||
* @param int $courseid course ID.
|
||||
* @return void.
|
||||
*/
|
||||
function badges_handle_course_deletion($courseid) {
|
||||
global $CFG, $DB;
|
||||
include_once $CFG->libdir . '/filelib.php';
|
||||
|
||||
$systemcontext = context_system::instance();
|
||||
$coursecontext = context_course::instance($courseid);
|
||||
$fs = get_file_storage();
|
||||
|
||||
// Move badges images to the system context.
|
||||
$fs->move_area_files_to_new_context($coursecontext->id, $systemcontext->id, 'badges', 'badgeimage');
|
||||
|
||||
// Get all course badges.
|
||||
$badges = $DB->get_records('badge', array('type' => BADGE_TYPE_COURSE, 'courseid' => $courseid));
|
||||
foreach ($badges as $badge) {
|
||||
// Archive badges in this course.
|
||||
$toupdate = new stdClass();
|
||||
$toupdate->id = $badge->id;
|
||||
$toupdate->type = BADGE_TYPE_SITE;
|
||||
$toupdate->courseid = null;
|
||||
$toupdate->status = BADGE_STATUS_ARCHIVED;
|
||||
$DB->update_record('badge', $toupdate);
|
||||
}
|
||||
}
|
||||
|
@ -4727,6 +4727,9 @@ function delete_course($courseorid, $showfeedback = true) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Handle course badges.
|
||||
badges_handle_course_deletion($courseid);
|
||||
|
||||
// make the course completely empty
|
||||
remove_course_contents($courseid, $showfeedback);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user