Skip to content

Commit

Permalink
Merge pull request #37 from talview/release/v1.3.0
Browse files Browse the repository at this point in the history
Release/v1.3.0
  • Loading branch information
rakeshprabhu authored Dec 5, 2023
2 parents 7e8570a + 2acbb69 commit 15be0c9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 18 deletions.
Binary file added phpcs.phar
Binary file not shown.
66 changes: 50 additions & 16 deletions rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
* @copyright 2020 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class quizaccess_proctor extends quiz_access_rule_base {
class quizaccess_proctor extends quiz_access_rule_base
{

/** @var access_manager $accessmanager Instance to manage the access to the quiz for this plugin. */
private $accessmanager;
Expand All @@ -51,7 +52,8 @@ class quizaccess_proctor extends quiz_access_rule_base {
* @param int $timenow the time that should be considered as 'now'.
* @param access_manager $accessmanager the quiz accessmanager.
*/
public function __construct(quiz $quizobj, int $timenow, access_manager $accessmanager) {
public function __construct(quiz $quizobj, int $timenow, access_manager $accessmanager)
{
parent::__construct($quizobj, $timenow);
$this->accessmanager = $accessmanager;
}
Expand All @@ -66,9 +68,9 @@ public function __construct(quiz $quizobj, int $timenow, access_manager $accessm
* time limits by the mod/quiz:ignoretimelimits capability.
* @return quiz_access_rule_base|null the rule, if applicable, else null.
*/
public static function make (quiz $quizobj, $timenow, $canignoretimelimits) {
public static function make(quiz $quizobj, $timenow, $canignoretimelimits)
{
$accessmanager = new access_manager($quizobj);

return new self($quizobj, $timenow, $accessmanager);
}

Expand All @@ -80,7 +82,8 @@ public static function make (quiz $quizobj, $timenow, $canignoretimelimits) {
* @param mod_quiz_mod_form $quizform the quiz settings form that is being built.
* @param MoodleQuickForm $mform the wrapped MoodleQuickForm.
*/
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform) {
public static function add_settings_form_fields(mod_quiz_mod_form $quizform, MoodleQuickForm $mform)
{
settings_provider::add_proctor_settings_fields($quizform, $mform);
}

Expand All @@ -94,13 +97,14 @@ public static function add_settings_form_fields(mod_quiz_mod_form $quizform, Moo
* @return array $errors the updated $errors array.
*/
public static function validate_settings_form_fields(array $errors,
array $data, $files, mod_quiz_mod_form $quizform) : array {
array $data, $files, mod_quiz_mod_form $quizform): array
{

$quizid = $data['instance'];
$cmid = $data['coursemodule'];
$context = $quizform->get_context();

$settings = settings_provider::filter_plugin_settings((object) $data);
$settings = settings_provider::filter_plugin_settings((object)$data);

// Validate basic settings using persistent class.
$quizsettings = (new quiz_settings())->from_record($settings);
Expand Down Expand Up @@ -132,7 +136,8 @@ public static function validate_settings_form_fields(array $errors,
* @param object $quiz the data from the quiz form, including $quiz->id
* which is the id of the quiz being saved.
*/
public static function save_settings($quiz) {
public static function save_settings($quiz)
{
global $USER, $DB;
$context = context_module::instance($quiz->coursemodule);

Expand Down Expand Up @@ -168,7 +173,7 @@ public static function save_settings($quiz) {
$proctordata->tsbenabled = (isset($quiz->tsbenabled) && $quiz->tsbenabled) ? 1 : 0;
$proctordata->usermodified = $USER->id;
$proctordata->reference_link = $quiz->reference_link;
if($proctor = $DB->get_record('quizaccess_proctor', array('quizid'=> $quiz->id))) {
if ($proctor = $DB->get_record('quizaccess_proctor', array('quizid' => $quiz->id))) {
$proctordata->id = $proctor->id;
$proctordata->timemodified = time();
$DB->update_record('quizaccess_proctor', $proctordata);
Expand All @@ -187,7 +192,8 @@ public static function save_settings($quiz) {
* @param object $quiz the data from the database, including $quiz->id
* which is the id of the quiz being deleted.
*/
public static function delete_settings($quiz) {
public static function delete_settings($quiz)
{
$quizsettings = quiz_settings::get_by_quiz_id($quiz->id);
// Check that there are existing settings.
if ($quizsettings !== false) {
Expand Down Expand Up @@ -215,7 +221,8 @@ public static function delete_settings($quiz) {
* used named placeholders, and the placeholder names should start with the
* plugin name, to avoid collisions.
*/
public static function get_settings_sql($quizid) : array {
public static function get_settings_sql($quizid): array
{
return [
'proctor.proctortype AS proctortype, '
. 'proctor.tsbenabled AS tsbenabled, '
Expand All @@ -227,32 +234,59 @@ public static function get_settings_sql($quizid) : array {
}



/**
* Sets up the attempt (review or summary) page with any special extra
* properties required by this rule.
*
* @param moodle_page $page the page object to initialise.
*/
public function setup_attempt_page($page) {
public function setup_attempt_page($page)
{
$page->set_title($this->quizobj->get_course()->shortname . ': ' . $page->title);
$page->set_heading($page->title);
$proctortype=$this->quizobj->get_quiz()->proctortype;
$proctortype = $this->quizobj->get_quiz()->proctortype;
$local_proview_enabled = get_config('local_proview', 'enabled');
$quizaccess_proctor_setting_enabled = get_config('quizaccess_proctor', 'enableproctor');
if ( $local_proview_enabled && $quizaccess_proctor_setting_enabled && $proctortype !== 'noproctor'){
if ($local_proview_enabled && $quizaccess_proctor_setting_enabled && $proctortype !== 'noproctor') {
$page->set_pagelayout('secure');
$page->set_popup_notification_allowed(false); // Prevent message notifications.
}

if ($this->is_tsb_required() && !strpos($_SERVER ['HTTP_USER_AGENT'], "Proview-SB")) {
$this->redirect_to_tsb_link();
}
}

/**
* This is called when the current attempt at the quiz is finished.
*/
public function current_attempt_finished() {
public function current_attempt_finished()
{
$this->accessmanager->clear_session_access();
}

public function is_tsb_required()
{
$quizaccess_proctor_setting_enabled = get_config('quizaccess_proctor', 'enableproctor');
$tsbenabled = $this->quizobj->get_quiz()->tsbenabled;
$proctortype = $this->quizobj->get_quiz()->proctortype;
return ($quizaccess_proctor_setting_enabled && $tsbenabled && $proctortype !== 'noproctor');
}

public function redirect_to_tsb_link()
{
global $PAGE, $CFG;
$baseUrl = $CFG->wwwroot;
$path = "/mod/quiz/view.php?id=" . $PAGE->cm->id;
$redirectURL = $baseUrl . $path;
$tsblink = "https://pages.talview.com/tsb/index.html?redirect_url=" . urlencode($redirectURL) . "&user=" . urlencode($_SERVER['HTTP_USER_AGENT']);
$PAGE->requires->js_amd_inline('
require(["jquery"], function($) {
$(document).ready(function() {
window.location.href = "' . $tsblink . '";
});
});
');
}
}

4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2023090601;
$plugin->version = 2023120302;
$plugin->requires = 2020061500;
$plugin->release = '1.2.0 (Build: 2023090601)';
$plugin->release = '1.3.0 (Build: 2023120302)';
$plugin->component = 'quizaccess_proctor';
$plugin->maturity = MATURITY_STABLE;

Expand Down

0 comments on commit 15be0c9

Please sign in to comment.