Skip to content

Commit

Permalink
MDL-23255 fixed inverted isset preventing visibility change in course…
Browse files Browse the repository at this point in the history
… edit form (creadit goes to Jay Knight) + fixed visibility of new course in hidden category when not allowed to change visibility; improved comments
  • Loading branch information
skodak committed Jul 14, 2010
1 parent 5ad337c commit db1218a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 6 additions & 2 deletions course/edit_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,13 @@ function definition() {
$mform->addElement('select', 'visible', get_string('availability'), $choices);
$mform->addHelpButton('visible', 'availability');
$mform->setDefault('visible', $courseconfig->visible);
if (!empty($course->id) and !has_capability('moodle/course:visibility', $coursecontext)) {
if (!has_capability('moodle/course:visibility', $context)) {
$mform->hardFreeze('visible');
$mform->setConstant('visible', $course->visible);
if (!empty($course->id)) {
$mform->setConstant('visible', $course->visible);
} else {
$mform->setConstant('visible', $category->visible);
}
}

//--------------------------------------------------------------------------------
Expand Down
13 changes: 6 additions & 7 deletions course/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -3471,12 +3471,11 @@ function create_course($data, $editoroptions = NULL) {
$data->summary_format = FORMAT_HTML;
}

// init visible flags
if (isset($data->visible)) {
$data->visibleold = $data->visible;
} else {
$data->visibleold = $data->visible = 1;
if (!isset($data->visible)) {
// data not from form, add missing visibility info
$data->visible = $category->category;
}
$data->visibleold = $data->visible;

$newcourseid = $DB->insert_record('course', $data);
$context = get_context_instance(CONTEXT_COURSE, $newcourseid, MUST_EXIST);
Expand Down Expand Up @@ -3557,8 +3556,8 @@ function update_course($data, $editoroptions = NULL) {
}
$movecat = (isset($data->category) and $oldcourse->category != $data->category);

// init visible flags
if (isset($data->visible)) {
if (!isset($data->visible)) {
// data not from form, add missing visibility info
$data->visible = $oldcourse->visible;
}

Expand Down

0 comments on commit db1218a

Please sign in to comment.