if ($forums = get_records('forum')) {
+ if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
+ notify('Default teacher role was not found. Roles and permissions '.
+ 'for all your forums will have to be manually set after '.
+ 'this upgrade.');
+ }
if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
notify('Default student role was not found. Roles and permissions '.
'for all your forums will have to be manually set after '.
'this upgrade.');
}
foreach ($forums as $forum) {
- if (!forum_convert_to_roles($forum, $forummod->id,
- $studentroles, $guestroles)) {
+ if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles,
+ $studentroles, $guestroles)) {
notify('Forum with id '.$forum->id.' was not upgraded');
}
}
execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('forum', 'user report', 'user', 'firstname||\' \'||lastname')");
}
- if ($oldversion < 2006081800) {
- // Upgrades for new roles and capabilities support.
- require_once($CFG->dirroot.'/mod/forum/lib.php');
-
- $forummod = get_record('modules', 'name', 'forum');
-
- if ($forums = get_records('forum')) {
-
- if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
- notify('Default student role was not found. Roles and permissions '.
- 'for all your forums will have to be manually set after '.
- 'this upgrade.');
- }
- if (!$guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
- notify('Default guest role was not found. Roles and permissions '.
- 'for teacher forums will have to be manually set after '.
- 'this upgrade.');
- }
-
- foreach ($forums as $forum) {
- if (!forum_convert_to_roles($forum, $forummod->id,
- $studentroles, $guestroles)) {
- notify('Forum with id '.$forum->id.' was not upgraded');
- }
- }
-
- // Drop column forum.open.
- modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN open;');
-
- // Drop column forum.assesspublic.
- modify_database('', 'ALTER TABLE prefix_forum DROP COLUMN assesspublic;');
-
- // We need to rebuild all the course caches to refresh the state of
- // the forum modules.
- include_once( "$CFG->dirroot/course/lib.php" );
- rebuild_course_cache();
-
- } // End if.
- }
-
-
if ($oldversion < 2006081800) {
// Upgrades for new roles and capabilities support.
require_once($CFG->dirroot.'/mod/forum/lib.php');
if ($forums = get_records('forum')) {
+ if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
+ notify('Default teacher role was not found. Roles and permissions '.
+ 'for all your forums will have to be manually set after '.
+ 'this upgrade.');
+ }
if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
notify('Default student role was not found. Roles and permissions '.
'for all your forums will have to be manually set after '.
'this upgrade.');
}
foreach ($forums as $forum) {
- if (!forum_convert_to_roles($forum, $forummod->id,
- $studentroles, $guestroles)) {
+ if (!forum_convert_to_roles($forum, $forummod->id, $teacherroles,
+ $studentroles, $guestroles)) {
notify('Forum with id '.$forum->id.' was not upgraded');
}
}
* @param $cmid - the course_module id for this forum instance
* @return boolean - forum was converted or not
*/
-function forum_convert_to_roles($forum, $forummodid, $studentroles=array(), $guestroles=array(), $cmid=NULL) {
+function forum_convert_to_roles($forum, $forummodid, $teacherroles=array(), $studentroles=array(), $guestroles=array(), $cmid=NULL) {
global $CFG;
foreach ($studentroles as $studentrole) {
assign_capability('mod/forum:rate', CAP_ALLOW, $studentrole->id, $context->id);
}
- // The legacy teacher role can already rate forum posts by default.
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/forum:rate', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
break;
case 2:
- // The legacy student role cannot rate forum posts by default.
- // The legacy teacher role can already rate forum posts by default.
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/forum:rate', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/forum:rate', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
break;
}
// 1 = Students can see everyone's ratings
switch ($forum->assesspublic) {
case 0:
- // This is already the behavior of the default legacy roles.
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/forum:viewanyrating', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
break;
case 1:
- assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id);
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/forum:viewanyrating', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
break;
}
}
-?>
+?>
\ No newline at end of file
// we need to convert the forum to use Roles. It means the backup
// was made pre Moodle 1.7. We check the backup_version to make
// sure.
- if ($restore->backup_version < 2006082300 &&
- isset($forum->open) && isset($forum->assesspublic)) {
+ if (($restore->backup_version < 2006082300) ||
+ (isset($forum->open) && isset($forum->assesspublic))) {
$forummod = get_record('modules', 'name', 'forum');
+ if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
+ notice('Default teacher role was not found. Roles and permissions '.
+ 'for all your forums will have to be manually set.');
+ }
if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
notice('Default student role was not found. Roles and permissions '.
'for all your forums will have to be manually set.');
}
require_once($CFG->dirroot.'/mod/forum/lib.php');
forum_convert_to_roles($forum, $forummod->id,
- $studentroles, $guestroles,
+ $teacherroles, $studentroles, $guestroles,
$restore->mods['forum']->instances[$mod->id]->restored_as_course_module);
}
break;
}
-
print_footer($course);
-?>
+?>
\ No newline at end of file