Skip to content
This repository has been archived by the owner on May 15, 2020. It is now read-only.

Commit

Permalink
Tidied up mod_base class and made assign grading form show up.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgibson committed Jul 8, 2012
1 parent a48c14e commit 22da552
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 10 deletions.
9 changes: 2 additions & 7 deletions classes/module_base.class.php
Expand Up @@ -245,9 +245,7 @@ public function postprocess_nodes_hook($nodes, $filters) {
* @param $params
* @return string
*/
public function process_data($data, $params) {
return '';
}
abstract public function process_data($data, $params);

/**
* Makes the contents of the pop up grading window
Expand All @@ -257,8 +255,5 @@ public function process_data($data, $params) {
* @return string HTML
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function grading_popup($params, $coursemodule) {
}


abstract public function grading_popup($params, $coursemodule);
}
116 changes: 114 additions & 2 deletions modules/assign/block_ajax_marking_assign.class.php
Expand Up @@ -59,12 +59,14 @@ public function __construct() {
}

/**
* Makes the grading interface for the pop up
* Makes the grading interface for the pop up. Robbed from /mod/assign/locallib.php
* line 1583ish - view_single_grade_page().
*
* @param array $params From $_GET
* @param object $coursemodule The coursemodule object that the user has been authenticated
* against
* @param bool $data
* @throws coding_exception
* @global $PAGE
* @global stdClass $CFG
* @global moodle_database $DB
Expand All @@ -74,10 +76,119 @@ public function __construct() {
*/
public function grading_popup($params, $coursemodule, $data = false) {

global $PAGE, $CFG, $DB, $OUTPUT;
global $PAGE, $CFG, $DB;

$modulecontext = context_module::instance($coursemodule->id);
$course = $DB->get_record('course', array('id' => $coursemodule->course));
$coursecontext = context_course::instance($course->id);

$assign = new assign($modulecontext, $coursemodule, $course);

/* @var mod_assign_renderer $renderer */
$renderer = $PAGE->get_renderer('mod_assign');

$output = '';

$offset = 1;

// Include grade form.
require_once($CFG->dirroot.'/mod/assign/gradeform.php');

// Need submit permission to submit an assignment.
require_capability('mod/assign:grade', $modulecontext);

/* Pinched from private method assign::get_grading_userid_list() */
$filter = get_user_preferences('assign_filter', '');
$table = new assign_grading_table($assign, 0, $filter, 0, false);
$useridlist = $table->get_column_data('userid');

$userid = $params['userid'];

$rownum = 0;
foreach ($useridlist as $key => $useridinlist) {
if ($useridinlist == $userid) {
$rownum = $key;
reset ($useridlist); // Just in case.
break;
}
}

$last = false;
if ($rownum == count($useridlist) - 1) {
$last = true;
}

// The placement of this is important so can pass the list of userids above.
if ($offset) {
$_POST = array();
}

$user = $DB->get_record('user', array('id' => $userid));
if ($user) {
$output .= $renderer->render(new assign_user_summary($user, $course->id,
has_capability('moodle/site:viewfullnames',
$coursecontext)));
}
$submission = $DB->get_record('assign_submission',
array('assignment' => $assign->get_instance()->id,
'userid' => $userid));

// Get the current grade. Pinched from assign::get_user_grade().
$grade = $DB->get_record('assign_grades',
array('assignment' => $assign->get_instance()->id,
'userid' => $userid));
// Pinched from assign::is_graded().
$isgraded = (!empty($grade) && $grade->grade !== null && $grade->grade >= 0);

if ($assign->can_view_submission($userid)) {
$gradelocked = ($grade && $grade->locked) || $assign->grading_disabled($userid);
$widget =
new assign_submission_status($assign->get_instance()->allowsubmissionsfromdate,
$assign->get_instance()->alwaysshowdescription,
$submission,
$assign->is_any_submission_plugin_enabled(),
$gradelocked,
$isgraded,
$assign->get_instance()->duedate,
$assign->get_submission_plugins(),
$assign->get_return_action(),
$assign->get_return_params(),
$assign->get_course_module()->id,
assign_submission_status::GRADER_VIEW,
false,
false);
$output .= $renderer->render($widget);
}
if ($grade) {
$data = new stdClass();
if ($grade->grade !== null && $grade->grade >= 0) {
$data->grade = format_float($grade->grade, 2);
}
} else {
$data = new stdClass();
$data->grade = '';
}

// Now show the grading form.
$customdata = array(
'useridlist' => $useridlist,
'rownum' => $rownum,
'last' => $last
);
$mform = new mod_assign_grade_form(null,
array($assign,
$data,
$customdata),
'post',
'',
array('class' => 'gradeform'));
$output .= $renderer->render(new assign_form('gradingform', $mform));

$assign->add_to_log('view grading form',
get_string('viewgradingformforstudent', 'assign',
array('id' => $user->id,
'fullname' => fullname($user))));

return $output;
}

Expand Down Expand Up @@ -203,4 +314,5 @@ public static function nextnodetype_filter($query) {
'on' => 'usertable.id = countwrapperquery.id');
$query->add_from($table);
}

}
23 changes: 23 additions & 0 deletions modules/journal/block_ajax_marking_journal.class.php
Expand Up @@ -160,4 +160,27 @@ public function query_factory() {
return $query;
}

/**
* This function will take the data returned by the grading popup and process it. Not always
* implemented as not all modules have a grading popup yet
*
* @param $data
* @param $params
* @return string
*/
public function process_data($data, $params) {
// TODO: Implement process_data() method.
}

/**
* Makes the contents of the pop up grading window
*
* @param $params
* @param $coursemodule
* @return string HTML
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function grading_popup($params, $coursemodule) {
return '';
}
}
12 changes: 11 additions & 1 deletion modules/workshop/block_ajax_marking_workshop.class.php
Expand Up @@ -162,7 +162,17 @@ public function grading_popup($params, $coursemodule) {

$workshopurl = new moodle_url('/mod/workshop/view.php?id='.$coursemodule->id);
redirect($workshopurl);

}

/**
* This function will take the data returned by the grading popup and process it. Not always
* implemented as not all modules have a grading popup yet
*
* @param $data
* @param $params
* @return string
*/
public function process_data($data, $params) {
return '';
}
}
10 changes: 10 additions & 0 deletions styles.css
Expand Up @@ -254,3 +254,13 @@ table.ygtvtable {
#page-blocks-ajax_marking-actions-grading_popup div.box.files > .helplink {
display: none;
}
/* Assign grading form has monster gap without these. */
#page-blocks-ajax_marking-actions-grading_popup .usersummary {
margin-bottom: 0;
}
/* These buttons are not needed */
#page-blocks-ajax_marking-actions-grading_popup #id_saveandshownext,
#page-blocks-ajax_marking-actions-grading_popup #id_nosaveandprevious,
#page-blocks-ajax_marking-actions-grading_popup #id_nosaveandnext {
display: none;
}

0 comments on commit 22da552

Please sign in to comment.