Skip to content
Browse files

ForumNG Add participation grading #2119

  • Loading branch information...
1 parent aa67f2b commit 8626296a38d6b3ba2e9be70d82a668d44321b075 @AlanFez AlanFez committed with sammarshallou Oct 26, 2012
View
2 backup/moodle2/backup_forumng_stepslib.php
@@ -45,7 +45,7 @@ protected function define_structure() {
'reportingemail', 'subscription', 'feedtype', 'feeditems',
'maxpostsperiod', 'maxpostsblock', 'postingfrom', 'postinguntil',
'typedata', 'magicnumber', 'completiondiscussions', 'completionreplies',
- 'completionposts', 'removeafter', 'removeto', 'shared', 'originalcmid'));
+ 'completionposts', 'removeafter', 'removeto', 'shared', 'originalcmid', 'gradingscale'));
$discussions = new backup_nested_element('discussions');
View
13 db/access.php
@@ -37,7 +37,7 @@
)
),
- // Ability to add new forumng to a course
+ // Ability to add new forumng to a course.
'mod/forumng:addinstance' => array(
'riskbitmask' => RISK_XSS,
@@ -305,6 +305,17 @@
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
)
+ ),
+
+ 'mod/forumng:grade' => array(
+
+ 'captype' => 'write',
+ 'contextlevel' => CONTEXT_MODULE,
+ 'archetypes' => array(
+ 'teacher' => CAP_ALLOW,
+ 'editingteacher' => CAP_ALLOW,
+ 'manager' => CAP_ALLOW
+ )
)
);
View
3 db/install.xml
@@ -38,6 +38,7 @@
<FIELD NAME="removeto" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="This field stores the mod instance id of the target forum. Null means delete old discussions permanently." PREVIOUS="removeafter" NEXT="shared"/>
<FIELD NAME="shared" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" COMMENT="If the forum is available for sharing on other courses, this flag will be set to 1." PREVIOUS="removeto" NEXT="originalcmid"/>
<FIELD NAME="originalcmid" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" COMMENT="If this forum is a reference to (clone of) a shared forum, this field is non-null and points to the original forum. (When this is set, other settings in this table are ignored.)" PREVIOUS="shared"/>
+ <FIELD NAME="gradingscale" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" COMMENT="grading scale" PREVIOUS="originalcmid"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" NEXT="course"/>
@@ -192,4 +193,4 @@
</TABLE>
</TABLES>
-</XMLDB>
+</XMLDB>
View
19 db/upgrade.php
@@ -25,11 +25,30 @@
function xmldb_forumng_upgrade($oldversion=0) {
global $CFG, $THEME, $DB;
+ $dbman = $DB->get_manager();
+
if ($oldversion < 2012070900) {
// Changed format of modinfo cache, so need to rebuild all courses.
rebuild_course_cache(0, true);
upgrade_mod_savepoint(true, 2012070900, 'forumng');
}
+ if ($oldversion < 2012102601) {
+ // Define field gradingscale to be added to forumng.
+ $table = new xmldb_table('forumng');
+ $field = new xmldb_field('gradingscale', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'grading');
+
+ // Launch add field gradingscale.
+ if (!$dbman->field_exists($table, $field)) {
+ $dbman->add_field($table, $field);
+ }
+
+ // Changed format of modinfo cache, so need to rebuild all courses.
+ rebuild_course_cache(0, true);
+
+ // ForumNG savepoint reached.
+ upgrade_mod_savepoint(true, 2012102601, 'forumng');
+ }
+
return true;
}
View
46 feature/userposts/internaldoc/grading.txt
@@ -0,0 +1,46 @@
+== OU ForumNG Grading Feature ==
+
+=== Description ===
+
+Display user participation within forumNG.
+
+Participation is defined as:
+
+* discussions created
+* posts replied to
+
+=== Capability requirements ===
+
+A user will be considered as participating in a forum if they have the capability to create a discussion and reply to a post within
+the context of the current forum instance and are not considered an adminstrator
+by standard Moodle legacy roles and capabilities.
+
+A user who has the capability '''mod/forumng:grade''' and has access to the current forum
+can view all user participation, subject to the groupmode settings and their membership of those groups.
+(A user who has the capability '''moodle/site:accessallgroups''' will be able to see all groups regardless of
+personal membership).
+
+=== Grading page display ===
+
+From the foum page the button to access the grading screens is 'view posts by user' which takes you to the user list screen.
+If you have the ability to '''mod/forumng:grade''' you will be presented with a Grade dropdown for each user. This screen will
+allow you to grade each user.
+
+To view an individual user's participation click on the link 'Show all posts by <name>'. This will take you to a screen containing
+that user's posts including replies and any discussion start posts if they started a discussion.
+If you have the ability to '''mod/forumng:grade''' you will see a Grade dropdown for that user.
+
+=== Grading ===
+
+A user with the capability ''mod/forumng:grade'' in relation to the current forum has the ability to add grade values.
+This can either be done as a bulk action on the '''View posts by user''' page or as a single update on the more detailed
+single user page.
+
+Grading will only be available if it has been set for the particular forum instance
+in the '''ForumNG administration''' '''Edit settings''' screen.
+
+To grade on the main 'User posts' list screen - you can change one or more grade dropdowns,
+then you must click the 'Save grades' button.
+
+To grade an individual named user's posts - you need to goto to the bottom of the page, choose a grade from the dropdown box,
+then you must click the 'Save grades' button.
View
110 feature/userposts/internaldoc/testcase.grading.txt
@@ -0,0 +1,110 @@
+This script describes steps to test the participation facility from a user
+perspective. It is intended to cover most of the UI and features.
+
+NOTE: In this test case, the word 'forum' always refers to the OU ForumNG.
+
+The test steps in this script follow on from each other and aren't independent.
+
+Initial setup
+=============
+
+This test case requires:
+
+- a course which has at least two groups defined (G1 and G2).
+- two test student users (U.S1, who is in group G1, and U.S2, in group G2).
+- one editing teacher (U.ET)
+
+The test server must have debugging set to DEVELOPER level and to display
+errors; during all parts of the test script, there should be no debugging
+warnings.
+
+The completion system must be enabled for (a) the site, and (b) the test
+course.
+
+CRE Creating forums and data
+============================
+
+CRE01 / admin
+ In your test course, create a forum called CRE01
+ Edit forum settings so that:
+ Under 'Grade' settings
+ Choose 'Teacher grades student' from Grade dropdown
+ Set 'Grading scale' to 100
+
+ Under 'Common module' settings
+ Choose 'Seperate groups' from Group mode
+ Leave 'Grouping' set to 'None'
+ Leave 'Visible' to 'Show'
+
+ Click on Save and display submit button
+
+CRE02 / admin
+ Go into the forum you have just created and start a seperate discussion for each group
+ For each discussion create a post
+
+CRE03 / U.S1 [change]
+ Go to forum CRE01 (you should be in group G1).
+ Reply to start discussion post created by admin user
+
+CRE04 / U.S2 [change]
+ Go to forum CRE01 (you should be in group G2).
+ Reply to start discussion post created by admin user
+
+CRE04 / U.ET [change]
+ Go to forum CRE01.
+ Click against 'View posts by user'
+
+GRD Grading
+===========
+
+GRD01 / U.ET
+ This should bring up a screen entitled User posts
+ It should show the student user
+ The number of Discussions started by that user
+ The number of Replies to posts
+ Grades per user, this is a dropdown that anybody with 'mod/forumng:grade' can be used to grade a user
+ - currently the only people that can grade a user are admin, teacher, editing teacher, and manager.
+ Check the grade dropdown to see that it contains a 'No grade' option and grades between 0/100 - 100/100
+ Note: 100 should be the value you set the scale at when you edited the forum settings
+ Choose 77 as a grade/score
+ Note: All users if you can grade them will have grade dropdown box even if they have not yet taken part in the forum
+ which will be set to a score of 'No grade'.
+ Click on Save Grades which will save the grades.
+ Click on the link that says 'Show all posts by <name>'
+
+GRD02 / U.ET
+ This takes you to a screen showing all posts by that user (including replies and discussions stated)
+ At the end of the posts is a section entitled 'User grade'
+ The Grade dropdown should be showing a grade of 77/100, which is the grade you set for that user on the previous screen
+ Change the grade to 95/100
+ Click on the Save changes button
+
+ This takes you back to the 'User posts' screen
+ Check to see that the Grade dropdown is showing 95/100 as the score against that user
+
+ GRD03 / U.ET
+ Click against Course administration on the left hand side
+ Click on the Grades icon/link in the now opened Course administration menu
+ This should bring up Grader report which shows all student participants
+ Student 1 should have a score of 95 for them under the forum heading whilst student 2 will have a score of 0
+ Check that the average scores shown for the forum and course are correct
+
+RGD Retest with grading disabled
+================================
+
+ RGD01 / admin[change]
+ Edit forum CRE01 settings so that:
+Under 'Grade' settings
+Choose 'No Grades' from Grade dropdown
+- This should gray out and make the 'Grading scale' dropdown non-active
+
+ RGD02 / U.ET [change]
+ Go to forum CRE01.
+ Click against 'View posts by user'
+
+ RGD03 / U.ET
+ This should bring up a screen entitled User posts
+ It should show the student user
+ The number of Discussions started by that user
+ The number of Replies to posts
+ Under Grades no grading information or dropdown grading list should be shown
View
5 feature/userposts/lang/en/forumngfeature_userposts.php
@@ -30,3 +30,8 @@
$string['userposts:view'] = 'View list of posts by user';
$string['pluginname'] = 'View posts by user';
$string['action'] = 'Action';
+
+// User participation.
+$string['savegrades'] = 'Save grades';
+$string['usergrade'] = 'User grade';
+$string['gradesupdated'] = 'Grades updated';
View
118 feature/userposts/list.php
@@ -42,45 +42,53 @@
throw new moodle_exception('notforsharedforum', 'forumngfeature_userposts');
}
-// Check forum access (using forum group, if required)
+// Check forum access (using forum group, if required).
$groupid = mod_forumng::get_activity_group($cm, true);
if ($groupid != mod_forumng::NO_GROUPS && $groupid != mod_forumng::ALL_GROUPS) {
$pageparams['group'] = $groupid;
}
-// Check access
+// Check access.
$forum->require_view($groupid);
require_capability('forumngfeature/userposts:view', $forum->get_context());
-// Print page header
+// Print page header.
$thisurl = new moodle_url('/mod/forumng/feature/userposts/list.php', $pageparams);
$out = $forum->init_page($thisurl, get_string('userposts', 'forumngfeature_userposts'));
print $out->header();
-// Display group selector if required
+// Display group selector if required.
groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/forumng/feature/userposts/list.php?' .
$forum->get_link_params(mod_forumng::PARAM_PLAIN));
print '<div class="clearer"></div>';
-// Get all users
+// Get all users.
if (!$users = $forum->get_monitored_users($groupid)) {
- // No users, print info and stop
+ // No users, print info and stop.
print_string('nothingtodisplay', 'forumng');
- // Display link to the discussion
+ // Display link to the discussion.
print link_arrow_left($forum->get_name(), '../../view.php?id=' . $cmid);
- // Display footer
+ // Display footer.
print $out->footer();
return;
}
$counts = $forum->get_all_user_post_counts($groupid);
+// Is grading enabled and available for the current user?
+$grades = array();
+$cangrade = $forum->can_grade();
+if ($cangrade) {
+ $grades = grade_get_grades($course->id, 'mod', 'forumng',
+ $forum->get_id(), array_keys($users));
+}
+
$data = array();
foreach ($users as $id => $u) {
- // Set table-row colour to gray for users without data (default)
+ // Set table-row colour to gray for users without data (default).
$span = "<span style='color:gray'>";
$row = array();
@@ -94,11 +102,11 @@
$count = (object)array('discussions'=>0, 'replies'=>0);
}
if ($count->discussions || $count->replies) {
- // Set table-row colour to black for students with data
+ // Set table-row colour to black for students with data.
$span = "<span style='color:black'>";
$showallpostsby = get_string('showallpostsby', 'forumngfeature_userposts', $username);
- // Build url and the params
+ // Build url and the params.
$url = $CFG->wwwroot .
"/mod/forumng/feature/userposts/user.php?" .
$forum->get_link_params(mod_forumng::PARAM_HTML) .
@@ -113,30 +121,98 @@
$row[2] = $span . $count->replies . "</span>";
$row[3] = $span . $showallpostsby . "</span>";
+ // Grades for all users regardless of whether they have participated or not.
+ $gradeitem = '';
+ if ($grades) {
+ $user = new stdClass();
+ $attributes = array('userid' => $id);
+ if (!isset($grades->items[0]->grades[$id]->grade)) {
+ $user->grade = -1;
+ } else {
+ $user->grade = $grades->items[0]->grades[$id]->grade;
+ $user->grade = abs($user->grade);
+ }
+ $menu = html_writer::select(make_grades_menu($forum->get_grading_scale()),
+ 'menu[' . $id . ']', $user->grade,
+ array(-1 => get_string('nograde')), $attributes);
+ $gradeitem = html_writer::tag('div', $menu, array('id' => 'gradeuser' . $id . ''));
+ }
+
+ $row[4] = $span . $gradeitem . "</span>";
$data[] = $row;
}
-// Setup the table layout
-$user = get_string('user');
+// Setup the table layout.
+$userstr = get_string('user');
$discussions = get_string('discussions', 'forumng');
$replies = get_string('replies', 'forumng');
$action = get_string('action', 'forumngfeature_userposts');
+$grade = '';
+if ($cangrade) {
+ $grade = get_string('grade', 'forumng');
+}
$table = new html_table();
-$table->head = array($user, $discussions, $replies, "<span class='accesshide'>$action</span>");
-$table->size = array('30%', '10%', '10%', '40%');
-$table->align = array('left', 'right', 'right', 'left');
-$table->width = '90%';
+$table->head = array($userstr, $discussions, $replies, "<span class='accesshide'>$action</span>", $grade);
+$table->size = array('30%', '10%', '10%', '40%', '10%');
+$table->align = array('left', 'right', 'right', 'left', 'left');
+$table->width = '100%';
$table->data = $data;
-// Display heading
+// Display heading.
print $out->heading(get_string('userposts', 'forumngfeature_userposts'));
-// Display the table
+// Print out participation form.
+if ($cangrade) {
+ print forumngfeature_userposts_grade_form_header($cmid, $groupid);
+}
+
+// Display the table.
print html_writer::tag('div', html_writer::table($table),
array('class' => 'forumng-userpoststable'));
-// Display link to the discussion
+// Print out grade form footer.
+if ($cangrade) {
+ print forumngfeature_userposts_grade_form_footer();
+}
+
+// Display link to the discussion.
$url = '../../view.php?id=' . $cmid;
print link_arrow_left($forum->get_name(), $url);
-// Display footer
+// Display footer.
print $out->footer();
+
+
+/**
+ * Creates save grades form tag and relevant hidden id tags.
+ * @param int $cmid course module id.
+ * @param int $groupid group id.
+ * @return string
+ */
+function forumngfeature_userposts_grade_form_header($cmid, $groupid) {
+ global $USER;
+ $formattrs = array();
+ $formattrs['action'] = new moodle_url('/mod/forumng/feature/userposts/savegrades.php');
+ $formattrs['id'] = 'savegrades';
+ $formattrs['method'] = 'post';
+ $formattrs['class'] = 'savegradeform';
+ $output = html_writer::start_tag('form', $formattrs);
+ $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'id',
+ 'value' => $cmid));
+ $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'group',
+ 'value' => $groupid));
+ $output .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey',
+ 'value' => $USER->sesskey));
+ return $output;
+}
+
+/**
+ * Creates save grades form end tag and submit button.
+ * @return string
+ */
+function forumngfeature_userposts_grade_form_footer() {
+ $savegrades = html_writer::empty_tag('input', array('type' => 'submit',
+ 'name' => 'savegrades', 'value' => get_string('savegrades', 'forumngfeature_userposts')));
+ $output = html_writer::tag('div', $savegrades, array('class' => 'savegradesbutton'));
+ $output .= html_writer::end_tag('form');
+ return $output;
+}
View
143 feature/userposts/locallib.php
@@ -0,0 +1,143 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Local library file for forumng. These are non-standard functions that are used
+ * only by forumng.
+ *
+ * @package mod
+ * @subpackage forumng
+ * @copyright 2012 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+/** Make sure this isn't being directly accessed */
+defined('MOODLE_INTERNAL') || die();
+
+// Include the files that are required by this module.
+require_once($CFG->dirroot . '/mod/forumng/lib.php');
+
+/**
+ * Grades users from the list.php or user.php page.
+ *
+ * @param array $newgrades mixed optional array/object of grade(s);
+ * @param object $cm course module object
+ * @param mod_forumng $forumng Forum
+ */
+function forumngfeature_userposts_update_grades($newgrades, $cm, mod_forumng $forumng) {
+ global $CFG, $SESSION;
+
+ require_once($CFG->libdir.'/gradelib.php');
+ $grades = grade_get_grades($forumng->get_course_id(), 'mod',
+ 'forumng', $forumng->get_id(), array_keys($newgrades));
+
+ foreach ($grades->items[0]->grades as $key => $grade) {
+ if (array_key_exists($key, $newgrades)) {
+ if ($newgrades[$key] != $grade->grade) {
+ if ($newgrades[$key] == -1) {
+ // No grade.
+ $grade->rawgrade = null;
+ } else {
+ $grade->rawgrade = $newgrades[$key];
+ }
+ $grade->userid = $key;
+ $forumng->cmidnumber = $cm->id;
+ forumngfeature_userposts_grade_item_update($forumng, $grade);
+ }
+ }
+ }
+
+ // Add a message to display to the page.
+ if (!isset($SESSION->forumnggradesupdated)) {
+ $SESSION->forumnggradesupdated = get_string('gradesupdated', 'forumngfeature_userposts');
+ }
+}
+
+/**
+ * Update grade item for given forumng.
+ *
+ * @param mod_forumng $forumng Forum with extra cmidnumber.
+ * @param mixed optional array/object of grade(s); 'reset' means reset grades in gradebook
+ * @return int 0 if ok, error code otherwise
+ */
+function forumngfeature_userposts_grade_item_update(mod_forumng $forumng, $grades = null) {
+ global $CFG;
+ require_once($CFG->libdir.'/gradelib.php');
+
+ $params = array('itemname' => $forumng->get_name());
+
+ $gradingscale = $forumng->get_grading_scale();
+ if ($gradingscale > 0) {
+ $params['gradetype'] = GRADE_TYPE_VALUE;
+ $params['grademax'] = $gradingscale;
+ $params['grademin'] = 0;
+ } else if ($gradingscale < 0) {
+ $params['gradetype'] = GRADE_TYPE_SCALE;
+ $params['scaleid'] = $gradingscale;
+ } else {
+ $params['gradetype'] = GRADE_TYPE_NONE;
+ }
+
+ if ($grades === 'reset') {
+ $params['reset'] = true;
+ $grades = null;
+ }
+
+ return grade_update('mod/forumng', $forumng->get_course_id(), 'mod',
+ 'forumng', $forumng->get_id(), 0, $grades, $params);
+}
+
+/**
+ * Render single user's grading form.
+ *
+ * @param int $cmid course module id
+ * @param mod_forumng $forumng Forum
+ * @param object $user object
+ * @param int $groupid id of group to which user belongs
+ */
+function forumngfeature_userposts_display_user_grade($cmid, mod_forumng $forumng, $user, $groupid) {
+ global $CFG;
+
+ require_once($CFG->libdir.'/gradelib.php');
+ $grades = grade_get_grades($forumng->get_course_id(), 'mod', 'forumng', $forumng->get_id(), $user->id);
+
+ if ($grades) {
+ if (!isset($grades->items[0]->grades[$user->id]->grade)) {
+ $user->grade = -1;
+ } else {
+ $user->grade = abs($grades->items[0]->grades[$user->id]->grade);
+ }
+ $grademenu = make_grades_menu($forumng->get_grading_scale());
+ $grademenu[-1] = get_string('nograde');
+
+ $formparams = array();
+ $formparams['id'] = $cmid;
+ $formparams['user'] = $user->id;
+ $formparams['group'] = $groupid;
+ $formaction = new moodle_url('/mod/forumng/feature/userposts/savegrades.php', $formparams);
+ $mform = new MoodleQuickForm('savegrade', 'post', $formaction,
+ '', array('class' => 'savegrade'));
+
+ $mform->addElement('header', 'usergrade', get_string('usergrade', 'forumngfeature_userposts'));
+
+ $mform->addElement('select', 'grade', get_string('grade'), $grademenu);
+ $mform->setDefault('grade', $user->grade);
+
+ $mform->addElement('submit', 'savechanges', get_string('savechanges'));
+
+ $mform->display();
+ }
+}
View
73 feature/userposts/savegrades.php
@@ -0,0 +1,73 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Page for saving grades for all or one user participation
+ *
+ * @package mod
+ * @subpackage forumng
+ * @copyright 2012 The Open University
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once(dirname(__FILE__) . '/../../../../config.php');
+require_once($CFG->dirroot . '/mod/forumng/lib.php');
+require_once($CFG->dirroot . '/mod/forumng/mod_forumng.php');
+require_once($CFG->dirroot. '/mod/forumng/feature/userposts/locallib.php');
+
+$id = required_param('id', PARAM_INT); // Course Module ID.
+$groupid = optional_param('group', 0, PARAM_INT);
+$userid = optional_param('user', 0, PARAM_INT);
+
+$params = array();
+$params['id'] = $id;
+$params['group'] = $groupid;
+
+$url = new moodle_url('/mod/forumng/feature/userposts/savegrades.php');
+
+$forum = mod_forumng::get_from_cmid($id, mod_forumng::CLONE_DIRECT);
+
+if (!$cm = $forum->get_course_module()) {
+ print_error('invalidcoursemodule');
+}
+
+$PAGE->set_cm($cm);
+
+$course = $forum->get_course();
+$context = get_context_instance(CONTEXT_MODULE, $cm->id);
+require_course_login($course, true, $cm);
+
+// Grading capability check.
+if (!$forum->can_grade()) {
+ print_error('nopermissiontoshow');
+}
+
+$mode = '';
+if (!empty($_POST['menu'])) {
+ $mode = 'bulk';
+ $gradeinfo = $_POST['menu'];
+} else if ($userid && !empty($_POST['grade'])) {
+ $gradeinfo[$userid] = $_POST['grade'];
+}
+// Update grades.
+if (!empty($gradeinfo)) {
+ forumngfeature_userposts_update_grades($gradeinfo, $cm, $forum);
+}
+
+// Rebuild course cache.
+rebuild_course_cache($course->id, true);
+// Redirect.
+redirect('list.php?id=' . $id . '&group=' . $groupid);
View
22 feature/userposts/user.php
@@ -27,6 +27,7 @@
require_once('../../../../config.php');
require_once($CFG->dirroot . '/mod/forumng/mod_forumng.php');
+require_once($CFG->dirroot . '/mod/forumng/feature/userposts/locallib.php');
$cmid = required_param('id', PARAM_INT);
$userid = required_param('user', PARAM_INT);
@@ -56,13 +57,13 @@
throw new invalid_parameter_exception("Not supported for shared forums.");
}
-// Check access
+// Check access.
$forum->require_view($groupid);
require_capability('forumngfeature/userposts:view', $forum->get_context());
$posts = $forum->get_all_posts_by_user($userid, $groupid);
-// Set pagename
+// Set pagename.
if ($posts) {
$post = reset($posts);
$user = $post->get_user();
@@ -80,13 +81,13 @@
$out = $forum->init_page($pageurl, $pagename, array($prevpage=>$prevurl));
print $out->header();
-foreach ($posts as $postid=>$post) {
+foreach ($posts as $postid => $post) {
print "<div class='forumng-userpostheading'>";
- // Get URL to post
+ // Get URL to post.
print '<a href="' . s($post->get_url()) . '">';
- // If this post is a reply, then print a link to the discussion
+ // If this post is a reply, then print a link to the discussion.
if (!$post->is_root_post()) {
print get_string('replyin', 'forumngfeature_userposts',
$post->get_discussion()->get_subject());
@@ -95,15 +96,20 @@
}
print "</a></div>";
- // Display this post
+ // Display this post.
$options = array(
mod_forumng_post::OPTION_NO_COMMANDS => true,
mod_forumng_post::OPTION_FIRST_UNREAD => false,
mod_forumng_post::OPTION_UNREAD_NOT_HIGHLIGHTED => true);
print $post->display(true, $options);
}
-// Display link to the discussion
+
+if ($forum->can_grade()) {
+ forumngfeature_userposts_display_user_grade( $cm->id, $forum, $user, $groupid);
+}
+
+// Display link to the discussion.
print link_arrow_left($prevpage, 'list.php?id=' . $cmid);
-// Display footer
+// Display footer.
print $out->footer();
View
2 feature/userposts/version.php
@@ -21,4 +21,4 @@
* @copyright 2011 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$plugin->version = 2011020300;
+$plugin->version = 2012102600;
View
12 lang/en/forumng.php
@@ -76,7 +76,7 @@
$string['ratings'] = 'Ratings';
$string['grading'] = 'Grade';
$string['grading_help'] = 'If you select this option, a grade for this forum will be added to the
-course gradebook and calcualted automatically. Leave this off for a non-assessed forum, or one you
+course gradebook and calculated automatically. Leave this off for a non-assessed forum, or one you
plan to assess manually.
The different ways to calculate grading are fairly self-explanatory; in each case, the grade for
@@ -114,6 +114,7 @@
$string['configreadafterdays'] = 'After this number of days, posts are considered to have been read
by all users.';
$string['trackreadposts'] = 'Track unread posts';
+$string['teacher_grades_students'] = 'Teacher grades students';
$string['grading_average'] = 'Average of ratings';
$string['grading_count'] = 'Count of ratings';
$string['grading_max'] = 'Maximum rating';
@@ -140,6 +141,7 @@
$string['forumng:managesubscriptions'] = 'Manage subscriptions';
$string['forumng:movediscussions'] = 'Move discussions';
$string['forumng:rate'] = 'Rate posts';
+$string['forumng:grade'] = 'Grade posts';
$string['forumng:replypost'] = 'Reply to posts';
$string['forumng:splitdiscussions'] = 'Split discussions';
$string['forumng:startdiscussion'] = 'Start new discussions';
@@ -515,11 +517,11 @@
$string['switchto_standard_link']='Switch to standard view.';
$string['displayversion'] = 'ForumNG version: <strong>{$a}</strong>';
-// OU only
+// OU only.
$string['externaldashboardadd'] = 'Add forum to dashboard';
$string['externaldashboardremove'] = 'Remove forum from dashboard';
-// New error strings
+// New error strings.
$string['error_fileexception'] = 'A file processing error occurred. This is likely to be caused by
system problems. You may wish to try again later.';
$string['error_subscribeparams'] = 'Parameters incorrect: requires either id or course or d.';
@@ -698,6 +700,7 @@
already forums that share it. If necessary, delete these other forums first.';
$string['error_nosharedforum'] = 'Forum <strong>{$a->name}</strong>: Could not restore as shared
forum; ID number {$a->idnumber} not found. Restored forum is an independent forum.';
+$string['error_ratingrequired'] = 'Grading chosen to be based on ratings, but ratings not enabled';
$string['advancedsearch'] = 'Advanced search';
$string['words'] = 'Search for';
@@ -803,3 +806,6 @@
To search by author or date, click &lsquo;More options&rsquo;.';
$string['notext'] = '(no text)';
+
+$string['grade'] = 'Grade';
+$string['gradingscale'] = 'Grading scale';
View
21 mod_form.php
@@ -156,12 +156,17 @@ function definition() {
$mform->addHelpButton('ratingthreshold', 'ratingthreshold', 'forumng');
$mform->disabledIf('ratingthreshold', 'enableratings', 'notchecked');
- // Grading
+ // Grading.
+ $mform->addElement('header', '', get_string('grading', 'forumng'));
+
$mform->addElement('select', 'grading', get_string('grade'),
mod_forumng::get_grading_options());
$mform->setDefault('grading', mod_forumng::GRADING_NONE);
$mform->addHelpButton('grading', 'grading', 'forumng');
- $mform->disabledIf('grading', 'enableratings', 'notchecked');
+
+ $mform->addElement('modgrade', 'gradingscale', get_string('gradingscale', 'forumng'));
+ $mform->disabledIf('gradingscale', 'grading', 'ne', mod_forumng::GRADING_MANUAL);
+ $mform->setDefault('gradingscale', 5);
// Blocking header
//////////////////
@@ -327,6 +332,15 @@ function validation($data, $files) {
}
}
}
+
+ // If grading is set to ratings and ratings not enabled.
+ if (!empty($data['grading'])) {
+ if ( ($data['grading'] > 0 && $data['grading'] < 6) && (empty($data['enableratings'])) ) {
+ // If grading between 1 and 5 (not = 6 and not = 0) and enableratings is empty (not checked).
+ $errors['enableratings'] = get_string('error_ratingrequired', 'forumng');
+ }
+ }
+
return $errors;
}
@@ -402,6 +416,9 @@ function add_completion_rules() {
$mform->addHelpButton('completionrepliesgroup', 'completionrepliesgroup', 'forumng');
$mform->disabledIf('completionreplies', 'completionrepliesenabled', 'notchecked');
+ // Restriction for grade completion
+ $mform->disabledIf('completionusegrade', 'grading', 'eq', 0);
+
return array('completiondiscussionsgroup',
'completionrepliesgroup', 'completionpostsgroup');
}
View
19 mod_forumng.php
@@ -79,6 +79,8 @@ class mod_forumng {
const GRADING_MIN = 4;
/** Grading: Sum of ratings. */
const GRADING_SUM = 5;
+ /** Grading: Teacher grades students */
+ const GRADING_MANUAL = 6;
/** Feed type: No feeds provided. */
const FEEDTYPE_NONE = 0;
@@ -247,6 +249,7 @@ public function get_max_posts_period($text = false, $midsentence = false) {
public static function get_grading_options() {
return array (
self::GRADING_NONE => get_string('grading_none', 'forumng'),
+ self::GRADING_MANUAL => get_string('teacher_grades_students', 'forumng'),
self::GRADING_AVERAGE => get_string('grading_average', 'forumng'),
self::GRADING_COUNT => get_string('grading_count', 'forumng'),
self::GRADING_MAX => get_string('grading_max', 'forumng'),
@@ -403,6 +406,14 @@ public function can_rate($created=0) {
&& has_capability('mod/forumng:rate', $this->get_context());
}
+ /**
+ * @return bool True if current user can grade a user
+ */
+ public function can_grade() {
+ return $this->get_grading() == self::GRADING_MANUAL
+ && has_capability('mod/forumng:grade', $this->get_context());
+ }
+
/** @return int ID of course that contains this forum */
public function get_course_id() {
return $this->forumfields->course;
@@ -674,6 +685,14 @@ public function get_grading() {
* @return int Scale used for ratings; 0 = disable,
* positive integer = 0..N scale, negative integer = defined scale
*/
+ public function get_grading_scale() {
+ return $this->forumfields->gradingscale;
+ }
+
+ /**
+ * @return int Scale used for ratings; 0 = disable,
+ * positive integer = 0..N scale, negative integer = defined scale
+ */
public function get_rating_scale() {
return $this->forumfields->ratingscale;
}
View
10 styles.css
@@ -899,3 +899,13 @@ padding-top: 1em;
#delete-form-html {
display: none;
}
+
+/*
+// forumfeature save grades
+///////////////////////////
+*/
+.savegradeform {
+ border-radius: 5px 5px 5px 5px;
+ max-width: 100%;
+ padding: 10px;
+}
View
2 version.php
@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-$module->version = 2012102600;
+$module->version = 2012102601;
$module->requires = 2011120100;
$module->cron = 60;

0 comments on commit 8626296

Please sign in to comment.
Something went wrong with that request. Please try again.