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,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 quizaccess_offlineattempts.
*
* @package quizaccess_offlineattempts
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace quizaccess_offlineattempts\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for quizaccess_offlineattempts implementing null_provider.
*
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
* @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';
}
}
@@ -0,0 +1,37 @@
<?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 the quizaccess_offlineattempts plugin.
*
* @package quizaccess_offlineattempts
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['allowofflineattempts'] = 'Allow quiz to be attempted offline using the mobile app';
$string['allowofflineattempts_help'] = 'If enabled, a mobile app user can download the quiz and attempt it offline.
Note: It is not possible for a quiz to be attempted offline if it has a time limit, or requires a network address, or uses any question behaviour other than deferred feedback (with or without CBM), or uses sequential navigation.';
$string['confirmdatasaved'] = 'I confirm that I do not have any unsaved work on a mobile device.';
$string['mobileapp'] = 'Mobile app';
$string['offlineattemptserror'] = 'It is not possible for a quiz to be attempted offline if it has a time limit, or requires a network address, or uses any question behaviour other than deferred feedback (with or without CBM), or uses sequential navigation.';
$string['offlinedatamessage'] = 'You have worked on this attempt using a mobile device. Data was last saved to this site {$a} ago.';
$string['pleaseconfirm'] = 'Please check and confirm that you do not have any unsaved work.';
$string['pluginname'] = 'Offline attempts access rule';
$string['privacy:metadata'] = 'The Offline attempts quiz access rule plugin does not store any personal data.';
@@ -0,0 +1,134 @@
<?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/>.
use mod_quiz\form\preflight_check_form;
use mod_quiz\local\access_rule_base;
use mod_quiz\quiz_settings;
/**
* A rule implementing the offlineattempts check.
*
* @package quizaccess_offlineattempts
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.2
*/
class quizaccess_offlineattempts extends access_rule_base {
public static function make(quiz_settings $quizobj, $timenow, $canignoretimelimits) {
global $CFG;
// If mobile services are off, the user won't be able to use any external app.
if (empty($CFG->enablemobilewebservice) or empty($quizobj->get_quiz()->allowofflineattempts)) {
return null;
}
return new self($quizobj, $timenow);
}
public function is_preflight_check_required($attemptid) {
global $SESSION, $DB;
// First, check if the user did something offline.
if (!empty($attemptid)) {
$timemodifiedoffline = $DB->get_field('quiz_attempts', 'timemodifiedoffline', ['id' => $attemptid]);
if (empty($timemodifiedoffline)) {
return false;
}
return empty($SESSION->offlineattemptscheckedquizzes[$this->quiz->id]);
} else {
// Starting a new attempt, we don't have to check anything here.
return false;
}
}
public function add_preflight_check_form_fields(preflight_check_form $quizform,
MoodleQuickForm $mform, $attemptid) {
global $DB;
$timemodifiedoffline = $DB->get_field('quiz_attempts', 'timemodifiedoffline', ['id' => $attemptid]);
$lasttime = format_time(time() - $timemodifiedoffline);
$mform->addElement('header', 'offlineattemptsheader', get_string('mobileapp', 'quizaccess_offlineattempts'));
$mform->addElement('static', 'offlinedatamessage', '',
get_string('offlinedatamessage', 'quizaccess_offlineattempts', $lasttime));
$mform->addElement('advcheckbox', 'confirmdatasaved', null,
get_string('confirmdatasaved', 'quizaccess_offlineattempts'));
}
public function validate_preflight_check($data, $files, $errors, $attemptid) {
// The user confirmed that he doesn't have unsaved work.
if (!empty($data['confirmdatasaved'])) {
return $errors;
}
$errors['confirmdatasaved'] = get_string('pleaseconfirm', 'quizaccess_offlineattempts');
return $errors;
}
public function notify_preflight_check_passed($attemptid) {
global $SESSION;
$SESSION->offlineattemptscheckedquizzes[$this->quiz->id] = true;
}
public function current_attempt_finished() {
global $SESSION;
// Clear the flag in the session that says that the user has already agreed to the notice.
if (!empty($SESSION->offlineattemptscheckedquizzes[$this->quiz->id])) {
unset($SESSION->offlineattemptscheckedquizzes[$this->quiz->id]);
}
}
public static function add_settings_form_fields(
mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
global $CFG;
// Allow to enable the access rule only if the Mobile services are enabled.
if ($CFG->enablemobilewebservice) {
$mform->addElement('selectyesno', 'allowofflineattempts',
get_string('allowofflineattempts', 'quizaccess_offlineattempts'));
$mform->addHelpButton('allowofflineattempts', 'allowofflineattempts', 'quizaccess_offlineattempts');
$mform->setDefault('allowofflineattempts', 0);
$mform->setAdvanced('allowofflineattempts');
$mform->disabledIf('allowofflineattempts', 'timelimit[number]', 'neq', 0);
$mform->disabledIf('allowofflineattempts', 'subnet', 'neq', '');
$mform->disabledIf('allowofflineattempts', 'navmethod', 'eq', 'sequential');
}
}
public static function validate_settings_form_fields(array $errors,
array $data, $files, mod_quiz_mod_form $quizform) {
global $CFG;
if ($CFG->enablemobilewebservice) {
// Do not allow offline attempts if:
// - The quiz uses a timer.
// - The quiz is restricted by subnet.
// - The question behaviour is not deferred feedback or deferred feedback with CBM.
// - The quiz uses the sequential navigation.
if (!empty($data['allowofflineattempts']) &&
(!empty($data['timelimit']) || !empty($data['subnet']) ||
$data['navmethod'] === 'sequential' ||
($data['preferredbehaviour'] != 'deferredfeedback' && $data['preferredbehaviour'] != 'deferredcbm'))) {
$errors['allowofflineattempts'] = get_string('offlineattemptserror', 'quizaccess_offlineattempts');
}
}
return $errors;
}
}
@@ -0,0 +1,51 @@
<?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 quizaccess_offlineattempts;
use mod_quiz\quiz_settings;
use quizaccess_offlineattempts;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/quiz/accessrule/offlineattempts/rule.php');
/**
* Unit tests for the quizaccess_offlineattempts plugin.
*
* @package quizaccess_offlineattempts
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class rule_test extends \basic_testcase {
public function test_offlineattempts_access_rule(): void {
$quiz = new \stdClass();
$quiz->allowofflineattempts = 1;
$cm = new \stdClass();
$cm->id = 0;
$quizobj = new quiz_settings($quiz, $cm, null);
$rule = new quizaccess_offlineattempts($quizobj, 0);
$attempt = new \stdClass();
$this->assertFalse($rule->prevent_access());
$this->assertFalse($rule->prevent_new_attempt(0, $attempt));
$this->assertFalse($rule->is_finished(0, $attempt));
$this->assertFalse($rule->end_time($attempt));
$this->assertFalse($rule->time_left_display($attempt, 0));
}
}
@@ -0,0 +1,29 @@
<?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 information for the quizaccess_offlineattempts plugin.
*
* @package quizaccess_offlineattempts
* @copyright 2016 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200;
$plugin->requires = 2024041600;
$plugin->component = 'quizaccess_offlineattempts';