Skip to content

Commit

Permalink
refactor: apply requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
janbritz committed Oct 22, 2024
1 parent 4e273bc commit cfdb0a5
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 60 deletions.
8 changes: 4 additions & 4 deletions classes/api/attempt_scored.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class attempt_scored extends attempt {
/** @var string */
public string $scoringstate;

/** @var string */
public string $scoringcode;
/** @var scoring_code */
public scoring_code $scoringcode;

/** @var float|null */
public ?float $score = null;
Expand All @@ -48,9 +48,9 @@ class attempt_scored extends attempt {
* @param int $variant
* @param attempt_ui $ui
* @param string $scoringstate
* @param string $scoringcode
* @param scoring_code $scoringcode
*/
public function __construct(int $variant, attempt_ui $ui, string $scoringstate, string $scoringcode) {
public function __construct(int $variant, attempt_ui $ui, string $scoringstate, scoring_code $scoringcode) {
parent::__construct($variant, $ui);

$this->scoringstate = $scoringstate;
Expand Down
32 changes: 32 additions & 0 deletions classes/api/scoring_code.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
// This file is part of the QuestionPy Moodle plugin - https://questionpy.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 qtype_questionpy\api;

/**
* Possible scoring states.
*
* @package qtype_questionpy
* @author Jan Britz
* @copyright 2024 TU Berlin, innoCampus {@link https://www.questionpy.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
enum scoring_code: string {
case automatically_scored = "AUTOMATICALLY_SCORED";
case needs_manual_scoring = "NEEDS_MANUAL_SCORING";
case response_not_scorable = "RESPONSE_NOT_SCORABLE";
case invalid_response = "INVALID_RESPONSE";
}
66 changes: 66 additions & 0 deletions classes/event/grading_response_failed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
// This file is part of the QuestionPy Moodle plugin - https://questionpy.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 qtype_questionpy\event;

use moodle_exception;
use moodle_url;

/**
* Grading attempt failed event.
*
* @package qtype_questionpy
* @author Jan Britz
* @copyright 2024 TU Berlin, innoCampus {@link https://www.questionpy.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grading_response_failed extends \core\event\base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['crud'] = 'c';
$this->data['edulevel'] = self::LEVEL_TEACHING;
}

/**
* Returns localised event name.
*
* @return string
* @throws moodle_exception
*/
public static function get_name() {
return get_string('event_grading_response_failed', 'qtype_questionpy');
}

/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return $this->other['description'];
}

/**
* Validate our custom data.
*/
public function validate_data() {
if (!isset($this->other['description'])) {
throw new \coding_exception('"description" is required in "other".');
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
use moodle_url;

/**
* QuestionPy application server request failed event.
* Starting attempt failed event.
*
* @package qtype_questionpy
* @author Jan Britz
* @copyright 2024 TU Berlin, innoCampus {@link https://www.questionpy.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class request_failed extends \core\event\base {
class starting_attempt_failed extends \core\event\base {
/**
* Initialise event parameters.
*/
Expand All @@ -43,7 +43,7 @@ protected function init() {
* @throws moodle_exception
*/
public static function get_name() {
return get_string('event_request_failed', 'qtype_questionpy');
return get_string('event_starting_attempt_failed', 'qtype_questionpy');
}

/**
Expand All @@ -52,31 +52,15 @@ public static function get_name() {
* @return string
*/
public function get_description() {
return "{$this->other['message']}\nThere was an error requesting the application server:\n{$this->other['info']}";
}

/**
* Returns the url to the QuestionPy plugin settings.
*
* @throws moodle_exception
*/
public function get_url() {
return new moodle_url('/admin/settings.php', ['section' => 'qtypesettingquestionpy']);
return $this->other['description'];
}

/**
* Validate our custom data.
*
* Require the following fields:
* - url
* - payload
* - message
*
* Throw \coding_exception or debugging() notice in case of any problems.
*/
public function validate_data() {
if (!isset($this->other['message'], $this->other['info'])) {
throw new \coding_exception('"message" and "info" are required in "other".');
if (!isset($this->other['description'])) {
throw new \coding_exception('"description" is required in "other".');
}
}
}
66 changes: 66 additions & 0 deletions classes/event/viewing_attempt_failed.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
// This file is part of the QuestionPy Moodle plugin - https://questionpy.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 qtype_questionpy\event;

use moodle_exception;
use moodle_url;

/**
* Viewing attempt failed event.
*
* @package qtype_questionpy
* @author Jan Britz
* @copyright 2024 TU Berlin, innoCampus {@link https://www.questionpy.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class viewing_attempt_failed extends \core\event\base {
/**
* Initialise event parameters.
*/
protected function init() {
$this->data['crud'] = 'r';
$this->data['edulevel'] = self::LEVEL_PARTICIPATING;
}

/**
* Returns localised event name.
*
* @return string
* @throws moodle_exception
*/
public static function get_name() {
return get_string('event_viewing_attempt_failed', 'qtype_questionpy');
}

/**
* Returns non-localised event description with id's for admin use only.
*
* @return string
*/
public function get_description() {
return $this->other['description'];
}

/**
* Validate our custom data.
*/
public function validate_data() {
if (!isset($this->other['description'])) {
throw new \coding_exception('"description" is required in "other".');
}
}
}
4 changes: 3 additions & 1 deletion lang/en/qtype_questionpy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
$string['curl_exec_error'] = 'Error while fetching from server. Error number: {$a}';
$string['curl_init_error'] = 'Could not initialize cURL. Error number: {$a}';
$string['curl_set_opt_error'] = 'Failed to set cURL option. Error number: {$a}';
$string['event_request_failed'] = 'Server request failed';
$string['event_grading_response_failed'] = 'Grading response failed';
$string['event_starting_attempt_failed'] = 'Starting attempt failed';
$string['event_viewing_attempt_failed'] = 'Viewing attempt failed';
$string['form_fallback_element_text'] = "The QuestionPy package is using a form element not supported by the Moodle"
. " plugin. Please ensure you are using a compatible package or contact your administrators.";
$string['formerror_noqpy_package'] = 'Selected file must be of type .qpy';
Expand Down
Loading

0 comments on commit cfdb0a5

Please sign in to comment.