Skip to content

Commit

Permalink
MDL-26349 Display the workshop final grades to participants when the …
Browse files Browse the repository at this point in the history
…activity is closed
  • Loading branch information
mudrd8mz committed Nov 7, 2012
1 parent 092977f commit 3cb4ce4
Show file tree
Hide file tree
Showing 5 changed files with 148 additions and 0 deletions.
1 change: 1 addition & 0 deletions mod/workshop/lang/en/workshop.php
Expand Up @@ -301,4 +301,5 @@
$string['workshop:viewpublishedsubmissions'] = 'View published submissions';
$string['workshop:viewreviewernames'] = 'View reviewer names';
$string['yourassessment'] = 'Your assessment';
$string['yourgrades'] = 'Your grades';
$string['yoursubmission'] = 'Your submission';
66 changes: 66 additions & 0 deletions mod/workshop/locallib.php
Expand Up @@ -2200,6 +2200,59 @@ public function get_feedbackauthor_form(moodle_url $actionurl, stdclass $submiss
'post', '', null, $editable);
}

/**
* Returns the information about the user's grades as they are stored in the gradebook
*
* The submission grade is returned for users with the capability mod/workshop:submit and the
* assessment grade is returned for users with the capability mod/workshop:peerassess. Unless the
* user has the capability to view hidden grades, grades must be visible to be returned. Null
* grades are not returned. If none grade is to be returned, this method returns false.
*
* @param int $userid the user's id
* @return workshop_final_grades|false
*/
public function get_gradebook_grades($userid) {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');

if (empty($userid)) {
throw new coding_exception('User id expected, empty value given.');
}

// Read data via the Gradebook API
$gradebook = grade_get_grades($this->course->id, 'mod', 'workshop', $this->id, $userid);

$grades = new workshop_final_grades();

if (has_capability('mod/workshop:submit', $this->context, $userid)) {
if (!empty($gradebook->items[0]->grades)) {
$submissiongrade = reset($gradebook->items[0]->grades);
if (!is_null($submissiongrade->grade)) {
if (!$submissiongrade->hidden or has_capability('moodle/grade:viewhidden', $this->context, $userid)) {
$grades->submissiongrade = $submissiongrade;
}
}
}
}

if ($this->usepeerassessment and has_capability('mod/workshop:peerassess', $this->context, $userid)) {
if (!empty($gradebook->items[1]->grades)) {
$assessmentgrade = reset($gradebook->items[1]->grades);
if (!is_null($assessmentgrade->grade)) {
if (!$assessmentgrade->hidden or has_capability('moodle/grade:viewhidden', $this->context, $userid)) {
$grades->assessmentgrade = $assessmentgrade;
}
}
}
}

if (!is_null($grades->submissiongrade) or !is_null($grades->assessmentgrade)) {
return $grades;
}

return false;
}

////////////////////////////////////////////////////////////////////////////////
// Internal methods (implementation details) //
////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -3471,3 +3524,16 @@ public function __construct(stdClass $assessment) {
$this->format = $assessment->feedbackreviewerformat;
}
}


/**
* Holds the final grades for the activity as are stored in the gradebook
*/
class workshop_final_grades implements renderable {

/** @var object the info from the gradebook about the grade for submission */
public $submissiongrade = null;

/** @var object the infor from the gradebook about the grade for assessment */
public $assessmentgrade = null;
}
41 changes: 41 additions & 0 deletions mod/workshop/renderer.php
Expand Up @@ -724,6 +724,47 @@ public function perpage_selector($current=10) {
return $this->output->container($this->output->render($select), 'perpagewidget');
}

/**
* Renders the user's final grades
*
* @param workshop_final_grades $grades with the info about grades in the gradebook
* @return string HTML
*/
protected function render_workshop_final_grades(workshop_final_grades $grades) {

$out = html_writer::start_tag('div', array('class' => 'finalgrades'));

if (!empty($grades->submissiongrade)) {
$cssclass = 'grade submissiongrade';
if ($grades->submissiongrade->hidden) {
$cssclass .= ' hiddengrade';
}
$out .= html_writer::tag(
'div',
html_writer::tag('div', get_string('submissiongrade', 'mod_workshop'), array('class' => 'gradetype')) .
html_writer::tag('div', $grades->submissiongrade->str_long_grade, array('class' => 'gradevalue')),
array('class' => $cssclass)
);
}

if (!empty($grades->assessmentgrade)) {
$cssclass = 'grade assessmentgrade';
if ($grades->assessmentgrade->hidden) {
$cssclass .= ' hiddengrade';
}
$out .= html_writer::tag(
'div',
html_writer::tag('div', get_string('gradinggrade', 'mod_workshop'), array('class' => 'gradetype')) .
html_writer::tag('div', $grades->assessmentgrade->str_long_grade, array('class' => 'gradevalue')),
array('class' => $cssclass)
);
}

$out .= html_writer::end_tag('div');

return $out;
}

////////////////////////////////////////////////////////////////////////////
// Internal rendering helper methods
////////////////////////////////////////////////////////////////////////////
Expand Down
32 changes: 32 additions & 0 deletions mod/workshop/styles.css
Expand Up @@ -458,6 +458,38 @@
color: #ee0000;
}

/**
* Final grades
*/
.path-mod-workshop #workshop-viewlet-yourgrades .finalgrades {
text-align: center;
}

.path-mod-workshop #workshop-viewlet-yourgrades .finalgrades .grade {
border: 1px solid #ddd;
margin: 1em;
padding: 2em;
display: inline-block;
-webkit-border-radius: 15px;
-moz-border-radius: 15px;
border-radius: 15px;
}

.path-mod-workshop #workshop-viewlet-yourgrades .finalgrades .grade.submissiongrade {
background-color: #d2ebff;
}

.path-mod-workshop #workshop-viewlet-yourgrades .finalgrades .grade.assessmentgrade {
background-color: #eee;
/*background-color: #e7f1c3;*/
}

.path-mod-workshop #workshop-viewlet-yourgrades .finalgrades .grade .gradevalue {
font-weight: bold;
font-size: x-large;
margin: 10px;
}

/**
* Edit assessment form
*/
Expand Down
8 changes: 8 additions & 0 deletions mod/workshop/view.php
Expand Up @@ -519,6 +519,14 @@
echo $output->box(format_text($conclusion, $workshop->conclusionformat, array('overflowdiv'=>true)), array('generalbox', 'conclusion'));
print_collapsible_region_end();
}
$finalgrades = $workshop->get_gradebook_grades($USER->id);
if (!empty($finalgrades)) {
print_collapsible_region_start('', 'workshop-viewlet-yourgrades', get_string('yourgrades', 'workshop'));
echo $output->box_start('generalbox grades-yourgrades');
echo $output->render($finalgrades);
echo $output->box_end();
print_collapsible_region_end();
}
if (has_capability('mod/workshop:viewallassessments', $PAGE->context)) {
$perpage = get_user_preferences('workshop_perpage', 10);
$groupid = groups_get_activity_group($workshop->cm, true);
Expand Down

0 comments on commit 3cb4ce4

Please sign in to comment.