Skip to content

Commit

Permalink
CTP-2779:
Browse files Browse the repository at this point in the history
- Allow multiple assessemnt component mappings to a single moodle activity
- Fix coding standards
  • Loading branch information
aydevworks committed Nov 6, 2023
1 parent a42dd91 commit 22b6c2b
Show file tree
Hide file tree
Showing 33 changed files with 981 additions and 344 deletions.
4 changes: 2 additions & 2 deletions apiclients/easikit/classes/requests/getcomponentgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class getcomponentgrade extends request {
'mod_code' => 'MOD_CODE',
'mod_occ_year_code' => 'AYR_CODE',
'mod_occ_psl_code' => 'PSL_CODE',
'mod_occ_mav' => 'MAV_OCCUR'
'mod_occ_mav' => 'MAV_OCCUR',
];

/** @var string request method */
Expand Down Expand Up @@ -85,7 +85,7 @@ public function process_response($response): array {
'MAB_PERC' => $matches[1],
'MAB_NAME' => $value['name'],
'MKS_CODE' => $value['mark_scheme']['code'],
'APA_ROMC' => $value['schedule']['location']['room']['identifier']
'APA_ROMC' => $value['schedule']['location']['room']['identifier'],
];
}
}
Expand Down
3 changes: 2 additions & 1 deletion apiclients/easikit/classes/requests/getmarkingschemes.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
class getmarkingschemes extends request {

/** @var string request method */
const METHOD = 'GET';

Expand Down Expand Up @@ -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'],
];
}
}
Expand Down
3 changes: 2 additions & 1 deletion apiclients/easikit/classes/requests/getstudent.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@
*/
class getstudent extends request {


/** @var string[] Fields mapping - Local data fields to SITS' fields */
const FIELDS_MAPPING = [
'idnumber' => 'STU_CODE',
'mapcode' => 'MAP_CODE',
'mabseq' => 'MAB_SEQ'
'mabseq' => 'MAB_SEQ',
];

/** @var string request method */
Expand Down
96 changes: 96 additions & 0 deletions apiclients/easikit/classes/requests/getstudents.php
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 <k.yeung@ucl.ac.uk>
*/
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']
);
}
}
4 changes: 4 additions & 0 deletions apiclients/easikit/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use sitsapiclient_easikit\requests\getcomponentgrade;
use sitsapiclient_easikit\requests\getmarkingschemes;
use sitsapiclient_easikit\requests\getstudent;
use sitsapiclient_easikit\requests\getstudents;
use sitsapiclient_easikit\requests\pushgrade;
use sitsapiclient_easikit\requests\pushsubmissionlog;
use sitsapiclient_easikit\requests\request;
Expand Down Expand Up @@ -66,6 +67,9 @@ public function build_request(string $action, \stdClass $data = null, submission
case manager::GET_STUDENT:
$request = new getstudent($data);
break;
case manager::GET_STUDENTS:
$request = new getstudents($data);
break;
case manager::PUSH_SUBMISSION_LOG:
$request = new pushsubmissionlog($data, $submission);
break;
Expand Down
3 changes: 2 additions & 1 deletion apiclients/easikit/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
class privacy_provider_test extends \advanced_testcase {

protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions apiclients/easikit/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
$plugin->version = 2023051900;
$plugin->requires = 2021051708;
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = array(
'local_sitsgradepush' => 2022020101
);
$plugin->dependencies = [
'local_sitsgradepush' => 2022020101,
];
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class getcomponentgrade extends request {
'mod_code' => 'MOD_CODE',
'mod_occ_year_code' => 'AYR_CODE',
'mod_occ_psl_code' => 'PSL_CODE',
'mod_occ_mav' => 'MAV_OCCUR'
'mod_occ_mav' => 'MAV_OCCUR',
];

/** @var string[] Endpoint params */
Expand Down Expand Up @@ -60,7 +60,7 @@ public function __construct(\stdClass $data) {
}

// Set the fields mapping, params fields and data.
parent::__construct(self::FIELDS_MAPPING, $endpointurl, self::ENDPOINT_PARAMS, $data);
parent::__construct(self::FIELDS_MAPPING, $endpointurl, self::ENDPOINT_PARAMS, $data);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions apiclients/stutalkdirect/classes/requests/getstudent.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class getstudent extends request {
const FIELDS_MAPPING = [
'idnumber' => 'STU_CODE',
'mapcode' => 'MAP_CODE',
'mabseq' => 'MAB_SEQ'
'mabseq' => 'MAB_SEQ',
];

/** @var string[] Endpoint params */
Expand Down Expand Up @@ -59,7 +59,7 @@ public function __construct(\stdClass $data) {
}

// Set the fields mapping, params fields and data.
parent::__construct(self::FIELDS_MAPPING, $endpointurl, self::ENDPOINT_PARAMS, $data);
parent::__construct(self::FIELDS_MAPPING, $endpointurl, self::ENDPOINT_PARAMS, $data);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion apiclients/stutalkdirect/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function send_request(irequest $request) {
curl_setopt(
$curlclient,
CURLOPT_HTTPHEADER,
array('Content-Type: application/json')
['Content-Type: application/json']
);
}

Expand Down
3 changes: 2 additions & 1 deletion apiclients/stutalkdirect/tests/privacy_provider_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
class privacy_provider_test extends \advanced_testcase {

protected function setUp(): void {
parent::setUp();
$this->resetAfterTest();
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions apiclients/stutalkdirect/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@
$plugin->version = 2023051700;
$plugin->requires = 2021051708;
$plugin->maturity = MATURITY_ALPHA;
$plugin->dependencies = array(
'local_sitsgradepush' => 2022020101
);
$plugin->dependencies = [
'local_sitsgradepush' => 2022020101,
];
70 changes: 70 additions & 0 deletions classes/cachemanager.php
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 <k.yeung@ucl.ac.uk>
*/
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);
}
}
9 changes: 5 additions & 4 deletions classes/errormanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* @author Alex Yeung <k.yeung@ucl.ac.uk>
*/
class errormanager {

/** @var int error type cannot be determined */
const ERROR_UNKNOWN = -99;

Expand Down Expand Up @@ -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 */
Expand All @@ -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'],
];

/**
Expand All @@ -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];
Expand All @@ -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;
Expand Down
Loading

0 comments on commit 22b6c2b

Please sign in to comment.