)
),
- 'mod/data:viewentriesfromallgrous' => array(
-
- 'captype' => 'read',
- 'contextlevel' => CONTEXT_MODULE,
- 'legacy' => array(
- 'guest' => CAP_PREVENT,
- 'student' => CAP_PREVENT,
- 'teacher' => CAP_ALLOW,
- 'editingteacher' => CAP_ALLOW,
- 'coursecreator' => CAP_ALLOW,
- 'admin' => CAP_ALLOW
- )
- ),
-
'mod/data:writeentry' => array(
'riskbitmask' => RISK_SPAM,
if ($oldversion < 2006081700) {
table_column('data', '', 'jstemplate', 'text', '', '', '', 'not null', 'csstemplate');
}
+ /*
+ if ($oldversion < 2006092000) {
+ // Upgrades for new roles and capabilities support.
+ require_once($CFG->dirroot.'/mod/data/lib.php');
+ $datamod = get_record('modules', 'name', 'data');
+
+ if ($data = get_records('data')) {
+
+ 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 ($data as $d) {
+ if (!data_convert_to_roles($d, $teacherroles, $studentroles)) {
+ notify('Data with id '.$d->id.' was not upgraded');
+ }
+ }
+ // 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.
+
+ modify_database('', 'ALTER TABLE prefix_data DROP COLUMN participants;');
+ modify_database('', 'ALTER TABLE prefix_data DROP COLUMN assesspublic;');
+ modify_database('', 'ALTER TABLE prefix_data DROP COLUMN groupmode;');
+
+ }
+ */
return true;
}
if ($oldversion < 2006081700) {
table_column('data', '', 'jstemplate', 'text', '', '', '', 'not null', 'csstemplate');
}
-
+ /*
+ if ($oldversion < 2006092000) {
+ // Upgrades for new roles and capabilities support.
+ require_once($CFG->dirroot.'/mod/data/lib.php');
+
+ $datamod = get_record('modules', 'name', 'data');
+
+ if ($data = get_records('data')) {
+
+ 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 ($data as $d) {
+ if (!data_convert_to_roles($d $teacherroles, $studentroles)) {
+ notify('Data with id '.$d->id.' was not upgraded');
+ }
+ }
+ // 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.
+
+ modify_database('', 'ALTER TABLE prefix_data DROP COLUMN participants;');
+ modify_database('', 'ALTER TABLE prefix_data DROP COLUMN assesspublic;');
+ modify_database('', 'ALTER TABLE prefix_data DROP COLUMN groupmode;');
+
+ }
+ */
return true;
}
-?>
+?>
\ No newline at end of file
}
}
-?>
+
+/**
+ * Converts a database (module instance) to use the Roles System
+ * @param $data - a data object with the same attributes as a record
+ * from the data database table
+ * @param $datamodid - the id of the data module, from the modules table
+ * @param $teacherroles - array of roles that have moodle/legacy:teacher
+ * @param $studentroles - array of roles that have moodle/legacy:student
+ * @param $guestroles - array of roles that have moodle/legacy:guest
+ * @param $cmid - the course_module id for this data instance
+ * @return boolean - data module was converted or not
+ */
+function data_convert_to_roles($data, $teacherroles=array(), $studentroles=array(), $cmid=NULL) {
+
+ global $CFG;
+
+ if (!isset($data->participants) && !isset($data->assesspublic)
+ && !isset($data->groupmode)) {
+ // We assume that this database has already been converted to use the
+ // Roles System. above fields get dropped the data module has been
+ // upgraded to use Roles.
+ return false;
+ }
+
+ if (empty($cmid)) {
+ // We were not given the course_module id. Try to find it.
+ if (!$cm = get_coursemodule_from_instance('forum', $forum->id)) {
+ notify('Could not get the course module for the forum');
+ return false;
+ } else {
+ $cmid = $cm->id;
+ }
+ }
+ $context = get_context_instance(CONTEXT_MODULE, $cmid);
+
+
+ // $data->participants:
+ // 1 - Only teachers can add entries
+ // 3 - Teachers and students can add entries
+ switch ($data->participants) {
+ case 1:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:writeentry', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:writeentry', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ case 3:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:writeentry', CAP_ALLOW, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:writeentry', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ }
+
+ // $data->assessed:
+ // 2 - Only teachers can rate posts
+ // 1 - Everyone can rate posts
+ // 0 - No one can rate posts
+ switch ($data->assessed) {
+ case 0:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:rate', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:rate', CAP_PREVENT, $teacherrole->id, $context->id);
+ }
+ break;
+ case 1:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:rate', CAP_ALLOW, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:rate', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ case 2:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:rate', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:rate', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ }
+
+ // $data->assesspublic:
+ // 0 - Students can only see their own ratings
+ // 1 - Students can see everyone's ratings
+ switch ($data->assesspublic) {
+ case 0:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:viewrating', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:viewrating', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ case 1:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('mod/data:viewrating', CAP_ALLOW, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('mod/data:viewrating', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ }
+
+ if (empty($cm)) {
+ $cm = get_record('course_modules', 'id', $cmid);
+ }
+
+ // $cm->groupmode:
+ // 0 - No groups
+ // 1 - Separate groups
+ // 2 - Visible groups
+ switch ($cm->groupmode) {
+ case 0:
+ break;
+ case 1:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('moodle/site:accessallgroups', CAP_PREVENT, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ case 2:
+ foreach ($studentroles as $studentrole) {
+ assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $studentrole->id, $context->id);
+ }
+ foreach ($teacherroles as $teacherrole) {
+ assign_capability('moodle/site:accessallgroups', CAP_ALLOW, $teacherrole->id, $context->id);
+ }
+ break;
+ }
+ return true;
+}
+
+
+?>
\ No newline at end of file
$database->assessed = backup_todb($info['MOD']['#']['ASSESSED']['0']['#']);
$database->assesspublic = backup_todb($info['MOD']['#']['ASSESSPUBLIC']['0']['#']);
- $newid = insert_record ("data",$database);
+ $newid = insert_record ('data', $database);
//Do some output
if (!defined('RESTORE_SILENTLY')) {
$status = $status and data_records_restore_mods ($mod->id, $newid, $info, $restore);
}
+
+ // If the backup contained $data->participants, $data->assesspublic
+ // and $data->groupmode, we need to convert the data to use Roles.
+ // It means the backup was made pre Moodle 1.7. We check the
+ // backup_version to make sure.
+ if (isset($database->participants) && isset($database->assesspublic)) {
+
+ if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
+ notice('Default teacher role was not found. Roles and permissions '.
+ 'for your database modules 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 database modules will have to be manually set.');
+ }
+ if (!$guestroles = get_roles_with_capability('moodle/legacy:guest', CAP_ALLOW)) {
+ notice('Default guest role was not found. Roles and permissions '.
+ 'for all your database modules will have to be manually set.');
+ }
+ require_once($CFG->dirroot.'/mod/data/lib.php');
+ data_convert_to_roles($database, $teacherroles, $studentroles,
+ $restore->mods['data']->instances[$mod->id]->restored_as_course_module);
+ }
+
} else {
$status = false;
}