-
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.
- Allow multiple assessemnt component mappings to a single moodle activity - Fix coding standards
- Loading branch information
1 parent
a42dd91
commit 22b6c2b
Showing
33 changed files
with
981 additions
and
344 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
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 <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'] | ||
); | ||
} | ||
} |
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
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 |
---|---|---|
@@ -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); | ||
} | ||
} |
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
Oops, something went wrong.