Skip to content

Commit

Permalink
Merge tag 'v1.8' into show-user-v1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
timwsuqld committed Sep 27, 2023
2 parents 39bfed8 + 30544e0 commit 286a8ab
Show file tree
Hide file tree
Showing 10 changed files with 234 additions and 131 deletions.
117 changes: 117 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Moodle plugin CI
on: [push, pull_request]

jobs:
test:
runs-on: 'ubuntu-latest'
strategy:
fail-fast: false
matrix:
include:
- php: '7.4'
moodle-branch: 'master'
database: 'pgsql'
- php: '7.4'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '7.3'
moodle-branch: 'MOODLE_310_STABLE'
database: 'pgsql'
- php: '7.2'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'

services:
postgres:
image: postgres
env:
POSTGRES_USER: 'postgres'
POSTGRES_HOST_AUTH_METHOD: 'trust'
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 3
ports:
- 5432:5432

mariadb:
image: mariadb
env:
MYSQL_USER: 'root'
MYSQL_ALLOW_EMPTY_PASSWORD: "true"
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval 10s --health-timeout 5s --health-retries 3

steps:
- name: Checkout
uses: actions/checkout@v2
with:
path: plugin

- name: Install node
uses: actions/setup-node@v1
with:
node-version: '14.15.0'

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, pgsql, mysqli

- name: Deploy moodle-plugin-ci
run: |
composer create-project -n --no-dev --prefer-dist moodlehq/moodle-plugin-ci ci ^3
# Add dirs to $PATH
echo $(cd ci/bin; pwd) >> $GITHUB_PATH
echo $(cd ci/vendor/bin; pwd) >> $GITHUB_PATH
# PHPUnit depends on en_AU.UTF-8 locale
sudo locale-gen en_AU.UTF-8
- name: Install Moodle
run: moodle-plugin-ci install --plugin ./plugin --db-host=127.0.0.1
env:
DB: ${{ matrix.database }}
MOODLE_BRANCH: ${{ matrix.moodle-branch }}

- name: phplint
if: ${{ always() }}
run: moodle-plugin-ci phplint

- name: phpcpd
if: ${{ always() }}
run: moodle-plugin-ci phpcpd

- name: phpmd
if: ${{ always() }}
run: moodle-plugin-ci phpmd

- name: codechecker
if: ${{ always() }}
run: moodle-plugin-ci codechecker

- name: validate
if: ${{ always() }}
run: moodle-plugin-ci validate

- name: savepoints
if: ${{ always() }}
run: moodle-plugin-ci savepoints

- name: mustache
if: ${{ always() }}
run: moodle-plugin-ci mustache

- name: grunt
if: ${{ always() }}
run: moodle-plugin-ci grunt

- name: phpunit
if: ${{ always() }}
run: moodle-plugin-ci phpunit

- name: behat
if: ${{ always() }}
run: moodle-plugin-ci behat --profile chrome
57 changes: 0 additions & 57 deletions .travis.yml

This file was deleted.

3 changes: 0 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ This 'report' is actually a tool like the standard Manual grading quiz report,
but which lets you grade all the responses by one student, rather than all
the responses to one question.

This version of the plugin, which is compatible with Moodle 3.4+ and later.
Older versions of this plugin will work with older Moodle versions.

You can install it from the Moodle plugins database using the link above.

Alternatively, you can install it using git. In the top-level folder of your
Expand Down
10 changes: 10 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change log for the Manual grading by student quiz report

## Changes in 1.8

* Fix capability checks when showing a link to the review page.


## Changes in 1.7

* Moodle 3.9 compatibility.
* Small OU-specific change for quiz_answersheets plugin.


## Changes in 1.6

Expand Down
51 changes: 49 additions & 2 deletions examconfirmationcode.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ class quiz_gradingstudents_report_exam_confirmation_code {
/** @var int value used in the calculation. */
const NUM_CODES = 194481; // This equals 21*21*21*21.

/**
* Can a quiz with this idnumber have a confirmation code?
*
* @param string|null $quizidnumber the quiz idnumber.
* @return string|null string like eca01 or exm01 if it can, null if it can't.
*/
public static function quiz_can_have_confirmation_code(?string $quizidnumber) {
if (!preg_match('~\w+-\w+\.((?i:eca|exm|icme)\d+)~', $quizidnumber, $matches)) {
return null;
}

return $matches[1];
}

/**
* Check for the correct idnumber and generate a confirmation code
*
Expand All @@ -55,12 +69,13 @@ class quiz_gradingstudents_report_exam_confirmation_code {
* @return null|string the computed code if relevant, else null.
*/
public static function get_confirmation_code($quizidnumber, $pi, $version = 1) {
if (!preg_match('~\w+-\w+\.((?i:eca|exm)\d+)~', $quizidnumber, $matches)) {
$task = self::quiz_can_have_confirmation_code($quizidnumber);
if (!$task) {
return null;
}
list($courseshortname, $notused) = explode('.', $quizidnumber, 2);
list($module, $pres) = explode('-', $courseshortname, 2);
$task = core_text::strtoupper($matches[1]);
$task = core_text::strtoupper($task);
$module = core_text::strtoupper($module);
$pres = core_text::strtoupper($pres);
return self::calculate_confirmation_code($pi, $module, $pres, $task, $version);
Expand Down Expand Up @@ -110,4 +125,36 @@ public static function calculate_hash($string) {

return $code;
}

/**
* Get the IDNumber of student that need to grade
*
* @param int $qubaid The id of question usage that need to grade
* @param int $quizid The id of quiz that need to grade
* @return string IDNumber of student that need to grade
*/
public static function get_student_id_number_by_question_usage_id($qubaid, $quizid): string {
global $DB;

$idnumber = '';
$params = [
'uniqueid' => $qubaid,
'state' => quiz_attempt::FINISHED,
'quiz' => $quizid
];

$attempt = $DB->get_record_sql('
SELECT u.idnumber
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
WHERE quiza.uniqueid = :uniqueid
AND quiza.state = :state
AND quiza.quiz = :quiz', $params);

if ($attempt) {
$idnumber = $attempt->idnumber;
}

return $idnumber;
}
}
2 changes: 1 addition & 1 deletion report.php
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ protected function display_index($includeauto) {
if (!$includeauto && $attempt->needsgrading == 0 && $attempt->manuallygraded == 0) {
continue;
}
if (has_capability ('mod/quiz:attempt', $this->context)) {
if (has_capability('mod/quiz:viewreports', $this->context)) {
$reviewlink = html_writer::tag('a',
get_string('attemptid', 'quiz_gradingstudents', $attempt->attemptnumber),
array('href' => new moodle_url('/mod/quiz/review.php',
Expand Down
74 changes: 23 additions & 51 deletions tests/behat/gradingstudents.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,80 +4,52 @@ Feature: Grading by students
Background:
Given the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | T1 | Teacher1 | teacher1@moodle.com | T1000 |
| teacher | T1 | Teacher | teacher@moodle.com | T1000 |
| student1 | S1 | Student1 | student1@moodle.com | S1000 |
| student2 | S2 | Student2 | student2@moodle.com | S2000 |
And the following "courses" exist:
| fullname | shortname | category |
| Course 1 | C1 | 0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| teacher | C1 | editingteacher |
| student1 | C1 | student |
| student2 | C1 | student |
When I log in as "admin"
And I am on "Course 1" course homepage
And I turn editing mode on
And I add a "Quiz" to section "1" and I fill the form with:
| Name | Quiz 1 |
| Description | Quiz 1 description |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "activities" exist:
| activity | name | course | idnumber |
| quiz | Quiz 1 | C1 | q1 |
And the following "questions" exist:
| questioncategory | qtype | name |
| Test questions | shortanswer | SA |
And quiz "Quiz 1" contains the following questions:
| question | page | maxmark |
| SA | 1 | |

And I add a "Short answer" question to the "Quiz 1" quiz with:
| Question name | Short answer 001 |
| Question text | Where is the capital city of France? |
| Answer 1 | Paris |
| Grade | 100% |

And I log out

@javascript
Scenario: report with no attempts
When I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
When I am on the "Quiz 1" "mod_quiz > View" page logged in as "teacher"
And I navigate to "Results > Manual grading by student" in current page administration
Then I should see "Manual grading by student"
And I should see "Quiz 1"
And I should see "Nothing to display"

@javascript
Scenario: Report with attempts
When I log in as "student1"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
And I press "Attempt quiz now"
Then I should see "Question 1"
And I should see "Not yet answered"
And I should see "Where is the capital city of France?"
When I set the field "Answer:" to "Paris"
And I press "Finish attempt ..."
Then I should see "Answer saved"
When I press "Submit all and finish"
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
And I log out

When I log in as "student2"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
And I press "Attempt quiz now"
Then I should see "Question 1"
And I should see "Not yet answered"
And I should see "Where is the capital city of France?"
When I set the field "Answer:" to "London or Berlin"
And I press "Finish attempt ..."
Then I should see "Answer saved"
When I press "Submit all and finish"
And I click on "Submit all and finish" "button" in the "Confirmation" "dialogue"
And I log out
Given user "student1" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | Frog |
And user "student2" has attempted "Quiz 1" with responses:
| slot | response |
| 1 | Cat |

When I log in as "teacher1"
And I am on "Course 1" course homepage
And I follow "Quiz 1"
When I am on the "Quiz 1" "mod_quiz > View" page logged in as "teacher"
And I navigate to "Results > Manual grading by student" in current page administration
Then I should see "Manual grading by student"
When I follow "Also show questions that have been graded automatically"
Then I should see "S1000"
And I should see "S2000"
And "Attempt 1" "link" should exist

# Adjust the mark for Student1
When I click on "update grades" "link" in the "S1000" "table_row"
Expand Down
Loading

0 comments on commit 286a8ab

Please sign in to comment.