Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions classes/models/coursework.php
Original file line number Diff line number Diff line change
Expand Up @@ -2653,22 +2653,36 @@ public function get_grade_item() {
/**
* Check if we can release marks for this coursework instance.
*
* @param bool $assumehasstufftopublish avoid potentially lengthy check that the coursework has stuff to publish?
* @return array
* @throws coding_exception
*/
public function can_release_marks() {
public function can_release_marks(bool $assumehasstufftopublish = false) {
if (!has_capability('mod/coursework:publish', $this->get_context())) {
return [
false,
get_string('no_permission_to_release_marks', 'mod_coursework'),
];
}

if (!$this->has_stuff_to_publish()) {
return [
false,
get_string('nofinalmarkedworkyet', 'mod_coursework'),
];
if (!$assumehasstufftopublish) {
$submissions = submission::find_all(['courseworkid' => $this->id()]);
$hasstufftopublish = false;
/**
* @var submission $submission
*/
foreach ($submissions as $submission) {
if ($submission->ready_to_publish()) {
$hasstufftopublish = true;
break;
}
}
if (!$hasstufftopublish) {
return [
false,
get_string('nofinalmarkedworkyet', 'mod_coursework'),
];
}
}

if ($this->blindmarking_enabled() && $this->moderation_enabled() && $this->unmoderated_work_exists()) {
Expand Down
7 changes: 5 additions & 2 deletions classes/renderers/grading_report_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public function get_grading_report_data(coursework $coursework): \stdClass {
$template = new stdClass();
$template->coursework = self::prepare_coursework_data($coursework);
$template->blindmarkingenabled = $blindmarking;
$template->releasemarks = $this->prepare_release_marks_button($coursework);
$template->tiienabled = $coursework->tii_enabled();

$currenturl = new moodle_url('/mod/coursework/view.php', ['id' => $coursework->get_course_module()->id]);
Expand Down Expand Up @@ -138,6 +137,10 @@ public function get_grading_report_data(coursework $coursework): \stdClass {
$template->tr[] = $trdata;
}

if ($markingsummary->readyforrelease > 0) {
$template->releasemarks = $this->prepare_release_marks_button($coursework);
}

// Sort markers a-z for dropdown filter.
if ($markersarray) {
usort($markersarray, function ($a, $b) {
Expand Down Expand Up @@ -342,7 +345,7 @@ protected static function prepare_actions_cell_data(
* @throws coding_exception
*/
protected function prepare_release_marks_button(coursework $coursework): ?stdClass {
[$canrelease] = $coursework->can_release_marks();
[$canrelease] = $coursework->can_release_marks(true);
if (!$canrelease) {
return null;
}
Expand Down