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,99 @@
<?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/>.
/**
* The report_questioninstances report viewed event.
*
* @package report_questioninstances
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_questioninstances\event;
defined('MOODLE_INTERNAL') || die();
/**
* The report_questioninstances report viewed event class.
*
* @property-read array $other {
* Extra information about the event.
*
* - string requestedqtype: Requested question type.
* }
*
* @package report_questioninstances
* @since Moodle 2.7
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class report_viewed extends \core\event\base {
/**
* Init method.
*
* @return void
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_OTHER;
$this->context = \context_system::instance();
}
/**
* Return localised event name.
*
* @return string
*/
public static function get_name() {
return get_string('eventreportviewed', 'report_questioninstances');
}
/**
* Returns description of what happened.
*
* @return string
*/
public function get_description() {
return "The user with id '$this->userid' viewed the question instances report.";
}
/**
* Returns relevant URL.
*
* @return \moodle_url
*/
public function get_url() {
return new \moodle_url('/report/questioninstances/index.php', array('qtype' => $this->other['requestedqtype']));
}
/**
* Custom validation.
*
* @throws \coding_exception
*/
protected function validate_data() {
parent::validate_data();
if (!isset($this->other['requestedqtype'])) {
throw new \coding_exception('The \'requestedqtype\' value must be set in other.');
}
}
public static function get_other_mapping() {
// Nothing to map.
return false;
}
}
@@ -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 report_questioninstances.
*
* @package report_questioninstances
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace report_questioninstances\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for report_questioninstances 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';
}
}
+38
View File
@@ -0,0 +1,38 @@
<?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/>.
/**
* Capabilities
*
* @package report_questioninstances
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'report/questioninstances:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_SYSTEM,
'archetypes' => array(
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/site:config',
)
);
+173
View File
@@ -0,0 +1,173 @@
<?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/>.
/**
* For a given question type, list the number of
*
* @package report
* @subpackage questioninstances
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../config.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/questionlib.php');
// Get URL parameters.
$requestedqtype = optional_param('qtype', '', PARAM_SAFEDIR);
// Print the header & check permissions.
admin_externalpage_setup('reportquestioninstances', '', null, '', array('pagelayout'=>'report'));
$PAGE->set_primary_active_tab('siteadminnode');
echo $OUTPUT->header();
// Log.
\report_questioninstances\event\report_viewed::create(array('other' => array('requestedqtype' => $requestedqtype)))->trigger();
// Prepare the list of capabilities to choose from
$qtypes = question_bank::get_all_qtypes();
$qtypechoices = array();
foreach ($qtypes as $qtype) {
$qtypechoices[$qtype->name()] = $qtype->local_name();
}
// Print the settings form.
echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter centerpara');
echo '<form method="get" action="." id="settingsform"><div>';
echo $OUTPUT->heading(get_string('reportsettings', 'report_questioninstances'));
echo '<p id="intro">', get_string('intro', 'report_questioninstances') , '</p>';
echo '<p><label for="menuqtype"> ' . get_string('questiontype', 'admin') . '</label> ';
echo html_writer::select($qtypechoices, 'qtype', $requestedqtype, array('_all_'=>get_string('all')));
echo '</p>';
echo '<p><input type="submit" class="btn btn-secondary" id="settingssubmit" value="' .
get_string('getreport', 'report_questioninstances') . '" /></p>';
echo '</div></form>';
echo $OUTPUT->box_end();
$params[] = \core_question\local\bank\question_version_status::QUESTION_STATUS_HIDDEN;
// If we have a qtype to report on, generate the report.
if ($requestedqtype) {
// Work out the bits needed for the SQL WHERE clauses.
if ($requestedqtype == 'missingtype') {
$title = get_string('reportformissingqtypes', 'report_questioninstances');
$othertypes = array_keys($qtypes);
$key = array_search('missingtype', $othertypes);
unset($othertypes[$key]);
list($sqlqtypetest, $params) = $DB->get_in_or_equal($othertypes, SQL_PARAMS_QM, '', false);
$sqlqtypetest = 'WHERE qtype ' . $sqlqtypetest;
} else if ($requestedqtype == '_all_') {
$title = get_string('reportforallqtypes', 'report_questioninstances');
$sqlqtypetest = '';
} else {
$title = get_string('reportforqtype', 'report_questioninstances',
question_bank::get_qtype($requestedqtype)->local_name());
$sqlqtypetest = 'WHERE qtype = ?';
$params [] = $requestedqtype;
}
// Get the question counts, and all the context information, for each
// context. That is, rows of these results can be used as $context objects.
$ctxpreload = context_helper::get_preload_record_columns_sql('con');
$ctxgroupby = implode(',', array_keys(context_helper::get_preload_record_columns('con')));
$counts = $DB->get_records_sql("
SELECT result.contextid, SUM(numquestions) AS numquestions, SUM(numhidden) AS numhidden, $ctxpreload
FROM (SELECT data.contextid, data.versionid, COUNT(data.numquestions) AS numquestions,
(SELECT COUNT(qv.id)
FROM {question_versions} qv
WHERE qv.id = data.versionid
AND qv.status = ?) AS numhidden
FROM (SELECT qv.id as versionid, qc.contextid, 1 AS numquestions
FROM {question} q
JOIN {question_versions} qv ON qv.questionid = q.id
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
JOIN {question_categories} qc ON qc.id = qbe.questioncategoryid
JOIN {context} con ON con.id = qc.contextid
$sqlqtypetest
AND qv.version = (SELECT MAX(v.version)
FROM {question_versions} v
JOIN {question_bank_entries} be
ON be.id = v.questionbankentryid
WHERE be.id = qbe.id)
AND (q.parent = 0 OR q.parent = q.id)) data
GROUP BY data.contextid, data.versionid) result
JOIN {context} con ON con.id = result.contextid
GROUP BY result.contextid, $ctxgroupby
ORDER BY numquestions DESC, numhidden ASC, con.contextlevel ASC, con.id ASC", $params);
// Print the report heading.
echo $OUTPUT->heading($title);
// Initialise the table.
$table = new html_table();
$table->head = array(
get_string('context', 'role'),
get_string('totalquestions', 'report_questioninstances'),
get_string('visiblequestions', 'report_questioninstances'),
get_string('hiddenquestions', 'report_questioninstances'));
$table->data = array();
$table->class = '';
$table->id = '';
// Add the data for each row.
$totalquestions = 0;
$totalvisible = 0;
$totalhidden = 0;
foreach ($counts as $count) {
// Work out a link for editing questions in this context.
context_helper::preload_from_record($count);
$context = context::instance_by_id($count->contextid);
$contextname = $context->get_context_name();
$url = question_edit_url($context);
if ($url) {
$contextname = '<a href="' . $url . '" title="' .
get_string('editquestionshere', 'report_questioninstances') .
'">' . $contextname . '</a>';
}
// Put the scores in the table.
$numvisible = $count->numquestions - $count->numhidden;
$table->data[] = array(
$contextname,
$count->numquestions,
$numvisible,
$count->numhidden);
// Update the totals.
$totalquestions += $count->numquestions;
$totalvisible += $numvisible;
$totalhidden += $count->numhidden;
}
// Add a totals row.
$table->data[] = array(
'<b>' . get_string('total') . '</b>',
$totalquestions,
$totalvisible,
$totalhidden);
// Print it.
echo html_writer::table($table);
}
// Footer.
echo $OUTPUT->footer();
@@ -0,0 +1,39 @@
<?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/>.
/**
* lang strings
*
* @package report
* @subpackage questioninstances
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['editquestionshere'] = 'Edit questions in this context';
$string['eventreportviewed'] = 'Report viewed';
$string['getreport'] = 'Get the report';
$string['hiddenquestions'] = 'Hidden';
$string['intro'] = 'This report lists all the contexts in the system where there are questions of a particular type.';
$string['pluginname'] = 'Question instances';
$string['questioninstances:view'] = 'View question instances report';
$string['reportforallqtypes'] = 'Report for all question types';
$string['reportformissingqtypes'] = 'Report for question of unknown types';
$string['reportforqtype'] = 'Report for question type \'{$a}\'';
$string['reportsettings'] = 'Report settings';
$string['totalquestions'] = 'Total';
$string['visiblequestions'] = 'Visible';
$string['privacy:metadata'] = 'The Question instances plugin does not store any personal data.';
+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/>.
/**
* Settings and links
*
* @package report
* @subpackage questioninstances
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
$ADMIN->add('reports', new admin_externalpage('reportquestioninstances', get_string('pluginname', 'report_questioninstances'), "$CFG->wwwroot/report/questioninstances/index.php", 'report/questioninstances:view'));
// no report settings
$settings = null;
@@ -0,0 +1,56 @@
@core @core_question @report @report_questioninstance
Feature: A Teacher can generate question instance reports
In order to see question instance reports
As a Teacher
I need to generate them
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | weeks |
And the following "question categories" exist:
| contextlevel | reference | name |
| Course | C1 | Test questions |
And the following "activities" exist:
| activity | course | name |
| quiz | C1 | Test quiz Q001 |
And the following "questions" exist:
| questioncategory | qtype | name |
| Test questions | truefalse | TF |
| Test questions | shortanswer | SA |
And quiz "Test quiz Q001" contains the following questions:
| question | page | maxmark |
| TF | 1 | 5.0 |
| SA | 1 | 5.0 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
And the following "question categories" exist:
| contextlevel | reference | name |
| Activity module | Test quiz Q001 | Quiz category |
Scenario: Generate general and specific report
Given I am on the "C1" "Course" page logged in as "admin"
And I navigate to "Reports > Question instances" in site administration
When I press "Get the report"
Then "Course: Course 1" row "Total" column of "generaltable" table should contain "2"
And "Course: Course 1" row "Visible" column of "generaltable" table should contain "2"
And "Course: Course 1" row "Hidden" column of "generaltable" table should contain "0"
Scenario: Generate report displaying hidden questions
Given I am on the "Test quiz Q001" "mod_quiz > question bank" page logged in as "admin"
And I choose "Delete" action for "TF" in the question bank
And I press "Delete"
And I navigate to "Reports > Question instances" in site administration
When I press "Get the report"
Then "Course: Course 1" row "Total" column of "generaltable" table should contain "2"
And "Course: Course 1" row "Visible" column of "generaltable" table should contain "1"
And "Course: Course 1" row "Hidden" column of "generaltable" table should contain "1"
And I set the field "menuqtype" to "True/False"
And I press "Get the report"
And "Course: Course 1" row "Total" column of "generaltable" table should contain "1"
And "Course: Course 1" row "Visible" column of "generaltable" table should contain "0"
And "Course: Course 1" row "Hidden" column of "generaltable" table should contain "1"
@@ -0,0 +1,64 @@
<?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/>.
/**
* Tests for question instances events.
*
* @package report_questioninstances
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
namespace report_questioninstances\event;
/**
* Class for question instances events.
*
* @package report_questioninstances
* @copyright 2014 Petr Skoda
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
class events_test extends \advanced_testcase {
/**
* Setup testcase.
*/
public function setUp(): void {
$this->setAdminUser();
$this->resetAfterTest();
}
/**
* Test the report viewed event.
*/
public function test_report_viewed(): void {
$requestedqtype = 'all';
$event = \report_questioninstances\event\report_viewed::create(array('other' => array('requestedqtype' => $requestedqtype)));
// Trigger and capture the event.
$sink = $this->redirectEvents();
$event->trigger();
$events = $sink->get_events();
$event = reset($events);
$this->assertInstanceOf('\report_questioninstances\event\report_viewed', $event);
$this->assertEquals(\context_system::instance(), $event->get_context());
$this->assertEventContextNotUsed($event);
$url = new \moodle_url('/report/questioninstances/index.php', array('qtype' => $requestedqtype));
$this->assertEquals($url, $event->get_url());
$event->get_name();
}
}
+30
View File
@@ -0,0 +1,30 @@
<?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 report
* @subpackage questioninstances
* @copyright 2008 Tim Hunt
* @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 = 'report_questioninstances'; // Full name of the plugin (used for diagnostics)