-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CTP-2779: Allow multiple assessment component mappings to a single ac…
…tivity (#26) - Allow multiple assessment component mappings to a single moodle activity - Fix coding standards
- Loading branch information
1 parent
a42dd91
commit 48c8fca
Showing
33 changed files
with
991 additions
and
346 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
* @author Alex Yeung <[email protected]> | ||
*/ | ||
class getmarkingschemes extends request { | ||
|
||
/** @var string request method */ | ||
const METHOD = 'GET'; | ||
|
||
|
@@ -66,7 +67,7 @@ public function process_response($response): array { | |
'MKS_CODE' => $markingscheme['identifier'], | ||
'MKS_MARKS' => $markingscheme['usage_indicator']['code'], | ||
'MKS_TYPE' => $markingscheme['type']['code'], | ||
'MKS_IUSE' => $markingscheme['in_use_indicator'] | ||
'MKS_IUSE' => $markingscheme['in_use_indicator'], | ||
]; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?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 sitsapiclient_easikit\requests; | ||
|
||
use local_sitsgradepush\cachemanager; | ||
|
||
/** | ||
* Class for getstudents request. | ||
* | ||
* @package sitsapiclient_easikit | ||
* @copyright 2023 onwards University College London {@link https://www.ucl.ac.uk/} | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Alex Yeung <[email protected]> | ||
*/ | ||
class getstudents extends request { | ||
|
||
|
||
|
||
/** @var string[] Fields mapping - Local data fields to SITS' fields */ | ||
const FIELDS_MAPPING = [ | ||
'mapcode' => 'MAP_CODE', | ||
'mabseq' => 'MAB_SEQ', | ||
]; | ||
|
||
/** @var string request method */ | ||
const METHOD = 'GET'; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param \stdClass $data | ||
* @throws \dml_exception | ||
* @throws \moodle_exception | ||
*/ | ||
public function __construct(\stdClass $data) { | ||
// Set request name. | ||
$this->name = 'Get students'; | ||
|
||
// Get request endpoint. | ||
$endpointurl = get_config('sitsapiclient_easikit', 'endpoint_get_student'); | ||
|
||
// Check if endpoint is set. | ||
if (empty($endpointurl)) { | ||
throw new \moodle_exception('Endpoint URL for ' . $this->name . ' is not set'); | ||
} | ||
|
||
// Set the fields mapping, params fields and data. | ||
parent::__construct(self::FIELDS_MAPPING, $endpointurl, $data); | ||
} | ||
|
||
/** | ||
* Process returned response. | ||
* | ||
* @param mixed $response | ||
* @return array | ||
*/ | ||
public function process_response($response): array { | ||
$result = []; | ||
if (!empty($response)) { | ||
// Convert response to suitable format. | ||
$response = json_decode($response, true); | ||
$result = $response['response']['student_collection']['student'] ?? []; | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** | ||
* Get endpoint url with params. | ||
* | ||
* @return string | ||
*/ | ||
public function get_endpoint_url_with_params(): string { | ||
// Return endpoint url with params. | ||
return sprintf( | ||
'%s/%s-%s/student', | ||
$this->endpointurl, | ||
$this->paramsdata['MAP_CODE'], | ||
$this->paramsdata['MAB_SEQ'] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
* @author Alex Yeung <[email protected]> | ||
*/ | ||
class privacy_provider_test extends \advanced_testcase { | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->resetAfterTest(); | ||
|
@@ -39,7 +40,7 @@ protected function setUp(): void { | |
* @return void | ||
* @throws \coding_exception | ||
*/ | ||
public function test_get_reason() { | ||
public function test_get_reason(): void { | ||
$reason = get_string(provider::get_reason(), 'sitsapiclient_easikit'); | ||
$this->assertEquals('This plugin does not store any personal data.', $reason); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ | |
* @author Alex Yeung <[email protected]> | ||
*/ | ||
class privacy_provider_test extends \advanced_testcase { | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
$this->resetAfterTest(); | ||
|
@@ -39,7 +40,7 @@ protected function setUp(): void { | |
* @return void | ||
* @throws \coding_exception | ||
*/ | ||
public function test_get_reason() { | ||
public function test_get_reason(): void { | ||
$reason = get_string(provider::get_reason(), 'sitsapiclient_stutalkdirect'); | ||
$this->assertEquals('This plugin does not store any personal data.', $reason); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?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 local_sitsgradepush; | ||
|
||
use cache; | ||
use cache_application; | ||
use cache_session; | ||
use cache_store; | ||
|
||
/** | ||
* Cache manager class for handling caches. | ||
* | ||
* @package local_sitsgradepush | ||
* @copyright 2023 onwards University College London {@link https://www.ucl.ac.uk/} | ||
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
* @author Alex Yeung <[email protected]> | ||
*/ | ||
class cachemanager { | ||
/** @var string Cache area for storing students in an assessment component.*/ | ||
const CACHE_AREA_STUDENTSPR = 'studentspr'; | ||
|
||
/** | ||
* Get cache. | ||
* | ||
* @param string $area | ||
* @param string $key | ||
* @return cache_application|cache_session|cache_store|null | ||
* @throws \coding_exception | ||
*/ | ||
public static function get_cache(string $area, string $key) { | ||
// Check if cache exists or expired. | ||
$cache = cache::make('local_sitsgradepush', $area)->get($key); | ||
// Expire key. | ||
$expires = 'expires_' . $key; | ||
if (empty($cache) || empty($expires) || time() >= $expires) { | ||
return null; | ||
} else { | ||
return $cache; | ||
} | ||
} | ||
|
||
/** | ||
* Set cache. | ||
* | ||
* @param string $area | ||
* @param string $key | ||
* @param mixed $value | ||
* @param int $expiresafter | ||
* @return void | ||
*/ | ||
public static function set_cache(string $area, string $key, mixed $value, int $expiresafter) { | ||
$cache = cache::make('local_sitsgradepush', $area); | ||
$cache->set($key, $value); | ||
$cache->set('expires_' . $key, $expiresafter); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
* @author Alex Yeung <[email protected]> | ||
*/ | ||
class errormanager { | ||
|
||
/** @var int error type cannot be determined */ | ||
const ERROR_UNKNOWN = -99; | ||
|
||
|
@@ -66,7 +67,7 @@ class errormanager { | |
self::ERROR_ATTEMPT_NUMBER_BLANK => 'Attempt number blank', | ||
self::ERROR_OVERWRITE_EXISTING_RECORD => 'Overwrite not allowed', | ||
self::ERROR_INVALID_MARKS => 'Invalid marks', | ||
self::ERROR_INVALID_HAND_IN_STATUS => 'Invalid hand in status' | ||
self::ERROR_INVALID_HAND_IN_STATUS => 'Invalid hand in status', | ||
]; | ||
|
||
/** @var array error types and their match error strings */ | ||
|
@@ -82,7 +83,7 @@ class errormanager { | |
'no further update allowed', | ||
], | ||
self::ERROR_INVALID_MARKS => ['Mark and/or Grade not valid'], | ||
self::ERROR_INVALID_HAND_IN_STATUS => ['handin_status provided is not in SUS table'] | ||
self::ERROR_INVALID_HAND_IN_STATUS => ['handin_status provided is not in SUS table'], | ||
]; | ||
|
||
/** | ||
|
@@ -91,7 +92,7 @@ class errormanager { | |
* @param int|null $errorcode error code | ||
* @return string error label | ||
*/ | ||
public static function get_error_label(int $errorcode = null) : string { | ||
public static function get_error_label(int $errorcode = null): string { | ||
// If no error code provided, return unknown error. | ||
if (!isset($errorcode)) { | ||
return self::ERROR_TYPES_LABEL[self::ERROR_UNKNOWN]; | ||
|
@@ -106,7 +107,7 @@ public static function get_error_label(int $errorcode = null) : string { | |
* @param string|null $errorstring | ||
* @return int | ||
*/ | ||
public static function identify_error(string $errorstring = null) : int { | ||
public static function identify_error(string $errorstring = null): int { | ||
// If no error string provided, return unknown error. | ||
if (!isset($errorstring)) { | ||
return self::ERROR_UNKNOWN; | ||
|
Oops, something went wrong.