first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,264 @@
<?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/>.
/**
* Block for displayed logged in user's course completion status.
* Displays overall, and individual criteria status for logged in user.
*
* @package block_completionstatus
* @copyright 2009-2012 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class block_completionstatus extends block_base {
public function init() {
global $CFG;
require_once("{$CFG->libdir}/completionlib.php");
$this->title = get_string('pluginname', 'block_completionstatus');
}
public function applicable_formats() {
return array('course' => true);
}
public function get_content() {
global $USER;
$rows = array();
$srows = array();
$prows = array();
// If content is cached.
if ($this->content !== null) {
return $this->content;
}
$course = $this->page->course;
$context = context_course::instance($course->id);
// Create empty content.
$this->content = new stdClass();
$this->content->text = '';
$this->content->footer = '';
// Can edit settings?
$can_edit = has_capability('moodle/course:update', $context);
// Get course completion data.
$info = new completion_info($course);
// Don't display if completion isn't enabled!
if (!completion_info::is_enabled_for_site()) {
if ($can_edit) {
$this->content->text .= get_string('completionnotenabledforsite', 'completion');
}
return $this->content;
} else if (!$info->is_enabled()) {
if ($can_edit) {
$this->content->text .= get_string('completionnotenabledforcourse', 'completion');
}
return $this->content;
}
// Load criteria to display.
$completions = $info->get_completions($USER->id);
// Check if this course has any criteria.
if (empty($completions)) {
if ($can_edit) {
$this->content->text .= get_string('nocriteriaset', 'completion');
}
return $this->content;
}
// Check this user is enroled.
if ($info->is_tracked_user($USER->id)) {
// Generate markup for criteria statuses.
$data = '';
// For aggregating activity completion.
$activities = array();
$activities_complete = 0;
// For aggregating course prerequisites.
$prerequisites = array();
$prerequisites_complete = 0;
// Flag to set if current completion data is inconsistent with what is stored in the database.
$pending_update = false;
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
$complete = $completion->is_complete();
if (!$pending_update && $criteria->is_pending($completion)) {
$pending_update = true;
}
// Activities are a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_ACTIVITY) {
$activities[$criteria->moduleinstance] = $complete;
if ($complete) {
$activities_complete++;
}
continue;
}
// Prerequisites are also a special case, so cache them and leave them till last.
if ($criteria->criteriatype == COMPLETION_CRITERIA_TYPE_COURSE) {
$prerequisites[$criteria->courseinstance] = $complete;
if ($complete) {
$prerequisites_complete++;
}
continue;
}
$row = new html_table_row();
$row->cells[0] = new html_table_cell($criteria->get_title());
$row->cells[1] = new html_table_cell($completion->get_status());
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate activities.
if (!empty($activities)) {
$a = new stdClass();
$a->first = $activities_complete;
$a->second = count($activities);
$row = new html_table_row();
$row->cells[0] = new html_table_cell(get_string('activitiescompleted', 'completion'));
$row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
$row->cells[1]->style = 'text-align: right;';
$srows[] = $row;
}
// Aggregate prerequisites.
if (!empty($prerequisites)) {
$a = new stdClass();
$a->first = $prerequisites_complete;
$a->second = count($prerequisites);
$row = new html_table_row();
$row->cells[0] = new html_table_cell(get_string('dependenciescompleted', 'completion'));
$row->cells[1] = new html_table_cell(get_string('firstofsecond', 'block_completionstatus', $a));
$row->cells[1]->style = 'text-align: right;';
$prows[] = $row;
$srows = array_merge($prows, $srows);
}
// Display completion status.
$table = new html_table();
$table->width = '100%';
$table->attributes = array('style'=>'font-size: 90%;', 'class'=>'');
$row = new html_table_row();
$content = html_writer::tag('b', get_string('status').': ');
// Is course complete?
$coursecomplete = $info->is_course_complete($USER->id);
// Load course completion.
$params = array(
'userid' => $USER->id,
'course' => $course->id
);
$ccompletion = new completion_completion($params);
// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($USER->id);
if ($pending_update) {
$content .= html_writer::tag('i', get_string('pending', 'completion'));
} else if ($coursecomplete) {
$content .= get_string('complete');
} else if (!$criteriacomplete && !$ccompletion->timestarted) {
$content .= html_writer::tag('i', get_string('notyetstarted', 'completion'));
} else {
$content .= html_writer::tag('i', get_string('inprogress', 'completion'));
}
$row->cells[0] = new html_table_cell($content);
$row->cells[0]->colspan = '2';
$rows[] = $row;
$row = new html_table_row();
$content = "";
// Get overall aggregation method.
$overall = $info->get_aggregation_method();
if ($overall == COMPLETION_AGGREGATION_ALL) {
$content .= get_string('criteriarequiredall', 'completion');
} else {
$content .= get_string('criteriarequiredany', 'completion');
}
$content .= ':';
$row->cells[0] = new html_table_cell($content);
$row->cells[0]->colspan = '2';
$rows[] = $row;
$row = new html_table_row();
$row->cells[0] = new html_table_cell(html_writer::tag('b', get_string('requiredcriteria', 'completion')));
$row->cells[1] = new html_table_cell(html_writer::tag('b', get_string('status')));
$row->cells[1]->style = 'text-align: right;';
$rows[] = $row;
// Array merge $rows and $data here.
$rows = array_merge($rows, $srows);
$table->data = $rows;
$this->content->text .= html_writer::table($table);
// Display link to detailed view.
$details = new moodle_url('/blocks/completionstatus/details.php', array('course' => $course->id));
$this->content->footer .= html_writer::link($details, get_string('moredetails', 'completion'));
} else {
// If user is not enrolled, show error.
$this->content->text = get_string('nottracked', 'completion');
}
if (has_capability('report/completion:view', $context)) {
$report = new moodle_url('/report/completion/index.php', array('course' => $course->id));
if (empty($this->content->footer)) {
$this->content->footer = '';
}
$this->content->footer .= html_writer::empty_tag('br');
$this->content->footer .= html_writer::link($report, get_string('viewcoursereport', 'completion'));
}
return $this->content;
}
/**
* This block shouldn't be added to a page if the completion tracking advanced feature is disabled.
*
* @param moodle_page $page
* @return bool
*/
public function can_block_be_added(moodle_page $page): bool {
global $CFG;
return $CFG->enablecompletion;
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Privacy Subsystem implementation for block_completionstatus.
*
* @package block_completionstatus
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace block_completionstatus\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for block_completionstatus implementing null_provider.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+41
View File
@@ -0,0 +1,41 @@
<?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/>.
/**
* Completion status block caps.
*
* @package block_completionstatus
* @copyright Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'block/completionstatus:addinstance' => array(
'riskbitmask' => RISK_SPAM | RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_BLOCK,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:manageblocks'
),
);
+60
View File
@@ -0,0 +1,60 @@
<?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/>.
/**
* This file keeps track of upgrades to the completion status block
*
* Sometimes, changes between versions involve alterations to database structures
* and other major things that may break installations.
*
* The upgrade function in this file will attempt to perform all the necessary
* actions to upgrade your older installation to the current version.
*
* If there's something it cannot do itself, it will tell you what you need to do.
*
* The commands in here will all be database-neutral, using the methods of
* database_manager class
*
* Please do not forget to use upgrade_set_timeout()
* before any action that may take longer time to finish.
*
* @since Moodle 2.0
* @package block_completionstatus
* @copyright 2012 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Handles upgrading instances of this block.
*
* @param int $oldversion
* @param object $block
*/
function xmldb_block_completionstatus_upgrade($oldversion, $block) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+265
View File
@@ -0,0 +1,265 @@
<?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/>.
/**
* Block for displaying logged in user's course completion status
*
* @package block_completionstatus
* @copyright 2009-2012 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../config.php');
require_once("{$CFG->libdir}/completionlib.php");
// Load data.
$id = required_param('course', PARAM_INT);
$userid = optional_param('user', 0, PARAM_INT);
// Load course.
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
// Load user.
if ($userid) {
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
} else {
$user = $USER;
}
// Check permissions.
require_login($course);
if (!completion_can_view_data($user->id, $course)) {
throw new \moodle_exception('cannotviewreport');
}
// Load completion data.
$info = new completion_info($course);
$returnurl = new moodle_url('/course/view.php', array('id' => $id));
// Don't display if completion isn't enabled.
if (!$info->is_enabled()) {
throw new \moodle_exception('completionnotenabled', 'completion', $returnurl);
}
// Check this user is enroled.
if (!$info->is_tracked_user($user->id)) {
if ($USER->id == $user->id) {
throw new \moodle_exception('notenroled', 'completion', $returnurl);
} else {
throw new \moodle_exception('usernotenroled', 'completion', $returnurl);
}
}
// Print header.
$page = get_string('completionprogressdetails', 'block_completionstatus');
$title = format_string($course->fullname) . ': ' . $page;
$PAGE->navbar->add($page);
$PAGE->set_pagelayout('report');
$PAGE->set_url('/blocks/completionstatus/details.php', array('course' => $course->id, 'user' => $user->id));
$PAGE->set_title(get_string('course') . ': ' . $course->fullname);
$PAGE->set_heading($title);
echo $OUTPUT->header();
// Display completion status.
echo html_writer::start_tag('table', array('class' => 'generalbox boxaligncenter'));
echo html_writer::start_tag('tbody');
// If not display logged in user, show user name.
if ($USER->id != $user->id) {
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('showinguser', 'completion') . ' ');
$url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $course->id));
echo html_writer::link($url, fullname($user));
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
}
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('status') . ' ');
// Is course complete?
$coursecomplete = $info->is_course_complete($user->id);
// Has this user completed any criteria?
$criteriacomplete = $info->count_course_user_data($user->id);
// Load course completion.
$params = array(
'userid' => $user->id,
'course' => $course->id,
);
$ccompletion = new completion_completion($params);
// Save row data.
$rows = array();
// Flag to set if current completion data is inconsistent with what is stored in the database.
$pendingupdate = false;
// Load criteria to display.
$completions = $info->get_completions($user->id);
// Loop through course criteria.
foreach ($completions as $completion) {
$criteria = $completion->get_criteria();
if (!$pendingupdate && $criteria->is_pending($completion)) {
$pendingupdate = true;
}
$row = array();
$row['type'] = $criteria->criteriatype;
$row['title'] = $criteria->get_title();
$row['status'] = $completion->get_status();
$row['complete'] = $completion->is_complete();
$row['timecompleted'] = $completion->timecompleted;
$row['details'] = $criteria->get_details($completion);
$rows[] = $row;
}
if ($pendingupdate) {
echo html_writer::tag('i', get_string('pending', 'completion'));
} else if ($coursecomplete) {
echo get_string('complete');
} else if (!$criteriacomplete && !$ccompletion->timestarted) {
echo html_writer::tag('i', get_string('notyetstarted', 'completion'));
} else {
echo html_writer::tag('i', get_string('inprogress', 'completion'));
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// Check if this course has any criteria.
if (empty($completions)) {
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::start_tag('br');
echo $OUTPUT->box(get_string('nocriteriaset', 'completion'), 'noticebox');
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
} else {
echo html_writer::start_tag('tr');
echo html_writer::start_tag('td', array('colspan' => '2'));
echo html_writer::tag('b', get_string('required') . ' ');
// Get overall aggregation method.
$overall = $info->get_aggregation_method();
if ($overall == COMPLETION_AGGREGATION_ALL) {
echo get_string('criteriarequiredall', 'completion');
} else {
echo get_string('criteriarequiredany', 'completion');
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
// Generate markup for criteria statuses.
echo html_writer::start_tag('table',
array('class' => 'generalbox logtable boxaligncenter', 'id' => 'criteriastatus', 'width' => '100%'));
echo html_writer::start_tag('tbody');
echo html_writer::start_tag('tr', array('class' => 'ccheader'));
echo html_writer::tag('th', get_string('criteriagroup', 'block_completionstatus'), array('class' => 'c0 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('criteria', 'completion'), array('class' => 'c1 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('requirement', 'block_completionstatus'), array('class' => 'c2 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('status'), array('class' => 'c3 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('complete'), array('class' => 'c4 header', 'scope' => 'col'));
echo html_writer::tag('th', get_string('completiondate', 'report_completion'), array('class' => 'c5 header', 'scope' => 'col'));
echo html_writer::end_tag('tr');
// Print table.
$last_type = '';
$agg_type = false;
$oddeven = 0;
foreach ($rows as $row) {
echo html_writer::start_tag('tr', array('class' => 'r' . $oddeven));
// Criteria group.
echo html_writer::start_tag('td', array('class' => 'cell c0'));
if ($last_type !== $row['details']['type']) {
$last_type = $row['details']['type'];
echo $last_type;
// Reset agg type.
$agg_type = true;
} else {
// Display aggregation type.
if ($agg_type) {
$agg = $info->get_aggregation_method($row['type']);
echo '('. html_writer::start_tag('i');
if ($agg == COMPLETION_AGGREGATION_ALL) {
echo core_text::strtolower(get_string('all', 'completion'));
} else {
echo core_text::strtolower(get_string('any', 'completion'));
}
echo ' ' . html_writer::end_tag('i') .core_text::strtolower(get_string('required')).')';
$agg_type = false;
}
}
echo html_writer::end_tag('td');
// Criteria title.
echo html_writer::start_tag('td', array('class' => 'cell c1'));
echo $row['details']['criteria'];
echo html_writer::end_tag('td');
// Requirement.
echo html_writer::start_tag('td', array('class' => 'cell c2'));
echo $row['details']['requirement'];
echo html_writer::end_tag('td');
// Status.
echo html_writer::start_tag('td', array('class' => 'cell c3'));
echo $row['details']['status'];
echo html_writer::end_tag('td');
// Is complete.
echo html_writer::start_tag('td', array('class' => 'cell c4'));
echo $row['complete'] ? get_string('yes') : get_string('no');
echo html_writer::end_tag('td');
// Completion data.
echo html_writer::start_tag('td', array('class' => 'cell c5'));
if ($row['timecompleted']) {
echo userdate($row['timecompleted'], get_string('strftimedatemonthtimeshort', 'langconfig'));
} else {
echo '-';
}
echo html_writer::end_tag('td');
echo html_writer::end_tag('tr');
// For row striping.
$oddeven = $oddeven ? 0 : 1;
}
echo html_writer::end_tag('tbody');
echo html_writer::end_tag('table');
}
echo $OUTPUT->footer();
@@ -0,0 +1,32 @@
<?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/>.
/**
* Strings for component 'block_completionstatus', language 'en', branch 'MOODLE_20_STABLE'
*
* @package block_completionstatus
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['completionprogressdetails'] = 'Completion progress details';
$string['completionstatus:addinstance'] = 'Add a new course completion status block';
$string['criteriagroup'] = 'Criteria group';
$string['firstofsecond'] = '{$a->first} of {$a->second}';
$string['pluginname'] = 'Course completion status';
$string['requirement'] = 'Requirement';
$string['returntocourse'] = 'Return to course';
$string['privacy:metadata'] = 'The Course completion status block only shows information about course completion and does not store any data of its own.';
@@ -0,0 +1,54 @@
@block @block_completionstatus
Feature: Enable Block Completion in a course
In order to view the completion block in a course
As a teacher
I can add completion block to a course
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
Scenario: Add the block to a the course where completion is disabled
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Enable completion tracking | No |
And I press "Save and display"
When I add the "Course completion status" block
Then I should see "Completion is not enabled for this course" in the "Course completion status" "block"
Scenario: Add the block to a the course where completion is not set
Given I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
When I add the "Course completion status" block
Then I should see "No completion criteria set for this course" in the "Course completion status" "block"
Scenario: Add the block to a course with criteria and view as an untracked role.
Given the following "activities" exist:
| activity | course | idnumber | name | intro |
| page | C1 | page1 | Test page name | Test page description |
And I log in as "teacher1"
And I am on "Course 1" course homepage with editing mode on
And I follow "Test page name"
And I navigate to "Settings" in current page administration
And I set the following fields to these values:
| Add requirements | 1 |
| View the activity | 1 |
And I press "Save and return to course"
When I add the "Course completion status" block
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test page name | 1 |
And I press "Save changes"
Then I should see "You are currently not being tracked by completion in this course" in the "Course completion status" "block"
@@ -0,0 +1,88 @@
@block @block_completionstatus @core_completion
Feature: Enable Block Completion in a course using activity completion
In order to view the completion block in a course
As a teacher
I can add completion block to a course and set up activity completion
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activities" exist:
| activity | course | idnumber | name | gradepass | completion | completionview | completionusegrade | completionpassgrade |
| page | C1 | page1 | Test page name | | 2 | 1 | 0 | 0 |
| assign | C1 | assign1 | Test assign name | 50 | 2 | 0 | 1 | 1 |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| completionstatus | Course | C1 | course-view-* | side-pre |
Scenario: Completion status block when student has not started any activities
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test page name | 1 |
And I press "Save changes"
When I am on the "Course 1" course page logged in as student1
Then I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "0 of 1" in the "Activity completion" "table_row"
Scenario: Completion status block when student has completed a page
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test page name | 1 |
And I press "Save changes"
When I am on the "Test page name" "page activity" page logged in as student1
And I am on "Course 1" course homepage
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "1 of 1" in the "Activity completion" "table_row"
And I follow "More details"
And I should see "Yes" in the "Activity completion" "table_row"
Scenario: Completion status block with items with passing grade
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test assign name | 1 |
And I press "Save changes"
And the following "grade grades" exist:
| gradeitem | user | grade |
| Test assign name | student1 | 53 |
When I am on the "Course 1" course page logged in as student1
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "1 of 1" in the "Activity completion" "table_row"
And I trigger cron
And I am on "Course 1" course homepage
And I follow "More details"
And I should see "Achieving grade, Achieving passing grade" in the "Activity completion" "table_row"
And I should see "Yes" in the "Activity completion" "table_row"
Scenario: Completion status block with items with failing grade
Given I am on the "Course 1" course page logged in as teacher1
And the following "grade grades" exist:
| gradeitem | user | grade |
| Test assign name | student1 | 49 |
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Test assign name | 1 |
And I press "Save changes"
When I am on the "Course 1" course page logged in as student1
Then I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "0 of 1" in the "Activity completion" "table_row"
And I trigger cron
And I am on "Course 1" course homepage
And I follow "More details"
And I should see "Achieving grade, Achieving passing grade" in the "Activity completion" "table_row"
And I should see "No" in the "Activity completion" "table_row"
@@ -0,0 +1,89 @@
@block @block_completionstatus
Feature: Enable Block Completion in a course using manual completion by others
In order to view the completion block in a course
As a teacher
I can add completion block to a course and set up manual completion by others
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| teacher2 | Teacher | 2 | teacher1@example.com | T2 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher2 | C1 | teacher |
| student1 | C1 | student |
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| completionstatus | Course | C1 | course-view-* | side-pre |
Scenario: Add the block to a the course and mark a student complete.
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Teacher | 1 |
And I press "Save changes"
When I am on the "Course 1" course page logged in as student1
And I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "No" in the "Teacher" "table_row"
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Reports" in current page administration
And I click on "Course completion" "link" in the "region-main" "region"
And I follow "Click to mark user complete"
# Running completion task just after clicking sometimes fail, as record
# should be created before the task runs.
And I wait "1" seconds
And I run the scheduled task "core\task\completion_regular_task"
And I am on site homepage
And I am on the "Course 1" course page logged in as student1
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "Yes" in the "Teacher" "table_row"
And I follow "More details"
And I should see "Yes" in the "Marked complete by Teacher" "table_row"
Scenario: Add the block to a the course and require multiple roles to mark a student complete.
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| Teacher | 1 |
| Non-editing teacher | 1 |
| id_role_aggregation | ALL selected roles to mark when the condition is met |
And I press "Save changes"
When I am on the "Course 1" course page logged in as student1
And I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "No" in the "Teacher" "table_row"
And I should see "No" in the "Non-editing teacher" "table_row"
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Reports" in current page administration
And I click on "Course completion" "link" in the "region-main" "region"
And I follow "Click to mark user complete"
And I am on the "Course 1" course page logged in as student1
And I should see "Status: In progress" in the "Course completion status" "block"
And I should see "Yes" in the "Teacher" "table_row"
And I should see "No" in the "Non-editing teacher" "table_row"
And I follow "More details"
And I should see "Yes" in the "Marked complete by Teacher" "table_row"
And I should see "No" in the "Marked complete by Non-editing teacher" "table_row"
And I am on the "Course 1" course page logged in as teacher2
And I navigate to "Reports" in current page administration
And I click on "Course completion" "link" in the "region-main" "region"
And I follow "Click to mark user complete"
# Running completion task just after clicking sometimes fail, as record
# should be created before the task runs.
And I wait "1" seconds
And I run the scheduled task "core\task\completion_regular_task"
And I am on site homepage
And I am on the "Course 1" course page logged in as student1
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "Yes" in the "Teacher" "table_row"
And I should see "Yes" in the "Non-editing teacher" "table_row"
And I follow "More details"
And I should see "Yes" in the "Marked complete by Teacher" "table_row"
And I should see "Yes" in the "Marked complete by Non-editing teacher" "table_row"
@@ -0,0 +1,45 @@
@block @block_completionstatus @block_selfcompletion
Feature: Enable Block Completion in a course using manual self completion
In order to view the completion block in a course
As a teacher
I can add completion block to a course and set up manual self completion
Scenario: Add the block to a the course and manually complete the course
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@example.com | T1 |
| student1 | Student | 1 | student1@example.com | S1 |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I enable "selfcompletion" "block" plugin
And the following "blocks" exist:
| blockname | contextlevel | reference | pagetypepattern | defaultregion |
| completionstatus | Course | C1 | course-view-* | side-pre |
| selfcompletion | Course | C1 | course-view-* | side-pre |
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Course completion" in current page administration
And I expand all fieldsets
And I set the following fields to these values:
| id_criteria_self | 1 |
And I press "Save changes"
When I am on the "Course 1" course page logged in as student1
And I should see "Status: Not yet started" in the "Course completion status" "block"
And I should see "No" in the "Self completion" "table_row"
And I follow "Complete course"
And I should see "Confirm self completion"
And I press "Yes"
And I should see "Status: In progress" in the "Course completion status" "block"
# Running completion task just after clicking sometimes fail, as record
# should be created before the task runs.
And I wait "1" seconds
And I run the scheduled task "core\task\completion_regular_task"
And I am on "Course 1" course homepage
Then I should see "Status: Complete" in the "Course completion status" "block"
And I should see "Yes" in the "Self completion" "table_row"
And I follow "More details"
And I should see "Yes" in the "Self completion" "table_row"
@@ -0,0 +1,63 @@
<?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/>.
namespace block_completionstatus;
use advanced_testcase;
use block_completionstatus;
use context_course;
/**
* PHPUnit block_completionstatus tests
*
* @package block_completionstatus
* @category test
* @copyright 2021 Sara Arjona (sara@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @coversDefaultClass \block_completionstatus
*/
class completionstatus_test extends advanced_testcase {
public static function setUpBeforeClass(): void {
require_once(__DIR__ . '/../../moodleblock.class.php');
require_once(__DIR__ . '/../block_completionstatus.php');
}
/**
* Test the behaviour of can_block_be_added() method.
*
* @covers ::can_block_be_added
*/
public function test_can_block_be_added(): void {
$this->resetAfterTest();
$this->setAdminUser();
// Create a course and prepare the page where the block will be added.
$course = $this->getDataGenerator()->create_course();
$page = new \moodle_page();
$page->set_context(context_course::instance($course->id));
$page->set_pagelayout('course');
$block = new block_completionstatus();
// If blogs advanced feature is enabled, the method should return true.
set_config('enablecompletion', true);
$this->assertTrue($block->can_block_be_added($page));
// However, if the blogs advanced feature is disabled, the method should return false.
set_config('enablecompletion', false);
$this->assertFalse($block->can_block_be_added($page));
}
}
+31
View File
@@ -0,0 +1,31 @@
<?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/>.
/**
* Version info
*
* @package block_completionstatus
* @copyright 2009 Catalyst IT Ltd
* @author Aaron Barnes <aaronb@catalyst.net.nz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'block_completionstatus';
$plugin->dependencies = ['report_completion' => 2024041600];