diff --git a/admin/tool/analytics/classes/external.php b/admin/tool/analytics/classes/external.php
index 515c08a63dd4f..8ea300f473c37 100644
--- a/admin/tool/analytics/classes/external.php
+++ b/admin/tool/analytics/classes/external.php
@@ -24,15 +24,11 @@
namespace tool_analytics;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
/**
* This is the external API for this component.
diff --git a/admin/tool/behat/classes/external/get_entity_generator.php b/admin/tool/behat/classes/external/get_entity_generator.php
index 569ed5556664e..b56be482935c4 100644
--- a/admin/tool/behat/classes/external/get_entity_generator.php
+++ b/admin/tool/behat/classes/external/get_entity_generator.php
@@ -25,14 +25,22 @@
namespace tool_behat\external;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
+// Ensure we can load Behat and Facebook namespaces in behat libraries.
+require_once($CFG->dirroot . '/vendor/autoload.php');
+require_once($CFG->libdir . '/tests/behat/behat_data_generators.php');
/**
* External function for getting properties of entity generators.
*/
-class get_entity_generator extends \external_api {
+class get_entity_generator extends external_api {
/**
* Define parameters for external function.
@@ -42,11 +50,11 @@ class get_entity_generator extends \external_api {
* behat_data_generators::parse_entity_type, which validates the format of the parameter and throws an exception if it is not
* correct.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters([
- 'entitytype' => new \external_value(PARAM_RAW, 'Entity type that can be created by a generator.'),
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters([
+ 'entitytype' => new external_value(PARAM_RAW, 'Entity type that can be created by a generator.'),
]);
}
@@ -78,12 +86,12 @@ public static function execute(string $entitytype): array {
*
* Return required fields
*
- * @return \external_single_structure
+ * @return external_single_structure
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure([
- 'required' => new \external_multiple_structure(
- new \external_value(PARAM_TEXT, 'Required field'),
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure([
+ 'required' => new external_multiple_structure(
+ new external_value(PARAM_TEXT, 'Required field'),
'Required fields',
VALUE_OPTIONAL
),
diff --git a/admin/tool/dataprivacy/classes/external.php b/admin/tool/dataprivacy/classes/external.php
index 1db296f2e26d2..15cfc1916179f 100644
--- a/admin/tool/dataprivacy/classes/external.php
+++ b/admin/tool/dataprivacy/classes/external.php
@@ -21,30 +21,24 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace tool_dataprivacy;
+
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php');
-use coding_exception;
use context_helper;
use context_system;
use context_user;
-use core\invalid_persistent_exception;
use core\notification;
use core_user;
-use dml_exception;
-use external_api;
-use external_description;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
-use invalid_parameter_exception;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
use required_capability_exception;
-use restricted_context_exception;
use tool_dataprivacy\external\category_exporter;
use tool_dataprivacy\external\data_request_exporter;
use tool_dataprivacy\external\purpose_exporter;
@@ -136,7 +130,7 @@ public static function cancel_data_request($requestid) {
* Parameter description for cancel_data_request().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function cancel_data_request_returns() {
return new external_single_structure([
@@ -228,7 +222,7 @@ public static function contact_dpo($message) {
* Parameter description for contact_dpo().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function contact_dpo_returns() {
return new external_single_structure([
@@ -293,7 +287,7 @@ public static function mark_complete($requestid) {
* Parameter description for mark_complete().
*
* @since Moodle 3.5.2
- * @return external_description
+ * @return \core_external\external_description
*/
public static function mark_complete_returns() {
return new external_single_structure([
@@ -355,7 +349,7 @@ public static function get_data_request($requestid) {
* Parameter description for get_data_request().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_data_request_returns() {
return new external_single_structure([
@@ -427,7 +421,7 @@ public static function approve_data_request($requestid) {
* Parameter description for approve_data_request().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function approve_data_request_returns() {
return new external_single_structure([
@@ -506,7 +500,7 @@ public static function bulk_approve_data_requests($requestids) {
* Parameter description for bulk_approve_data_requests().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function bulk_approve_data_requests_returns() {
return new external_single_structure([
@@ -578,7 +572,7 @@ public static function deny_data_request($requestid) {
* Parameter description for deny_data_request().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function deny_data_request_returns() {
return new external_single_structure([
@@ -657,7 +651,7 @@ public static function bulk_deny_data_requests($requestids) {
* Parameter description for bulk_deny_data_requests().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
*/
public static function bulk_deny_data_requests_returns() {
return new external_single_structure([
@@ -740,7 +734,7 @@ public static function get_users($query) {
* Parameter description for get_users().
*
* @since Moodle 3.5
- * @return external_description
+ * @return \core_external\external_description
* @throws coding_exception
*/
public static function get_users_returns() {
diff --git a/admin/tool/dataprivacy/classes/external/data_request_exporter.php b/admin/tool/dataprivacy/classes/external/data_request_exporter.php
index 3c5ce09a04508..c6fbfd8c64c90 100644
--- a/admin/tool/dataprivacy/classes/external/data_request_exporter.php
+++ b/admin/tool/dataprivacy/classes/external/data_request_exporter.php
@@ -24,12 +24,9 @@
namespace tool_dataprivacy\external;
defined('MOODLE_INTERNAL') || die();
-use coding_exception;
use core\external\persistent_exporter;
use core_user;
use core_user\external\user_summary_exporter;
-use dml_exception;
-use moodle_exception;
use renderer_base;
use tool_dataprivacy\api;
use tool_dataprivacy\data_request;
diff --git a/admin/tool/dataprivacy/classes/external/purpose_exporter.php b/admin/tool/dataprivacy/classes/external/purpose_exporter.php
index 8e2423553a036..36bcb042118f0 100644
--- a/admin/tool/dataprivacy/classes/external/purpose_exporter.php
+++ b/admin/tool/dataprivacy/classes/external/purpose_exporter.php
@@ -24,9 +24,7 @@
namespace tool_dataprivacy\external;
defined('MOODLE_INTERNAL') || die();
-use coding_exception;
use core\external\persistent_exporter;
-use Exception;
use renderer_base;
use tool_dataprivacy\context_instance;
use tool_dataprivacy\purpose;
diff --git a/admin/tool/dataprivacy/tests/external/external_test.php b/admin/tool/dataprivacy/tests/external/external_test.php
index 0fc372cc6fa3f..7408592daf13b 100644
--- a/admin/tool/dataprivacy/tests/external/external_test.php
+++ b/admin/tool/dataprivacy/tests/external/external_test.php
@@ -24,6 +24,7 @@
namespace tool_dataprivacy\external;
+use core_external\external_api;
use externallib_advanced_testcase;
use tool_dataprivacy\api;
use tool_dataprivacy\context_instance;
@@ -123,7 +124,7 @@ public function test_approve_data_request() {
$this->setAdminUser();
api::update_request_status($datarequest->get('id'), api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::approve_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -139,7 +140,7 @@ public function test_approve_data_request_non_existent() {
$result = external::approve_data_request(1);
- $return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
@@ -165,7 +166,7 @@ public function test_cancel_data_request_other_user() {
$this->setUser($otheruser);
$result = external::cancel_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
@@ -194,7 +195,7 @@ public function test_cancel_data_request_other_user_as_requester() {
$datarequest = api::create_data_request($otheruser->id, api::DATAREQUEST_TYPE_EXPORT, $comment);
$result = external::cancel_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -250,7 +251,7 @@ public function test_cancel_data_request_other_user_as_child() {
$datarequest = api::create_data_request($otheruser->id, api::DATAREQUEST_TYPE_EXPORT, $comment);
$result = external::cancel_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -273,7 +274,7 @@ public function test_cancel_data_request() {
$this->setUser($requester);
$result = external::cancel_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::approve_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -290,7 +291,7 @@ public function test_contact_dpo() {
$this->setUser($user);
$message = 'Hello world!';
$result = external::contact_dpo($message);
- $return = (object) \external_api::clean_returnvalue(external::contact_dpo_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::contact_dpo_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -385,7 +386,7 @@ public function test_deny_data_request() {
$this->setAdminUser();
api::update_request_status($datarequest->get('id'), api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::approve_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -400,7 +401,7 @@ public function test_deny_data_request_non_existent() {
$this->setAdminUser();
$result = external::deny_data_request(1);
- $return = (object) \external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::deny_data_request_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
@@ -462,7 +463,7 @@ public function test_get_data_request() {
$this->setAdminUser();
$result = external::get_data_request($datarequest->get('id'));
- $return = (object) \external_api::clean_returnvalue(external::get_data_request_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::get_data_request_returns(), $result);
$this->assertEquals(api::DATAREQUEST_TYPE_EXPORT, $return->result['type']);
$this->assertEquals('sample comment', $return->result['comments']);
$this->assertEquals($requester->id, $return->result['userid']);
@@ -542,7 +543,7 @@ public function test_set_context_defaults($modulelevel, $override) {
$result = external::set_context_defaults(CONTEXT_MODULE, $categoryid, $purposeid, $modulename, $override);
// Extract the result.
- $return = \external_api::clean_returnvalue(external::set_context_defaults_returns(), $result);
+ $return = external_api::clean_returnvalue(external::set_context_defaults_returns(), $result);
$this->assertTrue($return['result']);
// Check the assignment context instance.
@@ -626,7 +627,7 @@ public function test_get_category_options($includeinherit, $includenotset) {
$result = external::get_category_options($includeinherit, $includenotset);
// Extract the options.
- $return = (object) \external_api::clean_returnvalue(external::get_category_options_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::get_category_options_returns(), $result);
$options = $return->options;
// Make sure everything checks out.
@@ -690,7 +691,7 @@ public function test_get_purpose_options($includeinherit, $includenotset) {
$result = external::get_purpose_options($includeinherit, $includenotset);
// Extract the options.
- $return = (object) \external_api::clean_returnvalue(external::get_purpose_options_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::get_purpose_options_returns(), $result);
$options = $return->options;
// Make sure everything checks out.
@@ -749,7 +750,7 @@ public function test_get_activity_options($inheritcategory, $inheritpurpose, $no
$result = external::get_activity_options($nodefaults);
// Extract the options.
- $return = (object) \external_api::clean_returnvalue(external::get_activity_options_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::get_activity_options_returns(), $result);
$options = $return->options;
// Make sure the options list is not empty.
@@ -792,7 +793,7 @@ public function test_bulk_approve_data_requests() {
api::update_request_status($requestid2, api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::bulk_approve_data_requests([$requestid1, $requestid2]);
- $return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -807,7 +808,7 @@ public function test_bulk_approve_data_requests_non_existent() {
$result = external::bulk_approve_data_requests([42]);
- $return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
$warning = reset($return->warnings);
@@ -895,7 +896,7 @@ public function test_bulk_deny_data_requests() {
api::update_request_status($requestid2, api::DATAREQUEST_STATUS_AWAITING_APPROVAL);
$result = external::bulk_deny_data_requests([$requestid1, $requestid2]);
- $return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertTrue($return->result);
$this->assertEmpty($return->warnings);
}
@@ -908,7 +909,7 @@ public function test_bulk_deny_data_requests_non_existent() {
$this->setAdminUser();
$result = external::bulk_deny_data_requests([42]);
- $return = (object) \external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
+ $return = (object) external_api::clean_returnvalue(external::bulk_approve_data_requests_returns(), $result);
$this->assertFalse($return->result);
$this->assertCount(1, $return->warnings);
diff --git a/admin/tool/lp/classes/external.php b/admin/tool/lp/classes/external.php
index 6e549ffb602e6..d59b54fa28ec2 100644
--- a/admin/tool/lp/classes/external.php
+++ b/admin/tool/lp/classes/external.php
@@ -24,38 +24,11 @@
namespace tool_lp;
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->libdir/grade/grade_scale.php");
-use context;
-use context_system;
use context_course;
-use context_helper;
+use context_system;
use context_user;
-use coding_exception;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_format_value;
-use external_single_structure;
-use external_multiple_structure;
-use invalid_parameter_exception;
-use required_capability_exception;
-
-use core_cohort\external\cohort_summary_exporter;
-use tool_lp\external\competency_path_exporter;
-use tool_lp\external\competency_summary_exporter;
-use tool_lp\external\course_competency_statistics_exporter;
-use core_course\external\course_module_summary_exporter;
-use core_course\external\course_summary_exporter;
-use tool_lp\external\template_statistics_exporter;
-use tool_lp\external\user_competency_summary_exporter;
-use tool_lp\external\user_competency_summary_in_course_exporter;
-use tool_lp\external\user_competency_summary_in_plan_exporter;
-use tool_lp\external\user_evidence_summary_exporter;
-use tool_lp\output\user_competency_summary_in_plan;
-use tool_lp\output\user_competency_summary_in_course;
-
use core_competency\api;
use core_competency\external\competency_exporter;
use core_competency\external\competency_framework_exporter;
@@ -66,7 +39,24 @@
use core_competency\external\user_competency_course_exporter;
use core_competency\external\user_competency_exporter;
use core_competency\external\user_competency_plan_exporter;
+use core_course\external\course_module_summary_exporter;
+use core_course\external\course_summary_exporter;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use core_user\external\user_summary_exporter;
+use tool_lp\external\competency_path_exporter;
+use tool_lp\external\competency_summary_exporter;
+use tool_lp\external\course_competency_statistics_exporter;
+use tool_lp\external\template_statistics_exporter;
+use tool_lp\external\user_competency_summary_exporter;
+use tool_lp\external\user_competency_summary_in_course_exporter;
+use tool_lp\external\user_competency_summary_in_plan_exporter;
+use tool_lp\external\user_evidence_summary_exporter;
+use tool_lp\output\user_competency_summary_in_course;
+use tool_lp\output\user_competency_summary_in_plan;
/**
* This is the external API for this tool.
@@ -109,7 +99,7 @@ protected static function get_context_parameters() {
/**
* Returns description of data_for_competency_frameworks_manage_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_competency_frameworks_manage_page_parameters() {
$params = array('pagecontext' => self::get_context_parameters());
@@ -145,7 +135,7 @@ public static function data_for_competency_frameworks_manage_page($pagecontext)
/**
* Returns description of data_for_competency_frameworks_manage_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_competency_frameworks_manage_page_returns() {
return new external_single_structure(array (
@@ -164,7 +154,7 @@ public static function data_for_competency_frameworks_manage_page_returns() {
/**
* Returns description of data_for_competencies_manage_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_competencies_manage_page_parameters() {
$competencyframeworkid = new external_value(
@@ -215,7 +205,7 @@ public static function data_for_competencies_manage_page($competencyframeworkid,
/**
* Returns description of data_for_competencies_manage_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_competencies_manage_page_returns() {
return new external_single_structure(array (
@@ -232,7 +222,7 @@ public static function data_for_competencies_manage_page_returns() {
/**
* Returns description of data_for_competency_summary() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_competency_summary_parameters() {
$competencyid = new external_value(
@@ -291,7 +281,7 @@ public static function data_for_competency_summary($competencyid, $includerelate
/**
* Returns description of data_for_competency_summary_() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_competency_summary_returns() {
return competency_summary_exporter::get_read_structure();
@@ -300,7 +290,7 @@ public static function data_for_competency_summary_returns() {
/**
* Returns description of list_courses_using_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_courses_using_competency_parameters() {
$competencyid = new external_value(
@@ -345,7 +335,7 @@ public static function list_courses_using_competency($competencyid) {
/**
* Returns description of list_courses_using_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_courses_using_competency_returns() {
return new external_multiple_structure(course_summary_exporter::get_read_structure());
@@ -355,7 +345,7 @@ public static function list_courses_using_competency_returns() {
/**
* Returns description of data_for_course_competenies_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_course_competencies_page_parameters() {
$courseid = new external_value(
@@ -399,7 +389,7 @@ public static function data_for_course_competencies_page($courseid, $moduleid) {
/**
* Returns description of data_for_course_competencies_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_course_competencies_page_returns() {
$ucc = user_competency_course_exporter::get_read_structure();
@@ -441,7 +431,7 @@ public static function data_for_course_competencies_page_returns() {
/**
* Returns description of data_for_templates_manage_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_templates_manage_page_parameters() {
$params = array('pagecontext' => self::get_context_parameters());
@@ -474,7 +464,7 @@ public static function data_for_templates_manage_page($pagecontext) {
/**
* Returns description of data_for_templates_manage_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_templates_manage_page_returns() {
return new external_single_structure(array (
@@ -494,7 +484,7 @@ public static function data_for_templates_manage_page_returns() {
/**
* Returns description of data_for_template_competenies_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_template_competencies_page_parameters() {
$templateid = new external_value(
@@ -535,7 +525,7 @@ public static function data_for_template_competencies_page($templateid, $pagecon
/**
* Returns description of data_for_template_competencies_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_template_competencies_page_returns() {
return new external_single_structure(array (
@@ -556,7 +546,7 @@ public static function data_for_template_competencies_page_returns() {
/**
* Returns description of data_for_plan_competenies_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_plan_page_parameters() {
$planid = new external_value(
@@ -593,7 +583,7 @@ public static function data_for_plan_page($planid) {
/**
* Returns description of data_for_plan_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_plan_page_returns() {
$uc = user_competency_exporter::get_read_structure();
@@ -624,7 +614,7 @@ public static function data_for_plan_page_returns() {
/**
* Returns description of data_for_plans_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_plans_page_parameters() {
$userid = new external_value(
@@ -661,7 +651,7 @@ public static function data_for_plans_page($userid) {
/**
* Returns description of data_for_plans_page() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_plans_page_returns() {
return new external_single_structure(array (
@@ -681,7 +671,7 @@ public static function data_for_plans_page_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_user_evidence_list_page_parameters() {
return new external_function_parameters(array(
@@ -711,7 +701,7 @@ public static function data_for_user_evidence_list_page($userid) {
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_user_evidence_list_page_returns() {
return new external_single_structure(array (
@@ -728,7 +718,7 @@ public static function data_for_user_evidence_list_page_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_user_evidence_page_parameters() {
return new external_function_parameters(array(
@@ -758,7 +748,7 @@ public static function data_for_user_evidence_page($id) {
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_user_evidence_page_returns() {
return new external_single_structure(array(
@@ -805,7 +795,7 @@ public static function data_for_related_competencies_section($competencyid) {
/**
* Returns description of data_for_related_competencies_section_returns() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function data_for_related_competencies_section_returns() {
return new external_single_structure(array(
@@ -920,7 +910,7 @@ public static function search_users($query, $capability = '', $limitfrom = 0, $l
/**
* Returns description of external function result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function search_users_returns() {
global $CFG;
@@ -934,7 +924,7 @@ public static function search_users_returns() {
/**
* Returns description of external function.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_user_competency_summary_parameters() {
$userid = new external_value(
@@ -979,7 +969,7 @@ public static function data_for_user_competency_summary($userid, $competencyid)
/**
* Returns description of external function.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_user_competency_summary_returns() {
return user_competency_summary_exporter::get_read_structure();
@@ -988,7 +978,7 @@ public static function data_for_user_competency_summary_returns() {
/**
* Returns description of data_for_user_competency_summary_in_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_user_competency_summary_in_plan_parameters() {
$competencyid = new external_value(
@@ -1035,7 +1025,7 @@ public static function data_for_user_competency_summary_in_plan($competencyid, $
/**
* Returns description of data_for_user_competency_summary_in_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_user_competency_summary_in_plan_returns() {
return user_competency_summary_in_plan_exporter::get_read_structure();
@@ -1044,7 +1034,7 @@ public static function data_for_user_competency_summary_in_plan_returns() {
/**
* Returns description of data_for_user_competency_summary_in_course() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_user_competency_summary_in_course_parameters() {
$userid = new external_value(
@@ -1097,10 +1087,9 @@ public static function data_for_user_competency_summary_in_course($userid, $comp
/**
* Returns description of data_for_user_competency_summary_in_course() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_user_competency_summary_in_course_returns() {
return user_competency_summary_in_course_exporter::get_read_structure();
}
-
}
diff --git a/admin/tool/lp/tests/externallib_test.php b/admin/tool/lp/tests/externallib_test.php
index ec76951b8ccea..db63e158c319b 100644
--- a/admin/tool/lp/tests/externallib_test.php
+++ b/admin/tool/lp/tests/externallib_test.php
@@ -17,15 +17,7 @@
namespace tool_lp;
use core_competency\api;
-use core_competency\invalid_persistent_exception;
-use core_competency\plan;
-use core_competency\related_competency;
-use core_competency\user_competency;
-use core_competency\user_competency_plan;
-use core_competency\plan_competency;
-use core_competency\template;
-use core_competency\template_competency;
-use core_competency\course_competency_settings;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -152,7 +144,7 @@ public function test_search_users_by_capability() {
// First we search with no capability assigned.
$this->setUser($ux);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
@@ -162,7 +154,7 @@ public function test_search_users_by_capability() {
$customrole = $this->assignUserCapability('moodle/competency:planview', $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
@@ -171,14 +163,14 @@ public function test_search_users_by_capability() {
$this->assignUserCapability('moodle/competency:planmanage', $usercontext->id, $customrole);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
// Now assign another role with the same capability (test duplicates).
role_assign($this->creatorrole, $ux->id, $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
@@ -187,7 +179,7 @@ public function test_search_users_by_capability() {
role_assign($this->creatorrole, $ux2->id, $systemcontext->id);
$this->setUser($ux2);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
@@ -196,7 +188,7 @@ public function test_search_users_by_capability() {
role_assign($this->creatorrole, $ux3->id, $usercontext->id);
$this->setUser($ux3);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
@@ -206,14 +198,14 @@ public function test_search_users_by_capability() {
// Now add a prevent override (will change nothing because we still have an ALLOW).
assign_capability('moodle/competency:planmanage', CAP_PREVENT, $customrole, $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
// Now change to a prohibit override (should prevent access).
assign_capability('moodle/competency:planmanage', CAP_PROHIBIT, $customrole, $usercontext->id);
$result = external::search_users('yyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
@@ -321,14 +313,14 @@ public function test_search_users() {
// No identity fields.
$CFG->showuseridentity = '';
$result = external::search_users('cats', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
// Filter by name.
$CFG->showuseridentity = '';
$result = external::search_users('dyyylan', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(2, $result['users']);
$this->assertEquals(2, $result['count']);
$this->assertEquals($u2->id, $result['users'][0]['id']);
@@ -337,7 +329,7 @@ public function test_search_users() {
// Filter by institution and name.
$CFG->showuseridentity = 'institution';
$result = external::search_users('bob', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(2, $result['users']);
$this->assertEquals(2, $result['count']);
$this->assertEquals($u1->id, $result['users'][0]['id']);
@@ -346,7 +338,7 @@ public function test_search_users() {
// Filter by id number.
$CFG->showuseridentity = 'idnumber';
$result = external::search_users('cats', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
$this->assertEquals($u1->id, $result['users'][0]['id']);
@@ -360,7 +352,7 @@ public function test_search_users() {
// Filter by email.
$CFG->showuseridentity = 'email';
$result = external::search_users('yyy', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(3, $result['users']);
$this->assertEquals(3, $result['count']);
$this->assertEquals($u2->id, $result['users'][0]['id']);
@@ -373,7 +365,7 @@ public function test_search_users() {
// Filter by any.
$CFG->showuseridentity = 'idnumber,email,phone1,phone2,department,institution';
$result = external::search_users('yyy', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(3, $result['users']);
$this->assertEquals(3, $result['count']);
$this->assertArrayHasKey('idnumber', $result['users'][0]);
@@ -389,12 +381,12 @@ public function test_search_users() {
// Only names are included.
$result = external::search_users('fish');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(0, $result['users']);
$this->assertEquals(0, $result['count']);
$result = external::search_users('bob', 'moodle/competency:planmanage');
- $result = \external_api::clean_returnvalue(external::search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_users_returns(), $result);
$this->assertCount(1, $result['users']);
$this->assertEquals(1, $result['count']);
$this->assertEquals($u1->id, $result['users'][0]['id']);
diff --git a/admin/tool/mobile/autologin.php b/admin/tool/mobile/autologin.php
index ffc0e899c5a23..1d8dcac2ae3a2 100644
--- a/admin/tool/mobile/autologin.php
+++ b/admin/tool/mobile/autologin.php
@@ -23,7 +23,6 @@
*/
require_once(__DIR__ . '/../../../config.php');
-require_once($CFG->libdir . '/externallib.php');
$userid = required_param('userid', PARAM_INT); // The user id the key belongs to (for double-checking).
$key = required_param('key', PARAM_ALPHANUMEXT); // The key generated by the tool_mobile_external::get_autologin_key() external function.
diff --git a/admin/tool/mobile/classes/api.php b/admin/tool/mobile/classes/api.php
index 78803c5df712f..ca83c4fef89fc 100644
--- a/admin/tool/mobile/classes/api.php
+++ b/admin/tool/mobile/classes/api.php
@@ -170,12 +170,12 @@ public static function get_public_config() {
// Check if contacting site support is available to all visitors.
$sitesupportavailable = (isset($CFG->supportavailability) && $CFG->supportavailability == CONTACT_SUPPORT_ANYONE);
- list($authinstructions, $notusedformat) = external_format_text($CFG->auth_instructions, FORMAT_MOODLE, $context->id);
- list($maintenancemessage, $notusedformat) = external_format_text($CFG->maintenance_message, FORMAT_MOODLE, $context->id);
+ [$authinstructions] = \core_external\util::format_text($CFG->auth_instructions, FORMAT_MOODLE, $context->id);
+ [$maintenancemessage] = \core_external\util::format_text($CFG->maintenance_message, FORMAT_MOODLE, $context->id);
$settings = array(
'wwwroot' => $CFG->wwwroot,
'httpswwwroot' => $CFG->wwwroot,
- 'sitename' => external_format_string($SITE->fullname, $context->id, true),
+ 'sitename' => \core_external\util::format_string($SITE->fullname, $context->id, true),
'guestlogin' => $CFG->guestloginbutton,
'rememberusername' => $CFG->rememberusername,
'authloginviaemail' => $CFG->authloginviaemail,
@@ -265,12 +265,12 @@ public static function get_config($section) {
if (empty($section) or $section == 'frontpagesettings') {
require_once($CFG->dirroot . '/course/format/lib.php');
// First settings that anyone can deduce.
- $settings->fullname = external_format_string($SITE->fullname, $context->id);
- $settings->shortname = external_format_string($SITE->shortname, $context->id);
+ $settings->fullname = \core_external\util::format_string($SITE->fullname, $context->id);
+ $settings->shortname = \core_external\util::format_string($SITE->shortname, $context->id);
// Return to a var instead of directly to $settings object because of differences between
// list() in php5 and php7. {@link http://php.net/manual/en/function.list.php}
- $formattedsummary = external_format_text($SITE->summary, $SITE->summaryformat,
+ $formattedsummary = \core_external\util::format_text($SITE->summary, $SITE->summaryformat,
$context->id);
$settings->summary = $formattedsummary[0];
$settings->summaryformat = $formattedsummary[1];
diff --git a/admin/tool/mobile/classes/external.php b/admin/tool/mobile/classes/external.php
index f9e56a57b1c34..b8d821328e358 100644
--- a/admin/tool/mobile/classes/external.php
+++ b/admin/tool/mobile/classes/external.php
@@ -23,22 +23,21 @@
*/
namespace tool_mobile;
-defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
+defined('MOODLE_INTERNAL') || die();
require_once("$CFG->dirroot/webservice/lib.php");
-use external_api;
-use external_files;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_settings;
+use core_external\external_value;
+use core_external\external_warnings;
use context_system;
use moodle_exception;
use moodle_url;
-use core_text;
use core_user;
use coding_exception;
@@ -76,7 +75,7 @@ public static function get_plugins_supporting_mobile() {
/**
* Returns description of get_plugins_supporting_mobile() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_plugins_supporting_mobile_returns() {
@@ -131,7 +130,7 @@ public static function get_public_config() {
/**
* Returns description of get_public_config() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function get_public_config_returns() {
@@ -237,7 +236,7 @@ public static function get_config($section = '') {
/**
* Returns description of get_config() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function get_config_returns() {
@@ -346,7 +345,7 @@ public static function get_autologin_key($privatetoken) {
/**
* Returns description of get_autologin_key() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function get_autologin_key_returns() {
@@ -525,7 +524,7 @@ public static function call_external_functions($requests) {
$webservicemanager = new \webservice;
$token = $webservicemanager->get_user_ws_token(required_param('wstoken', PARAM_ALPHANUM));
- $settings = \external_settings::get_instance();
+ $settings = external_settings::get_instance();
$defaultlang = current_language();
$responses = [];
@@ -672,9 +671,9 @@ public static function get_tokens_for_qr_login($qrloginkey, $userid) {
}
// Get an existing token or create a new one.
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
$privatetoken = $token->privatetoken; // Save it here, the next function removes it.
- external_log_token_request($token);
+ \core_external\util::log_token_request($token);
$result = [
'token' => $token->token,
@@ -687,7 +686,7 @@ public static function get_tokens_for_qr_login($qrloginkey, $userid) {
/**
* Returns description of get_tokens_for_qr_login() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.9
*/
public static function get_tokens_for_qr_login_returns() {
@@ -747,7 +746,7 @@ public static function validate_subscription_key(string $key): array {
/**
* Returns description of validate_subscription_key() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.9
*/
public static function validate_subscription_key_returns() {
diff --git a/admin/tool/mobile/launch.php b/admin/tool/mobile/launch.php
index 64d3ee8ac4c2c..c1fa2a6880f20 100644
--- a/admin/tool/mobile/launch.php
+++ b/admin/tool/mobile/launch.php
@@ -26,7 +26,6 @@
*/
require_once(__DIR__ . '/../../../config.php');
-require_once($CFG->libdir . '/externallib.php');
$serviceshortname = required_param('service', PARAM_ALPHANUMEXT);
$passport = required_param('passport', PARAM_RAW); // Passport send from the app to validate the response URL.
@@ -76,9 +75,9 @@
// Get an existing token or create a new one.
$timenow = time();
-$token = external_generate_token_for_current_user($service);
+$token = \core_external\util::generate_token_for_current_user($service);
$privatetoken = $token->privatetoken;
-external_log_token_request($token);
+\core_external\util::log_token_request($token);
// Don't return the private token if the user didn't just log in and a new token wasn't created.
if (empty($SESSION->justloggedin) and $token->timecreated < $timenow) {
diff --git a/admin/tool/mobile/tests/api_test.php b/admin/tool/mobile/tests/api_test.php
index 85ff4b9e40e65..7ebfd70318450 100644
--- a/admin/tool/mobile/tests/api_test.php
+++ b/admin/tool/mobile/tests/api_test.php
@@ -82,7 +82,7 @@ public function test_get_potential_config_issues() {
*/
public function test_pre_processor_message_send_callback() {
global $DB, $CFG;
- require_once($CFG->libdir . '/externallib.php');
+
$this->preventResetByRollback();
$this->resetAfterTest();
@@ -140,7 +140,7 @@ public function test_pre_processor_message_send_callback() {
$user3 = $this->getDataGenerator()->create_user();
$this->setUser($user3);
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
$message->userto = $user3;
$messageid = message_send($message);
diff --git a/admin/tool/mobile/tests/externallib_test.php b/admin/tool/mobile/tests/externallib_test.php
index 0155a29c3713d..fe793150e3631 100644
--- a/admin/tool/mobile/tests/externallib_test.php
+++ b/admin/tool/mobile/tests/externallib_test.php
@@ -17,6 +17,7 @@
namespace tool_mobile;
use externallib_advanced_testcase;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
@@ -42,7 +43,7 @@ class externallib_test extends externallib_advanced_testcase {
*/
public function test_get_plugins_supporting_mobile() {
$result = external::get_plugins_supporting_mobile();
- $result = \external_api::clean_returnvalue(external::get_plugins_supporting_mobile_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_plugins_supporting_mobile_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertArrayHasKey('plugins', $result);
$this->assertTrue(is_array($result['plugins']));
@@ -53,17 +54,25 @@ public function test_get_public_config() {
$this->resetAfterTest(true);
$result = external::get_public_config();
- $result = \external_api::clean_returnvalue(external::get_public_config_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
// Test default values.
$context = \context_system::instance();
- list($authinstructions, $notusedformat) = external_format_text($CFG->auth_instructions, FORMAT_MOODLE, $context->id);
- list($maintenancemessage, $notusedformat) = external_format_text($CFG->maintenance_message, FORMAT_MOODLE, $context->id);
+ [$authinstructions] = \core_external\util::format_text(
+ $CFG->auth_instructions,
+ FORMAT_MOODLE,
+ $context->id
+ );
+ [$maintenancemessage] = \core_external\util::format_text(
+ $CFG->maintenance_message,
+ FORMAT_MOODLE,
+ $context->id
+ );
$expected = array(
'wwwroot' => $CFG->wwwroot,
'httpswwwroot' => $CFG->wwwroot,
- 'sitename' => external_format_string($SITE->fullname, $context->id, true),
+ 'sitename' => \core_external\util::format_string($SITE->fullname, $context->id, true),
'guestlogin' => $CFG->guestloginbutton,
'rememberusername' => $CFG->rememberusername,
'authloginviaemail' => $CFG->authloginviaemail,
@@ -126,7 +135,7 @@ public function test_get_public_config() {
set_config('auth_name', 'CAS', 'auth_cas');
set_config('auth', 'oauth2,cas');
- list($authinstructions, $notusedformat) = external_format_text($authinstructions, FORMAT_MOODLE, $context->id);
+ list($authinstructions, $notusedformat) = \core_external\util::format_text($authinstructions, FORMAT_MOODLE, $context->id);
$expected['registerauth'] = 'email';
$expected['authinstructions'] = $authinstructions;
$expected['typeoflogin'] = api::LOGIN_VIA_BROWSER;
@@ -148,7 +157,7 @@ public function test_get_public_config() {
}
$result = external::get_public_config();
- $result = \external_api::clean_returnvalue(external::get_public_config_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
// First check providers.
$identityproviders = $result['identityproviders'];
unset($result['identityproviders']);
@@ -167,7 +176,7 @@ public function test_get_public_config() {
$newurl = 'validimage.png';
set_config('auth_logo', $newurl, 'auth_cas');
$result = external::get_public_config();
- $result = \external_api::clean_returnvalue(external::get_public_config_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_public_config_returns(), $result);
$this->assertStringContainsString($newurl, $result['identityproviders'][1]['iconurl']);
}
@@ -187,10 +196,10 @@ public function test_get_config(): void {
set_config('supportemail', 'test@test.com');
$result = external::get_config();
- $result = \external_api::clean_returnvalue(external::get_config_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_config_returns(), $result);
// SITE summary is null in phpunit which gets transformed to an empty string by format_text.
- [$sitesummary, $summaryformat] = external_format_text(
+ [$sitesummary, $summaryformat] = \core_external\util::format_text(
$SITE->summary,
$SITE->summaryformat,
\context_system::instance()->id
@@ -256,7 +265,7 @@ public function test_get_config(): void {
array_splice($expected, 11);
$result = external::get_config('frontpagesettings');
- $result = \external_api::clean_returnvalue(external::get_config_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_config_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($expected, $result['settings']);
}
@@ -273,7 +282,7 @@ public function test_get_autologin_key() {
$this->setUser($user);
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
// Check we got the private token.
$this->assertTrue(isset($token->privatetoken));
@@ -290,7 +299,7 @@ public function test_get_autologin_key() {
$this->setCurrentTimeStart();
$result = external::get_autologin_key($token->privatetoken);
- $result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Validate the key.
$this->assertEquals(32, \core_text::strlen($result['key']));
$key = $DB->get_record('user_private_key', array('value' => $result['key']));
@@ -377,7 +386,7 @@ public function test_get_autologin_key_missing_locked() {
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
$_GET['wstoken'] = $token->token; // Mock parameters.
// Fake the app.
@@ -385,13 +394,13 @@ public function test_get_autologin_key_missing_locked() {
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$result = external::get_autologin_key($token->privatetoken);
- $result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Mock last time request.
$mocktime = time() - 7 * MINSECS;
set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER);
$result = external::get_autologin_key($token->privatetoken);
- $result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// Change min time between requests to 30 seconds.
set_config('autologinmintimebetweenreq', 30, 'tool_mobile');
@@ -400,7 +409,7 @@ public function test_get_autologin_key_missing_locked() {
$mocktime = time() - MINSECS;
set_user_preference('tool_mobile_autologin_request_last', $mocktime, $USER);
$result = external::get_autologin_key($token->privatetoken); // All good, we were expecint 30 seconds or more.
- $result = \external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_autologin_key_returns(), $result);
// We just requested one token, we must wait.
$this->expectException('moodle_exception');
@@ -429,7 +438,7 @@ public function test_get_content() {
$paramval = 16;
$result = external::get_content('tool_mobile', 'test_view', array(array('name' => 'param1', 'value' => $paramval)));
- $result = \external_api::clean_returnvalue(external::get_content_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_content_returns(), $result);
$this->assertCount(1, $result['templates']);
$this->assertCount(1, $result['otherdata']);
$this->assertCount(2, $result['restrict']['users']);
@@ -453,7 +462,7 @@ public function test_get_content_disabled() {
$paramval = 16;
$result = external::get_content('tool_mobile', 'test_view_disabled',
array(array('name' => 'param1', 'value' => $paramval)));
- $result = \external_api::clean_returnvalue(external::get_content_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_content_returns(), $result);
$this->assertTrue($result['disabled']);
}
@@ -507,14 +516,13 @@ public function test_call_external_functions() {
// Setup WS token.
$webservicemanager = new \webservice;
$service = $webservicemanager->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
$_POST['wstoken'] = $token->token;
- // Workaround for \external_api::call_external_function requiring sesskey.
+ // Workaround for external_api::call_external_function requiring sesskey.
$_POST['sesskey'] = sesskey();
// Call some functions.
-
$requests = [
[
'function' => 'core_course_get_courses_by_field',
@@ -536,19 +544,19 @@ public function test_call_external_functions() {
$result = external::call_external_functions($requests);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(external::call_external_functions_returns(), $result);
+ $result = external_api::clean_returnvalue(external::call_external_functions_returns(), $result);
// Only 3 responses, the 4th request is not executed because the 3rd throws an exception.
$this->assertCount(3, $result['responses']);
$this->assertFalse($result['responses'][0]['error']);
- $coursedata = \external_api::clean_returnvalue(
+ $coursedata = external_api::clean_returnvalue(
\core_course_external::get_courses_by_field_returns(),
\core_course_external::get_courses_by_field('id', $course->id));
$this->assertEquals(json_encode($coursedata), $result['responses'][0]['data']);
$this->assertFalse($result['responses'][1]['error']);
- $userdata = \external_api::clean_returnvalue(
+ $userdata = external_api::clean_returnvalue(
\core_user_external::get_users_by_field_returns(),
\core_user_external::get_users_by_field('id', [$user1->id]));
$this->assertEquals(json_encode($userdata), $result['responses'][1]['data']);
@@ -644,14 +652,14 @@ public function test_get_tokens_for_qr_login() {
// Generate new tokens, the ones we expect to receive.
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
// Fake the app.
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$result = external::get_tokens_for_qr_login($qrloginkey, $USER->id);
- $result = \external_api::clean_returnvalue(external::get_tokens_for_qr_login_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_tokens_for_qr_login_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($token->token, $result['token']);
@@ -683,14 +691,14 @@ public function test_get_tokens_for_qr_login_ignore_ip_check() {
// Generate new tokens, the ones we expect to receive.
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
// Fake the app.
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
'AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/71.0.3578.99 Mobile Safari/537.36 MoodleMobile');
$result = external::get_tokens_for_qr_login($qrloginkey, $USER->id);
- $result = \external_api::clean_returnvalue(external::get_tokens_for_qr_login_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_tokens_for_qr_login_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($token->token, $result['token']);
@@ -722,7 +730,7 @@ public function test_get_tokens_for_qr_login_ip_check_mismatch() {
// Generate new tokens, the ones we expect to receive.
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
// Fake the app.
\core_useragent::instance(true, 'Mozilla/5.0 (Linux; Android 7.1.1; Moto G Play Build/NPIS26.48-43-2; wv) ' .
@@ -834,7 +842,7 @@ public function test_validate_subscription_key_valid() {
set_config('sitesubscriptionkey', json_encode($sitesubscriptionkey), 'tool_mobile');
$result = external::validate_subscription_key($sitesubscriptionkey['key']);
- $result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertTrue($result['validated']);
}
@@ -849,13 +857,13 @@ public function test_validate_subscription_key_invalid_key_first() {
set_config('sitesubscriptionkey', json_encode($sitesubscriptionkey), 'tool_mobile');
$result = external::validate_subscription_key('fakekey');
- $result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
// The valid one has been invalidated because the previous attempt.
$result = external::validate_subscription_key($sitesubscriptionkey['key']);
- $result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
}
@@ -867,7 +875,7 @@ public function test_validate_subscription_key_invalid_key() {
$this->resetAfterTest(true);
$result = external::validate_subscription_key('fakekey');
- $result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
}
@@ -882,7 +890,7 @@ public function test_validate_subscription_key_outdated() {
set_config('sitesubscriptionkey', json_encode($sitesubscriptionkey), 'tool_mobile');
$result = external::validate_subscription_key($sitesubscriptionkey['key']);
- $result = \external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
+ $result = external_api::clean_returnvalue(external::validate_subscription_key_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertFalse($result['validated']);
}
diff --git a/admin/tool/moodlenet/classes/external.php b/admin/tool/moodlenet/classes/external.php
index b2286381f8682..9d413ca8c82d7 100644
--- a/admin/tool/moodlenet/classes/external.php
+++ b/admin/tool/moodlenet/classes/external.php
@@ -26,15 +26,15 @@
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir .'/externallib.php');
require_once($CFG->libdir . '/filelib.php');
require_once(__DIR__ . '/../lib.php');
use core_course\external\course_summary_exporter;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* This is the external API for this component.
@@ -100,7 +100,7 @@ public static function verify_webfinger(string $profileurl, int $course, int $se
/**
* verify_webfinger return.
*
- * @return \external_description
+ * @return external_description
*/
public static function verify_webfinger_returns() {
return new external_single_structure([
@@ -171,11 +171,11 @@ public static function search_courses(string $searchvalue) {
/**
* search_courses_returns.
*
- * @return \external_description
+ * @return external_description
*/
public static function search_courses_returns() {
return new external_single_structure([
- 'courses' => new \external_multiple_structure(
+ 'courses' => new external_multiple_structure(
new external_single_structure([
'id' => new external_value(PARAM_INT, 'course id'),
'fullname' => new external_value(PARAM_TEXT, 'course full name'),
diff --git a/admin/tool/policy/classes/external.php b/admin/tool/policy/classes/external.php
index 34caab94b9e77..0d8be11511f0d 100644
--- a/admin/tool/policy/classes/external.php
+++ b/admin/tool/policy/classes/external.php
@@ -24,23 +24,13 @@
namespace tool_policy;
-defined('MOODLE_INTERNAL') || die();
-
-use coding_exception;
use context_system;
-use context_user;
-use core\invalid_persistent_exception;
-use dml_exception;
-use external_api;
-use external_description;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
-use invalid_parameter_exception;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
-use restricted_context_exception;
-use tool_policy\api;
use tool_policy\form\accept_policy;
/**
@@ -106,10 +96,10 @@ public static function get_policy_version($versionid, $behalfid = null) {
$version = api::get_policy_version($versionid);
$policy['name'] = $version->name;
$policy['versionid'] = $versionid;
- list($policy['content'], $notusedformat) = external_format_text(
+ list($policy['content'], $notusedformat) = \core_external\util::format_text(
$version->content,
$version->contentformat,
- SYSCONTEXTID,
+ \context_system::instance(),
'tool_policy',
'policydocumentcontent',
$version->id
@@ -133,7 +123,7 @@ public static function get_policy_version($versionid, $behalfid = null) {
/**
* Parameter description for get_policy_version().
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_policy_version_returns() {
return new external_single_structure([
@@ -190,7 +180,7 @@ public static function submit_accept_on_behalf($jsonformdata) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function submit_accept_on_behalf_returns() {
diff --git a/admin/tool/policy/tests/externallib_test.php b/admin/tool/policy/tests/externallib_test.php
index 05dd2fc07151d..b09a3b9a3e8f5 100644
--- a/admin/tool/policy/tests/externallib_test.php
+++ b/admin/tool/policy/tests/externallib_test.php
@@ -23,7 +23,6 @@
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/user/externallib.php');
@@ -87,21 +86,21 @@ public function test_get_policy_version() {
// View current policy version.
$result = external::get_policy_version($this->policy2->get('id'));
- $result = \external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
$this->assertCount(1, $result['result']);
$this->assertEquals($this->policy1->get('name'), $result['result']['policy']['name']);
$this->assertEquals($this->policy1->get('content'), $result['result']['policy']['content']);
// View draft policy version.
$result = external::get_policy_version($this->policy3->get('id'));
- $result = \external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
$this->assertCount(0, $result['result']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals(array_pop($result['warnings'])['warningcode'], 'errorusercantviewpolicyversion');
// Add test for non existing versionid.
$result = external::get_policy_version(999);
- $result = \external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
$this->assertCount(0, $result['result']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals(array_pop($result['warnings'])['warningcode'], 'errorpolicyversionnotfound');
@@ -109,7 +108,7 @@ public function test_get_policy_version() {
// View previous non-accepted version in behalf of a child.
$this->setUser($this->parent);
$result = external::get_policy_version($this->policy1->get('id'), $this->child->id);
- $result = \external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
$this->assertCount(0, $result['result']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals(array_pop($result['warnings'])['warningcode'], 'errorusercantviewpolicyversion');
@@ -117,7 +116,7 @@ public function test_get_policy_version() {
// Let the parent accept the policy on behalf of her child and view it again.
api::accept_policies($this->policy1->get('id'), $this->child->id);
$result = external::get_policy_version($this->policy1->get('id'), $this->child->id);
- $result = \external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
$this->assertCount(1, $result['result']);
$this->assertEquals($this->policy1->get('name'), $result['result']['policy']['name']);
$this->assertEquals($this->policy1->get('content'), $result['result']['policy']['content']);
@@ -125,7 +124,7 @@ public function test_get_policy_version() {
// Only parent is able to view the child policy version accepted by her child.
$this->setUser($this->adult);
$result = external::get_policy_version($this->policy1->get('id'), $this->child->id);
- $result = \external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_policy_version_returns(), $result);
$this->assertCount(0, $result['result']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals(array_pop($result['warnings'])['warningcode'], 'errorusercantviewpolicyversion');
@@ -143,7 +142,7 @@ public function test_get_config_with_site_policy_handler() {
$CFG->sitepolicyhandler = 'tool_policy';
$sitepolicymanager = new \core_privacy\local\sitepolicy\manager();
$result = external_mobile::get_config();
- $result = \external_api::clean_returnvalue(external_mobile::get_config_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external_mobile::get_config_returns(), $result);
$toolsitepolicy = $sitepolicymanager->get_embed_url();
foreach (array_values($result['settings']) as $r) {
if ($r['name'] == 'sitepolicy') {
@@ -176,7 +175,7 @@ public function test_agree_site_policy_with_handler() {
// Call WS to agree to the site policy. It will call tool_policy handler.
$result = \core_user_external::agree_site_policy();
- $result = \external_api::clean_returnvalue(\core_user_external::agree_site_policy_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(\core_user_external::agree_site_policy_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $USER->policyagreed);
@@ -184,7 +183,7 @@ public function test_agree_site_policy_with_handler() {
// Try again, we should get a warning.
$result = \core_user_external::agree_site_policy();
- $result = \external_api::clean_returnvalue(\core_user_external::agree_site_policy_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(\core_user_external::agree_site_policy_returns(), $result);
$this->assertFalse($result['status']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('alreadyagreed', $result['warnings'][0]['warningcode']);
@@ -211,14 +210,14 @@ public function test_checkcanaccept_with_handler() {
// Default user can accept policies.
$this->setUser($adult);
$result = external_mobile::get_config();
- $result = \external_api::clean_returnvalue(external_mobile::get_config_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external_mobile::get_config_returns(), $result);
$toolsitepolicy = $sitepolicymanager->accept();
$this->assertTrue($toolsitepolicy);
// Child user can not accept policies.
$this->setUser($child);
$result = external_mobile::get_config();
- $result = \external_api::clean_returnvalue(external_mobile::get_config_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external_mobile::get_config_returns(), $result);
$this->expectException(\required_capability_exception::class);
$sitepolicymanager->accept();
}
diff --git a/admin/tool/templatelibrary/classes/external.php b/admin/tool/templatelibrary/classes/external.php
index edda9f2dc4acb..372e01afd2a3e 100644
--- a/admin/tool/templatelibrary/classes/external.php
+++ b/admin/tool/templatelibrary/classes/external.php
@@ -14,25 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external API for this tool.
- *
- * @package tool_templatelibrary
- * @copyright 2015 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace tool_templatelibrary;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_format_value;
-use external_single_structure;
-use external_multiple_structure;
-use invalid_parameter_exception;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_value;
/**
* This is the external API for this tool.
@@ -91,7 +78,7 @@ public static function list_templates($component, $search, $themename = '') {
/**
* Returns description of list_templates() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function list_templates_returns() {
return new external_multiple_structure(new external_value(PARAM_RAW, 'The template name (format is component/templatename)'));
@@ -132,7 +119,7 @@ public static function load_canonical_template($component, $template) {
/**
* Returns description of load_canonical_template() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function load_canonical_template_returns() {
return new external_value(PARAM_RAW, 'template');
diff --git a/admin/tool/usertours/classes/external/tour.php b/admin/tool/usertours/classes/external/tour.php
index 342fd445a9278..649becb5de8d8 100644
--- a/admin/tool/usertours/classes/external/tour.php
+++ b/admin/tool/usertours/classes/external/tour.php
@@ -14,23 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Web Service functions for steps.
- *
- * @package tool_usertours
- * @copyright 2016 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace tool_usertours\external;
-defined('MOODLE_INTERNAL') || die();
-
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_multiple_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use tool_usertours\tour as tourinstance;
use tool_usertours\step;
diff --git a/admin/tool/usertours/classes/output/step.php b/admin/tool/usertours/classes/output/step.php
index 8485acbc62cb7..a3f5f81a02400 100644
--- a/admin/tool/usertours/classes/output/step.php
+++ b/admin/tool/usertours/classes/output/step.php
@@ -73,13 +73,13 @@ public function export_for_template(\renderer_base $output) {
$result = (object) [
'stepid' => $step->get_id(),
- 'title' => external_format_text(
+ 'title' => \core_external\util::format_text(
helper::get_string_from_input($step->get_title()),
FORMAT_HTML,
$PAGE->context->id,
'tool_usertours'
)[0],
- 'content' => external_format_text(
+ 'content' => \core_external\util::format_text(
$content,
$step->get_contentformat(),
$PAGE->context->id,
diff --git a/admin/tool/usertours/db/upgrade.php b/admin/tool/usertours/db/upgrade.php
index 694bf33016dd8..157a377aadce5 100644
--- a/admin/tool/usertours/db/upgrade.php
+++ b/admin/tool/usertours/db/upgrade.php
@@ -102,7 +102,8 @@ function xmldb_tool_usertours_upgrade($oldversion) {
} else {
// Field was added by previous upgrade step with the default value is FORMAT_HTML.
// Need to drop the field and re-create with the new structure to make sure all the existing tours use FORMAT_MOODLE.
- // FORMAT_MOODLE will force the external_format_text method to use nl2br to convert the new line to line break tag.
+ // FORMAT_MOODLE will force the \core_external\util::format_text method to use nl2br to
+ // convert the new line to line break tag.
$dbman->drop_field($table, $field);
// Add the field again.
$dbman->add_field($table, $field);
diff --git a/admin/tool/usertours/lib.php b/admin/tool/usertours/lib.php
index 9591ea8005975..7ff8bbd6339a7 100644
--- a/admin/tool/usertours/lib.php
+++ b/admin/tool/usertours/lib.php
@@ -22,9 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
-
-use core\output\inplace_editable;
+use core_external\external_api;
use tool_usertours\helper;
/**
@@ -33,7 +31,7 @@
* @param string $itemtype The type of item.
* @param int $itemid The ID of the item.
* @param mixed $newvalue The new value
- * @return inplace_editable
+ * @return \core\output\inplace_editable
*/
function tool_usertours_inplace_editable($itemtype, $itemid, $newvalue) {
$context = \context_system::instance();
diff --git a/admin/tool/xmldb/classes/external.php b/admin/tool/xmldb/classes/external.php
index 8e56a45334696..1716dd4aad147 100644
--- a/admin/tool/xmldb/classes/external.php
+++ b/admin/tool/xmldb/classes/external.php
@@ -14,17 +14,9 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Web services
- *
- * @package tool_xmldb
- * @copyright 2018 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
/**
* tool_xmldb external function
@@ -124,4 +116,4 @@ public static function invoke_move_action_returns() {
return null;
}
-}
\ No newline at end of file
+}
diff --git a/admin/webservice/service_functions.php b/admin/webservice/service_functions.php
index e7848787e9044..14c7951ed1d57 100644
--- a/admin/webservice/service_functions.php
+++ b/admin/webservice/service_functions.php
@@ -24,7 +24,6 @@
*/
require_once('../../config.php');
require_once($CFG->libdir . '/adminlib.php');
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/lib.php');
require_once('forms.php');
@@ -123,4 +122,3 @@
$functions = $webservicemanager->get_external_functions(array($service->id));
echo $renderer->admin_service_function_list($functions, $service);
echo $OUTPUT->footer();
-
diff --git a/admin/webservice/testclient.php b/admin/webservice/testclient.php
index c7b77cc8fa25e..96548ae4b1297 100644
--- a/admin/webservice/testclient.php
+++ b/admin/webservice/testclient.php
@@ -26,7 +26,6 @@
require('../../config.php');
require_once($CFG->libdir.'/adminlib.php');
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . "/" . $CFG->admin . "/webservice/testclient_forms.php");
$function = optional_param('function', '', PARAM_PLUGIN);
@@ -49,7 +48,7 @@
$allfunctions = $DB->get_records('external_functions', array(), 'name ASC');
$functions = array();
foreach ($allfunctions as $f) {
- $finfo = external_api::external_function_info($f);
+ $finfo = \core_external\external_api::external_function_info($f);
if (!empty($finfo->testclientpath) and file_exists($CFG->dirroot.'/'.$finfo->testclientpath)) {
//some plugins may want to have own test client forms
include_once($CFG->dirroot.'/'.$finfo->testclientpath);
@@ -115,7 +114,7 @@
} else if ($data = $mform->get_data()) {
- $functioninfo = external_api::external_function_info($function);
+ $functioninfo = \core_external\external_api::external_function_info($function);
// first load lib of selected protocol
require_once("$CFG->dirroot/webservice/$protocol/locallib.php");
@@ -140,7 +139,7 @@
$params = $mform->get_params();
// now test the parameters, this also fixes PHP data types
- $params = external_api::validate_parameters($functioninfo->parameters_desc, $params);
+ $params = \core_external\external_api::validate_parameters($functioninfo->parameters_desc, $params);
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('pluginname', 'webservice_'.$protocol).': '.$function);
diff --git a/admin/webservice/tokens.php b/admin/webservice/tokens.php
index e21ef3a3265fd..32628d8d37eff 100644
--- a/admin/webservice/tokens.php
+++ b/admin/webservice/tokens.php
@@ -25,7 +25,6 @@
require(__DIR__ . '/../../config.php');
require_once($CFG->libdir . '/adminlib.php');
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/lib.php');
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
@@ -69,8 +68,14 @@
// Generate the token.
if (empty($errormsg)) {
- external_generate_token(EXTERNAL_TOKEN_PERMANENT, $data->service, $data->user, context_system::instance(),
- $data->validuntil, $data->iprestriction);
+ \core_external\util::generate_token(
+ EXTERNAL_TOKEN_PERMANENT,
+ \core_external\util::get_service_by_id($data->service),
+ $data->user,
+ context_system::instance(),
+ $data->validuntil,
+ $data->iprestriction
+ );
redirect($PAGE->url);
}
}
diff --git a/analytics/lib.php b/analytics/lib.php
index 9b6b41d4bb68f..827a745ebb58f 100644
--- a/analytics/lib.php
+++ b/analytics/lib.php
@@ -22,7 +22,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+use core_external\external_api;
/**
* Implements the inplace editable feature.
@@ -33,9 +33,8 @@
* @return \core\output\inplace_editable
*/
function core_analytics_inplace_editable($itemtype, $itemid, $newvalue) {
-
if ($itemtype === 'modelname') {
- \external_api::validate_context(context_system::instance());
+ external_api::validate_context(context_system::instance());
require_capability('moodle/analytics:managemodels', \context_system::instance());
$model = new \core_analytics\model($itemid);
diff --git a/auth/classes/external.php b/auth/classes/external.php
index 2cb651dd162ad..498c1879607a1 100644
--- a/auth/classes/external.php
+++ b/auth/classes/external.php
@@ -24,9 +24,14 @@
* @since Moodle 3.2
*/
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/authlib.php');
/**
diff --git a/auth/classes/output/login.php b/auth/classes/output/login.php
index 1f0bbd77ab9b0..c2bb00b15ac29 100644
--- a/auth/classes/output/login.php
+++ b/auth/classes/output/login.php
@@ -23,9 +23,6 @@
*/
namespace core_auth\output;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
use context_system;
use help_icon;
@@ -149,7 +146,7 @@ public function export_for_template(renderer_base $output) {
$data->hasidentityproviders = !empty($this->identityproviders);
$data->hasinstructions = !empty($this->instructions) || $this->cansignup;
$data->identityproviders = $identityproviders;
- list($data->instructions, $data->instructionsformat) = external_format_text($this->instructions, FORMAT_MOODLE,
+ list($data->instructions, $data->instructionsformat) = \core_external\util::format_text($this->instructions, FORMAT_MOODLE,
context_system::instance()->id);
$data->loginurl = $this->loginurl->out(false);
$data->signupurl = $this->signupurl->out(false);
diff --git a/auth/email/classes/external.php b/auth/email/classes/external.php
index 52e7227bae738..042d06f8a74cd 100644
--- a/auth/email/classes/external.php
+++ b/auth/email/classes/external.php
@@ -24,9 +24,16 @@
* @since Moodle 3.2
*/
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/authlib.php');
require_once($CFG->dirroot . '/user/editlib.php');
require_once($CFG->dirroot . '/user/profile/lib.php');
@@ -106,10 +113,10 @@ public static function get_signup_settings() {
$result['profilefields'] = array();
foreach ($fields as $field) {
$fielddata = $field->object->get_field_config_for_external();
- $fielddata['categoryname'] = external_format_string($field->categoryname, $context->id);
- $fielddata['name'] = external_format_string($fielddata['name'], $context->id);
+ $fielddata['categoryname'] = \core_external\util::format_string($field->categoryname, $context->id);
+ $fielddata['name'] = \core_external\util::format_string($fielddata['name'], $context->id);
list($fielddata['defaultdata'], $fielddata['defaultdataformat']) =
- external_format_text($fielddata['defaultdata'], $fielddata['defaultdataformat'], $context->id);
+ \core_external\util::format_text($fielddata['defaultdata'], $fielddata['defaultdataformat'], $context->id);
$result['profilefields'][] = $fielddata;
}
diff --git a/auth/email/tests/external/external_test.php b/auth/email/tests/external/external_test.php
index 4c203e3c3d6a9..e69e90e585be4 100644
--- a/auth/email/tests/external/external_test.php
+++ b/auth/email/tests/external/external_test.php
@@ -70,7 +70,7 @@ public function test_get_signup_settings() {
$CFG->sitepolicy = 'https://moodle.org';
$result = auth_email_external::get_signup_settings();
- $result = \external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
// Check expected data.
$this->assertEquals(array('firstname', 'lastname'), $result['namefields']);
@@ -101,10 +101,6 @@ public function test_get_signup_settings() {
* Test get_signup_settings with mathjax in a profile field.
*/
public function test_get_signup_settings_with_mathjax_in_profile_fields() {
- global $CFG, $DB;
-
- require_once($CFG->dirroot . '/lib/externallib.php');
-
// Enable MathJax filter in content and headings.
$this->configure_filters([
['name' => 'mathjaxloader', 'state' => TEXTFILTER_ON, 'move' => -1, 'applytostrings' => true],
@@ -119,12 +115,12 @@ public function test_get_signup_settings_with_mathjax_in_profile_fields() {
'datatype' => 'textarea', 'signup' => 1, 'visible' => 1, 'required' => 1, 'sortorder' => 2));
$result = auth_email_external::get_signup_settings();
- $result = \external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(auth_email_external::get_signup_settings_returns(), $result);
// Format the original data.
$sitecontext = \context_system::instance();
- $categoryname = external_format_string($categoryname, $sitecontext->id);
- $fieldname = external_format_string($fieldname, $sitecontext->id);
+ $categoryname = \core_external\util::format_string($categoryname, $sitecontext->id);
+ $fieldname = \core_external\util::format_string($fieldname, $sitecontext->id);
// Whip up a array with named entries to easily check against.
$namedarray = array();
@@ -173,7 +169,7 @@ public function test_signup_user() {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email, $city, $country,
'', '', $customprofilefields);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$user = $DB->get_record('user', array('username' => $username));
@@ -194,7 +190,7 @@ public function test_signup_user() {
$password = 'abc';
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email, $city, $country,
'', '', $customprofilefields);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertFalse($result['success']);
$this->assertCount(3, $result['warnings']);
$expectederrors = array('username', 'email', 'password');
diff --git a/auth/tests/external/external_test.php b/auth/tests/external/external_test.php
index f8a56d45938c2..07a47aa39c6a7 100644
--- a/auth/tests/external/external_test.php
+++ b/auth/tests/external/external_test.php
@@ -28,6 +28,7 @@
use auth_email_external;
use core_auth_external;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -85,14 +86,14 @@ public function test_confirm_user() {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$secret = $DB->get_field('user', 'secret', array('username' => $username));
// Confirm the user.
$result = core_auth_external::confirm_user($username, $secret);
- $result = \external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
+ $result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$confirmed = $DB->get_field('user', 'confirmed', array('username' => $username));
@@ -100,7 +101,7 @@ public function test_confirm_user() {
// Try to confirm the user again.
$result = core_auth_external::confirm_user($username, $secret);
- $result = \external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
+ $result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertFalse($result['success']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('alreadyconfirmed', $result['warnings'][0]['warningcode']);
@@ -119,7 +120,7 @@ public function test_age_digital_consent_verification_is_not_enabled() {
$CFG->agedigitalconsentverification = 0;
$result = core_auth_external::is_age_digital_consent_verification_enabled();
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_auth_external::is_age_digital_consent_verification_enabled_returns(), $result);
$this->assertFalse($result['status']);
}
@@ -132,7 +133,7 @@ public function test_age_digital_consent_verification_is_enabled() {
$CFG->agedigitalconsentverification = 1;
$result = core_auth_external::is_age_digital_consent_verification_enabled();
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_auth_external::is_age_digital_consent_verification_enabled_returns(), $result);
$this->assertTrue($result['status']);
}
@@ -151,12 +152,12 @@ public function test_resend_confirmation_email() {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$result = core_auth_external::resend_confirmation_email($username, $password);
- $result = \external_api::clean_returnvalue(core_auth_external::resend_confirmation_email_returns(), $result);
+ $result = external_api::clean_returnvalue(core_auth_external::resend_confirmation_email_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEmpty($result['warnings']);
$confirmed = $DB->get_field('user', 'confirmed', array('username' => $username));
@@ -176,7 +177,7 @@ public function test_resend_confirmation_email_invalid_username() {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
@@ -199,7 +200,7 @@ public function test_resend_confirmation_email_invalid_password() {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
@@ -223,14 +224,14 @@ public function test_resend_confirmation_email_already_confirmed_user() {
// Create new user.
$result = auth_email_external::signup_user($username, $password, $firstname, $lastname, $email);
- $result = \external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
+ $result = external_api::clean_returnvalue(auth_email_external::signup_user_returns(), $result);
$this->assertTrue($result['success']);
$this->assertEmpty($result['warnings']);
$secret = $DB->get_field('user', 'secret', array('username' => $username));
// Confirm the user.
$result = core_auth_external::confirm_user($username, $secret);
- $result = \external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
+ $result = external_api::clean_returnvalue(core_auth_external::confirm_user_returns(), $result);
$this->assertTrue($result['success']);
$this->expectException('\moodle_exception');
diff --git a/backup/externallib.php b/backup/externallib.php
index 7f902cffca20c..fee868f5b11fb 100644
--- a/backup/externallib.php
+++ b/backup/externallib.php
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
/**
* External backup API.
*
@@ -24,9 +23,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
@@ -101,7 +105,7 @@ public static function get_async_backup_progress($backupids, $contextid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_async_backup_progress_returns() {
@@ -172,7 +176,7 @@ public static function get_async_backup_links_backup($filename, $contextid) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_async_backup_links_backup_returns() {
@@ -238,7 +242,7 @@ public static function get_async_backup_links_restore($backupid, $contextid) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_async_backup_links_restore_returns() {
@@ -321,7 +325,7 @@ public static function get_copy_progress($copies) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.9
*/
public static function get_copy_progress_returns() {
@@ -400,7 +404,7 @@ public static function submit_copy_form($jsonformdata) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.9
*/
public static function submit_copy_form_returns() {
diff --git a/backup/tests/externallib_test.php b/backup/tests/externallib_test.php
index ee39842a30252..fed9e12675586 100644
--- a/backup/tests/externallib_test.php
+++ b/backup/tests/externallib_test.php
@@ -18,6 +18,7 @@
use backup;
use core_backup_external;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -90,7 +91,7 @@ public function test_get_copy_progress() {
$returnvalue = core_backup_external::get_copy_progress($params);
// We need to execute the return values cleaning process to simulate the web service server.
- $returnvalue = \external_api::clean_returnvalue(core_backup_external::get_copy_progress_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_backup_external::get_copy_progress_returns(), $returnvalue);
$this->assertEquals(\backup::STATUS_AWAITING, $returnvalue[0]['status']);
$this->assertEquals(0, $returnvalue[0]['progress']);
@@ -111,7 +112,7 @@ public function test_get_copy_progress() {
$params = array('copies' => $copydetails);
$returnvalue = core_backup_external::get_copy_progress($params);
- $returnvalue = \external_api::clean_returnvalue(core_backup_external::get_copy_progress_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_backup_external::get_copy_progress_returns(), $returnvalue);
$this->assertEquals(\backup::STATUS_FINISHED_OK, $returnvalue[0]['status']);
$this->assertEquals(1, $returnvalue[0]['progress']);
@@ -160,7 +161,7 @@ public function test_submit_copy_form() {
$returnvalue = core_backup_external::submit_copy_form($jsonformdata);
- $returnjson = \external_api::clean_returnvalue(core_backup_external::submit_copy_form_returns(), $returnvalue);
+ $returnjson = external_api::clean_returnvalue(core_backup_external::submit_copy_form_returns(), $returnvalue);
$copyids = json_decode($returnjson, true);
$backuprec = $DB->get_record('backup_controllers', array('backupid' => $copyids['backupid']));
diff --git a/badges/classes/external.php b/badges/classes/external.php
index df841f760d30e..b8e856d9be346 100644
--- a/badges/classes/external.php
+++ b/badges/classes/external.php
@@ -26,10 +26,15 @@
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/badgeslib.php');
use core_badges\external\user_badge_exporter;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* Badges external functions
diff --git a/badges/tests/external/external_test.php b/badges/tests/external/external_test.php
index 126c2d7f13b6d..6bbd8c739ec78 100644
--- a/badges/tests/external/external_test.php
+++ b/badges/tests/external/external_test.php
@@ -27,6 +27,8 @@
namespace core_badges\external;
use core_badges_external;
+use core_external\external_api;
+use core_external\external_settings;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -214,12 +216,12 @@ public function test_get_my_user_badges() {
}
$result = core_badges_external::get_user_badges();
- $result = \external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
+ $result = external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
$this->assertEquals($expectedbadges, $result['badges']);
// Pagination and filtering.
$result = core_badges_external::get_user_badges(0, $this->course->id, 0, 1, '', true);
- $result = \external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
+ $result = external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
$this->assertCount(1, $result['badges']);
$this->assertEquals($coursebadge, $result['badges'][0]);
}
@@ -232,7 +234,7 @@ public function test_get_other_user_badges() {
$this->setUser($this->teacher);
$result = core_badges_external::get_user_badges($this->student->id);
- $result = \external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
+ $result = external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
$this->assertCount(2, $result['badges']);
@@ -264,7 +266,7 @@ public function test_get_user_badges_filter_issuername(): void {
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
- \external_settings::get_instance()->set_filter(true);
+ external_settings::get_instance()->set_filter(true);
// Update issuer name of test badge.
$issuername = 'Issuer (en)Issuer (es)';
@@ -272,7 +274,7 @@ public function test_get_user_badges_filter_issuername(): void {
// Retrieve student badges.
$result = core_badges_external::get_user_badges($this->student->id);
- $result = \external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
+ $result = external_api::clean_returnvalue(core_badges_external::get_user_badges_returns(), $result);
// Site badge will be last, because it has the earlier issued date.
$badge = end($result['badges']);
diff --git a/blocks/accessreview/classes/external/get_module_data.php b/blocks/accessreview/classes/external/get_module_data.php
index d6933f5d28b77..5c2e901fccde5 100644
--- a/blocks/accessreview/classes/external/get_module_data.php
+++ b/blocks/accessreview/classes/external/get_module_data.php
@@ -14,27 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Web service to fetch module data.
- *
- * @package block_accessreview
- * @copyright 2020 onward Brickfield Education Labs Ltd, https://www.brickfield.ie
- * @author 2020 Max Larkin
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace block_accessreview\external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use tool_brickfield\manager;
-defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
-
/**
* Web service to fetch module data.
*
diff --git a/blocks/accessreview/classes/external/get_section_data.php b/blocks/accessreview/classes/external/get_section_data.php
index 29d9836be9c52..70601f851de06 100644
--- a/blocks/accessreview/classes/external/get_section_data.php
+++ b/blocks/accessreview/classes/external/get_section_data.php
@@ -14,26 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Web service to fetch section data.
- *
- * @package block_accessreview
- * @copyright 2020 onward Brickfield Education Labs Ltd, https://www.brickfield.ie
- * @author 2020 Max Larkin
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace block_accessreview\external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use tool_brickfield\manager;
-defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
-
/**
* Web service to fetch section data.
*
diff --git a/blocks/classes/external.php b/blocks/classes/external.php
index 5f1458bcbe974..0d6fc224b0bc8 100644
--- a/blocks/classes/external.php
+++ b/blocks/classes/external.php
@@ -24,9 +24,17 @@
* @since Moodle 3.3
*/
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/my/lib.php");
/**
diff --git a/blocks/classes/external/fetch_addable_blocks.php b/blocks/classes/external/fetch_addable_blocks.php
index d649e5114b37b..e58934e98f26b 100644
--- a/blocks/classes/external/fetch_addable_blocks.php
+++ b/blocks/classes/external/fetch_addable_blocks.php
@@ -14,31 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method used for fetching the addable blocks in a given page.
- *
- * @package core_block
- * @since Moodle 3.11
- * @copyright 2020 Mihail Geshoski
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_block\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* This is the external method used for fetching the addable blocks in a given page.
*
+ * @package core_block
+ * @since Moodle 3.11
* @copyright 2020 Mihail Geshoski
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/blocks/html/block_html.php b/blocks/html/block_html.php
index cb1f6a6b7990c..2e77ca9488963 100644
--- a/blocks/html/block_html.php
+++ b/blocks/html/block_html.php
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\util as external_util;
+
/**
* Form for editing HTML block instances.
*
@@ -21,9 +23,7 @@
* @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
class block_html extends block_base {
-
function init() {
$this->title = get_string('pluginname', 'block_html');
}
@@ -87,9 +87,6 @@ function get_content() {
}
public function get_content_for_external($output) {
- global $CFG;
- require_once($CFG->libdir . '/externallib.php');
-
$bc = new stdClass;
$bc->title = null;
$bc->content = '';
@@ -113,8 +110,15 @@ public function get_content_for_external($output) {
if (isset($this->config->format)) {
$format = $this->config->format;
}
- list($bc->content, $bc->contentformat) =
- external_format_text($this->config->text, $format, $this->context, 'block_html', 'content', null, $filteropt);
+ [$bc->content, $bc->contentformat] = \core_external\util::format_text(
+ $this->config->text,
+ $format,
+ $this->context,
+ 'block_html',
+ 'content',
+ null,
+ $filteropt
+ );
$bc->files = external_util::get_area_files($this->context->id, 'block_html', 'content', false, false);
}
diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php
index 393e90a8c78e9..742b93b3b0766 100644
--- a/blocks/moodleblock.class.php
+++ b/blocks/moodleblock.class.php
@@ -278,7 +278,7 @@ public function get_content_for_output($output) {
* Return an object containing all the block content to be returned by external functions.
*
* If your block is returning formatted content or provide files for download, you should override this method to use the
- * external_format_text, external_format_string functions for formatting or external_util::get_area_files for files.
+ * \core_external\util::format_text, \core_external\util::format_string functions for formatting or external_util::get_area_files for files.
*
* @param core_renderer $output the rendered used for output
* @return stdClass object containing the block title, central content, footer and linked files (if any).
diff --git a/blocks/recentlyaccesseditems/classes/external.php b/blocks/recentlyaccesseditems/classes/external.php
index ddfea0dfafd1a..1e5c910aae7c9 100644
--- a/blocks/recentlyaccesseditems/classes/external.php
+++ b/blocks/recentlyaccesseditems/classes/external.php
@@ -14,23 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External API.
- *
- * @package block_recentlyaccesseditems
- * @copyright 2018 Victor Deniz
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace block_recentlyaccesseditems;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
use block_recentlyaccesseditems\external\recentlyaccesseditems_item_exporter;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_multiple_structure;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_value;
use context_user;
use context_module;
@@ -92,7 +82,7 @@ public static function get_recent_items(int $limit = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.6
*/
public static function get_recent_items_returns() {
diff --git a/blocks/starredcourses/classes/external.php b/blocks/starredcourses/classes/external.php
index d1ace2cd0f3fd..8aaa738d5a996 100644
--- a/blocks/starredcourses/classes/external.php
+++ b/blocks/starredcourses/classes/external.php
@@ -21,14 +21,16 @@
* @copyright 2018 Simey Lameze
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
+defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/externallib.php');
-use \core_course\external\course_summary_exporter;
+use core_course\external\course_summary_exporter;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_value;
/**
* Starred courses block external functions.
@@ -107,7 +109,7 @@ public static function get_starred_courses($limit, $offset) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.6
*/
public static function get_starred_courses_returns() {
diff --git a/blocks/tests/externallib_test.php b/blocks/tests/externallib_test.php
index 8291879622d18..5d5b92784d660 100644
--- a/blocks/tests/externallib_test.php
+++ b/blocks/tests/externallib_test.php
@@ -63,7 +63,7 @@ public function test_get_course_blocks() {
// Check for the new block.
$result = core_block_external::get_course_blocks($course->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
// Expect the new block.
$this->assertCount(1, $result['blocks']);
@@ -92,7 +92,7 @@ public function test_get_course_blocks_site_home() {
// Check for the new block.
$result = core_block_external::get_course_blocks(SITEID);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
// Expect the new block.
$this->assertCount(1, $result['blocks']);
@@ -119,7 +119,7 @@ public function test_get_course_blocks_overrides() {
// Try default blocks.
$result = core_block_external::get_course_blocks($course->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
// Expect 4 default blocks.
$this->assertCount(4, $result['blocks']);
@@ -202,7 +202,7 @@ public function test_get_course_blocks_contents() {
// Check for the new block.
$result = core_block_external::get_course_blocks($course->id, true);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
// Expect the new block.
$this->assertCount(1, $result['blocks']);
@@ -236,8 +236,6 @@ public function test_get_course_blocks_contents() {
public function test_get_course_blocks_contents_with_mathjax() {
global $DB, $CFG;
- require_once($CFG->dirroot . '/lib/externallib.php');
-
$this->resetAfterTest(true);
// Enable MathJax filter in content and headings.
@@ -292,12 +290,12 @@ public function test_get_course_blocks_contents_with_mathjax() {
// Check for the new block.
$result = core_block_external::get_course_blocks($course->id, true);
- $result = \external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_course_blocks_returns(), $result);
// Format the original data.
$sitecontext = \context_system::instance();
- $title = external_format_string($title, $coursecontext->id);
- list($body, $bodyformat) = external_format_text($body, $bodyformat, $coursecontext->id, 'block_html', 'content');
+ $title = \core_external\util::format_string($title, $coursecontext->id);
+ list($body, $bodyformat) = \core_external\util::format_text($body, $bodyformat, $coursecontext, 'block_html', 'content');
// Check that the block data is formatted.
$this->assertCount(1, $result['blocks']);
@@ -336,7 +334,7 @@ public function test_get_dashboard_blocks_default_dashboard() {
// Check for the default blocks.
$result = core_block_external::get_dashboard_blocks($user->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
// Expect all default blocks defined in blocks_add_default_system_blocks().
$this->assertCount(count($alldefaultblocksordered), $result['blocks']);
$returnedblocks = array();
@@ -390,7 +388,7 @@ public function test_get_dashboard_blocks_default_dashboard_including_sticky_blo
// Check for the default blocks plus the sticky.
$result = core_block_external::get_dashboard_blocks($user->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
// Expect all default blocks defined in blocks_add_default_system_blocks() plus sticky one.
$this->assertCount(count($alldefaultblocks) + 1, $result['blocks']);
$found = false;
@@ -441,7 +439,7 @@ public function test_get_dashboard_blocks_custom_user_dashboard() {
// Check for the new block as admin for a user.
$result = core_block_external::get_dashboard_blocks($user->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
// Expect all default blocks defined in blocks_add_default_system_blocks() plus the one we added.
$this->assertCount(count($alldefaultblocks) + 1, $result['blocks']);
$found = false;
@@ -499,7 +497,7 @@ public function test_get_dashboard_blocks_my_courses() {
// Check for the default blocks.
$result = core_block_external::get_dashboard_blocks($user->id, false, MY_PAGE_COURSES);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(core_block_external::get_dashboard_blocks_returns(), $result);
// Expect all default blocks defined in blocks_add_default_system_blocks().
$this->assertCount(count($alldefaultblocksordered), $result['blocks']);
$returnedblocks = [];
diff --git a/blog/classes/external.php b/blog/classes/external.php
index e199d359b3582..c139f20523d04 100644
--- a/blog/classes/external.php
+++ b/blog/classes/external.php
@@ -25,16 +25,15 @@
namespace core_blog;
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir .'/externallib.php');
require_once($CFG->dirroot .'/blog/lib.php');
require_once($CFG->dirroot .'/blog/locallib.php');
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_system;
use context_course;
use moodle_exception;
@@ -195,7 +194,7 @@ public static function get_entries($filters = array(), $page = 0, $perpage = 10)
/**
* Returns description of get_entries() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.6
*/
public static function get_entries_returns() {
@@ -277,7 +276,7 @@ public static function view_entries($filters = array()) {
/**
* Returns description of view_entries() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.6
*/
public static function view_entries_returns() {
diff --git a/blog/classes/external/post_exporter.php b/blog/classes/external/post_exporter.php
index e608c32b754bc..fcc97b88d2b07 100644
--- a/blog/classes/external/post_exporter.php
+++ b/blog/classes/external/post_exporter.php
@@ -25,8 +25,8 @@
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
-use external_util;
-use external_files;
+use core_external\util as external_util;
+use core_external\external_files;
use renderer_base;
use context_system;
use core_tag\external\tag_item_exporter;
diff --git a/blog/tests/external/external_test.php b/blog/tests/external/external_test.php
index d75489bd43e10..c51ec1436a407 100644
--- a/blog/tests/external/external_test.php
+++ b/blog/tests/external/external_test.php
@@ -24,6 +24,8 @@
namespace core_blog\external;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -108,7 +110,7 @@ public function test_get_public_entries_global_level_by_non_logged_users() {
$DB->set_field('post', 'publishstate', 'public', array('id' => $this->postid));
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertCount(1, $result['entries'][0]['tags']);
$this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
@@ -144,7 +146,7 @@ public function test_get_public_entries_global_level_by_guest_users() {
$this->setGuestUser();
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertCount(1, $result['entries'][0]['tags']);
$this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
@@ -162,7 +164,7 @@ public function test_get_not_public_entries_global_level_by_non_logged_users() {
$CFG->bloglevel = BLOG_GLOBAL_LEVEL;
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -177,7 +179,7 @@ public function test_get_not_public_entries_global_level_by_guest_user() {
$this->setGuestUser();
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -198,7 +200,7 @@ public function test_get_not_public_entries_site_level_by_guest_users() {
$this->setGuestUser();
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -209,7 +211,7 @@ public function test_get_site_entries_site_level_by_normal_users() {
$this->setUser($this->userid);
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
@@ -225,7 +227,7 @@ public function test_get_draft_entries_site_level_by_author_users() {
$this->setUser($this->userid);
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
@@ -242,7 +244,7 @@ public function test_get_draft_entries_site_level_by_not_author_users() {
$this->setUser($user);
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -258,7 +260,7 @@ public function test_get_draft_entries_site_level_by_admin_users() {
$this->setAdminUser();
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
@@ -275,7 +277,7 @@ public function test_get_draft_entries_user_level_by_author_users() {
$this->setUser($this->userid);
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
@@ -293,7 +295,7 @@ public function test_get_draft_entries_user_level_by_not_author_users() {
$this->setUser($user);
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -310,7 +312,7 @@ public function test_get_draft_entries_user_level_by_admin_users() {
$this->setAdminUser();
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
}
@@ -336,7 +338,7 @@ public function test_get_all_entries_including_pagination() {
$this->setUser($this->userid);
$result = \core_blog\external::get_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(2, $result['entries']);
$this->assertEquals(2, $result['totalentries']);
$this->assertCount(0, $result['entries'][0]['tags']);
@@ -344,13 +346,13 @@ public function test_get_all_entries_including_pagination() {
$this->assertEquals('tag1', $result['entries'][1]['tags'][0]['rawname']);
$result = \core_blog\external::get_entries(array(), 0, 1);
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals(2, $result['totalentries']);
$this->assertEquals($newpost->id, $result['entries'][0]['id']);
$result = \core_blog\external::get_entries(array(), 1, 1);
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertEquals(2, $result['totalentries']);
$this->assertEquals($this->postid, $result['entries'][0]['id']);
@@ -374,19 +376,19 @@ public function test_get_entries_filtering_by_course() {
// There is one entry associated with a course.
$result = \core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $this->courseid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
$this->assertCount(1, $result['entries'][0]['tags']);
$this->assertEquals('tag1', $result['entries'][0]['tags'][0]['rawname']);
// There is no entry associated with a wrong course.
$result = \core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $anothercourse->id)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
// There is no entry associated with a module.
$result = \core_blog\external::get_entries(array(array('name' => 'cmid', 'value' => $this->cmid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -409,17 +411,17 @@ public function test_get_entries_filtering_by_module() {
// There is no entry associated with a course.
$result = \core_blog\external::get_entries(array(array('name' => 'courseid', 'value' => $this->courseid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
// There is one entry associated with a module.
$result = \core_blog\external::get_entries(array(array('name' => 'cmid', 'value' => $this->cmid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// There is no entry associated with a wrong module.
$result = \core_blog\external::get_entries(array(array('name' => 'cmid', 'value' => $anothermodule->cmid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -430,12 +432,12 @@ public function test_get_entries_filtering_by_author() {
$this->setAdminUser();
// Filter by author.
$result = \core_blog\external::get_entries(array(array('name' => 'userid', 'value' => $this->userid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// No author.
$anotheruser = $this->getDataGenerator()->create_user();
$result = \core_blog\external::get_entries(array(array('name' => 'userid', 'value' => $anotheruser->id)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -446,7 +448,7 @@ public function test_get_entries_filtering_by_entry() {
$this->setAdminUser();
// Filter by correct entry.
$result = \core_blog\external::get_entries(array(array('name' => 'entryid', 'value' => $this->postid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// Non-existent entry.
$this->expectException('\moodle_exception');
@@ -460,11 +462,11 @@ public function test_get_entries_filtering_by_search() {
$this->setAdminUser();
// Filter by correct search.
$result = \core_blog\external::get_entries(array(array('name' => 'search', 'value' => 'test')));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// Non-existent search.
$result = \core_blog\external::get_entries(array(array('name' => 'search', 'value' => 'abc')));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -475,14 +477,14 @@ public function test_get_entries_filtering_by_tag() {
$this->setAdminUser();
// Filter by correct tag.
$result = \core_blog\external::get_entries(array(array('name' => 'tag', 'value' => 'tag1')));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// Create tag.
$tag = $this->getDataGenerator()->create_tag(array('userid' => $this->userid, 'name' => 'tag2',
'isstandard' => 1));
$result = \core_blog\external::get_entries(array(array('name' => 'tag', 'value' => 'tag2')));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -493,7 +495,7 @@ public function test_get_entries_filtering_by_tagid() {
$this->setAdminUser();
// Filter by correct tag.
$result = \core_blog\external::get_entries(array(array('name' => 'tagid', 'value' => $this->tagid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// Non-existent tag.
@@ -502,7 +504,7 @@ public function test_get_entries_filtering_by_tagid() {
'isstandard' => 1));
$result = \core_blog\external::get_entries(array(array('name' => 'tagid', 'value' => $tag->id)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -518,7 +520,7 @@ public function test_get_entries_filtering_by_group() {
// Filter by correct group.
$result = \core_blog\external::get_entries(array(array('name' => 'groupid', 'value' => $this->groupid)));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// Non-existent group.
$anotheruser = $this->getDataGenerator()->create_user();
@@ -540,7 +542,7 @@ public function test_get_entries_multiple_filter() {
array('name' => 'tagid', 'value' => $this->tagid),
array('name' => 'userid', 'value' => $this->userid),
));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(1, $result['entries']);
// Non-existent multiple filter.
@@ -548,7 +550,7 @@ public function test_get_entries_multiple_filter() {
array('name' => 'search', 'value' => 'www'),
array('name' => 'userid', 'value' => $this->userid),
));
- $result = \external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::get_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
}
@@ -584,7 +586,7 @@ public function test_view_blog_entries_without_filtering() {
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = \core_blog\external::view_entries();
- $result = \external_api::clean_returnvalue(\core_blog\external::view_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::view_entries_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -615,7 +617,7 @@ public function test_view_blog_entries_with_filtering() {
array('name' => 'tagid', 'value' => $this->tagid),
array('name' => 'userid', 'value' => $this->userid),
));
- $result = \external_api::clean_returnvalue(\core_blog\external::view_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_blog\external::view_entries_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
diff --git a/calendar/classes/external/calendar_event_exporter.php b/calendar/classes/external/calendar_event_exporter.php
index bfa2368a09a13..875865d394c86 100644
--- a/calendar/classes/external/calendar_event_exporter.php
+++ b/calendar/classes/external/calendar_event_exporter.php
@@ -27,7 +27,6 @@
defined('MOODLE_INTERNAL') || die();
use \core_calendar\local\event\container;
-use \core_course\external\course_summary_exporter;
use \renderer_base;
require_once($CFG->dirroot . '/course/lib.php');
/**
@@ -117,9 +116,13 @@ protected function get_other_values(renderer_base $output) {
$today = $this->related['type']->timestamp_to_date_array($this->related['today']);
if ($hascourse) {
- $values['popupname'] = external_format_string($this->event->get_name(), \context_course::instance($course->id), true);
+ $values['popupname'] = \core_external\util::format_string(
+ $this->event->get_name(),
+ \context_course::instance($course->id),
+ true
+ );
} else {
- $values['popupname'] = external_format_string($this->event->get_name(), \context_system::instance(), true);
+ $values['popupname'] = \core_external\util::format_string($this->event->get_name(), \context_system::instance(), true);
}
$times = $this->event->get_times();
diff --git a/calendar/classes/external/date_exporter.php b/calendar/classes/external/date_exporter.php
index 4615b6c626534..f18c62ee1f90a 100644
--- a/calendar/classes/external/date_exporter.php
+++ b/calendar/classes/external/date_exporter.php
@@ -27,8 +27,6 @@
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
-use renderer_base;
-use moodle_url;
/**
* Class for normalising the date data.
diff --git a/calendar/classes/external/event_exporter.php b/calendar/classes/external/event_exporter.php
index 1bbe0b7356a74..80939f46f9476 100644
--- a/calendar/classes/external/event_exporter.php
+++ b/calendar/classes/external/event_exporter.php
@@ -28,9 +28,7 @@
require_once($CFG->dirroot . "/calendar/lib.php");
-use \core_calendar\local\event\entities\action_event_interface;
use \core_calendar\local\event\container;
-use \core_course\external\course_summary_exporter;
use \renderer_base;
/**
diff --git a/calendar/classes/external/event_exporter_base.php b/calendar/classes/external/event_exporter_base.php
index aca99fefafab1..dc638cd5b74d7 100644
--- a/calendar/classes/external/event_exporter_base.php
+++ b/calendar/classes/external/event_exporter_base.php
@@ -79,7 +79,7 @@ public function __construct(event_interface $event, $related = []) {
$event->get_id()
);
$data->descriptionformat = $event->get_description()->get_format();
- $data->location = external_format_text($event->get_location(), FORMAT_PLAIN, $related['context']->id)[0];
+ $data->location = \core_external\util::format_text($event->get_location(), FORMAT_PLAIN, $related['context']->id)[0];
$data->groupid = $groupid;
$data->userid = $userid;
$data->categoryid = $categoryid;
diff --git a/calendar/classes/external/events_related_objects_cache.php b/calendar/classes/external/events_related_objects_cache.php
index 48998950712ab..dd38cb1cfe153 100644
--- a/calendar/classes/external/events_related_objects_cache.php
+++ b/calendar/classes/external/events_related_objects_cache.php
@@ -26,9 +26,7 @@
defined('MOODLE_INTERNAL') || die();
-use context;
use \core_calendar\local\event\entities\event_interface;
-use stdClass;
/**
* Class to providing the related objects when exporting a list of calendar events.
@@ -90,7 +88,7 @@ public function __construct(array $events, array $courses = null) {
* Get the related course object for a given event.
*
* @param event_interface $event The event object.
- * @return stdClass|null
+ * @return \stdClass|null
*/
public function get_course(event_interface $event) {
if (is_null($this->courses)) {
@@ -109,7 +107,7 @@ public function get_course(event_interface $event) {
* Get the related context for a given event.
*
* @param event_interface $event The event object.
- * @return context|null
+ * @return \context|null
*/
public function get_context(event_interface $event) {
global $USER;
@@ -141,7 +139,7 @@ public function get_context(event_interface $event) {
* Get the related group object for a given event.
*
* @param event_interface $event The event object.
- * @return stdClass|null
+ * @return \stdClass|null
*/
public function get_group(event_interface $event) {
if (is_null($this->groups)) {
@@ -160,7 +158,7 @@ public function get_group(event_interface $event) {
* Get the related course module for a given event.
*
* @param event_interface $event The event object.
- * @return stdClass|null
+ * @return \stdClass|null
*/
public function get_course_module(event_interface $event) {
if (!$event->get_course_module()) {
@@ -182,7 +180,7 @@ public function get_course_module(event_interface $event) {
* Get the related module instance for a given event.
*
* @param event_interface $event The event object.
- * @return stdClass|null
+ * @return \stdClass|null
*/
public function get_module_instance(event_interface $event) {
if (!$event->get_course_module()) {
diff --git a/calendar/classes/external/export/token.php b/calendar/classes/external/export/token.php
index 9c530a019894f..dfe692f72896d 100644
--- a/calendar/classes/external/export/token.php
+++ b/calendar/classes/external/export/token.php
@@ -28,16 +28,14 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/calendar/lib.php');
use context_system;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
/**
@@ -84,7 +82,7 @@ public static function execute() {
/**
* Returns description of method result value.
*
- * @return external_description.
+ * @return \core_external\external_description.
* @since Moodle 3.10
*/
public static function execute_returns() {
diff --git a/calendar/classes/external/subscription/delete.php b/calendar/classes/external/subscription/delete.php
index ef6be587d0ab3..5ced38c8a9037 100644
--- a/calendar/classes/external/subscription/delete.php
+++ b/calendar/classes/external/subscription/delete.php
@@ -29,11 +29,11 @@
require_once($CFG->dirroot . '/calendar/lib.php');
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* Calendar external API for deleting the subscription.
diff --git a/calendar/classes/external/week_day_exporter.php b/calendar/classes/external/week_day_exporter.php
index 80ddbf03e8c3a..937f0c30b0234 100644
--- a/calendar/classes/external/week_day_exporter.php
+++ b/calendar/classes/external/week_day_exporter.php
@@ -27,7 +27,6 @@
defined('MOODLE_INTERNAL') || die();
use renderer_base;
-use moodle_url;
/**
* Class for displaying the day on month view.
diff --git a/calendar/externallib.php b/calendar/externallib.php
index d8eb9b60cb3a2..a9f062d78303f 100644
--- a/calendar/externallib.php
+++ b/calendar/externallib.php
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
/**
* External calendar API
*
@@ -27,18 +26,25 @@
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . '/calendar/lib.php');
-use \core_calendar\local\api as local_api;
-use \core_calendar\local\event\container as event_container;
-use \core_calendar\local\event\forms\create as create_event_form;
-use \core_calendar\local\event\forms\update as update_event_form;
-use \core_calendar\local\event\mappers\create_update_form_mapper;
-use \core_calendar\external\event_exporter;
-use \core_calendar\external\events_exporter;
-use \core_calendar\external\events_grouped_by_course_exporter;
-use \core_calendar\external\events_related_objects_cache;
+use core_calendar\local\api as local_api;
+use core_calendar\local\event\container as event_container;
+use core_calendar\local\event\forms\create as create_event_form;
+use core_calendar\local\event\forms\update as update_event_form;
+use core_calendar\local\event\mappers\create_update_form_mapper;
+use core_calendar\external\event_exporter;
+use core_calendar\external\events_exporter;
+use core_calendar\external\events_grouped_by_course_exporter;
+use core_calendar\external\events_related_objects_cache;
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util as external_util;
/**
* Calendar external functions
@@ -50,8 +56,6 @@
* @since Moodle 2.5
*/
class core_calendar_external extends external_api {
-
-
/**
* Returns description of method parameters
*
@@ -107,7 +111,7 @@ public static function delete_calendar_events($events) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function delete_calendar_events_returns() {
@@ -358,7 +362,7 @@ public static function get_calendar_events($events = array(), $options = array()
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function get_calendar_events_returns() {
@@ -480,7 +484,7 @@ public static function get_calendar_action_events_by_timesort($timesortfrom = 0,
* Returns description of method result value.
*
* @since Moodle 3.3
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_action_events_by_timesort_returns() {
return events_exporter::get_read_structure();
@@ -567,7 +571,7 @@ public static function get_calendar_action_events_by_course(
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_action_events_by_course_returns() {
return events_exporter::get_read_structure();
@@ -655,7 +659,7 @@ public static function get_calendar_action_events_by_courses(
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_action_events_by_courses_returns() {
return events_grouped_by_course_exporter::get_read_structure();
@@ -718,7 +722,7 @@ public static function create_calendar_events($events) {
$event['instance'] = 0;
$event['subscriptionid'] = null;
$event['uuid']= '';
- $event['format'] = external_validate_format($event['format']);
+ $event['format'] = external_util::validate_format($event['format']);
if ($event['repeats'] > 0) {
$event['repeat'] = 1;
} else {
@@ -753,7 +757,7 @@ public static function create_calendar_events($events) {
/**
* Returns description of method result value.
*
- * @return external_description.
+ * @return \core_external\external_description.
* @since Moodle 2.5
*/
public static function create_calendar_events_returns() {
@@ -844,7 +848,7 @@ public static function get_calendar_event_by_id($eventid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_event_by_id_returns() {
$eventstructure = event_exporter::get_read_structure();
@@ -983,7 +987,7 @@ public static function submit_create_update_form($formdata) {
/**
* Returns description of method result value.
*
- * @return external_description.
+ * @return \core_external\external_description.
*/
public static function submit_create_update_form_returns() {
$eventstructure = event_exporter::get_read_structure();
@@ -1077,7 +1081,7 @@ public static function get_calendar_monthly_view_parameters() {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_monthly_view_returns() {
return \core_calendar\external\month_exporter::get_read_structure();
@@ -1138,7 +1142,7 @@ public static function get_calendar_day_view_parameters() {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_day_view_returns() {
return \core_calendar\external\calendar_day_exporter::get_read_structure();
@@ -1215,7 +1219,7 @@ public static function update_event_start_day($eventid, $daytimestamp) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function update_event_start_day_returns() {
return new external_single_structure(
@@ -1270,7 +1274,7 @@ public static function get_calendar_upcoming_view_parameters() {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_calendar_upcoming_view_returns() {
return \core_calendar\external\calendar_upcoming_exporter::get_read_structure();
@@ -1322,7 +1326,7 @@ public static function get_calendar_access_information($courseid = 0) {
/**
* Returns description of method result value.
*
- * @return external_description.
+ * @return \core_external\external_description.
* @since Moodle 3.7
*/
public static function get_calendar_access_information_returns() {
@@ -1382,7 +1386,7 @@ public static function get_allowed_event_types($courseid = 0) {
/**
* Returns description of method result value.
*
- * @return external_description.
+ * @return \core_external\external_description.
* @since Moodle 3.7
*/
public static function get_allowed_event_types_returns() {
diff --git a/calendar/lib.php b/calendar/lib.php
index 2cc2a0cef91a1..bf5f15c279f69 100644
--- a/calendar/lib.php
+++ b/calendar/lib.php
@@ -23,6 +23,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
}
@@ -975,7 +977,7 @@ public function format_external_name() {
$this->editorcontext = $this->get_context();
}
- return external_format_string($this->properties->name, $this->editorcontext->id);
+ return \core_external\util::format_string($this->properties->name, $this->editorcontext->id);
}
/**
@@ -993,7 +995,11 @@ public function format_external_text() {
if (!calendar_is_valid_eventtype($this->properties->eventtype)) {
// We don't have a context here, do a normal format_text.
- return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id);
+ return \core_external\util::format_text(
+ $this->properties->description,
+ $this->properties->format,
+ $this->editorcontext
+ );
}
}
@@ -1004,8 +1010,14 @@ public function format_external_text() {
$itemid = $this->properties->id;
}
- return external_format_text($this->properties->description, $this->properties->format, $this->editorcontext->id,
- 'calendar', 'event_description', $itemid);
+ return \core_external\util::format_text(
+ $this->properties->description,
+ $this->properties->format,
+ $this->editorcontext,
+ 'calendar',
+ 'event_description',
+ $itemid
+ );
}
}
@@ -4010,7 +4022,7 @@ function calendar_inplace_editable(string $itemtype, int $itemid, int $newvalue)
$subscription = calendar_get_subscription($itemid);
$context = calendar_get_calendar_context($subscription);
- \external_api::validate_context($context);
+ external_api::validate_context($context);
$updateresult = \core_calendar\output\refreshintervalcollection::update($itemid, $newvalue);
@@ -4025,5 +4037,5 @@ function calendar_inplace_editable(string $itemtype, int $itemid, int $newvalue)
return $updateresult;
}
- \external_api::validate_context(context_system::instance());
+ external_api::validate_context(context_system::instance());
}
diff --git a/calendar/tests/externallib_test.php b/calendar/tests/externallib_test.php
index febd9a484cc14..ca1284d725f09 100644
--- a/calendar/tests/externallib_test.php
+++ b/calendar/tests/externallib_test.php
@@ -18,6 +18,7 @@
use core_calendar_external;
use externallib_advanced_testcase;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
@@ -359,14 +360,14 @@ public function test_get_calendar_events() {
$options = array ('siteevents' => true, 'userevents' => true);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
// Check to see if we got all events.
$this->assertEquals(5, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
$options = array ('siteevents' => true, 'userevents' => true, 'timeend' => time() + 7*WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(5, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
@@ -392,71 +393,71 @@ public function test_get_calendar_events() {
$this->setUser($user);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events'])); // site, user.
$this->assertEquals(2, count($events['warnings'])); // course, group.
$role = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(4, count($events['events'])); // site, user, both course events.
$this->assertEquals(1, count($events['warnings'])); // group.
$options = array ('siteevents' => true, 'userevents' => true, 'timeend' => time() + HOURSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(3, count($events['events'])); // site, user, one course event.
$this->assertEquals(1, count($events['warnings'])); // group.
groups_add_member($group, $user);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(4, count($events['events'])); // site, user, group, one course event.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array ('courseids' => array($course->id), 'groupids' => array($group->id));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(4, count($events['events'])); // site, user, group, one course event.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array ('groupids' => array($group->id, 23));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(3, count($events['events'])); // site, user, group.
$this->assertEquals(1, count($events['warnings']));
$paramevents = array ('courseids' => array(23));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events'])); // site, user.
$this->assertEquals(1, count($events['warnings']));
$paramevents = array ();
$options = array ('siteevents' => false, 'userevents' => false, 'timeend' => time() + 7*WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(0, count($events['events'])); // nothing returned.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array ('eventids' => array($siteevent->id, $groupevent->id));
$options = array ('siteevents' => false, 'userevents' => false, 'timeend' => time() + 7*WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events'])); // site, group.
$this->assertEquals(0, count($events['warnings']));
$paramevents = array ('eventids' => array($siteevent->id));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events'])); // site.
$this->assertEquals(0, count($events['warnings']));
// Try getting a course event by its id.
$paramevents = array ('eventids' => array($courseevent->id));
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
@@ -469,7 +470,7 @@ public function test_get_calendar_events() {
$paramevents = array ('courseids' => array($course->id));
$options = array ('siteevents' => true, 'userevents' => true, 'timeend' => time() + WEEKSECS);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertCount(5, $events['events']);
@@ -480,7 +481,7 @@ public function test_get_calendar_events() {
\course_modinfo::clear_instance_cache();
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
// Expect one less.
$this->assertCount(4, $events['events']);
@@ -503,7 +504,7 @@ public function test_get_calendar_events() {
$paramevents = array('categoryids' => array($category2b->id));
$options = array('timeend' => time() + 7 * WEEKSECS, 'userevents' => false, 'siteevents' => false);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
// Should be just one, since there's just one category event of the course I am enrolled (course3 - cat2b).
$this->assertEquals(1, count($events['events']));
@@ -515,7 +516,7 @@ public function test_get_calendar_events() {
$paramevents = array('courseids' => array($course3->id));
$options = array('timeend' => time() + 7 * WEEKSECS, 'userevents' => false, 'siteevents' => false);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
$this->assertEquals($catevent2->id, $events['events'][0]['id']);
$this->assertEquals(0, count($events['warnings']));
@@ -525,7 +526,7 @@ public function test_get_calendar_events() {
$paramevents = array('categoryids' => array($category2->id, $category->id));
$options = array('timeend' => time() + 7 * WEEKSECS, 'userevents' => false, 'siteevents' => false);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
$this->assertEquals($catevent2->id, $events['events'][0]['id']);
$this->assertEquals(0, count($events['warnings']));
@@ -535,7 +536,7 @@ public function test_get_calendar_events() {
$paramevents = array('categoryids' => array($category->id, $category2->id, $category2b->id));
$options = array('timeend' => time() + 7 * WEEKSECS, 'userevents' => false, 'siteevents' => false);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
$this->assertEquals($catevent1->id, $events['events'][0]['id']);
@@ -565,7 +566,7 @@ public function test_get_calendar_events_with_mathjax() {
// Now call the WebService.
$events = core_calendar_external::get_calendar_events();
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
// Format the original data.
$sitecontext = \context_system::instance();
@@ -606,7 +607,7 @@ public function test_core_create_calendar_events() {
array('name' => 'user')
);
$eventsret = core_calendar_external::create_calendar_events($events);
- $eventsret = \external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
+ $eventsret = external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
// Check to see if things were created properly.
$aftercount = $DB->count_records('event');
@@ -630,7 +631,7 @@ public function test_core_create_calendar_events() {
$this->assignUserCapability('moodle/calendar:manageentries', $coursecontext->id, $role->id);
$this->assignUserCapability('moodle/calendar:managegroupentries', $coursecontext->id, $role->id);
$eventsret = core_calendar_external::create_calendar_events($events);
- $eventsret = \external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
+ $eventsret = external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
// Check to see if things were created properly.
$aftercount = $DB->count_records('event');
$this->assertEquals($prevcount + 4, $aftercount);
@@ -641,7 +642,7 @@ public function test_core_create_calendar_events() {
$this->setGuestUser();
$prevcount = $DB->count_records('event');
$eventsret = core_calendar_external::create_calendar_events($events);
- $eventsret = \external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
+ $eventsret = external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
$aftercount = $DB->count_records('event');
$this->assertEquals($prevcount, $aftercount);
$this->assertEquals(0, count($eventsret['events']));
@@ -652,7 +653,7 @@ public function test_core_create_calendar_events() {
$this->unassignUserCapability('moodle/calendar:managegroupentries', $coursecontext->id, $role->id);
$prevcount = $DB->count_records('event');
$eventsret = core_calendar_external::create_calendar_events($events);
- $eventsret = \external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
+ $eventsret = external_api::clean_returnvalue(core_calendar_external::create_calendar_events_returns(), $eventsret);
$aftercount = $DB->count_records('event');
$this->assertEquals($prevcount + 1, $aftercount); // User event.
$this->assertEquals(1, count($eventsret['events']));
@@ -694,7 +695,7 @@ public function test_get_calendar_action_events_by_timesort_after_time() {
$event8 = $this->create_calendar_event('Event 8', $user->id, 'user', 0, 1, array_merge($params, ['timesort' => 8]));
$result = core_calendar_external::get_calendar_action_events_by_timesort(5);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -709,7 +710,7 @@ public function test_get_calendar_action_events_by_timesort_after_time() {
$this->assertEquals($event8->id, $result['lastid']);
$result = core_calendar_external::get_calendar_action_events_by_timesort(9);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -721,7 +722,7 @@ public function test_get_calendar_action_events_by_timesort_after_time() {
// Requesting action events on behalf of another user.
$this->setAdminUser();
$result = core_calendar_external::get_calendar_action_events_by_timesort(5, null, 0, 20, false, $user->id);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -771,7 +772,7 @@ public function test_get_calendar_action_events_by_timesort_before_time() {
$event8 = $this->create_calendar_event('Event 8', $user->id, 'user', 0, 1, array_merge($params, ['timesort' => 9]));
$result = core_calendar_external::get_calendar_action_events_by_timesort(null, 5);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -786,7 +787,7 @@ public function test_get_calendar_action_events_by_timesort_before_time() {
$this->assertEquals($event4->id, $result['lastid']);
$result = core_calendar_external::get_calendar_action_events_by_timesort(null, 1);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -799,7 +800,7 @@ public function test_get_calendar_action_events_by_timesort_before_time() {
$this->setAdminUser();
$result = core_calendar_external::get_calendar_action_events_by_timesort(null, 5, 0, 20, false, $user->id);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -848,7 +849,7 @@ public function test_get_calendar_events_override() {
$paramevents = array('courseids' => array($course->id));
$options = array ('siteevents' => true, 'userevents' => true);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
$this->assertEquals('Base event', $events['events'][0]['name']);
@@ -856,7 +857,7 @@ public function test_get_calendar_events_override() {
// Retrieve events for the first student - both events are returned.
$this->setUser($user);
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(2, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
$this->assertEquals('Base event', $events['events'][0]['name']);
@@ -866,7 +867,7 @@ public function test_get_calendar_events_override() {
$this->setUser($teacher);
$paramevents = ['eventids' => [$event2->id]];
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(1, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
$this->assertEquals('User event', $events['events'][0]['name']);
@@ -875,7 +876,7 @@ public function test_get_calendar_events_override() {
$this->setUser($anotheruser);
$paramevents = ['eventids' => [$event2->id, $event1->id]];
$events = core_calendar_external::get_calendar_events($paramevents, $options);
- $events = \external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
+ $events = external_api::clean_returnvalue(core_calendar_external::get_calendar_events_returns(), $events);
$this->assertEquals(0, count($events['events']));
$this->assertEquals(0, count($events['warnings']));
}
@@ -914,7 +915,7 @@ public function test_get_calendar_action_events_by_timesort_time_range() {
$event8 = $this->create_calendar_event('Event 8', $user->id, 'user', 0, 1, array_merge($params, ['timesort' => 8]));
$result = core_calendar_external::get_calendar_action_events_by_timesort(3, 6);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -929,7 +930,7 @@ public function test_get_calendar_action_events_by_timesort_time_range() {
$this->assertEquals($event6->id, $result['lastid']);
$result = core_calendar_external::get_calendar_action_events_by_timesort(10, 15);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -974,7 +975,7 @@ public function test_get_calendar_action_events_by_timesort_time_limit_offset()
$event8 = $this->create_calendar_event('Event 8', $user->id, 'user', 0, 1, array_merge($params, ['timesort' => 8]));
$result = core_calendar_external::get_calendar_action_events_by_timesort(2, 7, $event3->id, 2);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -987,7 +988,7 @@ public function test_get_calendar_action_events_by_timesort_time_limit_offset()
$this->assertEquals($event5->id, $result['lastid']);
$result = core_calendar_external::get_calendar_action_events_by_timesort(2, 7, $event5->id, 2);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -1000,7 +1001,7 @@ public function test_get_calendar_action_events_by_timesort_time_limit_offset()
$this->assertEquals($event7->id, $result['lastid']);
$result = core_calendar_external::get_calendar_action_events_by_timesort(2, 7, $event7->id, 2);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_timesort_returns(),
$result
);
@@ -1128,7 +1129,7 @@ public function test_get_calendar_action_events_by_course_after_time() {
}
$result = core_calendar_external::get_calendar_action_events_by_course($course1->id, 5);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1141,7 +1142,7 @@ public function test_get_calendar_action_events_by_course_after_time() {
$this->assertEquals('Event 8', $result[3]['name']);
$result = core_calendar_external::get_calendar_action_events_by_course($course1->id, 9);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1192,7 +1193,7 @@ public function test_get_calendar_action_events_by_course_before_time() {
}
$result = core_calendar_external::get_calendar_action_events_by_course($course1->id, null, 5);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1205,7 +1206,7 @@ public function test_get_calendar_action_events_by_course_before_time() {
$this->assertEquals('Event 4', $result[3]['name']);
$result = core_calendar_external::get_calendar_action_events_by_course($course1->id, null, 1);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1256,7 +1257,7 @@ public function test_get_calendar_action_events_by_course_time_range() {
}
$result = core_calendar_external::get_calendar_action_events_by_course($course1->id, 3, 6);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1269,7 +1270,7 @@ public function test_get_calendar_action_events_by_course_time_range() {
$this->assertEquals('Event 6', $result[3]['name']);
$result = core_calendar_external::get_calendar_action_events_by_course($course1->id, 10, 15);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1322,7 +1323,7 @@ public function test_get_calendar_action_events_by_course_time_limit_offset() {
$result = core_calendar_external::get_calendar_action_events_by_course(
$course1->id, 2, 7, $records[2]->id, 2);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1334,7 +1335,7 @@ public function test_get_calendar_action_events_by_course_time_limit_offset() {
$result = core_calendar_external::get_calendar_action_events_by_course(
$course1->id, 2, 7, $records[4]->id, 2);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1346,7 +1347,7 @@ public function test_get_calendar_action_events_by_course_time_limit_offset() {
$result = core_calendar_external::get_calendar_action_events_by_course(
$course1->id, 2, 7, $records[6]->id, 2);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1389,7 +1390,7 @@ public function test_get_calendar_action_events_by_course_with_search() {
// No result found for fake search.
$result = core_calendar_external::get_calendar_action_events_by_course($course->id, null, null, 0, 20, 'Fake search');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1398,7 +1399,7 @@ public function test_get_calendar_action_events_by_course_with_search() {
// Search for event name called 'Event 1'.
$result = core_calendar_external::get_calendar_action_events_by_course($course->id, null, null, 0, 20, 'Event 1');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1408,7 +1409,7 @@ public function test_get_calendar_action_events_by_course_with_search() {
// Search for activity type called 'assign'.
$result = core_calendar_external::get_calendar_action_events_by_course($course->id, null, null, 0, 20, 'assign');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_course_returns(),
$result
);
@@ -1479,7 +1480,7 @@ public function test_get_action_events_by_courses() {
}
$result = core_calendar_external::get_calendar_action_events_by_courses([], 1);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1488,7 +1489,7 @@ public function test_get_action_events_by_courses() {
$this->assertEmpty($result);
$result = core_calendar_external::get_calendar_action_events_by_courses([$course1->id], 3);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1498,7 +1499,7 @@ public function test_get_action_events_by_courses() {
$this->assertEmpty($groupedbycourse[$course1->id]);
$result = core_calendar_external::get_calendar_action_events_by_courses([$course1->id], 1);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1510,7 +1511,7 @@ public function test_get_action_events_by_courses() {
$result = core_calendar_external::get_calendar_action_events_by_courses(
[$course1->id, $course2->id], 1);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1526,7 +1527,7 @@ public function test_get_action_events_by_courses() {
$result = core_calendar_external::get_calendar_action_events_by_courses(
[$course1->id, $course2->id], 2, 4);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1541,7 +1542,7 @@ public function test_get_action_events_by_courses() {
$result = core_calendar_external::get_calendar_action_events_by_courses(
[$course1->id, $course2->id], 1, null, 1);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1615,7 +1616,7 @@ public function test_get_action_events_by_courses_with_search() {
// No result found for fake search.
$result = core_calendar_external::get_calendar_action_events_by_courses([$course1->id, $course2->id, $course3->id],
1, null, 20, 'Fake search');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1628,7 +1629,7 @@ public function test_get_action_events_by_courses_with_search() {
// Search for event name called 'Event 1'.
$result = core_calendar_external::get_calendar_action_events_by_courses([$course1->id, $course2->id, $course3->id],
1, null, 20, 'Event 1');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1643,7 +1644,7 @@ public function test_get_action_events_by_courses_with_search() {
// Search for activity type called 'assign'.
$result = core_calendar_external::get_calendar_action_events_by_courses([$course1->id, $course2->id, $course3->id],
1, null, 20, 'assign');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::get_calendar_action_events_by_courses_returns(),
$result
);
@@ -1715,7 +1716,7 @@ public function test_update_event_start_day() {
);
$result = core_calendar_external::update_event_start_day($event->id, $newstartdate->getTimestamp());
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::update_event_start_day_returns(),
$result
);
@@ -1757,7 +1758,7 @@ public function test_update_event_start_day_no_permission() {
assign_capability('moodle/calendar:manageownentries', CAP_PROHIBIT, $roleid, $context, true);
$this->expectException(\moodle_exception::class);
$result = core_calendar_external::update_event_start_day($event->id, $newstartdate->getTimestamp());
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::update_event_start_day_returns(),
$result
);
@@ -1801,7 +1802,7 @@ public function test_update_event_start_day_module_event() {
assign_capability('moodle/calendar:manageentries', CAP_ALLOW, $roleid, $context, true);
$this->expectException(\moodle_exception::class);
$result = core_calendar_external::update_event_start_day($event->id, $newstartdate->getTimestamp());
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::update_event_start_day_returns(),
$result
);
@@ -1854,7 +1855,7 @@ public function test_submit_create_update_form_validation_error() {
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -1916,7 +1917,7 @@ public function test_submit_create_update_form_create_user_event() {
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -1982,7 +1983,7 @@ public function test_submit_create_update_form_create_user_event_no_permission()
$this->expectException(\moodle_exception::class);
- \external_api::clean_returnvalue(
+ external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2043,7 +2044,7 @@ public function test_submit_create_update_form_create_site_event() {
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2108,7 +2109,7 @@ public function test_submit_create_update_form_create_site_event_no_permission()
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2174,7 +2175,7 @@ public function test_submit_create_update_form_create_course_event() {
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2243,7 +2244,7 @@ public function test_submit_create_update_form_create_course_event_no_permission
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2309,7 +2310,7 @@ public function test_submit_create_update_form_create_course_event_not_enrolled(
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2378,7 +2379,7 @@ public function test_submit_create_update_form_create_group_event_group_member_m
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2452,7 +2453,7 @@ public function test_submit_create_update_form_create_group_event_group_member_m
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2525,7 +2526,7 @@ public function test_submit_create_update_form_create_group_event_access_all_gro
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2598,7 +2599,7 @@ public function test_submit_create_update_form_create_group_event_non_member_no_
$this->resetAfterTest(true);
$this->setUser($user);
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_calendar_external::submit_create_update_form_returns(),
core_calendar_external::submit_create_update_form($querystring)
);
@@ -2626,7 +2627,7 @@ public function test_get_calendar_monthly_view_no_course_permission() {
$timestart = new \DateTime();
// Admin can load the course.
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_monthly_view_returns(),
core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'),
$course->id, null, false, true, $timestart->format('j'))
@@ -2634,7 +2635,7 @@ public function test_get_calendar_monthly_view_no_course_permission() {
$this->assertEquals($data['courseid'], $course->id);
// User enrolled in the course can load the course calendar.
$this->setUser($user1);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_monthly_view_returns(),
core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'),
$course->id, null, false, true, $timestart->format('j'))
@@ -2643,7 +2644,7 @@ public function test_get_calendar_monthly_view_no_course_permission() {
// User not enrolled in the course cannot load the course calendar.
$this->setUser($user2);
$this->expectException(\require_login_exception::class);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_monthly_view_returns(),
core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'),
$course->id, null, false, false, $timestart->format('j'))
@@ -2658,7 +2659,7 @@ public function test_get_calendar_monthly_view_with_day_provided() {
$this->setAdminUser();
$timestart = new \DateTime();
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_monthly_view_returns(),
core_calendar_external::get_calendar_monthly_view($timestart->format('Y'), $timestart->format('n'),
SITEID, null, false, true, $timestart->format('j'))
@@ -2686,7 +2687,7 @@ public function test_get_calendar_day_view_no_course_permission() {
$timestart = new \DateTime();
// Admin can load the course.
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_day_view_returns(),
core_calendar_external::get_calendar_day_view($timestart->format('Y'), $timestart->format('n'),
$timestart->format('j'), $course->id, null)
@@ -2694,7 +2695,7 @@ public function test_get_calendar_day_view_no_course_permission() {
$this->assertEquals($data['courseid'], $course->id);
// User enrolled in the course can load the course calendar.
$this->setUser($user1);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_day_view_returns(),
core_calendar_external::get_calendar_day_view($timestart->format('Y'), $timestart->format('n'),
$timestart->format('j'), $course->id, null)
@@ -2703,7 +2704,7 @@ public function test_get_calendar_day_view_no_course_permission() {
// User not enrolled in the course cannot load the course calendar.
$this->setUser($user2);
$this->expectException(\require_login_exception::class);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_day_view_returns(),
core_calendar_external::get_calendar_day_view($timestart->format('Y'), $timestart->format('n'),
$timestart->format('j'), $course->id, null)
@@ -2729,14 +2730,14 @@ public function test_get_calendar_upcoming_view_no_course_permission() {
$courseevent = $this->create_calendar_event($name, $USER->id, 'course', 0, time(), $record);
// Admin can load the course.
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_upcoming_view_returns(),
core_calendar_external::get_calendar_upcoming_view($course->id, null)
);
$this->assertEquals($data['courseid'], $course->id);
// User enrolled in the course can load the course calendar.
$this->setUser($user1);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_upcoming_view_returns(),
core_calendar_external::get_calendar_upcoming_view($course->id, null)
);
@@ -2744,7 +2745,7 @@ public function test_get_calendar_upcoming_view_no_course_permission() {
// User not enrolled in the course cannot load the course calendar.
$this->setUser($user2);
$this->expectException(\require_login_exception::class);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_upcoming_view_returns(),
core_calendar_external::get_calendar_upcoming_view($course->id, null)
);
@@ -2769,14 +2770,14 @@ public function test_get_calendar_event_by_id_no_course_permission() {
$courseevent = $this->create_calendar_event($name, $USER->id, 'course', 0, time(), $record);
// Admin can load the course event.
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_event_by_id_returns(),
core_calendar_external::get_calendar_event_by_id($courseevent->id)
);
$this->assertEquals($data['event']['id'], $courseevent->id);
// User enrolled in the course can load the course event.
$this->setUser($user1);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_event_by_id_returns(),
core_calendar_external::get_calendar_event_by_id($courseevent->id)
);
@@ -2784,7 +2785,7 @@ public function test_get_calendar_event_by_id_no_course_permission() {
// User not enrolled in the course cannot load the course event.
$this->setUser($user2);
$this->expectException(\moodle_exception::class);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_event_by_id_returns(),
core_calendar_external::get_calendar_event_by_id($courseevent->id)
);
@@ -2833,7 +2834,7 @@ public function test_get_calendar_event_by_id_prevent_read_other_users_events(
$this->setUser($user);
}
$userevent = $this->create_calendar_event('user event', $USER->id, 'user', 0, time());
- $results = \external_api::clean_returnvalue(
+ $results = external_api::clean_returnvalue(
core_calendar_external::get_calendar_event_by_id_returns(),
core_calendar_external::get_calendar_event_by_id($userevent->id)
);
@@ -2855,7 +2856,7 @@ public function test_get_calendar_event_by_id_prevent_read_other_users_events(
// Setup if exception is expected for the test.
$this->expectException(\moodle_exception::class);
}
- \external_api::clean_returnvalue(
+ external_api::clean_returnvalue(
core_calendar_external::get_calendar_event_by_id_returns(),
core_calendar_external::get_calendar_event_by_id($userevent->id)
);
@@ -3015,14 +3016,14 @@ public function test_get_calendar_events_hidden_category() {
];
$options = [];
// Admin can load the category event.
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_events_returns(),
core_calendar_external::get_calendar_events($events, $options)
);
$this->assertEquals($data['events'][0]['id'], $categoryevent->id);
// User with no special permission to see hidden categories will not see the event.
$this->setUser($user1);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_events_returns(),
core_calendar_external::get_calendar_events($events, $options)
);
@@ -3040,7 +3041,7 @@ public function test_get_calendar_access_information_for_admins() {
$CFG->calendar_adminseesall = 1;
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_access_information_returns(),
core_calendar_external::get_calendar_access_information()
);
@@ -3056,7 +3057,7 @@ public function test_get_calendar_access_information_for_authenticated_users() {
$this->resetAfterTest(true);
$this->setUser($this->getDataGenerator()->create_user());
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_access_information_returns(),
core_calendar_external::get_calendar_access_information()
);
@@ -3079,7 +3080,7 @@ public function test_get_calendar_access_information_for_student_users() {
$this->setUser($user);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_access_information_returns(),
core_calendar_external::get_calendar_access_information($course->id)
);
@@ -3103,7 +3104,7 @@ public function test_get_calendar_access_information_for_teacher_users() {
$this->setUser($user);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_calendar_access_information_returns(),
core_calendar_external::get_calendar_access_information($course->id)
);
@@ -3120,7 +3121,7 @@ public function test_get_allowed_event_types_for_admins() {
$this->resetAfterTest(true);
$this->setAdminUser();
$CFG->calendar_adminseesall = 1;
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_allowed_event_types_returns(),
core_calendar_external::get_allowed_event_types()
);
@@ -3132,7 +3133,7 @@ public function test_get_allowed_event_types_for_admins() {
public function test_get_allowed_event_types_for_authenticated_users() {
$this->resetAfterTest(true);
$this->setUser($this->getDataGenerator()->create_user());
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_allowed_event_types_returns(),
core_calendar_external::get_allowed_event_types()
);
@@ -3149,7 +3150,7 @@ public function test_get_allowed_event_types_for_student_users() {
$role = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
$this->setUser($user);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_allowed_event_types_returns(),
core_calendar_external::get_allowed_event_types($course->id)
);
@@ -3167,7 +3168,7 @@ public function test_get_allowed_event_types_for_teacher_users() {
$this->getDataGenerator()->enrol_user($user->id, $course->id, $role->id);
$this->getDataGenerator()->create_group(['courseid' => $course->id]);
$this->setUser($user);
- $data = \external_api::clean_returnvalue(
+ $data = external_api::clean_returnvalue(
core_calendar_external::get_allowed_event_types_returns(),
core_calendar_external::get_allowed_event_types($course->id)
);
diff --git a/cohort/classes/output/cohortidnumber.php b/cohort/classes/output/cohortidnumber.php
index 454fdde638b7b..324500c693c6c 100644
--- a/cohort/classes/output/cohortidnumber.php
+++ b/cohort/classes/output/cohortidnumber.php
@@ -24,6 +24,7 @@
namespace core_cohort\output;
+use core_external\external_api;
use lang_string;
/**
@@ -61,7 +62,7 @@ public static function update($cohortid, $newvalue) {
global $DB;
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortcontext = \context::instance_by_id($cohort->contextid);
- \external_api::validate_context($cohortcontext);
+ external_api::validate_context($cohortcontext);
require_capability('moodle/cohort:manage', $cohortcontext);
$record = (object)array('id' => $cohort->id, 'idnumber' => $newvalue, 'contextid' => $cohort->contextid);
cohort_update_cohort($record);
diff --git a/cohort/classes/output/cohortname.php b/cohort/classes/output/cohortname.php
index 7ac5950ebf9b6..3234316d8c9e6 100644
--- a/cohort/classes/output/cohortname.php
+++ b/cohort/classes/output/cohortname.php
@@ -24,6 +24,7 @@
namespace core_cohort\output;
+use core_external\external_api;
use lang_string;
/**
@@ -61,7 +62,7 @@ public static function update($cohortid, $newvalue) {
global $DB;
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$cohortcontext = \context::instance_by_id($cohort->contextid);
- \external_api::validate_context($cohortcontext);
+ external_api::validate_context($cohortcontext);
require_capability('moodle/cohort:manage', $cohortcontext);
$newvalue = clean_param($newvalue, PARAM_TEXT);
if (strval($newvalue) !== '') {
diff --git a/cohort/externallib.php b/cohort/externallib.php
index 08f62ee78f24c..74a32fe7fd08a 100644
--- a/cohort/externallib.php
+++ b/cohort/externallib.php
@@ -14,6 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
+
/**
* External cohort API
*
@@ -22,11 +31,6 @@
* @copyright MediaTouch 2000 srl
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
class core_cohort_external extends external_api {
/**
@@ -123,12 +127,12 @@ public static function create_cohorts($cohorts) {
}
// Validate format.
- $cohort->descriptionformat = external_validate_format($cohort->descriptionformat);
+ $cohort->descriptionformat = util::validate_format($cohort->descriptionformat);
$cohort->id = cohort_add_cohort($cohort);
list($cohort->description, $cohort->descriptionformat) =
- external_format_text($cohort->description, $cohort->descriptionformat,
- $context->id, 'cohort', 'description', $cohort->id);
+ \core_external\util::format_text($cohort->description, $cohort->descriptionformat,
+ $context, 'cohort', 'description', $cohort->id);
$cohortids[] = (array)$cohort;
}
$transaction->allow_commit();
@@ -139,7 +143,7 @@ public static function create_cohorts($cohorts) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function create_cohorts_returns() {
@@ -267,8 +271,8 @@ public static function get_cohorts($cohortids = array()) {
}
list($cohort->description, $cohort->descriptionformat) =
- external_format_text($cohort->description, $cohort->descriptionformat,
- $context->id, 'cohort', 'description', $cohort->id);
+ \core_external\util::format_text($cohort->description, $cohort->descriptionformat,
+ $context, 'cohort', 'description', $cohort->id);
$cohortsinfo[] = (array) $cohort;
}
@@ -279,7 +283,7 @@ public static function get_cohorts($cohortids = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function get_cohorts_returns() {
@@ -403,8 +407,8 @@ public static function search_cohorts($query, $context, $includes = 'parents', $
}
list($cohort->description, $cohort->descriptionformat) =
- external_format_text($cohort->description, $cohort->descriptionformat,
- $cohortcontext->id, 'cohort', 'description', $cohort->id);
+ \core_external\util::format_text($cohort->description, $cohort->descriptionformat,
+ $cohortcontext, 'cohort', 'description', $cohort->id);
$cohorts[$key] = $cohort;
}
@@ -415,7 +419,7 @@ public static function search_cohorts($query, $context, $includes = 'parents', $
/**
* Returns description of external function result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function search_cohorts_returns() {
return new external_single_structure(array(
@@ -534,7 +538,7 @@ public static function update_cohorts($cohorts) {
}
if (!empty($cohort->description)) {
- $cohort->descriptionformat = external_validate_format($cohort->descriptionformat);
+ $cohort->descriptionformat = util::validate_format($cohort->descriptionformat);
}
cohort_update_cohort($cohort);
@@ -808,7 +812,7 @@ public static function get_cohort_members($cohortids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function get_cohort_members_returns() {
diff --git a/cohort/tests/externallib_test.php b/cohort/tests/externallib_test.php
index 83e2a9727478d..75310b0c528f0 100644
--- a/cohort/tests/externallib_test.php
+++ b/cohort/tests/externallib_test.php
@@ -17,6 +17,7 @@
namespace core_cohort;
use core_cohort_external;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -84,7 +85,7 @@ public function test_create_cohorts() {
// Call the external function.
$this->setCurrentTimeStart();
$createdcohorts = core_cohort_external::create_cohorts(array($cohort1, $cohort2));
- $createdcohorts = \external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);
+ $createdcohorts = external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);
// Check we retrieve the good total number of created cohorts + no error on capability.
$this->assertEquals(2, count($createdcohorts));
@@ -117,7 +118,7 @@ public function test_create_cohorts() {
// Call when $CFG->allowcohortthemes is disabled.
set_config('allowcohortthemes', 0);
$createdcohorts = core_cohort_external::create_cohorts(array($cohort4));
- $createdcohorts = \external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);
+ $createdcohorts = external_api::clean_returnvalue(core_cohort_external::create_cohorts_returns(), $createdcohorts);
foreach ($createdcohorts as $createdcohort) {
$dbcohort = $DB->get_record('cohort', array('id' => $createdcohort['id']));
if ($createdcohort['idnumber'] == $cohort4['idnumber']) {
@@ -195,7 +196,7 @@ public function test_get_cohorts() {
// Call the external function.
$returnedcohorts = core_cohort_external::get_cohorts(array(
$cohort1->id, $cohort2->id));
- $returnedcohorts = \external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
+ $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
// Check we retrieve the good total number of enrolled cohorts + no error on capability.
$this->assertEquals(2, count($returnedcohorts));
@@ -215,7 +216,7 @@ public function test_get_cohorts() {
// Call the external function.
$returnedcohorts = core_cohort_external::get_cohorts(array(
$cohort1->id, $cohort2->id));
- $returnedcohorts = \external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
+ $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
// Check we retrieve the good total number of enrolled cohorts + no error on capability.
$this->assertEquals(2, count($returnedcohorts));
@@ -224,7 +225,7 @@ public function test_get_cohorts() {
set_config('allowcohortthemes', 0);
$returnedcohorts = core_cohort_external::get_cohorts(array(
$cohort1->id));
- $returnedcohorts = \external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
+ $returnedcohorts = external_api::clean_returnvalue(core_cohort_external::get_cohorts_returns(), $returnedcohorts);
foreach ($returnedcohorts as $enrolledcohort) {
if ($enrolledcohort['idnumber'] == $cohort1->idnumber) {
$this->assertNull($enrolledcohort['theme']);
@@ -437,7 +438,7 @@ public function test_add_cohort_members() {
// Call the external function.
$addcohortmembers = core_cohort_external::add_cohort_members(array($cohort1));
- $addcohortmembers = \external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $addcohortmembers);
+ $addcohortmembers = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $addcohortmembers);
// Check we retrieve the good total number of created cohorts + no error on capability.
$this->assertEquals(1, count($addcohortmembers));
@@ -479,14 +480,14 @@ public function test_delete_cohort_members() {
'usertype' => array('type' => 'id', 'value' => $user1->id)
);
$cohortmembers1 = core_cohort_external::add_cohort_members(array($cohortaddmember1));
- $cohortmembers1 = \external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers1);
+ $cohortmembers1 = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers1);
$cohortaddmember2 = array(
'cohorttype' => array('type' => 'id', 'value' => $cohort2->id),
'usertype' => array('type' => 'id', 'value' => $user2->id)
);
$cohortmembers2 = core_cohort_external::add_cohort_members(array($cohortaddmember2));
- $cohortmembers2 = \external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers2);
+ $cohortmembers2 = external_api::clean_returnvalue(core_cohort_external::add_cohort_members_returns(), $cohortmembers2);
// Check we retrieve no cohorts + no error on capability.
$this->assertEquals(2, $DB->count_records_select('cohort_members', ' ((cohortid = :idcohort1 AND userid = :iduser1)
diff --git a/comment/classes/external.php b/comment/classes/external.php
index 1eb3d8e07e1ea..bb1ef8ebce7aa 100644
--- a/comment/classes/external.php
+++ b/comment/classes/external.php
@@ -24,9 +24,16 @@
* @since Moodle 2.9
*/
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/comment/lib.php");
/**
@@ -118,7 +125,7 @@ public static function get_comments($contextlevel, $instanceid, $component, $ite
foreach ($comments as $key => $comment) {
- list($comments[$key]->content, $comments[$key]->format) = external_format_text($comment->content,
+ list($comments[$key]->content, $comments[$key]->format) = \core_external\util::format_text($comment->content,
$comment->format,
$context->id,
$params['component'],
@@ -140,7 +147,7 @@ public static function get_comments($contextlevel, $instanceid, $component, $ite
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function get_comments_returns() {
@@ -264,7 +271,7 @@ public static function add_comments($comments) {
/**
* Returns description of method result value for the add_comments method.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function add_comments_returns() {
@@ -356,7 +363,7 @@ public static function delete_comments(array $comments) {
/**
* Returns description of method result value for the delete_comments() method.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function delete_comments_returns() {
diff --git a/comment/tests/externallib_test.php b/comment/tests/externallib_test.php
index 4465b1ec47ed9..4ac3746dc2ffc 100644
--- a/comment/tests/externallib_test.php
+++ b/comment/tests/externallib_test.php
@@ -18,6 +18,7 @@
use comment_exception;
use core_comment_external;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -121,7 +122,7 @@ public function test_get_comments() {
]
];
$result = core_comment_external::add_comments($inputdata);
- $result = \external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
$ids = array_column($result, 'id');
// Verify we can get the comments.
@@ -132,7 +133,7 @@ public function test_get_comments() {
$area = 'database_entry';
$page = 0;
$result = core_comment_external::get_comments($contextlevel, $instanceid, $component, $itemid, $area, $page);
- $result = \external_api::clean_returnvalue(core_comment_external::get_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::get_comments_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['comments']);
@@ -149,7 +150,7 @@ public function test_get_comments() {
// Test sort direction and pagination.
$CFG->commentsperpage = 1;
$result = core_comment_external::get_comments($contextlevel, $instanceid, $component, $itemid, $area, $page, 'ASC');
- $result = \external_api::clean_returnvalue(core_comment_external::get_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::get_comments_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['comments']); // Only one per page.
@@ -159,7 +160,7 @@ public function test_get_comments() {
// Next page.
$result = core_comment_external::get_comments($contextlevel, $instanceid, $component, $itemid, $area, $page + 1, 'ASC');
- $result = \external_api::clean_returnvalue(core_comment_external::get_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::get_comments_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['comments']);
@@ -235,7 +236,7 @@ public function test_add_comments_single() {
'area' => 'database_entry'
]
]);
- $result = \external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
// Verify the result contains 1 result having the correct structure.
$this->assertCount(1, $result);
@@ -318,7 +319,7 @@ public function test_add_comments_multiple_all_valid() {
]
];
$result = core_comment_external::add_comments($inputdata);
- $result = \external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
// Two comments should have been created.
$this->assertCount(2, $result);
@@ -390,14 +391,14 @@ public function test_delete_comments_own_user() {
'area' => 'database_entry'
]
]);
- $result = \external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
// Delete those comments we just created.
$result = core_comment_external::delete_comments([
$result[0]['id'],
$result[1]['id']
]);
- $result = \external_api::clean_returnvalue(core_comment_external::delete_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::delete_comments_returns(), $result);
$this->assertEquals([], $result);
}
@@ -419,7 +420,7 @@ public function test_delete_comment_other_student() {
'area' => 'database_entry'
]
]);
- $result = \external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
// Now, as student 2, try to delete the comment made by student 1. Verify we can't.
$this->setUser($student2);
@@ -445,12 +446,12 @@ public function test_delete_comments_as_teacher() {
'area' => 'database_entry'
]
]);
- $result = \external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::add_comments_returns(), $result);
// Verify teachers can delete the comment.
$this->setUser($teacher1);
$result = core_comment_external::delete_comments([$result[0]['id']]);
- $result = \external_api::clean_returnvalue(core_comment_external::delete_comments_returns(), $result);
+ $result = external_api::clean_returnvalue(core_comment_external::delete_comments_returns(), $result);
$this->assertEquals([], $result);
}
}
diff --git a/competency/classes/external.php b/competency/classes/external.php
index bd4b3017f1efc..6f814534284a2 100644
--- a/competency/classes/external.php
+++ b/competency/classes/external.php
@@ -25,30 +25,15 @@
namespace core_competency;
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->libdir/grade/grade_scale.php");
-use context;
-use context_system;
use context_course;
use context_module;
-use context_helper;
+use context_system;
use context_user;
-use coding_exception;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_format_value;
-use external_single_structure;
-use external_multiple_structure;
-use invalid_parameter_exception;
-use required_capability_exception;
-use grade_scale;
-
use core_competency\external\competency_exporter;
use core_competency\external\competency_framework_exporter;
use core_competency\external\course_competency_exporter;
-use core_competency\external\course_competency_settings_exporter;
use core_competency\external\course_module_competency_exporter;
use core_competency\external\evidence_exporter;
use core_competency\external\performance_helper;
@@ -58,6 +43,13 @@
use core_competency\external\user_competency_plan_exporter;
use core_competency\external\user_evidence_competency_exporter;
use core_competency\external\user_evidence_exporter;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use grade_scale;
+use invalid_parameter_exception;
/**
* External API class.
@@ -101,7 +93,7 @@ protected static function get_context_parameters() {
/**
* Returns description of create_competency_framework() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function create_competency_framework_parameters() {
$structure = competency_framework_exporter::get_create_structure();
@@ -141,7 +133,7 @@ public static function create_competency_framework($competencyframework) {
/**
* Returns description of create_competency_framework() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function create_competency_framework_returns() {
return competency_framework_exporter::get_read_structure();
@@ -150,7 +142,7 @@ public static function create_competency_framework_returns() {
/**
* Returns description of read_competency_framework() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function read_competency_framework_parameters() {
$id = new external_value(
@@ -189,7 +181,7 @@ public static function read_competency_framework($id) {
/**
* Returns description of read_competency_framework() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function read_competency_framework_returns() {
return competency_framework_exporter::get_read_structure();
@@ -198,7 +190,7 @@ public static function read_competency_framework_returns() {
/**
* Returns description of competency_viewed() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function competency_viewed_parameters() {
$id = new external_value(
@@ -228,7 +220,7 @@ public static function competency_viewed($id) {
/**
* Returns description of competency_viewed() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function competency_viewed_returns() {
return new external_value(PARAM_BOOL, 'True if the event competency viewed was logged');
@@ -237,7 +229,7 @@ public static function competency_viewed_returns() {
/**
* Returns description of duplicate_competency_framework() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function duplicate_competency_framework_parameters() {
$id = new external_value(
@@ -277,7 +269,7 @@ public static function duplicate_competency_framework($id) {
/**
* Returns description of duplicate_competency_framework() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function duplicate_competency_framework_returns() {
return competency_framework_exporter::get_read_structure();
@@ -286,7 +278,7 @@ public static function duplicate_competency_framework_returns() {
/**
* Returns description of delete_competency_framework() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_competency_framework_parameters() {
$id = new external_value(
@@ -321,7 +313,7 @@ public static function delete_competency_framework($id) {
/**
* Returns description of delete_competency_framework() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function delete_competency_framework_returns() {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
@@ -330,7 +322,7 @@ public static function delete_competency_framework_returns() {
/**
* Returns description of update_competency_framework() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function update_competency_framework_parameters() {
$structure = competency_framework_exporter::get_update_structure();
@@ -362,7 +354,7 @@ public static function update_competency_framework($competencyframework) {
/**
* Returns description of update_competency_framework() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function update_competency_framework_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -371,7 +363,7 @@ public static function update_competency_framework_returns() {
/**
* Returns description of list_competency_frameworks() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_competency_frameworks_parameters() {
$sort = new external_value(
@@ -489,7 +481,7 @@ public static function list_competency_frameworks($sort, $order, $skip, $limit,
/**
* Returns description of list_competency_frameworks() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_competency_frameworks_returns() {
return new external_multiple_structure(competency_framework_exporter::get_read_structure());
@@ -498,7 +490,7 @@ public static function list_competency_frameworks_returns() {
/**
* Returns description of count_competency_frameworks() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_competency_frameworks_parameters() {
$includes = new external_value(
@@ -537,7 +529,7 @@ public static function count_competency_frameworks($context, $includes) {
/**
* Returns description of count_competency_frameworks() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_competency_frameworks_returns() {
return new external_value(PARAM_INT, 'The number of competency frameworks found.');
@@ -546,7 +538,7 @@ public static function count_competency_frameworks_returns() {
/**
* Returns description of competency_framework_viewed() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function competency_framework_viewed_parameters() {
$id = new external_value(
@@ -578,7 +570,7 @@ public static function competency_framework_viewed($id) {
/**
* Returns description of competency_framework_viewed() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function competency_framework_viewed_returns() {
return new external_value(PARAM_BOOL, 'True if the event competency framework was logged');
@@ -587,7 +579,7 @@ public static function competency_framework_viewed_returns() {
/**
* Returns description of create_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function create_competency_parameters() {
$structure = competency_exporter::get_create_structure();
@@ -624,7 +616,7 @@ public static function create_competency($competency) {
/**
* Returns description of create_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function create_competency_returns() {
return competency_exporter::get_read_structure();
@@ -633,7 +625,7 @@ public static function create_competency_returns() {
/**
* Returns description of read_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function read_competency_parameters() {
$id = new external_value(
@@ -673,7 +665,7 @@ public static function read_competency($id) {
/**
* Returns description of read_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function read_competency_returns() {
return competency_exporter::get_read_structure();
@@ -682,7 +674,7 @@ public static function read_competency_returns() {
/**
* Returns description of delete_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_competency_parameters() {
$id = new external_value(
@@ -718,7 +710,7 @@ public static function delete_competency($id) {
/**
* Returns description of delete_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function delete_competency_returns() {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
@@ -727,7 +719,7 @@ public static function delete_competency_returns() {
/**
* Returns description of update_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function update_competency_parameters() {
$structure = competency_exporter::get_update_structure();
@@ -758,7 +750,7 @@ public static function update_competency($competency) {
/**
* Returns description of update_competency_framework() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function update_competency_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -767,7 +759,7 @@ public static function update_competency_returns() {
/**
* Returns description of list_competencies() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_competencies_parameters() {
$filters = new external_multiple_structure(new external_single_structure(
@@ -880,7 +872,7 @@ public static function list_competencies($filters, $sort, $order, $skip, $limit)
/**
* Returns description of list_competencies() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_competencies_returns() {
return new external_multiple_structure(competency_exporter::get_read_structure());
@@ -889,7 +881,7 @@ public static function list_competencies_returns() {
/**
* Returns description of search_competencies() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function search_competencies_parameters() {
$searchtext = new external_value(
@@ -946,7 +938,7 @@ public static function search_competencies($searchtext, $competencyframeworkid)
/**
* Returns description of search_competencies() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function search_competencies_returns() {
return new external_multiple_structure(competency_exporter::get_read_structure());
@@ -955,7 +947,7 @@ public static function search_competencies_returns() {
/**
* Returns description of count_competencies() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_competencies_parameters() {
$filters = new external_multiple_structure(new external_single_structure(
@@ -1007,7 +999,7 @@ public static function count_competencies($filters) {
/**
* Returns description of count_competencies() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_competencies_returns() {
return new external_value(PARAM_INT, 'The number of competencies found.');
@@ -1016,7 +1008,7 @@ public static function count_competencies_returns() {
/**
* Returns description of set_parent_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function set_parent_competency_parameters() {
$competencyid = new external_value(
@@ -1059,7 +1051,7 @@ public static function set_parent_competency($competencyid, $parentid) {
/**
* Returns description of set_parent_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function set_parent_competency_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -1068,7 +1060,7 @@ public static function set_parent_competency_returns() {
/**
* Returns description of move_up_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function move_up_competency_parameters() {
$competencyid = new external_value(
@@ -1102,7 +1094,7 @@ public static function move_up_competency($competencyid) {
/**
* Returns description of move_up_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function move_up_competency_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -1111,7 +1103,7 @@ public static function move_up_competency_returns() {
/**
* Returns description of move_down_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function move_down_competency_parameters() {
$competencyid = new external_value(
@@ -1145,7 +1137,7 @@ public static function move_down_competency($competencyid) {
/**
* Returns description of move_down_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function move_down_competency_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -1154,7 +1146,7 @@ public static function move_down_competency_returns() {
/**
* Returns description of count_courses_using_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_courses_using_competency_parameters() {
$competencyid = new external_value(
@@ -1188,7 +1180,7 @@ public static function count_courses_using_competency($competencyid) {
/**
* Returns description of count_courses_using_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_courses_using_competency_returns() {
return new external_value(PARAM_INT, 'The number of courses using this competency');
@@ -1197,7 +1189,7 @@ public static function count_courses_using_competency_returns() {
/**
* Returns description of count_competencies_in_course() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_competencies_in_course_parameters() {
$courseid = new external_value(
@@ -1230,7 +1222,7 @@ public static function count_competencies_in_course($courseid) {
/**
* Returns description of count_competencies_in_course() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_competencies_in_course_returns() {
return new external_value(PARAM_INT, 'The number of competencies in this course.');
@@ -1239,7 +1231,7 @@ public static function count_competencies_in_course_returns() {
/**
* Returns description of list_course_module_competencies() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_course_module_competencies_parameters() {
$cmid = new external_value(
@@ -1290,7 +1282,7 @@ public static function list_course_module_competencies($cmid) {
/**
* Returns description of list_course_module_competencies() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_course_module_competencies_returns() {
return new external_multiple_structure(
@@ -1304,7 +1296,7 @@ public static function list_course_module_competencies_returns() {
/**
* Returns description of list_course_competencies() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_course_competencies_parameters() {
$courseid = new external_value(
@@ -1321,7 +1313,7 @@ public static function list_course_competencies_parameters() {
/**
* Returns description of count_course_module_competencies() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_course_module_competencies_parameters() {
$cmid = new external_value(
@@ -1355,7 +1347,7 @@ public static function count_course_module_competencies($cmid) {
/**
* Returns description of count_course_module_competencies() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_course_module_competencies_returns() {
return new external_value(PARAM_INT, 'The number of competencies found.');
@@ -1403,7 +1395,7 @@ public static function list_course_competencies($courseid) {
/**
* Returns description of list_course_competencies() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_course_competencies_returns() {
return new external_multiple_structure(
@@ -1417,7 +1409,7 @@ public static function list_course_competencies_returns() {
/**
* Returns description of add_competency_to_course() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function add_competency_to_course_parameters() {
$courseid = new external_value(
@@ -1456,7 +1448,7 @@ public static function add_competency_to_course($courseid, $competencyid) {
/**
* Returns description of add_competency_to_course() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function add_competency_to_course_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -1465,7 +1457,7 @@ public static function add_competency_to_course_returns() {
/**
* Returns description of remove_competency_from_course() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function remove_competency_from_course_parameters() {
$courseid = new external_value(
@@ -1504,7 +1496,7 @@ public static function remove_competency_from_course($courseid, $competencyid) {
/**
* Returns description of remove_competency_from_course() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function remove_competency_from_course_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -1513,7 +1505,7 @@ public static function remove_competency_from_course_returns() {
/**
* Returns description of reorder_course_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function reorder_course_competency_parameters() {
$courseid = new external_value(
@@ -1560,7 +1552,7 @@ public static function reorder_course_competency($courseid, $competencyidfrom, $
/**
* Returns description of reorder_course_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function reorder_course_competency_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -1569,7 +1561,7 @@ public static function reorder_course_competency_returns() {
/**
* Returns description of reorder_template_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function reorder_template_competency_parameters() {
$templateid = new external_value(
@@ -1619,7 +1611,7 @@ public static function reorder_template_competency($templateid, $competencyidfro
/**
* Returns description of reorder_template_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function reorder_template_competency_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -1628,7 +1620,7 @@ public static function reorder_template_competency_returns() {
/**
* Returns description of create_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function create_template_parameters() {
$structure = template_exporter::get_create_structure();
@@ -1665,7 +1657,7 @@ public static function create_template($template) {
/**
* Returns description of create_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function create_template_returns() {
return template_exporter::get_read_structure();
@@ -1674,7 +1666,7 @@ public static function create_template_returns() {
/**
* Returns description of read_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function read_template_parameters() {
$id = new external_value(
@@ -1711,7 +1703,7 @@ public static function read_template($id) {
/**
* Returns description of read_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function read_template_returns() {
return template_exporter::get_read_structure();
@@ -1720,7 +1712,7 @@ public static function read_template_returns() {
/**
* Returns description of delete_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_template_parameters() {
$id = new external_value(
@@ -1764,7 +1756,7 @@ public static function delete_template($id, $deleteplans = true) {
/**
* Returns description of delete_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function delete_template_returns() {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
@@ -1773,7 +1765,7 @@ public static function delete_template_returns() {
/**
* Returns description of update_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function update_template_parameters() {
$structure = template_exporter::get_update_structure();
@@ -1802,7 +1794,7 @@ public static function update_template($template) {
/**
* Returns description of update_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function update_template_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -1811,7 +1803,7 @@ public static function update_template_returns() {
/**
* Returns description of duplicate_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function duplicate_template_parameters() {
$templateid = new external_value(
@@ -1849,7 +1841,7 @@ public static function duplicate_template($id) {
/**
* Returns description of duplicate_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function duplicate_template_returns() {
return template_exporter::get_read_structure();
@@ -1858,7 +1850,7 @@ public static function duplicate_template_returns() {
/**
* Returns description of list_templates() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_templates_parameters() {
$sort = new external_value(
@@ -1963,7 +1955,7 @@ public static function list_templates($sort, $order, $skip, $limit, $context, $i
/**
* Returns description of list_templates() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_templates_returns() {
return new external_multiple_structure(template_exporter::get_read_structure());
@@ -1972,7 +1964,7 @@ public static function list_templates_returns() {
/**
* Returns description of count_templates() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_templates_parameters() {
$includes = new external_value(
@@ -2010,7 +2002,7 @@ public static function count_templates($context, $includes) {
/**
* Returns description of count_templates() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_templates_returns() {
return new external_value(PARAM_INT, 'The number of learning plan templates found.');
@@ -2019,7 +2011,7 @@ public static function count_templates_returns() {
/**
* Returns description of count_templates_using_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_templates_using_competency_parameters() {
$competencyid = new external_value(
@@ -2053,7 +2045,7 @@ public static function count_templates_using_competency($competencyid) {
/**
* Returns description of count_templates_using_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_templates_using_competency_returns() {
return new external_value(PARAM_INT, 'The number of learning plan templates using this competency');
@@ -2062,7 +2054,7 @@ public static function count_templates_using_competency_returns() {
/**
* Returns description of list_templates_using_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_templates_using_competency_parameters() {
$competencyid = new external_value(
@@ -2108,7 +2100,7 @@ public static function list_templates_using_competency($competencyid) {
/**
* Returns description of list_templates_using_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_templates_using_competency_returns() {
return new external_multiple_structure(template_exporter::get_read_structure());
@@ -2117,7 +2109,7 @@ public static function list_templates_using_competency_returns() {
/**
* Returns description of count_competencies_in_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function count_competencies_in_template_parameters() {
$templateid = new external_value(
@@ -2150,7 +2142,7 @@ public static function count_competencies_in_template($templateid) {
/**
* Returns description of count_competencies_in_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function count_competencies_in_template_returns() {
return new external_value(PARAM_INT, 'The number of competencies in this learning plan template.');
@@ -2159,7 +2151,7 @@ public static function count_competencies_in_template_returns() {
/**
* Returns description of list_competencies_in_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_competencies_in_template_parameters() {
$templateid = new external_value(
@@ -2206,7 +2198,7 @@ public static function list_competencies_in_template($templateid) {
/**
* Returns description of list_competencies_in_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_competencies_in_template_returns() {
return new external_multiple_structure(competency_exporter::get_read_structure());
@@ -2215,7 +2207,7 @@ public static function list_competencies_in_template_returns() {
/**
* Returns description of add_competency_to_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function add_competency_to_template_parameters() {
$templateid = new external_value(
@@ -2258,7 +2250,7 @@ public static function add_competency_to_template($templateid, $competencyid) {
/**
* Returns description of add_competency_to_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function add_competency_to_template_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -2267,7 +2259,7 @@ public static function add_competency_to_template_returns() {
/**
* Returns description of add_competency_to_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function add_competency_to_plan_parameters() {
$planid = new external_value(
@@ -2309,7 +2301,7 @@ public static function add_competency_to_plan($planid, $competencyid) {
/**
* Returns description of add_competency_to_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function add_competency_to_plan_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -2318,7 +2310,7 @@ public static function add_competency_to_plan_returns() {
/**
* Returns description of remove_competency_from_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function remove_competency_from_plan_parameters() {
$planid = new external_value(
@@ -2359,7 +2351,7 @@ public static function remove_competency_from_plan($planid, $competencyid) {
/**
* Returns description of remove_competency_from_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function remove_competency_from_plan_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -2368,7 +2360,7 @@ public static function remove_competency_from_plan_returns() {
/**
* Returns description of remove_competency_from_template() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function remove_competency_from_template_parameters() {
$templateid = new external_value(
@@ -2391,7 +2383,7 @@ public static function remove_competency_from_template_parameters() {
/**
* Returns description of reorder_plan_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function reorder_plan_competency_parameters() {
$planid = new external_value(
@@ -2441,7 +2433,7 @@ public static function reorder_plan_competency($planid, $competencyidfrom, $comp
/**
* Returns description of reorder_plan_competency() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function reorder_plan_competency_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -2450,7 +2442,7 @@ public static function reorder_plan_competency_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_cancel_review_request_parameters() {
return new external_function_parameters(array(
@@ -2481,7 +2473,7 @@ public static function user_competency_cancel_review_request($userid, $competenc
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_cancel_review_request_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -2490,7 +2482,7 @@ public static function user_competency_cancel_review_request_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_request_review_parameters() {
return new external_function_parameters(array(
@@ -2521,7 +2513,7 @@ public static function user_competency_request_review($userid, $competencyid) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_request_review_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -2530,7 +2522,7 @@ public static function user_competency_request_review_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_start_review_parameters() {
return new external_function_parameters(array(
@@ -2561,7 +2553,7 @@ public static function user_competency_start_review($userid, $competencyid) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_start_review_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -2570,7 +2562,7 @@ public static function user_competency_start_review_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_stop_review_parameters() {
return new external_function_parameters(array(
@@ -2601,7 +2593,7 @@ public static function user_competency_stop_review($userid, $competencyid) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_stop_review_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -2610,7 +2602,7 @@ public static function user_competency_stop_review_returns() {
/**
* Returns description of template_has_related_data() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function template_has_related_data_parameters() {
$templateid = new external_value(
@@ -2644,7 +2636,7 @@ public static function template_has_related_data($templateid) {
/**
* Returns description of template_has_related_data() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function template_has_related_data_returns() {
return new external_value(PARAM_BOOL, 'True if the template has related data');
@@ -2671,7 +2663,7 @@ public static function remove_competency_from_template($templateid, $competencyi
/**
* Returns description of remove_competency_from_template() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function remove_competency_from_template_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -2680,7 +2672,7 @@ public static function remove_competency_from_template_returns() {
/**
* Returns description of create_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function create_plan_parameters() {
$structure = plan_exporter::get_create_structure();
@@ -2714,7 +2706,7 @@ public static function create_plan($plan) {
/**
* Returns description of create_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function create_plan_returns() {
return plan_exporter::get_read_structure();
@@ -2723,7 +2715,7 @@ public static function create_plan_returns() {
/**
* Returns description of update_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function update_plan_parameters() {
$structure = plan_exporter::get_update_structure();
@@ -2757,7 +2749,7 @@ public static function update_plan($plan) {
/**
* Returns description of update_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function update_plan_returns() {
return plan_exporter::get_read_structure();
@@ -2766,7 +2758,7 @@ public static function update_plan_returns() {
/**
* Returns description of complete_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function complete_plan_parameters() {
$planid = new external_value(
@@ -2795,7 +2787,7 @@ public static function complete_plan($planid) {
/**
* Returns description of complete_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function complete_plan_returns() {
return new external_value(PARAM_BOOL, 'True if completing learning plan was successful');
@@ -2804,7 +2796,7 @@ public static function complete_plan_returns() {
/**
* Returns description of reopen_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function reopen_plan_parameters() {
$planid = new external_value(
@@ -2833,7 +2825,7 @@ public static function reopen_plan($planid) {
/**
* Returns description of reopen_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function reopen_plan_returns() {
return new external_value(PARAM_BOOL, 'True if reopening learning plan was successful');
@@ -2842,7 +2834,7 @@ public static function reopen_plan_returns() {
/**
* Returns description of read_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function read_plan_parameters() {
$id = new external_value(
@@ -2878,7 +2870,7 @@ public static function read_plan($id) {
/**
* Returns description of read_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function read_plan_returns() {
return plan_exporter::get_read_structure();
@@ -2887,7 +2879,7 @@ public static function read_plan_returns() {
/**
* Returns description of delete_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_plan_parameters() {
$id = new external_value(
@@ -2922,7 +2914,7 @@ public static function delete_plan($id) {
/**
* Returns description of delete_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function delete_plan_returns() {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
@@ -2931,7 +2923,7 @@ public static function delete_plan_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_cancel_review_request_parameters() {
return new external_function_parameters(array(
@@ -2959,7 +2951,7 @@ public static function plan_cancel_review_request($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_cancel_review_request_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -2968,7 +2960,7 @@ public static function plan_cancel_review_request_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_request_review_parameters() {
return new external_function_parameters(array(
@@ -2996,7 +2988,7 @@ public static function plan_request_review($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_request_review_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -3005,7 +2997,7 @@ public static function plan_request_review_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_start_review_parameters() {
return new external_function_parameters(array(
@@ -3033,7 +3025,7 @@ public static function plan_start_review($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_start_review_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -3042,7 +3034,7 @@ public static function plan_start_review_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_stop_review_parameters() {
return new external_function_parameters(array(
@@ -3070,7 +3062,7 @@ public static function plan_stop_review($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function plan_stop_review_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -3079,7 +3071,7 @@ public static function plan_stop_review_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function approve_plan_parameters() {
return new external_function_parameters(array(
@@ -3107,7 +3099,7 @@ public static function approve_plan($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function approve_plan_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -3116,7 +3108,7 @@ public static function approve_plan_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function unapprove_plan_parameters() {
return new external_function_parameters(array(
@@ -3144,7 +3136,7 @@ public static function unapprove_plan($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function unapprove_plan_returns() {
return new external_value(PARAM_BOOL, 'The success');
@@ -3153,7 +3145,7 @@ public static function unapprove_plan_returns() {
/**
* External function parameters structure.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_plan_competencies_parameters() {
return new external_function_parameters(array(
@@ -3208,7 +3200,7 @@ public static function list_plan_competencies($id) {
/**
* External function return structure.
*
- * @return \external_description
+ * @return external_description
*/
public static function list_plan_competencies_returns() {
$uc = user_competency_exporter::get_read_structure();
@@ -3229,7 +3221,7 @@ public static function list_plan_competencies_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_user_plans_parameters() {
return new external_function_parameters(array(
@@ -3266,7 +3258,7 @@ public static function list_user_plans($userid) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function list_user_plans_returns() {
return new external_multiple_structure(
@@ -3277,7 +3269,7 @@ public static function list_user_plans_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_description
+ * @return external_description
*/
public static function read_user_evidence_parameters() {
return new external_function_parameters(array(
@@ -3308,7 +3300,7 @@ public static function read_user_evidence($id) {
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function read_user_evidence_returns() {
return user_evidence_exporter::get_read_structure();
@@ -3317,7 +3309,7 @@ public static function read_user_evidence_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_user_evidence_parameters() {
return new external_function_parameters(array(
@@ -3343,7 +3335,7 @@ public static function delete_user_evidence($id) {
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function delete_user_evidence_returns() {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
@@ -3352,7 +3344,7 @@ public static function delete_user_evidence_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function create_user_evidence_competency_parameters() {
return new external_function_parameters(array(
@@ -3386,7 +3378,7 @@ public static function create_user_evidence_competency($userevidenceid, $compete
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function create_user_evidence_competency_returns() {
return user_evidence_competency_exporter::get_read_structure();
@@ -3395,7 +3387,7 @@ public static function create_user_evidence_competency_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_user_evidence_competency_parameters() {
return new external_function_parameters(array(
@@ -3426,7 +3418,7 @@ public static function delete_user_evidence_competency($userevidenceid, $compete
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function delete_user_evidence_competency_returns() {
return new external_value(PARAM_BOOL, 'True if the delete was successful');
@@ -3435,7 +3427,7 @@ public static function delete_user_evidence_competency_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function request_review_of_user_evidence_linked_competencies_parameters() {
return new external_function_parameters(array(
@@ -3463,7 +3455,7 @@ public static function request_review_of_user_evidence_linked_competencies($id)
/**
* Returns description of external function result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function request_review_of_user_evidence_linked_competencies_returns() {
return new external_value(PARAM_BOOL, 'True if all competencies were send to review');
@@ -3508,7 +3500,7 @@ public static function get_scale_values($scaleid) {
// Add a key (make the first value 1).
$scalevalues[$key] = array(
'id' => $key + 1,
- 'name' => external_format_string($value, $context->id)
+ 'name' => \core_external\util::format_string($value, $context->id)
);
}
return $scalevalues;
@@ -3573,7 +3565,7 @@ public static function add_related_competency($competencyid, $relatedcompetencyi
/**
* Returns description of add_related_competency_returns() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function add_related_competency_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -3623,7 +3615,7 @@ public static function remove_related_competency($competencyid, $relatedcompeten
/**
* Returns description of remove_related_competency_returns() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function remove_related_competency_returns() {
return new external_value(PARAM_BOOL, 'True if successful.');
@@ -3632,7 +3624,7 @@ public static function remove_related_competency_returns() {
/**
* Returns description of update_ruleoutcome_course_competency() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function set_course_competency_ruleoutcome_parameters() {
$coursecompetencyid = new external_value(
@@ -3676,7 +3668,7 @@ public static function set_course_competency_ruleoutcome($coursecompetencyid, $r
/**
* Returns description of update_ruleoutcome_course_competency() result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function set_course_competency_ruleoutcome_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful');
@@ -3686,7 +3678,7 @@ public static function set_course_competency_ruleoutcome_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function grade_competency_parameters() {
$userid = new external_value(
@@ -3762,7 +3754,7 @@ public static function grade_competency($userid, $competencyid, $grade, $note =
/**
* Returns description of external function result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function grade_competency_returns() {
return evidence_exporter::get_read_structure();
@@ -3771,7 +3763,7 @@ public static function grade_competency_returns() {
/**
* Returns description of grade_competency_in_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function grade_competency_in_plan_parameters() {
$planid = new external_value(
@@ -3849,7 +3841,7 @@ public static function grade_competency_in_plan($planid, $competencyid, $grade,
/**
* Returns description of grade_competency_in_plan() result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function grade_competency_in_plan_returns() {
return evidence_exporter::get_read_structure();
@@ -3858,7 +3850,7 @@ public static function grade_competency_in_plan_returns() {
/**
* Returns description of user_competency_viewed() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_viewed_parameters() {
$usercompetencyid = new external_value(
@@ -3892,7 +3884,7 @@ public static function user_competency_viewed($usercompetencyid) {
/**
* Returns description of user_competency_viewed() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function user_competency_viewed_returns() {
return new external_value(PARAM_BOOL, 'True if the event user competency viewed was logged');
@@ -3901,7 +3893,7 @@ public static function user_competency_viewed_returns() {
/**
* Returns description of user_competency_viewed_in_plan() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_viewed_in_plan_parameters() {
$competencyid = new external_value(
@@ -3950,7 +3942,7 @@ public static function user_competency_viewed_in_plan($competencyid, $userid, $p
/**
* Returns description of user_competency_viewed_in_plan() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function user_competency_viewed_in_plan_returns() {
return new external_value(PARAM_BOOL, 'True if the event user competency viewed in plan was logged');
@@ -3959,7 +3951,7 @@ public static function user_competency_viewed_in_plan_returns() {
/**
* Returns description of user_competency_viewed_in_course() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_viewed_in_course_parameters() {
$competencyid = new external_value(
@@ -4008,7 +4000,7 @@ public static function user_competency_viewed_in_course($competencyid, $userid,
/**
* Returns description of user_competency_viewed_in_course() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function user_competency_viewed_in_course_returns() {
return new external_value(PARAM_BOOL, 'True if the event user competency viewed in course was logged');
@@ -4017,7 +4009,7 @@ public static function user_competency_viewed_in_course_returns() {
/**
* Returns description of user_competency_plan_viewed() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function user_competency_plan_viewed_parameters() {
$competencyid = new external_value(
@@ -4066,7 +4058,7 @@ public static function user_competency_plan_viewed($competencyid, $userid, $plan
/**
* Returns description of user_competency_plan_viewed() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function user_competency_plan_viewed_returns() {
return new external_value(PARAM_BOOL, 'True if the event user competency plan viewed was logged');
@@ -4075,7 +4067,7 @@ public static function user_competency_plan_viewed_returns() {
/**
* Returns description of grade_competency_in_course() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function grade_competency_in_course_parameters() {
$courseid = new external_value(
@@ -4162,7 +4154,7 @@ public static function grade_competency_in_course($courseid, $userid, $competenc
/**
* Returns description of grade_competency_in_course() result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function grade_competency_in_course_returns() {
return evidence_exporter::get_read_structure();
@@ -4171,7 +4163,7 @@ public static function grade_competency_in_course_returns() {
/**
* Returns description of unlink_plan_from_template_() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function unlink_plan_from_template_parameters() {
$planid = new external_value(
@@ -4206,7 +4198,7 @@ public static function unlink_plan_from_template($planid) {
/**
* Returns description of unlink_plan_from_template_() result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function unlink_plan_from_template_returns() {
return new external_value(PARAM_BOOL, 'True if the unlink was successful');
@@ -4215,7 +4207,7 @@ public static function unlink_plan_from_template_returns() {
/**
* Returns description of template_viewed() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function template_viewed_parameters() {
$id = new external_value(
@@ -4251,7 +4243,7 @@ public static function template_viewed($id) {
/**
* Returns description of template_viewed() result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function template_viewed_returns() {
return new external_value(PARAM_BOOL, 'True if the log of the view was successful');
@@ -4260,7 +4252,7 @@ public static function template_viewed_returns() {
/**
* Returns description of update_course_competency_settings() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function update_course_competency_settings_parameters() {
$courseid = new external_value(
@@ -4306,7 +4298,7 @@ public static function update_course_competency_settings($courseid, $settings) {
/**
* Returns description of update_course_competency_settings() result value.
*
- * @return \external_value
+ * @return external_value
*/
public static function update_course_competency_settings_returns() {
return new external_value(PARAM_BOOL, 'True if the update was successful.');
@@ -4315,7 +4307,7 @@ public static function update_course_competency_settings_returns() {
/**
* Returns description of external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_evidence_parameters() {
return new external_function_parameters(array(
@@ -4344,7 +4336,7 @@ public static function delete_evidence($id) {
/**
* Returns description of external function result value.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function delete_evidence_returns() {
return new external_value(PARAM_BOOL, 'The success');
diff --git a/competency/tests/external/external_test.php b/competency/tests/external/external_test.php
index 8f3b842a69486..cf43e0ecdf91c 100644
--- a/competency/tests/external/external_test.php
+++ b/competency/tests/external/external_test.php
@@ -35,6 +35,7 @@
use core_competency\template_competency;
use core_competency\user_competency;
use core_competency\user_competency_plan;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -201,7 +202,7 @@ protected function create_competency_framework($number = 1, $system = true) {
'contextid' => $system ? \context_system::instance()->id : \context_coursecat::instance($this->category->id)->id
);
$result = external::create_competency_framework($framework);
- return (object) \external_api::clean_returnvalue(external::create_competency_framework_returns(), $result);
+ return (object) external_api::clean_returnvalue(external::create_competency_framework_returns(), $result);
}
protected function create_plan($number, $userid, $templateid, $status, $duedate) {
@@ -215,7 +216,7 @@ protected function create_plan($number, $userid, $templateid, $status, $duedate)
'duedate' => $duedate
);
$result = external::create_plan($plan);
- return (object) \external_api::clean_returnvalue(external::create_plan_returns(), $result);
+ return (object) external_api::clean_returnvalue(external::create_plan_returns(), $result);
}
protected function create_template($number, $system) {
@@ -228,7 +229,7 @@ protected function create_template($number, $system) {
'contextid' => $system ? \context_system::instance()->id : \context_coursecat::instance($this->category->id)->id
);
$result = external::create_template($template);
- return (object) \external_api::clean_returnvalue(external::create_template_returns(), $result);
+ return (object) external_api::clean_returnvalue(external::create_template_returns(), $result);
}
protected function update_template($templateid, $number) {
@@ -240,7 +241,7 @@ protected function update_template($templateid, $number) {
'visible' => true
);
$result = external::update_template($template);
- return \external_api::clean_returnvalue(external::update_template_returns(), $result);
+ return external_api::clean_returnvalue(external::update_template_returns(), $result);
}
protected function update_plan($planid, $number, $userid, $templateid, $status, $duedate) {
@@ -255,7 +256,7 @@ protected function update_plan($planid, $number, $userid, $templateid, $status,
'duedate' => $duedate
);
$result = external::update_plan($plan);
- return \external_api::clean_returnvalue(external::update_plan_returns(), $result);
+ return external_api::clean_returnvalue(external::update_plan_returns(), $result);
}
protected function update_competency_framework($id, $number = 1, $system = true) {
@@ -273,7 +274,7 @@ protected function update_competency_framework($id, $number = 1, $system = true)
'contextid' => $system ? \context_system::instance()->id : \context_coursecat::instance($this->category->id)->id
);
$result = external::update_competency_framework($framework);
- return \external_api::clean_returnvalue(external::update_competency_framework_returns(), $result);
+ return external_api::clean_returnvalue(external::update_competency_framework_returns(), $result);
}
protected function create_competency($number, $frameworkid) {
@@ -285,7 +286,7 @@ protected function create_competency($number, $frameworkid) {
'competencyframeworkid' => $frameworkid
);
$result = external::create_competency($competency);
- return (object) \external_api::clean_returnvalue(external::create_competency_returns(), $result);
+ return (object) external_api::clean_returnvalue(external::create_competency_returns(), $result);
}
protected function update_competency($id, $number) {
@@ -297,7 +298,7 @@ protected function update_competency($id, $number) {
'descriptionformat' => FORMAT_HTML
);
$result = external::update_competency($competency);
- return \external_api::clean_returnvalue(external::update_competency_returns(), $result);
+ return external_api::clean_returnvalue(external::update_competency_returns(), $result);
}
/**
@@ -392,7 +393,7 @@ public function test_read_competency_frameworks_with_manage_permissions() {
$id = $result->id;
$result = external::read_competency_framework($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -418,7 +419,7 @@ public function test_read_competency_frameworks_with_manage_permissions_in_categ
$this->setUser($this->catcreator);
$id = $incat->id;
$result = external::read_competency_framework($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -434,7 +435,7 @@ public function test_read_competency_frameworks_with_manage_permissions_in_categ
try {
$id = $insystem->id;
$result = external::read_competency_framework($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
$this->fail('User cannot read a framework at system level.');
} catch (\required_capability_exception $e) {
// All good.
@@ -452,7 +453,7 @@ public function test_read_competency_frameworks_with_read_permissions() {
$this->setUser($this->user);
$id = $result->id;
$result = external::read_competency_framework($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -478,7 +479,7 @@ public function test_read_competency_frameworks_with_read_permissions_in_categor
$this->setUser($this->catuser);
$id = $incat->id;
$result = external::read_competency_framework($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_framework_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -509,7 +510,7 @@ public function test_delete_competency_frameworks_with_manage_permissions() {
$id = $result->id;
$result = external::delete_competency_framework($id);
- $result = \external_api::clean_returnvalue(external::delete_competency_framework_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_framework_returns(), $result);
$this->assertTrue($result);
}
@@ -526,14 +527,14 @@ public function test_delete_competency_frameworks_with_manage_permissions_in_cat
$this->setUser($this->catcreator);
$id = $incat->id;
$result = external::delete_competency_framework($id);
- $result = \external_api::clean_returnvalue(external::delete_competency_framework_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_framework_returns(), $result);
$this->assertTrue($result);
try {
$id = $insystem->id;
$result = external::delete_competency_framework($id);
- $result = \external_api::clean_returnvalue(external::delete_competency_framework_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_framework_returns(), $result);
$this->fail('Current user cannot should not be able to delete the framework.');
} catch (\required_capability_exception $e) {
// All good.
@@ -644,13 +645,13 @@ public function test_list_and_count_competency_frameworks_with_manage_permission
$result = $this->create_competency_framework(4, false);
$result = external::count_competency_frameworks(array('contextid' => \context_system::instance()->id), 'self');
- $result = \external_api::clean_returnvalue(external::count_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competency_frameworks_returns(), $result);
$this->assertEquals($result, 3);
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => \context_system::instance()->id), 'self', false);
- $result = \external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertEquals(count($result), 3);
$result = (object) $result[0];
@@ -690,7 +691,7 @@ public function test_list_competency_frameworks_with_query() {
// Search on both ID number and shortname.
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => \context_system::instance()->id), 'self', false, 'bee');
- $result = \external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertCount(2, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework1->get('id'), $f->id);
@@ -700,7 +701,7 @@ public function test_list_competency_frameworks_with_query() {
// Search on ID number.
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => \context_system::instance()->id), 'self', false, 'beer');
- $result = \external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertCount(1, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework2->get('id'), $f->id);
@@ -708,7 +709,7 @@ public function test_list_competency_frameworks_with_query() {
// Search on shortname.
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => \context_system::instance()->id), 'self', false, 'cinnamon');
- $result = \external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertCount(1, $result);
$f = (object) array_shift($result);
$this->assertEquals($framework1->get('id'), $f->id);
@@ -716,7 +717,7 @@ public function test_list_competency_frameworks_with_query() {
// No match.
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => \context_system::instance()->id), 'self', false, 'pwnd!');
- $result = \external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertCount(0, $result);
}
@@ -732,12 +733,12 @@ public function test_list_and_count_competency_frameworks_with_read_permissions(
$this->setUser($this->user);
$result = external::count_competency_frameworks(array('contextid' => \context_system::instance()->id), 'self');
- $result = \external_api::clean_returnvalue(external::count_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competency_frameworks_returns(), $result);
$this->assertEquals($result, 3);
$result = external::list_competency_frameworks('shortname', 'ASC', 0, 10,
array('contextid' => \context_system::instance()->id), 'self', false);
- $result = \external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competency_frameworks_returns(), $result);
$this->assertEquals(count($result), 3);
$result = (object) $result[0];
@@ -845,7 +846,7 @@ public function test_read_competencies_with_manage_permissions() {
$id = $competency->id;
$result = external::read_competency($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -873,7 +874,7 @@ public function test_read_competencies_with_manage_permissions_in_category() {
$this->setUser($this->catcreator);
$id = $incat->id;
$result = external::read_competency($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -905,7 +906,7 @@ public function test_read_competencies_with_read_permissions() {
$this->setUser($this->user);
$id = $competency->id;
$result = external::read_competency($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -932,7 +933,7 @@ public function test_read_competencies_with_read_permissions_in_category() {
$this->setUser($this->catuser);
$id = $incat->id;
$result = external::read_competency($id);
- $result = (object) \external_api::clean_returnvalue(external::read_competency_returns(), $result);
+ $result = (object) external_api::clean_returnvalue(external::read_competency_returns(), $result);
$this->assertGreaterThan(0, $result->timecreated);
$this->assertGreaterThan(0, $result->timemodified);
@@ -962,7 +963,7 @@ public function test_delete_competency_with_manage_permissions() {
$id = $result->id;
$result = external::delete_competency($id);
- $result = \external_api::clean_returnvalue(external::delete_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_returns(), $result);
$this->assertTrue($result);
}
@@ -981,7 +982,7 @@ public function test_delete_competency_with_manage_permissions_in_category() {
$this->setUser($this->catcreator);
$id = $incat->id;
$result = external::delete_competency($id);
- $result = \external_api::clean_returnvalue(external::delete_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_returns(), $result);
$this->assertTrue($result);
@@ -1075,15 +1076,15 @@ public function test_count_competencies_with_filters() {
$c5 = $lpg->create_competency(array('competencyframeworkid' => $f2->get('id')));
$result = external::count_competencies(array(array('column' => 'competencyframeworkid', 'value' => $f2->get('id'))));
- $result = \external_api::clean_returnvalue(external::count_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competencies_returns(), $result);
$this->assertEquals(2, $result);
$result = external::count_competencies(array(array('column' => 'competencyframeworkid', 'value' => $f1->get('id'))));
- $result = \external_api::clean_returnvalue(external::count_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competencies_returns(), $result);
$this->assertEquals(3, $result);
$result = external::count_competencies(array(array('column' => 'shortname', 'value' => 'A')));
- $result = \external_api::clean_returnvalue(external::count_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competencies_returns(), $result);
$this->assertEquals(1, $result);
}
@@ -1098,12 +1099,12 @@ public function test_list_and_count_competencies_with_manage_permissions() {
$result = $this->create_competency(3, $framework->id);
$result = external::count_competencies(array());
- $result = \external_api::clean_returnvalue(external::count_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competencies_returns(), $result);
$this->assertEquals($result, 3);
array('id' => $result = external::list_competencies(array(), 'shortname', 'ASC', 0, 10, \context_system::instance()->id));
- $result = \external_api::clean_returnvalue(external::list_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competencies_returns(), $result);
$this->assertEquals(count($result), 3);
$result = (object) $result[0];
@@ -1129,12 +1130,12 @@ public function test_list_and_count_competencies_with_read_permissions() {
$this->setUser($this->user);
$result = external::count_competencies(array());
- $result = \external_api::clean_returnvalue(external::count_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_competencies_returns(), $result);
$this->assertEquals($result, 3);
array('id' => $result = external::list_competencies(array(), 'shortname', 'ASC', 0, 10, \context_system::instance()->id));
- $result = \external_api::clean_returnvalue(external::list_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competencies_returns(), $result);
$this->assertEquals(count($result), 3);
$result = (object) $result[0];
@@ -1160,7 +1161,7 @@ public function test_search_competencies_with_read_permissions() {
$this->setUser($this->user);
$result = external::search_competencies('short', $framework->id);
- $result = \external_api::clean_returnvalue(external::search_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_competencies_returns(), $result);
$this->assertEquals(count($result), 3);
$result = (object) $result[0];
@@ -1699,7 +1700,7 @@ public function test_reorder_template_competencies() {
// This is a move up.
external::reorder_template_competency($template->id, $competency4->id, $competency2->id);
$result = external::list_competencies_in_template($template->id);
- $result = \external_api::clean_returnvalue(external::list_competencies_in_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competencies_in_template_returns(), $result);
$r1 = (object) $result[0];
$r2 = (object) $result[1];
@@ -1712,7 +1713,7 @@ public function test_reorder_template_competencies() {
// This is a move down.
external::reorder_template_competency($template->id, $competency1->id, $competency4->id);
$result = external::list_competencies_in_template($template->id);
- $result = \external_api::clean_returnvalue(external::list_competencies_in_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_competencies_in_template_returns(), $result);
$r1 = (object) $result[0];
$r2 = (object) $result[1];
@@ -1907,7 +1908,7 @@ public function test_read_template() {
}
$result = external::read_template($cattemplate->id);
- $result = \external_api::clean_returnvalue(external::read_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($cattemplate->id, $result['id']);
$this->assertEquals('shortname2', $result['shortname']);
$this->assertEquals('description2', $result['description']);
@@ -1921,7 +1922,7 @@ public function test_read_template() {
accesslib_clear_all_caches_for_unit_testing();
$this->assertTrue(has_capability('moodle/competency:templateview', \context_system::instance()));
$result = external::read_template($systemplate->id);
- $result = \external_api::clean_returnvalue(external::read_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($systemplate->id, $result['id']);
$this->assertEquals('shortname1', $result['shortname']);
$this->assertEquals('description1', $result['description']);
@@ -1931,7 +1932,7 @@ public function test_read_template() {
$this->assertEquals(userdate(0), $result['duedateformatted']);
$result = external::read_template($cattemplate->id);
- $result = \external_api::clean_returnvalue(external::read_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($cattemplate->id, $result['id']);
$this->assertEquals('shortname2', $result['shortname']);
$this->assertEquals('description2', $result['description']);
@@ -1986,7 +1987,7 @@ public function test_update_template() {
$result = $this->update_template($cattemplate->id, 3);
$this->assertTrue($result);
$result = external::read_template($cattemplate->id);
- $result = \external_api::clean_returnvalue(external::read_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($cattemplate->id, $result['id']);
$this->assertEquals('shortname3', $result['shortname']);
$this->assertEquals("description3", $result['description']);
@@ -2000,7 +2001,7 @@ public function test_update_template() {
$result = $this->update_template($systemplate->id, 4);
$this->assertTrue($result);
$result = external::read_template($systemplate->id);
- $result = \external_api::clean_returnvalue(external::read_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($systemplate->id, $result['id']);
$this->assertEquals('shortname4', $result['shortname']);
$this->assertEquals('description4', $result['description']);
@@ -2012,7 +2013,7 @@ public function test_update_template() {
$result = $this->update_template($cattemplate->id, 5);
$this->assertTrue($result);
$result = external::read_template($cattemplate->id);
- $result = \external_api::clean_returnvalue(external::read_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::read_template_returns(), $result);
$this->assertEquals($cattemplate->id, $result['id']);
$this->assertEquals('shortname5', $result['shortname']);
$this->assertEquals('description5', $result['description']);
@@ -2064,17 +2065,17 @@ public function test_delete_template() {
}
$result = external::delete_template($cat1->id);
- $result = \external_api::clean_returnvalue(external::delete_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_template_returns(), $result);
$this->assertTrue($result);
$this->assertFalse($DB->record_exists(template::TABLE, array('id' => $cat1->id)));
// User with system permissions.
$this->setUser($this->creator);
$result = external::delete_template($sys1->id);
- $result = \external_api::clean_returnvalue(external::delete_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_template_returns(), $result);
$this->assertTrue($result);
$result = external::delete_template($cat2->id);
- $result = \external_api::clean_returnvalue(external::delete_template_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_template_returns(), $result);
$this->assertTrue($result);
$this->assertFalse($DB->record_exists(template::TABLE, array('id' => $sys1->id)));
$this->assertFalse($DB->record_exists(template::TABLE, array('id' => $cat2->id)));
@@ -2110,7 +2111,7 @@ public function test_list_templates() {
assign_capability('moodle/competency:templateview', CAP_ALLOW, $this->userrole, $catcontextid, true);
accesslib_clear_all_caches_for_unit_testing();
$result = external::list_templates('id', 'ASC', 0, 10, array('contextid' => $syscontextid), 'children', false);
- $result = \external_api::clean_returnvalue(external::list_templates_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_templates_returns(), $result);
$this->assertCount(2, $result);
$this->assertEquals($cat1->id, $result[0]['id']);
$this->assertEquals($cat2->id, $result[1]['id']);
@@ -2119,7 +2120,7 @@ public function test_list_templates() {
assign_capability('moodle/competency:templateview', CAP_ALLOW, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing();
$result = external::list_templates('id', 'DESC', 0, 3, array('contextid' => $catcontextid), 'parents', false);
- $result = \external_api::clean_returnvalue(external::list_templates_returns(), $result);
+ $result = external_api::clean_returnvalue(external::list_templates_returns(), $result);
$this->assertCount(3, $result);
$this->assertEquals($cat2->id, $result[0]['id']);
$this->assertEquals($cat1->id, $result[1]['id']);
@@ -2201,14 +2202,14 @@ public function test_count_templates() {
assign_capability('moodle/competency:templateview', CAP_ALLOW, $this->userrole, $catcontextid, true);
accesslib_clear_all_caches_for_unit_testing();
$result = external::count_templates(array('contextid' => $syscontextid), 'children');
- $result = \external_api::clean_returnvalue(external::count_templates_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_templates_returns(), $result);
$this->assertEquals(3, $result);
// User with system permissions.
assign_capability('moodle/competency:templateview', CAP_ALLOW, $this->userrole, $syscontextid, true);
accesslib_clear_all_caches_for_unit_testing();
$result = external::count_templates(array('contextid' => $catcontextid), 'parents');
- $result = \external_api::clean_returnvalue(external::count_templates_returns(), $result);
+ $result = external_api::clean_returnvalue(external::count_templates_returns(), $result);
$this->assertEquals(5, $result);
}
@@ -2231,7 +2232,7 @@ public function test_add_related_competency() {
// The lower one always as competencyid.
$result = external::add_related_competency($competency1->get('id'), $competency2->get('id'));
- $result = \external_api::clean_returnvalue(external::add_related_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::add_related_competency_returns(), $result);
$this->assertTrue($result);
$this->assertTrue($DB->record_exists_select(
related_competency::TABLE, 'competencyid = :cid AND relatedcompetencyid = :rid',
@@ -2249,7 +2250,7 @@ public function test_add_related_competency() {
));
$result = external::add_related_competency($competency3->get('id'), $competency1->get('id'));
- $result = \external_api::clean_returnvalue(external::add_related_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::add_related_competency_returns(), $result);
$this->assertTrue($result);
$this->assertTrue($DB->record_exists_select(
related_competency::TABLE, 'competencyid = :cid AND relatedcompetencyid = :rid',
@@ -2274,7 +2275,7 @@ public function test_add_related_competency() {
'competencyid = :cid AND relatedcompetencyid = :rid',
array('rid' => $competency1->get('id'), 'cid' => $competency2->get('id'))));
$result = external::add_related_competency($competency2->get('id'), $competency1->get('id'));
- $result = \external_api::clean_returnvalue(external::add_related_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::add_related_competency_returns(), $result);
$this->assertTrue($result);
$this->assertEquals(1, $DB->count_records_select(related_competency::TABLE,
'competencyid = :cid AND relatedcompetencyid = :rid',
@@ -2324,18 +2325,18 @@ public function test_remove_related_competency() {
// Returns false when the relation does not exist.
$result = external::remove_related_competency($c1->get('id'), $c3->get('id'));
- $result = \external_api::clean_returnvalue(external::remove_related_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::remove_related_competency_returns(), $result);
$this->assertFalse($result);
// Returns true on success.
$result = external::remove_related_competency($c2->get('id'), $c3->get('id'));
- $result = \external_api::clean_returnvalue(external::remove_related_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::remove_related_competency_returns(), $result);
$this->assertTrue($result);
$this->assertEquals(1, related_competency::count_records());
// We don't need to specify competencyid and relatedcompetencyid in the right order.
$result = external::remove_related_competency($c2->get('id'), $c1->get('id'));
- $result = \external_api::clean_returnvalue(external::remove_related_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::remove_related_competency_returns(), $result);
$this->assertTrue($result);
$this->assertEquals(0, related_competency::count_records());
}
@@ -2362,7 +2363,7 @@ public function test_search_competencies_including_related() {
$rc24 = $lpg->create_related_competency(array('competencyid' => $c2->get('id'), 'relatedcompetencyid' => $c4->get('id')));
$result = external::search_competencies('comp', $framework->get('id'), true);
- $result = \external_api::clean_returnvalue(external::search_competencies_returns(), $result);
+ $result = external_api::clean_returnvalue(external::search_competencies_returns(), $result);
$this->assertCount(5, $result);
@@ -2584,7 +2585,7 @@ public function test_fix_sortorder_when_delete_competency() {
$this->assertEquals(3, $c2d->get('sortorder'));
$result = external::delete_competency($c1->get('id'));
- $result = \external_api::clean_returnvalue(external::delete_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_returns(), $result);
$c2->read();
$c2a->read();
@@ -2599,7 +2600,7 @@ public function test_fix_sortorder_when_delete_competency() {
$this->assertEquals(3, $c2d->get('sortorder'));
$result = external::delete_competency($c2b->get('id'));
- $result = \external_api::clean_returnvalue(external::delete_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::delete_competency_returns(), $result);
$c2->read();
$c2a->read();
@@ -2637,7 +2638,7 @@ public function test_fix_sortorder_when_moving_competency() {
$this->assertEquals(1, $c2b->get('sortorder'));
$result = external::set_parent_competency($c2a->get('id'), $c1->get('id'));
- $result = \external_api::clean_returnvalue(external::set_parent_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::set_parent_competency_returns(), $result);
$c1->read();
$c1a->read();
@@ -2655,7 +2656,7 @@ public function test_fix_sortorder_when_moving_competency() {
// Move a root node.
$result = external::set_parent_competency($c2->get('id'), $c1b->get('id'));
- $result = \external_api::clean_returnvalue(external::set_parent_competency_returns(), $result);
+ $result = external_api::clean_returnvalue(external::set_parent_competency_returns(), $result);
$c1->read();
$c1a->read();
diff --git a/completion/classes/external.php b/completion/classes/external.php
index 6bb4ece1a3aff..6c32bd9312efb 100644
--- a/completion/classes/external.php
+++ b/completion/classes/external.php
@@ -24,9 +24,15 @@
* @since Moodle 2.9
*/
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->libdir/completionlib.php");
/**
@@ -283,7 +289,7 @@ public static function get_activities_completion_status($courseid, $userid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function get_activities_completion_status_returns() {
@@ -460,7 +466,7 @@ public static function get_course_completion_status($courseid, $userid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function get_course_completion_status_returns() {
diff --git a/completion/tests/externallib_test.php b/completion/tests/externallib_test.php
index c293e1de1e563..8289932ec1bac 100644
--- a/completion/tests/externallib_test.php
+++ b/completion/tests/externallib_test.php
@@ -17,6 +17,7 @@
namespace core_completion;
use core_completion_external;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -58,7 +59,7 @@ public function test_update_activity_completion_status_manually() {
$result = core_completion_external::update_activity_completion_status_manually($data->cmid, true);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::update_activity_completion_status_manually_returns(), $result);
// Check in DB.
@@ -73,7 +74,7 @@ public function test_update_activity_completion_status_manually() {
$result = core_completion_external::update_activity_completion_status_manually($data->cmid, false);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::update_activity_completion_status_manually_returns(), $result);
$this->assertEquals(0, $DB->get_field('course_modules_completion', 'completionstate',
@@ -152,7 +153,7 @@ public function test_get_activities_completion_status() {
$result = core_completion_external::get_activities_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::get_activities_completion_status_returns(), $result);
// We added 6 activities, but only 4 with completion enabled and one of those is hidden.
@@ -230,7 +231,7 @@ public function test_get_activities_completion_status() {
$this->setUser($teacher);
$result = core_completion_external::get_activities_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::get_activities_completion_status_returns(), $result);
$this->assertCount($numberofcompletions, $result['statuses']);
@@ -240,7 +241,7 @@ public function test_get_activities_completion_status() {
$result = core_completion_external::get_activities_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::get_activities_completion_status_returns(), $result);
// Check forum has been overriden by the teacher.
@@ -261,7 +262,7 @@ public function test_get_activities_completion_status() {
$result = core_completion_external::get_activities_completion_status($course->id, $teacher->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::get_activities_completion_status_returns(), $result);
$this->assertCount($numberofcompletions, $result['statuses']);
@@ -300,7 +301,7 @@ public function test_get_activities_completion_status() {
groups_add_member($group1->id, $teacher->id);
$result = core_completion_external::get_activities_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::get_activities_completion_status_returns(), $result);
$this->assertCount($numberofcompletions, $result['statuses']);
}
@@ -337,28 +338,28 @@ public function test_override_activity_completion_status() {
// Test overriding the status of the manual-completion-activity 'incomplete'.
$this->setUser($teacher);
$result = core_completion_external::override_activity_completion_status($student->id, $data->cmid, COMPLETION_INCOMPLETE);
- $result = \external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
+ $result = external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
$this->assertEquals($result['state'], COMPLETION_INCOMPLETE);
$completiondata = $completion->get_data($cmdata, false, $student->id);
$this->assertEquals(COMPLETION_INCOMPLETE, $completiondata->completionstate);
// Test overriding the status of the manual-completion-activity back to 'complete'.
$result = core_completion_external::override_activity_completion_status($student->id, $data->cmid, COMPLETION_COMPLETE);
- $result = \external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
+ $result = external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
$this->assertEquals($result['state'], COMPLETION_COMPLETE);
$completiondata = $completion->get_data($cmdata, false, $student->id);
$this->assertEquals(COMPLETION_COMPLETE, $completiondata->completionstate);
// Test overriding the status of the auto-completion-activity to 'complete'.
$result = core_completion_external::override_activity_completion_status($student->id, $forum->cmid, COMPLETION_COMPLETE);
- $result = \external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
+ $result = external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
$this->assertEquals($result['state'], COMPLETION_COMPLETE);
$completionforum = $completion->get_data($cmforum, false, $student->id);
$this->assertEquals(COMPLETION_COMPLETE, $completionforum->completionstate);
// Test overriding the status of the auto-completion-activity to 'incomplete'.
$result = core_completion_external::override_activity_completion_status($student->id, $forum->cmid, COMPLETION_INCOMPLETE);
- $result = \external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
+ $result = external_api::clean_returnvalue(core_completion_external::override_activity_completion_status_returns(), $result);
$this->assertEquals($result['state'], COMPLETION_INCOMPLETE);
$completionforum = $completion->get_data($cmforum, false, $student->id);
$this->assertEquals(COMPLETION_INCOMPLETE, $completionforum->completionstate);
@@ -483,7 +484,7 @@ public function test_get_course_completion_status() {
$result = core_completion_external::get_course_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $studentresult = \external_api::clean_returnvalue(
+ $studentresult = external_api::clean_returnvalue(
core_completion_external::get_course_completion_status_returns(), $result);
// 3 different criteria.
@@ -500,7 +501,7 @@ public function test_get_course_completion_status() {
$this->setUser($teacher);
$result = core_completion_external::get_course_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $teacherresult = \external_api::clean_returnvalue(
+ $teacherresult = external_api::clean_returnvalue(
core_completion_external::get_course_completion_status_returns(), $result);
$this->assertEquals($studentresult, $teacherresult);
@@ -521,7 +522,7 @@ public function test_get_course_completion_status() {
groups_add_member($group1->id, $teacher->id);
$result = core_completion_external::get_course_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $teacherresult = \external_api::clean_returnvalue(
+ $teacherresult = external_api::clean_returnvalue(
core_completion_external::get_course_completion_status_returns(), $result);
$this->assertEquals($studentresult, $teacherresult);
@@ -572,7 +573,7 @@ public function test_mark_course_self_completed() {
$result = core_completion_external::mark_course_self_completed($course->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::mark_course_self_completed_returns(), $result);
// We expect a valid result.
@@ -580,7 +581,7 @@ public function test_mark_course_self_completed() {
$result = core_completion_external::get_course_completion_status($course->id, $student->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_completion_external::get_course_completion_status_returns(), $result);
// Course must be completed.
diff --git a/contentbank/classes/external/delete_content.php b/contentbank/classes/external/delete_content.php
index caf18c26f2483..535436e21ef04 100644
--- a/contentbank/classes/external/delete_content.php
+++ b/contentbank/classes/external/delete_content.php
@@ -14,33 +14,21 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for deleting a content.
- *
- * @package core_contentbank
- * @since Moodle 3.9
- * @copyright 2020 Sara Arjona
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_contentbank\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
use core_contentbank\contentbank;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* This is the external method for deleting a content.
*
+ * @package core_contentbank
+ * @since Moodle 3.9
* @copyright 2020 Sara Arjona
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/contentbank/classes/external/rename_content.php b/contentbank/classes/external/rename_content.php
index 48c270f588d29..3b435d50ca129 100644
--- a/contentbank/classes/external/rename_content.php
+++ b/contentbank/classes/external/rename_content.php
@@ -14,31 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External API to rename content bank content.
- *
- * @package core_contentbank
- * @copyright 2020 Amaia Anabitarte
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_contentbank\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
use core_contentbank\contentbank;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* This is the external method for renaming a content.
*
+ * @package core_contentbank
* @copyright 2020 Amaia Anabitarte
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/contentbank/classes/external/set_content_visibility.php b/contentbank/classes/external/set_content_visibility.php
index dd5b880feb2fd..ff6fcb0da527d 100644
--- a/contentbank/classes/external/set_content_visibility.php
+++ b/contentbank/classes/external/set_content_visibility.php
@@ -16,16 +16,11 @@
namespace core_contentbank\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* External API to set the visibility of content bank content.
diff --git a/contentbank/tests/external/delete_content_test.php b/contentbank/tests/external/delete_content_test.php
index 0e801302e185c..5a0a890d14166 100644
--- a/contentbank/tests/external/delete_content_test.php
+++ b/contentbank/tests/external/delete_content_test.php
@@ -33,7 +33,7 @@
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_content.php');
use dml_missing_record_exception;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
/**
diff --git a/contentbank/tests/external/rename_content_test.php b/contentbank/tests/external/rename_content_test.php
index 6f7f6ff56a62d..2668b3f2e9c36 100644
--- a/contentbank/tests/external/rename_content_test.php
+++ b/contentbank/tests/external/rename_content_test.php
@@ -33,7 +33,7 @@
require_once($CFG->dirroot . '/contentbank/tests/fixtures/testable_content.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
/**
* Core content bank external functions tests.
diff --git a/course/classes/external/get_enrolled_courses_with_action_events_by_timeline_classification.php b/course/classes/external/get_enrolled_courses_with_action_events_by_timeline_classification.php
index cbf7ced2329b6..91214f5f61d20 100644
--- a/course/classes/external/get_enrolled_courses_with_action_events_by_timeline_classification.php
+++ b/course/classes/external/get_enrolled_courses_with_action_events_by_timeline_classification.php
@@ -21,11 +21,11 @@
use context_user;
use core_calendar_external;
use core_course_external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
require_once("{$CFG->dirroot}/calendar/externallib.php");
require_once("{$CFG->dirroot}/course/externallib.php");
diff --git a/course/classes/external/helper_for_get_mods_by_courses.php b/course/classes/external/helper_for_get_mods_by_courses.php
index 8a1a33fbaea15..f874afad0c725 100644
--- a/course/classes/external/helper_for_get_mods_by_courses.php
+++ b/course/classes/external/helper_for_get_mods_by_courses.php
@@ -17,11 +17,11 @@
namespace core_course\external;
use context_module;
-use external_description;
-use external_files;
-use external_format_value;
-use external_util;
-use external_value;
+use core_external\external_description;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\util as external_util;
+use core_external\external_value;
/**
* This class helps implement the get_..._by_courses web service that every activity should have.
@@ -86,10 +86,10 @@ public static function standard_coursemodule_element_values(\stdClass $modinstan
public static function format_name_and_intro(\stdClass $modinstance, string $component) {
$context = context_module::instance($modinstance->coursemodule);
- $modinstance->name = external_format_string($modinstance->name, $context->id);
+ $modinstance->name = \core_external\util::format_string($modinstance->name, $context);
- [$modinstance->intro, $modinstance->introformat] = external_format_text(
- $modinstance->intro, $modinstance->introformat, $context->id,
+ [$modinstance->intro, $modinstance->introformat] = \core_external\util::format_text(
+ $modinstance->intro, $modinstance->introformat, $context,
$component, 'intro', null, ['noclean' => true]);
$modinstance->introfiles = external_util::get_area_files($context->id, $component, 'intro', false, false);
}
diff --git a/course/classes/output/course_module_name.php b/course/classes/output/course_module_name.php
index 7f30f90b3bf4f..070d4b1ebc365 100644
--- a/course/classes/output/course_module_name.php
+++ b/course/classes/output/course_module_name.php
@@ -24,9 +24,10 @@
namespace core_course\output;
+use cm_info;
use context_module;
+use core_external\external_api;
use lang_string;
-use cm_info;
/**
* Class to prepare a course module name for display and in-place editing
@@ -93,7 +94,7 @@ public function export_for_template(\renderer_base $output) {
public static function update($itemid, $newvalue) {
$context = context_module::instance($itemid);
// Check access.
- \external_api::validate_context($context);
+ external_api::validate_context($context);
require_capability('moodle/course:manageactivities', $context);
// Trim module name and Update value.
diff --git a/course/externallib.php b/course/externallib.php
index 0397a8d9ed164..eb1c4364016e5 100644
--- a/course/externallib.php
+++ b/course/externallib.php
@@ -27,10 +27,15 @@
defined('MOODLE_INTERNAL') || die;
use core_course\external\course_summary_exporter;
-use core_availability\info;
-
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
require_once(__DIR__ . "/lib.php");
/**
@@ -208,8 +213,8 @@ public static function get_course_contents($courseid, $options = array()) {
$options = (object) array('noclean' => true);
list($sectionvalues['summary'], $sectionvalues['summaryformat']) =
- external_format_text($section->summary, $section->summaryformat,
- $context->id, 'course', 'section', $section->id, $options);
+ \core_external\util::format_text($section->summary, $section->summaryformat,
+ $context, 'course', 'section', $section->id, $options);
$sectionvalues['section'] = $section->section;
$sectionvalues['hiddenbynumsections'] = $section->section > $coursenumsections ? 1 : 0;
$sectionvalues['uservisible'] = $section->uservisible;
@@ -264,7 +269,7 @@ public static function get_course_contents($courseid, $options = array()) {
//common info (for people being able to see the module or availability dates)
$module['id'] = $cm->id;
- $module['name'] = external_format_string($cm->name, $modcontext->id);
+ $module['name'] = \core_external\util::format_string($cm->name, $modcontext);
$module['instance'] = $cm->instance;
$module['contextid'] = $modcontext->id;
$module['modname'] = (string) $cm->modname;
@@ -291,8 +296,8 @@ public static function get_course_contents($courseid, $options = array()) {
if (!empty($cm->showdescription) or $module['noviewlink']) {
// We want to use the external format. However from reading get_formatted_content(), $cm->content format is always FORMAT_HTML.
$options = array('noclean' => true);
- list($module['description'], $descriptionformat) = external_format_text($cm->content,
- FORMAT_HTML, $modcontext->id, $cm->modname, 'intro', $cm->id, $options);
+ list($module['description'], $descriptionformat) = \core_external\util::format_text($cm->content,
+ FORMAT_HTML, $modcontext, $cm->modname, 'intro', $cm->id, $options);
}
//url of the module
@@ -423,7 +428,7 @@ public static function get_course_contents($courseid, $options = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function get_course_contents_returns() {
@@ -600,12 +605,12 @@ public static function get_courses($options = array()) {
$courseinfo = array();
$courseinfo['id'] = $course->id;
- $courseinfo['fullname'] = external_format_string($course->fullname, $context->id);
- $courseinfo['shortname'] = external_format_string($course->shortname, $context->id);
- $courseinfo['displayname'] = external_format_string(get_course_display_name_for_list($course), $context->id);
+ $courseinfo['fullname'] = \core_external\util::format_string($course->fullname, $context);
+ $courseinfo['shortname'] = \core_external\util::format_string($course->shortname, $context);
+ $courseinfo['displayname'] = \core_external\util::format_string(get_course_display_name_for_list($course), $context);
$courseinfo['categoryid'] = $course->category;
list($courseinfo['summary'], $courseinfo['summaryformat']) =
- external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', 0);
+ \core_external\util::format_text($course->summary, $course->summaryformat, $context, 'course', 'summary', 0);
$courseinfo['format'] = $course->format;
$courseinfo['startdate'] = $course->startdate;
$courseinfo['enddate'] = $course->enddate;
@@ -676,7 +681,7 @@ public static function get_courses($options = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function get_courses_returns() {
@@ -921,7 +926,7 @@ public static function create_courses($courses) {
$course['category'] = $course['categoryid'];
// Summary format.
- $course['summaryformat'] = external_validate_format($course['summaryformat']);
+ $course['summaryformat'] = util::validate_format($course['summaryformat']);
if (!empty($course['courseformatoptions'])) {
foreach ($course['courseformatoptions'] as $option) {
@@ -950,7 +955,7 @@ public static function create_courses($courses) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function create_courses_returns() {
@@ -1095,7 +1100,7 @@ public static function update_courses($courses) {
// Summary format.
if (array_key_exists('summaryformat', $course) && ($oldcourse->summaryformat != $course['summaryformat'])) {
require_capability('moodle/course:changesummary', $context);
- $course['summaryformat'] = external_validate_format($course['summaryformat']);
+ $course['summaryformat'] = util::validate_format($course['summaryformat']);
}
// Check if user can change visibility.
@@ -1175,7 +1180,7 @@ public static function update_courses($courses) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function update_courses_returns() {
@@ -1262,7 +1267,7 @@ public static function delete_courses($courseids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function delete_courses_returns() {
@@ -1497,7 +1502,7 @@ public static function duplicate_course($courseid, $fullname, $shortname, $categ
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function duplicate_course_returns() {
@@ -1685,7 +1690,7 @@ public static function import_course($importfrom, $importto, $deletecontent = 0,
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.4
*/
public static function import_course_returns() {
@@ -1913,10 +1918,10 @@ public static function get_categories($criteria = array(), $addsubcategories = t
$categoryinfo = array();
$categoryinfo['id'] = $category->id;
- $categoryinfo['name'] = external_format_string($category->name, $context);
+ $categoryinfo['name'] = \core_external\util::format_string($category->name, $context);
list($categoryinfo['description'], $categoryinfo['descriptionformat']) =
- external_format_text($category->description, $category->descriptionformat,
- $context->id, 'coursecat', 'description', null);
+ \core_external\util::format_text($category->description, $category->descriptionformat,
+ $context, 'coursecat', 'description', null);
$categoryinfo['parent'] = $category->parent;
$categoryinfo['sortorder'] = $category->sortorder;
$categoryinfo['coursecount'] = $category->coursecount;
@@ -1974,7 +1979,7 @@ private static function compare_categories_by_sortorder($category1, $category2)
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function get_categories_returns() {
@@ -2061,14 +2066,14 @@ public static function create_categories($categories) {
require_capability('moodle/category:manage', $context);
// this will validate format and throw an exception if there are errors
- external_validate_format($category['descriptionformat']);
+ util::validate_format($category['descriptionformat']);
$newcategory = core_course_category::create($category);
$context = context_coursecat::instance($newcategory->id);
$createdcategories[] = array(
'id' => $newcategory->id,
- 'name' => external_format_string($newcategory->name, $context),
+ 'name' => \core_external\util::format_string($newcategory->name, $context),
);
}
@@ -2144,7 +2149,7 @@ public static function update_categories($categories) {
require_capability('moodle/category:manage', $categorycontext);
// this will throw an exception if descriptionformat is not valid
- external_validate_format($cat['descriptionformat']);
+ util::validate_format($cat['descriptionformat']);
$category->update($cat);
}
@@ -2155,7 +2160,7 @@ public static function update_categories($categories) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function update_categories_returns() {
@@ -2381,7 +2386,7 @@ public static function view_course($courseid, $sectionnumber = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function view_course_returns() {
@@ -2476,24 +2481,24 @@ protected static function get_course_public_information(core_course_list_element
// Format summary.
list($summary, $summaryformat) =
- external_format_text($course->summary, $course->summaryformat, $coursecontext->id, 'course', 'summary', null);
+ \core_external\util::format_text($course->summary, $course->summaryformat, $coursecontext, 'course', 'summary', null);
$categoryname = '';
if (!empty($category)) {
- $categoryname = external_format_string($category->name, $category->get_context());
+ $categoryname = \core_external\util::format_string($category->name, $category->get_context());
}
$displayname = get_course_display_name_for_list($course);
$coursereturns = array();
$coursereturns['id'] = $course->id;
- $coursereturns['fullname'] = external_format_string($course->fullname, $coursecontext->id);
- $coursereturns['displayname'] = external_format_string($displayname, $coursecontext->id);
- $coursereturns['shortname'] = external_format_string($course->shortname, $coursecontext->id);
+ $coursereturns['fullname'] = \core_external\util::format_string($course->fullname, $coursecontext);
+ $coursereturns['displayname'] = \core_external\util::format_string($displayname, $coursecontext);
+ $coursereturns['shortname'] = \core_external\util::format_string($course->shortname, $coursecontext);
$coursereturns['categoryid'] = $course->category;
$coursereturns['categoryname'] = $categoryname;
$coursereturns['summary'] = $summary;
$coursereturns['summaryformat'] = $summaryformat;
- $coursereturns['summaryfiles'] = external_util::get_area_files($coursecontext->id, 'course', 'summary', false, false);
+ $coursereturns['summaryfiles'] = util::get_area_files($coursecontext->id, 'course', 'summary', false, false);
$coursereturns['overviewfiles'] = $files;
$coursereturns['contacts'] = $coursecontacts;
$coursereturns['enrollmentmethods'] = $enroltypes;
@@ -2722,7 +2727,7 @@ protected static function get_course_structure($onlypublicdata = true) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function search_courses_returns() {
@@ -2809,7 +2814,7 @@ public static function get_course_module($cmid) {
$scaleitems = $outcome->load_scale();
$info->outcomes[] = array(
'id' => $id,
- 'name' => external_format_string($outcome->get_name(), $context->id),
+ 'name' => \core_external\util::format_string($outcome->get_name(), $context),
'scale' => $scaleitems->scale
);
}
@@ -2830,7 +2835,7 @@ public static function get_course_module($cmid) {
$info->downloadcontent = $cm->downloadcontent;
}
// Format name.
- $info->name = external_format_string($cm->name, $context->id);
+ $info->name = \core_external\util::format_string($cm->name, $context);
$result = array();
$result['cm'] = $info;
$result['warnings'] = $warnings;
@@ -2840,7 +2845,7 @@ public static function get_course_module($cmid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_course_module_returns() {
@@ -2944,7 +2949,7 @@ public static function get_course_module_by_instance($module, $instance) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_course_module_by_instance_returns() {
@@ -2981,7 +2986,7 @@ public static function get_user_navigation_options($courseids) {
$params = self::validate_parameters(self::get_user_navigation_options_parameters(), array('courseids' => $courseids));
$courseoptions = array();
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], array(), true);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], array(), true);
if (!empty($courses)) {
foreach ($courses as $course) {
@@ -3015,7 +3020,7 @@ public static function get_user_navigation_options($courseids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function get_user_navigation_options_returns() {
@@ -3071,7 +3076,7 @@ public static function get_user_administration_options($courseids) {
$params = self::validate_parameters(self::get_user_administration_options_parameters(), array('courseids' => $courseids));
$courseoptions = array();
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], array(), true);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], array(), true);
if (!empty($courses)) {
foreach ($courses as $course) {
@@ -3101,7 +3106,7 @@ public static function get_user_administration_options($courseids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function get_user_administration_options_returns() {
@@ -3186,7 +3191,7 @@ public static function get_courses_by_field($field = '', $value = '') {
// Load and validate all courses. This is called because it loads the courses
// more efficiently.
- list ($courses, $warnings) = external_util::validate_courses($courseids, [],
+ list ($courses, $warnings) = util::validate_courses($courseids, [],
false, true);
} else {
$courses = $DB->get_records('course', array($params['field'] => $value), 'id ASC');
@@ -3265,7 +3270,7 @@ public static function get_courses_by_field($field = '', $value = '') {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function get_courses_by_field_returns() {
@@ -3375,7 +3380,7 @@ public static function check_updates($courseid, $tocheck, $filter = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function check_updates_returns() {
@@ -3474,7 +3479,7 @@ public static function get_updates_since($courseid, $since, $filter = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function get_updates_since_returns() {
@@ -3614,7 +3619,7 @@ public static function edit_module($action, $id, $sectionreturn = null) {
* Return structure for edit_module()
*
* @since Moodle 3.3
- * @return external_description
+ * @return \core_external\external_description
*/
public static function edit_module_returns() {
return new external_value(PARAM_RAW, 'html to replace the current module with');
@@ -3680,7 +3685,7 @@ public static function get_module($id, $sectionreturn = null) {
* Return structure for get_module()
*
* @since Moodle 3.3
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_module_returns() {
return new external_value(PARAM_RAW, 'html to replace the current module with');
@@ -3735,7 +3740,7 @@ public static function edit_section($action, $id, $sectionreturn) {
* Return structure for edit_section()
*
* @since Moodle 3.3
- * @return external_description
+ * @return \core_external\external_description
*/
public static function edit_section_returns() {
return new external_value(PARAM_RAW, 'Additional data for javascript (JSON-encoded string)');
@@ -3937,7 +3942,7 @@ function($favourite) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_enrolled_courses_by_timeline_classification_returns() {
return new external_single_structure(
@@ -4051,7 +4056,7 @@ public static function set_favourite_courses(
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function set_favourite_courses_returns() {
return new external_single_structure(
@@ -4135,7 +4140,7 @@ public static function get_recent_courses(int $userid = 0, int $limit = 0, int $
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.6
*/
public static function get_recent_courses_returns() {
@@ -4199,7 +4204,7 @@ public static function get_enrolled_users_by_cmid(int $cmid, int $groupid = 0, b
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_enrolled_users_by_cmid_returns() {
return new external_single_structure([
@@ -4211,7 +4216,7 @@ public static function get_enrolled_users_by_cmid_returns() {
/**
* Create user return value description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function user_description() {
$userfields = array(
@@ -4273,7 +4278,7 @@ public static function add_content_item_to_user_favourites(string $componentname
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function add_content_item_to_user_favourites_returns() {
return \core_course\local\exporters\course_content_item_exporter::get_read_structure();
@@ -4322,7 +4327,7 @@ public static function remove_content_item_from_user_favourites(string $componen
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function remove_content_item_from_user_favourites_returns() {
return \core_course\local\exporters\course_content_item_exporter::get_read_structure();
@@ -4331,7 +4336,7 @@ public static function remove_content_item_from_user_favourites_returns() {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_course_content_items_returns() {
return new external_single_structure([
@@ -4414,7 +4419,7 @@ public static function toggle_activity_recommendation(string $area, int $id): ar
/**
* Returns warnings.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function toggle_activity_recommendation_returns() {
return new external_single_structure(
@@ -4477,7 +4482,7 @@ public static function get_activity_chooser_footer(int $courseid, int $sectionid
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_activity_chooser_footer_returns() {
return new external_single_structure(
diff --git a/course/format/classes/base.php b/course/format/classes/base.php
index b3d10e33802f5..eae5e3caf3b4c 100644
--- a/course/format/classes/base.php
+++ b/course/format/classes/base.php
@@ -38,7 +38,7 @@
use moodle_url;
use lang_string;
use completion_info;
-use external_api;
+use core_external\external_api;
use stdClass;
use cache;
use core_courseformat\output\legacy_renderer;
diff --git a/course/format/classes/external/get_state.php b/course/format/classes/external/get_state.php
index 99c354f21bd3f..76970e0777f93 100644
--- a/course/format/classes/external/get_state.php
+++ b/course/format/classes/external/get_state.php
@@ -16,14 +16,9 @@
namespace core_courseformat\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
/**
* Class for exporting a course state.
@@ -41,11 +36,9 @@ class get_state extends external_api {
* @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
- return new external_function_parameters(
- [
- 'courseid' => new external_value(PARAM_INT, 'course id', VALUE_REQUIRED),
- ]
- );
+ return new external_function_parameters([
+ 'courseid' => new external_value(PARAM_INT, 'course id', VALUE_REQUIRED),
+ ]);
}
/**
diff --git a/course/format/classes/external/update_course.php b/course/format/classes/external/update_course.php
index 870ea6985adb9..7552484774fe4 100644
--- a/course/format/classes/external/update_course.php
+++ b/course/format/classes/external/update_course.php
@@ -16,15 +16,10 @@
namespace core_courseformat\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_multiple_structure;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_value;
use moodle_exception;
use coding_exception;
use context_course;
diff --git a/course/format/classes/output/local/content/cm/title.php b/course/format/classes/output/local/content/cm/title.php
index e0948a12a4a12..e7cc8b3c5da5d 100644
--- a/course/format/classes/output/local/content/cm/title.php
+++ b/course/format/classes/output/local/content/cm/title.php
@@ -35,7 +35,7 @@
use renderable;
use section_info;
use stdClass;
-use external_api;
+use core_external\external_api;
use context_module;
/**
diff --git a/course/format/classes/output/local/state/cm.php b/course/format/classes/output/local/state/cm.php
index 6e92823b7bf0e..8d6fbc49556c7 100644
--- a/course/format/classes/output/local/state/cm.php
+++ b/course/format/classes/output/local/state/cm.php
@@ -72,8 +72,7 @@ public function __construct(course_format $format, section_info $section, cm_inf
* @return stdClass data context for a mustache template
*/
public function export_for_template(renderer_base $output): stdClass {
- global $USER, $CFG;
- require_once($CFG->libdir . '/externallib.php');
+ global $USER;
$format = $this->format;
$section = $this->section;
@@ -83,7 +82,7 @@ public function export_for_template(renderer_base $output): stdClass {
$data = (object)[
'id' => $cm->id,
'anchor' => "module-{$cm->id}",
- 'name' => external_format_string($cm->name, $cm->context, true),
+ 'name' => \core_external\util::format_string($cm->name, $cm->context, true),
'visible' => !empty($cm->visible),
'stealth' => $cm->is_stealth(),
'sectionid' => $section->id,
diff --git a/course/format/tests/external/get_state_test.php b/course/format/tests/external/get_state_test.php
index bcedd162f7f84..9ba874a371d47 100644
--- a/course/format/tests/external/get_state_test.php
+++ b/course/format/tests/external/get_state_test.php
@@ -21,7 +21,7 @@
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
/**
* Tests for the get_state class.
diff --git a/course/format/tests/output/local/state/cm_test.php b/course/format/tests/output/local/state/cm_test.php
index 2899af7c2896b..7c4a99d9e12e1 100644
--- a/course/format/tests/output/local/state/cm_test.php
+++ b/course/format/tests/output/local/state/cm_test.php
@@ -18,7 +18,6 @@
use availability_date\condition;
use core_availability\tree;
-use context_course;
use stdClass;
/**
@@ -39,7 +38,6 @@ public static function setupBeforeClass(): void {
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/format/tests/fixtures/format_theunittest.php');
require_once($CFG->dirroot . '/course/format/tests/fixtures/format_theunittest_output_course_format_state.php');
- require_once($CFG->libdir . '/externallib.php');
}
/**
diff --git a/course/format/tests/output/local/state/section_test.php b/course/format/tests/output/local/state/section_test.php
index ef12f894a759f..3cbc0e33946a5 100644
--- a/course/format/tests/output/local/state/section_test.php
+++ b/course/format/tests/output/local/state/section_test.php
@@ -18,7 +18,6 @@
use availability_date\condition;
use core_availability\tree;
-use context_course;
use stdClass;
/**
@@ -39,7 +38,6 @@ public static function setupBeforeClass(): void {
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/format/tests/fixtures/format_theunittest.php');
require_once($CFG->dirroot . '/course/format/tests/fixtures/format_theunittest_output_course_format_state.php');
- require_once($CFG->libdir . '/externallib.php');
}
/**
diff --git a/course/format/tests/output/local/state/state_test.php b/course/format/tests/output/local/state/state_test.php
index 3c964c98e241f..81f18543f1c97 100644
--- a/course/format/tests/output/local/state/state_test.php
+++ b/course/format/tests/output/local/state/state_test.php
@@ -35,7 +35,6 @@ public static function setupBeforeClass(): void {
require_once($CFG->dirroot . '/course/lib.php');
require_once($CFG->dirroot . '/course/format/tests/fixtures/format_theunittest.php');
require_once($CFG->dirroot . '/course/format/tests/fixtures/format_theunittest_output_course_format_state.php');
- require_once($CFG->dirroot . '/lib/externallib.php');
}
/**
diff --git a/course/format/tests/stateactions_test.php b/course/format/tests/stateactions_test.php
index 985681f937db7..5ef1ba2ad1a4b 100644
--- a/course/format/tests/stateactions_test.php
+++ b/course/format/tests/stateactions_test.php
@@ -30,16 +30,6 @@
* @coversDefaultClass \core_courseformat\stateactions
*/
class stateactions_test extends \advanced_testcase {
-
- /**
- * Setup to ensure that fixtures are loaded.
- */
- public static function setupBeforeClass(): void {
- global $CFG;
- // State data uses external_format_string.
- require_once($CFG->dirroot . '/lib/externallib.php');
- }
-
/**
* Helper method to create an activity into a section and add it to the $sections and $activities arrays.
*
diff --git a/course/format/topics/tests/format_topics_test.php b/course/format/topics/tests/format_topics_test.php
index 31794cfe4520d..eca87a7f7ccff 100644
--- a/course/format/topics/tests/format_topics_test.php
+++ b/course/format/topics/tests/format_topics_test.php
@@ -16,6 +16,8 @@
namespace format_topics;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -151,7 +153,7 @@ public function test_update_inplace_editable() {
$this->getDataGenerator()->enrol_user($user->id, $course->id, $teacherrole->id);
$res = \core_external::update_inplace_editable('format_topics', 'sectionname', $section->id, 'New section name');
- $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
+ $res = external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('New section name', $res['value']);
$this->assertEquals('New section name', $DB->get_field('course_sections', 'name', ['id' => $section->id]));
}
diff --git a/course/format/weeks/tests/format_weeks_test.php b/course/format/weeks/tests/format_weeks_test.php
index dd5eb990a366c..385fb5586aaa8 100644
--- a/course/format/weeks/tests/format_weeks_test.php
+++ b/course/format/weeks/tests/format_weeks_test.php
@@ -16,6 +16,8 @@
namespace format_weeks;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -149,7 +151,7 @@ public function test_update_inplace_editable() {
$this->getDataGenerator()->enrol_user($user->id, $course->id, $teacherrole->id);
$res = \core_external::update_inplace_editable('format_weeks', 'sectionname', $section->id, 'New section name');
- $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
+ $res = external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('New section name', $res['value']);
$this->assertEquals('New section name', $DB->get_field('course_sections', 'name', array('id' => $section->id)));
}
diff --git a/course/tests/courselib_test.php b/course/tests/courselib_test.php
index a811dd38b0797..1b2e5e677f565 100644
--- a/course/tests/courselib_test.php
+++ b/course/tests/courselib_test.php
@@ -38,7 +38,7 @@
use course_request;
use core_course_category;
use enrol_imsenterprise\imsenterprise_test;
-use external_api;
+use core_external\external_api;
use grade_item;
use grading_manager;
use moodle_exception;
diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php
index e547b781f4350..3a25d9b07000b 100644
--- a/course/tests/externallib_test.php
+++ b/course/tests/externallib_test.php
@@ -745,13 +745,18 @@ public function test_get_courses () {
$coursecontext = context_course::instance($course['id']);
$dbcourse = $generatedcourses[$course['id']];
$this->assertEquals($course['idnumber'], $dbcourse->idnumber);
- $this->assertEquals($course['fullname'], external_format_string($dbcourse->fullname, $coursecontext->id));
- $this->assertEquals($course['displayname'], external_format_string(get_course_display_name_for_list($dbcourse),
- $coursecontext->id));
+ $this->assertEquals(
+ $course['fullname'],
+ \core_external\util::format_string($dbcourse->fullname, $coursecontext->id)
+ );
+ $this->assertEquals(
+ $course['displayname'],
+ \core_external\util::format_string(get_course_display_name_for_list($dbcourse), $coursecontext->id)
+ );
// Summary was converted to the HTML format.
$this->assertEquals($course['summary'], format_text($dbcourse->summary, FORMAT_MOODLE, array('para' => false)));
$this->assertEquals($course['summaryformat'], FORMAT_HTML);
- $this->assertEquals($course['shortname'], external_format_string($dbcourse->shortname, $coursecontext->id));
+ $this->assertEquals($course['shortname'], \core_external\util::format_string($dbcourse->shortname, $coursecontext->id));
$this->assertEquals($course['categoryid'], $dbcourse->category);
$this->assertEquals($course['format'], $dbcourse->format);
$this->assertEquals($course['showgrades'], $dbcourse->showgrades);
diff --git a/customfield/externallib.php b/customfield/externallib.php
index 1f26bd89e3a23..27a2860331b06 100644
--- a/customfield/externallib.php
+++ b/customfield/externallib.php
@@ -14,6 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
/**
* External interface library for customfields component
*
@@ -21,17 +27,6 @@
* @copyright 2018 David Matamoros
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once($CFG->libdir . "/externallib.php");
-
-/**
- * Class core_customfield_external
- *
- * @copyright 2018 David Matamoros
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
class core_customfield_external extends external_api {
/**
diff --git a/customfield/lib.php b/customfield/lib.php
index b3ec2d66adf9a..0c3986d640637 100644
--- a/customfield/lib.php
+++ b/customfield/lib.php
@@ -22,6 +22,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die;
/**
@@ -36,7 +38,7 @@ function core_customfield_inplace_editable($itemtype, $itemid, $newvalue) {
if ($itemtype === 'category') {
$category = core_customfield\category_controller::create($itemid);
$handler = $category->get_handler();
- \external_api::validate_context($handler->get_configuration_context());
+ external_api::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
diff --git a/enrol/externallib.php b/enrol/externallib.php
index b70ca45a619f1..e0333a3b8ca47 100644
--- a/enrol/externallib.php
+++ b/enrol/externallib.php
@@ -14,12 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
/**
- * External course participation api.
- *
- * This api is mostly read only, the actual enrol and unenrol
- * support is in each enrol plugin.
+ * Course participations External functions.
*
* @package core_enrol
* @category external
@@ -27,16 +23,23 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Enrol external functions
*
+ * This api is mostly read only, the actual enrol and unenrol
+ * support is in each enrol plugin.
+ *
* @package core_enrol
* @category external
- * @copyright 2011 Jerome Mouneyrac
+ * @copyright 2010 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.2
*/
@@ -352,11 +355,11 @@ function($favourite) {
$enrolledusercount = $DB->count_records_sql($enrolledsql, $enrolledparams);
}
- $displayname = external_format_string(get_course_display_name_for_list($course), $context->id);
+ $displayname = \core_external\util::format_string(get_course_display_name_for_list($course), $context);
list($course->summary, $course->summaryformat) =
- external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', null);
- $course->fullname = external_format_string($course->fullname, $context->id);
- $course->shortname = external_format_string($course->shortname, $context->id);
+ \core_external\util::format_text($course->summary, $course->summaryformat, $context, 'course', 'summary', null);
+ $course->fullname = \core_external\util::format_string($course->fullname, $context);
+ $course->shortname = \core_external\util::format_string($course->shortname, $context);
$progress = null;
$completed = null;
@@ -449,7 +452,7 @@ function($favourite) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_users_courses_returns() {
return new external_multiple_structure(
@@ -494,7 +497,7 @@ public static function get_users_courses_returns() {
/**
* Returns description of method parameters value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_potential_users_parameters() {
return new external_function_parameters(
@@ -598,7 +601,7 @@ public static function get_potential_users($courseid, $enrolid, $search, $search
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_potential_users_returns() {
global $CFG;
@@ -894,7 +897,7 @@ public static function get_enrolled_users($courseid, $options = []) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_enrolled_users_returns() {
return new external_multiple_structure(
@@ -1015,7 +1018,7 @@ public static function get_course_enrolment_methods($courseid) {
/**
* Returns description of get_course_enrolment_methods() result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_course_enrolment_methods_returns() {
return new external_multiple_structure(
@@ -1090,7 +1093,7 @@ public static function submit_user_enrolment_form($formdata) {
/**
* Returns description of submit_user_enrolment_form() result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function submit_user_enrolment_form_returns() {
return new external_single_structure([
@@ -1164,7 +1167,7 @@ public static function unenrol_user_enrolment($ueid) {
/**
* Returns description of unenrol_user_enrolment() result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function unenrol_user_enrolment_returns() {
return new external_single_structure(
diff --git a/enrol/guest/classes/external.php b/enrol/guest/classes/external.php
index 65850b934888e..57642ef0ed6d1 100644
--- a/enrol/guest/classes/external.php
+++ b/enrol/guest/classes/external.php
@@ -24,9 +24,15 @@
* @since Moodle 3.1
*/
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/enrollib.php');
/**
diff --git a/enrol/guest/tests/external/external_test.php b/enrol/guest/tests/external/external_test.php
index 360e4ebf0f7fc..5cd6a66cb0435 100644
--- a/enrol/guest/tests/external/external_test.php
+++ b/enrol/guest/tests/external/external_test.php
@@ -25,6 +25,7 @@
namespace enrol_guest\external;
+use core_external\external_api;
use enrol_guest_external;
use externallib_advanced_testcase;
@@ -74,7 +75,7 @@ public function test_get_instance_info() {
$this->setAdminUser();
$result = enrol_guest_external::get_instance_info($instance);
- $result = \external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
$this->assertEquals($instance, $result['instanceinfo']['id']);
$this->assertEquals($course->id, $result['instanceinfo']['courseid']);
@@ -86,7 +87,7 @@ public function test_get_instance_info() {
$DB->set_field('enrol', 'status', ENROL_INSTANCE_DISABLED, array('id' => $instance));
$result = enrol_guest_external::get_instance_info($instance);
- $result = \external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
$this->assertEquals($instance, $result['instanceinfo']['id']);
$this->assertEquals($course->id, $result['instanceinfo']['courseid']);
$this->assertEquals('guest', $result['instanceinfo']['type']);
@@ -109,7 +110,7 @@ public function test_get_instance_info() {
$DB->set_field('course', 'visible', 1, array('id' => $course->id));
$this->setUser($student);
$result = enrol_guest_external::get_instance_info($instance);
- $result = \external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_guest_external::get_instance_info_returns(), $result);
$this->assertEquals($instance, $result['instanceinfo']['id']);
$this->assertEquals($course->id, $result['instanceinfo']['courseid']);
diff --git a/enrol/manual/externallib.php b/enrol/manual/externallib.php
index a538ac334290b..000ad30ca0026 100644
--- a/enrol/manual/externallib.php
+++ b/enrol/manual/externallib.php
@@ -14,6 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
/**
* External course participation api.
*
@@ -24,19 +30,6 @@
* @category external
* @copyright 2011 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
-/**
- * Manual enrolment external functions.
- *
- * @package enrol_manual
- * @category external
- * @copyright 2011 Jerome Mouneyrac
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.2
*/
class enrol_manual_external extends external_api {
diff --git a/enrol/meta/classes/external/add_instances.php b/enrol/meta/classes/external/add_instances.php
index 8e52cabb9254e..07f0e71dab56c 100644
--- a/enrol/meta/classes/external/add_instances.php
+++ b/enrol/meta/classes/external/add_instances.php
@@ -16,11 +16,11 @@
namespace enrol_meta\external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use invalid_parameter_exception;
use context_course;
use moodle_exception;
diff --git a/enrol/meta/classes/external/delete_instances.php b/enrol/meta/classes/external/delete_instances.php
index 1fb3e6883ed70..fb3c70f94db01 100644
--- a/enrol/meta/classes/external/delete_instances.php
+++ b/enrol/meta/classes/external/delete_instances.php
@@ -16,11 +16,11 @@
namespace enrol_meta\external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use invalid_parameter_exception;
use context_course;
use moodle_exception;
diff --git a/enrol/meta/tests/external/add_instances_test.php b/enrol/meta/tests/external/add_instances_test.php
index 16ce1643014e7..4481718ab7cd6 100644
--- a/enrol/meta/tests/external/add_instances_test.php
+++ b/enrol/meta/tests/external/add_instances_test.php
@@ -16,9 +16,10 @@
namespace enrol_meta\external;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
@@ -126,7 +127,7 @@ public function test_add_instances() {
// Add instance.
$result = add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
- $result = \external_api::clean_returnvalue(add_instances::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 1);
@@ -138,7 +139,7 @@ public function test_add_instances() {
// Add same instance.
$result = add_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
- $result = \external_api::clean_returnvalue(add_instances::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 0);
diff --git a/enrol/meta/tests/external/delete_instances_test.php b/enrol/meta/tests/external/delete_instances_test.php
index 53c79dd74f60e..5f3a35a5f83fe 100644
--- a/enrol/meta/tests/external/delete_instances_test.php
+++ b/enrol/meta/tests/external/delete_instances_test.php
@@ -16,9 +16,10 @@
namespace enrol_meta\external;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
@@ -121,7 +122,7 @@ public function test_delete_instances() {
// Delete instance.
$result = delete_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
- $result = \external_api::clean_returnvalue(add_instances::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 1);
@@ -133,7 +134,7 @@ public function test_delete_instances() {
// Delete same instance.
$result = delete_instances::execute([['metacourseid' => $metacourse->id, 'courseid' => $course->id]]);
- $result = \external_api::clean_returnvalue(add_instances::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(add_instances::execute_returns(), $result);
$this->assertEquals($result[0]['metacourseid'], $metacourse->id);
$this->assertEquals($result[0]['courseid'], $course->id);
$this->assertEquals($result[0]['status'], 0);
diff --git a/enrol/self/externallib.php b/enrol/self/externallib.php
index 5a2270eb6107c..a4e7ae18d81d6 100644
--- a/enrol/self/externallib.php
+++ b/enrol/self/externallib.php
@@ -14,17 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Self enrol plugin external functions
- *
- * @package enrol_self
- * @copyright 2013 Rajesh Taneja
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* Self enrolment external functions.
@@ -42,9 +36,9 @@ class enrol_self_external extends external_api {
* @return external_function_parameters
*/
public static function get_instance_info_parameters() {
- return new external_function_parameters(
- array('instanceid' => new external_value(PARAM_INT, 'instance id of self enrolment plugin.'))
- );
+ return new external_function_parameters([
+ 'instanceid' => new external_value(PARAM_INT, 'instance id of self enrolment plugin.'),
+ ]);
}
/**
@@ -87,7 +81,7 @@ public static function get_instance_info($instanceid) {
/**
* Returns description of get_instance_info() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_instance_info_returns() {
return new external_single_structure(
@@ -243,7 +237,7 @@ public static function enrol_user($courseid, $password = '', $instanceid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function enrol_user_returns() {
diff --git a/enrol/self/tests/externallib_test.php b/enrol/self/tests/externallib_test.php
index 21c5d6ede2643..5fae34204a531 100644
--- a/enrol/self/tests/externallib_test.php
+++ b/enrol/self/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace enrol_self;
+use core_external\external_api;
use enrol_self_external;
use externallib_advanced_testcase;
@@ -76,7 +77,7 @@ public function test_get_instance_info() {
$this->setAdminUser();
$instanceinfo1 = enrol_self_external::get_instance_info($instanceid1);
- $instanceinfo1 = \external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo1);
+ $instanceinfo1 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo1);
$this->assertEquals($instanceid1, $instanceinfo1['id']);
$this->assertEquals($course->id, $instanceinfo1['courseid']);
@@ -86,7 +87,7 @@ public function test_get_instance_info() {
$this->assertFalse(isset($instanceinfo1['enrolpassword']));
$instanceinfo2 = enrol_self_external::get_instance_info($instanceid2);
- $instanceinfo2 = \external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo2);
+ $instanceinfo2 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo2);
$this->assertEquals($instanceid2, $instanceinfo2['id']);
$this->assertEquals($course->id, $instanceinfo2['courseid']);
$this->assertEquals('self', $instanceinfo2['type']);
@@ -95,7 +96,7 @@ public function test_get_instance_info() {
$this->assertFalse(isset($instanceinfo2['enrolpassword']));
$instanceinfo3 = enrol_self_external::get_instance_info($instanceid3);
- $instanceinfo3 = \external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo3);
+ $instanceinfo3 = external_api::clean_returnvalue(enrol_self_external::get_instance_info_returns(), $instanceinfo3);
$this->assertEquals($instanceid3, $instanceinfo3['id']);
$this->assertEquals($course->id, $instanceinfo3['courseid']);
$this->assertEquals('self', $instanceinfo3['type']);
@@ -151,7 +152,7 @@ public function test_enrol_user() {
// Self enrol me.
$result = enrol_self_external::enrol_user($course1->id);
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertTrue($result['status']);
self::assertEquals(1, $DB->count_records('user_enrolments', array('enrolid' => $instance1->id)));
@@ -173,14 +174,14 @@ public function test_enrol_user() {
// Try not passing a key.
$result = enrol_self_external::enrol_user($course2->id);
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertFalse($result['status']);
self::assertCount(1, $result['warnings']);
self::assertEquals('4', $result['warnings'][0]['warningcode']);
// Try passing an invalid key.
$result = enrol_self_external::enrol_user($course2->id, 'invalidkey');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertFalse($result['status']);
self::assertCount(1, $result['warnings']);
self::assertEquals('4', $result['warnings'][0]['warningcode']);
@@ -188,14 +189,14 @@ public function test_enrol_user() {
// Try passing an invalid key with hint.
$selfplugin->set_config('showhint', true);
$result = enrol_self_external::enrol_user($course2->id, 'invalidkey');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertFalse($result['status']);
self::assertCount(1, $result['warnings']);
self::assertEquals('3', $result['warnings'][0]['warningcode']);
// Everything correct, now.
$result = enrol_self_external::enrol_user($course2->id, 'abcdef');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertTrue($result['status']);
self::assertEquals(1, $DB->count_records('user_enrolments', array('enrolid' => $instance2->id)));
@@ -212,14 +213,14 @@ public function test_enrol_user() {
self::setUser($user2);
// Try passing and invalid key for group.
$result = enrol_self_external::enrol_user($course2->id, 'invalidkey');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertFalse($result['status']);
self::assertCount(1, $result['warnings']);
self::assertEquals('2', $result['warnings'][0]['warningcode']);
// Now, everything ok.
$result = enrol_self_external::enrol_user($course2->id, 'zyx');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertTrue($result['status']);
self::assertEquals(2, $DB->count_records('user_enrolments', array('enrolid' => $instance2->id)));
@@ -236,20 +237,20 @@ public function test_enrol_user() {
self::setUser($user3);
$result = enrol_self_external::enrol_user($course2->id, 'invalidkey');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertFalse($result['status']);
self::assertCount(2, $result['warnings']);
// Now, everything ok.
$result = enrol_self_external::enrol_user($course2->id, 'zyx');
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertTrue($result['status']);
self::assertTrue(is_enrolled($context2, $user3));
// Now test passing an instance id.
self::setUser($user4);
$result = enrol_self_external::enrol_user($course2->id, 'abcdef', $instance3id);
- $result = \external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
+ $result = external_api::clean_returnvalue(enrol_self_external::enrol_user_returns(), $result);
self::assertTrue($result['status']);
self::assertTrue(is_enrolled($context2, $user3));
self::assertCount(0, $result['warnings']);
diff --git a/enrol/tests/externallib_test.php b/enrol/tests/externallib_test.php
index 45289cb53d1c3..b0199c0bafe7a 100644
--- a/enrol/tests/externallib_test.php
+++ b/enrol/tests/externallib_test.php
@@ -17,6 +17,7 @@
namespace core_enrol;
use core_enrol_external;
+use core_external\external_api;
use enrol_user_enrolment_form;
use externallib_advanced_testcase;
@@ -348,7 +349,7 @@ public function test_get_enrolled_users_visibility($settings, $results) {
$enrolledusers = core_enrol_external::get_enrolled_users($course->id, $options);
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
// We are only interested in ids to check visibility.
$viewed = array();
@@ -405,7 +406,7 @@ public function test_get_enrolled_users_active_suspended() {
$suspendedusers = core_enrol_external::get_enrolled_users($course->id, $options);
// We need to execute the return values cleaning process to simulate the web service server.
- $suspendedusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $suspendedusers);
+ $suspendedusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $suspendedusers);
$this->assertCount(2, $suspendedusers);
foreach ($suspendedusers as $suspendeduser) {
@@ -420,7 +421,7 @@ public function test_get_enrolled_users_active_suspended() {
$activeusers = core_enrol_external::get_enrolled_users($course->id, $options);
// We need to execute the return values cleaning process to simulate the web service server.
- $activeusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $activeusers);
+ $activeusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $activeusers);
$this->assertCount(4, $activeusers);
foreach ($activeusers as $activeuser) {
@@ -434,7 +435,7 @@ public function test_get_enrolled_users_active_suspended() {
$allusers = core_enrol_external::get_enrolled_users($course->id, $options);
// We need to execute the return values cleaning process to simulate the web service server.
- $allusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $allusers);
+ $allusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $allusers);
$this->assertCount(6, $allusers);
// Active and suspended. Test exception is thrown.
@@ -462,8 +463,10 @@ public function test_get_users_courses() {
$timenow = time();
$coursedata1 = array(
- 'fullname' => 'Course 1', // Adding tags here to check that external_format_string works.
- 'shortname' => 'Course 1', // Adding tags here to check that external_format_string works.
+ // Adding tags here to check that \core_external\util::format_string works.
+ 'fullname' => 'Course 1',
+ // Adding tags here to check that \core_external\util::format_string works.
+ 'shortname' => 'Course 1',
'summary' => 'Lightwork Course 1 description',
'summaryformat' => FORMAT_MOODLE,
'lang' => 'en',
@@ -523,19 +526,25 @@ public function test_get_users_courses() {
$enrolledincourses = core_enrol_external::get_users_courses($student->id, true);
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledincourses = \external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
// Check we retrieve the good total number of enrolled users.
$this->assertEquals(2, count($enrolledincourses));
// We need to format summary and summaryformat before to compare them with those values returned by the webservice.
- list($course1->summary, $course1->summaryformat) =
- external_format_text($course1->summary, $course1->summaryformat, $contexts[$course1->id]->id, 'course', 'summary', 0);
+ [$course1->summary, $course1->summaryformat] = \core_external\util::format_text(
+ $course1->summary,
+ $course1->summaryformat,
+ $contexts[$course1->id],
+ 'course',
+ 'summary',
+ 0
+ );
// Check there are no differences between $course1 properties and course values returned by the webservice
// only for those fields listed in the $coursedata1 array.
- $course1->fullname = external_format_string($course1->fullname, $contexts[$course1->id]->id);
- $course1->shortname = external_format_string($course1->shortname, $contexts[$course1->id]->id);
+ $course1->fullname = \core_external\util::format_string($course1->fullname, $contexts[$course1->id]->id);
+ $course1->shortname = \core_external\util::format_string($course1->shortname, $contexts[$course1->id]->id);
foreach ($enrolledincourses as $courseenrol) {
if ($courseenrol['id'] == $course1->id) {
foreach ($coursedata1 as $fieldname => $value) {
@@ -572,7 +581,7 @@ public function test_get_users_courses() {
// Check that returnusercount works correctly.
$enrolledincourses = core_enrol_external::get_users_courses($student->id, false);
- $enrolledincourses = \external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
foreach ($enrolledincourses as $courseenrol) {
$this->assertFalse(isset($courseenrol['enrolledusercount']));
}
@@ -581,7 +590,7 @@ public function test_get_users_courses() {
$this->setAdminUser();
$enrolledincourses = core_enrol_external::get_users_courses($student->id, true);
- $enrolledincourses = \external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
$this->assertEquals(2, count($enrolledincourses));
foreach ($enrolledincourses as $courseenrol) {
if ($courseenrol['id'] == $course1->id) {
@@ -604,7 +613,7 @@ public function test_get_users_courses() {
$this->setUser($otherstudent);
$enrolledincourses = core_enrol_external::get_users_courses($student->id, true);
- $enrolledincourses = \external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
$this->assertEquals(1, count($enrolledincourses));
$this->assertEquals($timenow, $enrolledincourses[0]['lastaccess']); // I can see this, not hidden.
@@ -613,7 +622,7 @@ public function test_get_users_courses() {
// Change some global profile visibility fields.
$CFG->hiddenuserfields = 'lastaccess';
$enrolledincourses = core_enrol_external::get_users_courses($student->id, true);
- $enrolledincourses = \external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
$this->assertEquals(0, $enrolledincourses[0]['lastaccess']); // I can't see this, hidden by global setting.
}
@@ -728,16 +737,22 @@ public function test_get_users_courses_with_mathjax() {
$enrolledincourses = core_enrol_external::get_users_courses($student->id, true);
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledincourses = \external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
+ $enrolledincourses = external_api::clean_returnvalue(core_enrol_external::get_users_courses_returns(), $enrolledincourses);
// Check that the amount of courses is the right one.
$this->assertCount(1, $enrolledincourses);
// Filter the values to compare them with the returned ones.
- $course->fullname = external_format_string($course->fullname, $context->id);
- $course->shortname = external_format_string($course->shortname, $context->id);
- list($course->summary, $course->summaryformat) =
- external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', 0);
+ $course->fullname = \core_external\util::format_string($course->fullname, $context->id);
+ $course->shortname = \core_external\util::format_string($course->shortname, $context->id);
+ [$course->summary, $course->summaryformat] = \core_external\util::format_text(
+ $course->summary,
+ $course->summaryformat,
+ $context,
+ 'course',
+ 'summary',
+ 0
+ );
// Compare the values.
$this->assertStringContainsString('', $enrolledincourses[0]['fullname']);
@@ -789,7 +804,7 @@ public function test_get_course_enrolment_methods() {
// Check if information is returned.
$enrolmentmethods = core_enrol_external::get_course_enrolment_methods($course1->id);
- $enrolmentmethods = \external_api::clean_returnvalue(core_enrol_external::get_course_enrolment_methods_returns(),
+ $enrolmentmethods = external_api::clean_returnvalue(core_enrol_external::get_course_enrolment_methods_returns(),
$enrolmentmethods);
// Enrolment information is currently returned by self enrolment plugin, so count == 1.
// This should be changed as we implement get_enrol_info() for other enrolment plugins.
@@ -807,7 +822,7 @@ public function test_get_course_enrolment_methods() {
'customint6' => 1,
'password' => 'test'));
$enrolmentmethods = core_enrol_external::get_course_enrolment_methods($course2->id);
- $enrolmentmethods = \external_api::clean_returnvalue(core_enrol_external::get_course_enrolment_methods_returns(),
+ $enrolmentmethods = external_api::clean_returnvalue(core_enrol_external::get_course_enrolment_methods_returns(),
$enrolmentmethods);
$this->assertCount(1, $enrolmentmethods);
@@ -865,7 +880,7 @@ public function test_get_enrolled_users_without_parameters() {
$enrolledusers = core_enrol_external::get_enrolled_users($data->course->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
// Check the result set.
$this->assertEquals(3, count($enrolledusers));
@@ -887,7 +902,7 @@ public function test_get_enrolled_users_with_parameters() {
));
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
// Check the result set, we should only get the 3rd result, which is $user3.
$this->assertCount(1, $enrolledusers);
@@ -908,7 +923,7 @@ public function test_get_enrolled_users_including_lastcourseaccess() {
// Call the external function.
$enrolledusers = core_enrol_external::get_enrolled_users($data->course->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
// Check the result set.
$this->assertEquals(3, count($enrolledusers));
@@ -927,7 +942,7 @@ public function test_get_enrolled_users_including_lastcourseaccess() {
$DB->insert_record('user_lastaccess', $lastaccess);
$enrolledusers = core_enrol_external::get_enrolled_users($data->course->id);
- $enrolledusers = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_returns(), $enrolledusers);
// Check the result set.
$this->assertEquals(3, count($enrolledusers));
@@ -1009,7 +1024,7 @@ public function test_get_enrolled_users_with_capability_without_parameters() {
);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
+ $result = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
// Check an array containing the expected user for the course capability is returned.
$expecteduserlist = $result[0];
@@ -1042,7 +1057,7 @@ public function test_get_enrolled_users_with_capability_with_parameters () {
);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
+ $result = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
// Check an array containing the expected user for the course capability is returned.
$expecteduserlist = $result[0]['users'];
@@ -1070,7 +1085,7 @@ public function test_get_enrolled_users_with_capability_including_lastcourseacce
$result = core_enrol_external::get_enrolled_users_with_capability($parameters, array());
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
+ $result = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
// Check an array containing the expected user for the course capability is returned.
$expecteduserlist = $result[0];
@@ -1092,7 +1107,7 @@ public function test_get_enrolled_users_with_capability_including_lastcourseacce
$result = core_enrol_external::get_enrolled_users_with_capability($parameters, array());
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
+ $result = external_api::clean_returnvalue(core_enrol_external::get_enrolled_users_with_capability_returns(), $result);
// Check the result set.
$expecteduserlist = $result[0];
@@ -1234,7 +1249,7 @@ public function test_submit_user_enrolment_form($customdata, $expectedresult, $v
$querystring = http_build_query($formdata, '', '&');
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
core_enrol_external::submit_user_enrolment_form_returns(),
core_enrol_external::submit_user_enrolment_form($querystring)
);
@@ -1299,13 +1314,13 @@ public function test_unenerol_user_enrolment() {
// Invalid data by passing invalid ueid.
$data = core_enrol_external::unenrol_user_enrolment(101010);
- $data = \external_api::clean_returnvalue(core_enrol_external::unenrol_user_enrolment_returns(), $data);
+ $data = external_api::clean_returnvalue(core_enrol_external::unenrol_user_enrolment_returns(), $data);
$this->assertFalse($data['result']);
$this->assertNotEmpty($data['errors']);
// Valid data.
$data = core_enrol_external::unenrol_user_enrolment($ueid);
- $data = \external_api::clean_returnvalue(core_enrol_external::unenrol_user_enrolment_returns(), $data);
+ $data = external_api::clean_returnvalue(core_enrol_external::unenrol_user_enrolment_returns(), $data);
$this->assertTrue($data['result']);
$this->assertEmpty($data['errors']);
diff --git a/files/classes/external/delete/draft.php b/files/classes/external/delete/draft.php
index 3ad88a8b2e87d..3f77b3e5ef8bd 100644
--- a/files/classes/external/delete/draft.php
+++ b/files/classes/external/delete/draft.php
@@ -28,15 +28,14 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/filelib.php');
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_user;
/**
diff --git a/files/classes/external/get/unused_draft.php b/files/classes/external/get/unused_draft.php
index 9bb952286babf..6344af205556a 100644
--- a/files/classes/external/get/unused_draft.php
+++ b/files/classes/external/get/unused_draft.php
@@ -28,15 +28,13 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/filelib.php');
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_user;
/**
diff --git a/files/externallib.php b/files/externallib.php
index 6f3748cd8d75a..f1b174bfef05f 100644
--- a/files/externallib.php
+++ b/files/externallib.php
@@ -24,10 +24,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
-require_once("$CFG->libdir/filelib.php");
+require_once("{$CFG->libdir}/filelib.php");
/**
* Files external functions
@@ -47,20 +52,22 @@ class core_files_external extends external_api {
* @since Moodle 2.2
*/
public static function get_files_parameters() {
- return new external_function_parameters(
- array(
- 'contextid' => new external_value(PARAM_INT, 'context id Set to -1 to use contextlevel and instanceid.'),
- 'component' => new external_value(PARAM_TEXT, 'component'),
- 'filearea' => new external_value(PARAM_TEXT, 'file area'),
- 'itemid' => new external_value(PARAM_INT, 'associated id'),
- 'filepath' => new external_value(PARAM_PATH, 'file path'),
- 'filename' => new external_value(PARAM_TEXT, 'file name'),
- 'modified' => new external_value(PARAM_INT, 'timestamp to return files changed after this time.', VALUE_DEFAULT, null),
- 'contextlevel' => new external_value(PARAM_ALPHA, 'The context level for the file location.', VALUE_DEFAULT, null),
- 'instanceid' => new external_value(PARAM_INT, 'The instance id for where the file is located.', VALUE_DEFAULT, null)
-
- )
- );
+ return new external_function_parameters([
+ 'contextid' => new external_value(PARAM_INT, 'context id Set to -1 to use contextlevel and instanceid.'),
+ 'component' => new external_value(PARAM_TEXT, 'component'),
+ 'filearea' => new external_value(PARAM_TEXT, 'file area'),
+ 'itemid' => new external_value(PARAM_INT, 'associated id'),
+ 'filepath' => new external_value(PARAM_PATH, 'file path'),
+ 'filename' => new external_value(PARAM_TEXT, 'file name'),
+ 'modified' => new external_value(
+ PARAM_INT,
+ 'timestamp to return files changed after this time.',
+ VALUE_DEFAULT,
+ null
+ ),
+ 'contextlevel' => new external_value(PARAM_ALPHA, 'The context level for the file location.', VALUE_DEFAULT, null),
+ 'instanceid' => new external_value(PARAM_INT, 'The instance id for where the file is located.', VALUE_DEFAULT, null),
+ ]);
}
/**
@@ -82,7 +89,7 @@ public static function get_files_parameters() {
public static function get_files($contextid, $component, $filearea, $itemid, $filepath, $filename, $modified = null,
$contextlevel = null, $instanceid = null) {
- $parameters = array(
+ $parameters = [
'contextid' => $contextid,
'component' => $component,
'filearea' => $filearea,
@@ -91,7 +98,8 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
'filename' => $filename,
'modified' => $modified,
'contextlevel' => $contextlevel,
- 'instanceid' => $instanceid);
+ 'instanceid' => $instanceid,
+ ];
$fileinfo = self::validate_parameters(self::get_files_parameters(), $parameters);
$browser = get_file_browser();
@@ -146,7 +154,7 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
if ($child->is_directory()) {
if ((is_null($modified)) or ($modified < $timemodified)) {
- $node = array(
+ $node = [
'contextid' => $params['contextid'],
'component' => $params['component'],
'filearea' => $params['filearea'],
@@ -159,13 +167,13 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
'timecreated' => $timecreated,
'filesize' => 0,
'author' => null,
- 'license' => null
- );
- $list[] = $node;
+ 'license' => null,
+ ];
+ $list[] = $node;
}
} else {
if ((is_null($modified)) or ($modified < $timemodified)) {
- $node = array(
+ $node = [
'contextid' => $params['contextid'],
'component' => $params['component'],
'filearea' => $params['filearea'],
@@ -178,9 +186,9 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
'timecreated' => $timecreated,
'filesize' => $child->get_filesize(),
'author' => $child->get_author(),
- 'license' => $child->get_license()
- );
- $list[] = $node;
+ 'license' => $child->get_license(),
+ ];
+ $list[] = $node;
}
}
}
@@ -197,41 +205,35 @@ public static function get_files($contextid, $component, $filearea, $itemid, $fi
* @since Moodle 2.2
*/
public static function get_files_returns() {
- return new external_single_structure(
- array(
- 'parents' => new external_multiple_structure(
- new external_single_structure(
- array(
- 'contextid' => new external_value(PARAM_INT, ''),
- 'component' => new external_value(PARAM_COMPONENT, ''),
- 'filearea' => new external_value(PARAM_AREA, ''),
- 'itemid' => new external_value(PARAM_INT, ''),
- 'filepath' => new external_value(PARAM_TEXT, ''),
- 'filename' => new external_value(PARAM_TEXT, ''),
- )
- )
- ),
- 'files' => new external_multiple_structure(
- new external_single_structure(
- array(
- 'contextid' => new external_value(PARAM_INT, ''),
- 'component' => new external_value(PARAM_COMPONENT, ''),
- 'filearea' => new external_value(PARAM_AREA, ''),
- 'itemid' => new external_value(PARAM_INT, ''),
- 'filepath' => new external_value(PARAM_TEXT, ''),
- 'filename' => new external_value(PARAM_TEXT, ''),
- 'isdir' => new external_value(PARAM_BOOL, ''),
- 'url' => new external_value(PARAM_TEXT, ''),
- 'timemodified' => new external_value(PARAM_INT, ''),
- 'timecreated' => new external_value(PARAM_INT, 'Time created', VALUE_OPTIONAL),
- 'filesize' => new external_value(PARAM_INT, 'File size', VALUE_OPTIONAL),
- 'author' => new external_value(PARAM_TEXT, 'File owner', VALUE_OPTIONAL),
- 'license' => new external_value(PARAM_TEXT, 'File license', VALUE_OPTIONAL),
- )
- )
- )
- )
- );
+ return new external_single_structure([
+ 'parents' => new external_multiple_structure(
+ new external_single_structure([
+ 'contextid' => new external_value(PARAM_INT, ''),
+ 'component' => new external_value(PARAM_COMPONENT, ''),
+ 'filearea' => new external_value(PARAM_AREA, ''),
+ 'itemid' => new external_value(PARAM_INT, ''),
+ 'filepath' => new external_value(PARAM_TEXT, ''),
+ 'filename' => new external_value(PARAM_TEXT, ''),
+ ])
+ ),
+ 'files' => new external_multiple_structure(
+ new external_single_structure([
+ 'contextid' => new external_value(PARAM_INT, ''),
+ 'component' => new external_value(PARAM_COMPONENT, ''),
+ 'filearea' => new external_value(PARAM_AREA, ''),
+ 'itemid' => new external_value(PARAM_INT, ''),
+ 'filepath' => new external_value(PARAM_TEXT, ''),
+ 'filename' => new external_value(PARAM_TEXT, ''),
+ 'isdir' => new external_value(PARAM_BOOL, ''),
+ 'url' => new external_value(PARAM_TEXT, ''),
+ 'timemodified' => new external_value(PARAM_INT, ''),
+ 'timecreated' => new external_value(PARAM_INT, 'Time created', VALUE_OPTIONAL),
+ 'filesize' => new external_value(PARAM_INT, 'File size', VALUE_OPTIONAL),
+ 'author' => new external_value(PARAM_TEXT, 'File owner', VALUE_OPTIONAL),
+ 'license' => new external_value(PARAM_TEXT, 'File license', VALUE_OPTIONAL),
+ ])
+ ),
+ ]);
}
/**
@@ -241,21 +243,24 @@ public static function get_files_returns() {
* @since Moodle 2.2
*/
public static function upload_parameters() {
- return new external_function_parameters(
- array(
- 'contextid' => new external_value(PARAM_INT, 'context id', VALUE_DEFAULT, null),
- 'component' => new external_value(PARAM_COMPONENT, 'component'),
- 'filearea' => new external_value(PARAM_AREA, 'file area'),
- 'itemid' => new external_value(PARAM_INT, 'associated id'),
- 'filepath' => new external_value(PARAM_PATH, 'file path'),
- 'filename' => new external_value(PARAM_FILE, 'file name'),
- 'filecontent' => new external_value(PARAM_TEXT, 'file content'),
- 'contextlevel' => new external_value(PARAM_ALPHA, 'The context level to put the file in,
- (block, course, coursecat, system, user, module)', VALUE_DEFAULT, null),
- 'instanceid' => new external_value(PARAM_INT, 'The Instance id of item associated
- with the context level', VALUE_DEFAULT, null)
- )
- );
+ return new external_function_parameters([
+ 'contextid' => new external_value(PARAM_INT, 'context id', VALUE_DEFAULT, null),
+ 'component' => new external_value(PARAM_COMPONENT, 'component'),
+ 'filearea' => new external_value(PARAM_AREA, 'file area'),
+ 'itemid' => new external_value(PARAM_INT, 'associated id'),
+ 'filepath' => new external_value(PARAM_PATH, 'file path'),
+ 'filename' => new external_value(PARAM_FILE, 'file name'),
+ 'filecontent' => new external_value(PARAM_TEXT, 'file content'),
+ 'contextlevel' => new external_value(
+ PARAM_ALPHA,
+ 'The context level to put the file in,
+ (block, course, coursecat, system, user, module)',
+ VALUE_DEFAULT,
+ null
+ ),
+ 'instanceid' => new external_value(PARAM_INT, 'The Instance id of item associated
+ with the context level', VALUE_DEFAULT, null),
+ ]);
}
/**
@@ -273,13 +278,24 @@ public static function upload_parameters() {
* @return array
* @since Moodle 2.2
*/
- public static function upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent, $contextlevel, $instanceid) {
+ public static function upload(
+ $contextid,
+ $component,
+ $filearea,
+ $itemid,
+ $filepath,
+ $filename,
+ $filecontent,
+ $contextlevel,
+ $instanceid
+ ) {
global $USER, $CFG;
- $fileinfo = self::validate_parameters(self::upload_parameters(), array(
- 'contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid,
- 'filepath' => $filepath, 'filename' => $filename, 'filecontent' => $filecontent, 'contextlevel' => $contextlevel,
- 'instanceid' => $instanceid));
+ $fileinfo = self::validate_parameters(self::upload_parameters(), [
+ 'contextid' => $contextid, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid,
+ 'filepath' => $filepath, 'filename' => $filename, 'filecontent' => $filecontent, 'contextlevel' => $contextlevel,
+ 'instanceid' => $instanceid,
+ ]);
if (!isset($fileinfo['filecontent'])) {
throw new moodle_exception('nofile');
@@ -309,7 +325,7 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
$filepath = '/';
}
- // Only allow uploads to draft area
+ // Only allow uploads to draft area.
if (!($fileinfo['component'] == 'user' and $fileinfo['filearea'] == 'draft')) {
throw new coding_exception('File can be uploaded to user draft area only');
} else {
@@ -353,15 +369,15 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
$info = $dir->create_file_from_pathname($filename, $savedfilepath);
$params = $info->get_params();
unlink($savedfilepath);
- return array(
- 'contextid'=>$params['contextid'],
- 'component'=>$params['component'],
- 'filearea'=>$params['filearea'],
- 'itemid'=>$params['itemid'],
- 'filepath'=>$params['filepath'],
- 'filename'=>$params['filename'],
- 'url'=>$info->get_url()
- );
+ return [
+ 'contextid' => $params['contextid'],
+ 'component' => $params['component'],
+ 'filearea' => $params['filearea'],
+ 'itemid' => $params['itemid'],
+ 'filepath' => $params['filepath'],
+ 'filename' => $params['filename'],
+ 'url' => $info->get_url(),
+ ];
} else {
throw new moodle_exception('nofile');
}
@@ -374,16 +390,14 @@ public static function upload($contextid, $component, $filearea, $itemid, $filep
* @since Moodle 2.2
*/
public static function upload_returns() {
- return new external_single_structure(
- array(
- 'contextid' => new external_value(PARAM_INT, ''),
- 'component' => new external_value(PARAM_COMPONENT, ''),
- 'filearea' => new external_value(PARAM_AREA, ''),
- 'itemid' => new external_value(PARAM_INT, ''),
- 'filepath' => new external_value(PARAM_TEXT, ''),
- 'filename' => new external_value(PARAM_FILE, ''),
- 'url' => new external_value(PARAM_TEXT, ''),
- )
- );
+ return new external_single_structure([
+ 'contextid' => new external_value(PARAM_INT, ''),
+ 'component' => new external_value(PARAM_COMPONENT, ''),
+ 'filearea' => new external_value(PARAM_AREA, ''),
+ 'itemid' => new external_value(PARAM_INT, ''),
+ 'filepath' => new external_value(PARAM_TEXT, ''),
+ 'filename' => new external_value(PARAM_FILE, ''),
+ 'url' => new external_value(PARAM_TEXT, ''),
+ ]);
}
}
diff --git a/files/tests/externallib_test.php b/files/tests/externallib_test.php
index 9b1c7928056a9..d513ecff899c9 100644
--- a/files/tests/externallib_test.php
+++ b/files/tests/externallib_test.php
@@ -16,9 +16,10 @@
namespace core_files;
-use core_files_external;
+use core_external\external_api;
use core_files\external\delete\draft;
use core_files\external\get\unused_draft;
+use core_files_external;
defined('MOODLE_INTERNAL') || die();
@@ -66,7 +67,7 @@ public function test_upload() {
// Call the api to create a file.
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,
$filename, $filecontent, $contextlevel, $instanceid);
- $fileinfo = \external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
+ $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
// Get the created draft item id.
$itemid = $fileinfo['itemid'];
@@ -82,7 +83,7 @@ public function test_upload() {
// Call the api to create a file.
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid,
$filepath, $filename, $filecontent, $contextlevel, $instanceid);
- $fileinfo = \external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
+ $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
$file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
$this->assertNotEmpty($file);
@@ -95,7 +96,7 @@ public function test_upload() {
$this->assertEmpty($file);
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,
$filename, $filecontent, $contextlevel, $instanceid);
- $fileinfo = \external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
+ $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
$file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
$this->assertNotEmpty($file);
@@ -152,7 +153,7 @@ public function test_upload_param_area() {
// Make sure the file is created.
$fileinfo = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath, $filename, $filecontent,
'user', $USER->id);
- $fileinfo = \external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
+ $fileinfo = external_api::clean_returnvalue(core_files_external::upload_returns(), $fileinfo);
$browser = get_file_browser();
$file = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename);
$this->assertNotEmpty($file);
@@ -233,7 +234,7 @@ public function test_get_files() {
// The first time is with a valid context ID.
$filename = '';
$testfilelisting = core_files_external::get_files($context->id, $component, $filearea, $itemid, '/', $filename);
- $testfilelisting = \external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting);
+ $testfilelisting = external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting);
// With the information that we have provided we should get an object exactly like the one below.
$coursecontext = \context_course::instance($course->id);
@@ -294,7 +295,7 @@ public function test_get_files() {
$contextlevel = 'module';
$instanceid = $module->cmid;
$testfilelisting = core_files_external::get_files($nocontext, $component, $filearea, $itemid, '/', $filename, $modified, $contextlevel, $instanceid);
- $testfilelisting = \external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting);
+ $testfilelisting = external_api::clean_returnvalue(core_files_external::get_files_returns(), $testfilelisting);
$this->assertEquals($testfilelisting, $testdata);
}
@@ -330,12 +331,12 @@ public function test_delete_draft_files() {
// Check two files were created (one file and one directory).
$files = core_files_external::get_files($context->id, 'user', 'draft', $draftitemid, '/', '');
- $files = \external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
+ $files = external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
$this->assertCount(2, $files['files']);
// Check the folder has one file.
$files = core_files_external::get_files($context->id, 'user', 'draft', $draftitemid, '/fakefolder/', '');
- $files = \external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
+ $files = external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
$this->assertCount(1, $files['files']);
// Delete a file and a folder.
@@ -344,11 +345,11 @@ public function test_delete_draft_files() {
['filepath' => '/fakefolder/', 'filename' => ''],
];
$paths = draft::execute($draftitemid, $filestodelete);
- $paths = \external_api::clean_returnvalue(draft::execute_returns(), $paths);
+ $paths = external_api::clean_returnvalue(draft::execute_returns(), $paths);
// Check everything was deleted.
$files = core_files_external::get_files($context->id, 'user', 'draft', $draftitemid, '/', '');
- $files = \external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
+ $files = external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
$this->assertCount(0, $files['files']);
}
@@ -363,7 +364,7 @@ public function test_get_unused_draft_itemid() {
// Add files to user draft area.
$result = unused_draft::execute();
- $result = \external_api::clean_returnvalue(unused_draft::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(unused_draft::execute_returns(), $result);
$filerecordinline = [
'contextid' => $result['contextid'],
@@ -385,7 +386,7 @@ public function test_get_unused_draft_itemid() {
$context = \context_user::instance($USER->id);
// Check two files were created (one file and one directory).
$files = core_files_external::get_files($context->id, 'user', 'draft', $result['itemid'], '/', '');
- $files = \external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
+ $files = external_api::clean_returnvalue(core_files_external::get_files_returns(), $files);
$this->assertCount(2, $files['files']);
}
}
diff --git a/filter/classes/external.php b/filter/classes/external.php
index 07911a9ec5558..65fadc5570fe5 100644
--- a/filter/classes/external.php
+++ b/filter/classes/external.php
@@ -25,15 +25,14 @@
namespace core_filters;
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/filterlib.php');
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use Exception;
/**
diff --git a/filter/tests/external/external_test.php b/filter/tests/external/external_test.php
index 5f33d892b9f13..6ce13059e39b2 100644
--- a/filter/tests/external/external_test.php
+++ b/filter/tests/external/external_test.php
@@ -26,8 +26,9 @@
namespace core_filters\external;
-use externallib_advanced_testcase;
+use core_external\external_api;
use core_filters\external;
+use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -77,7 +78,7 @@ public function test_get_available_in_context_category() {
}
$result = external::get_available_in_context(array(array('contextlevel' => 'coursecat', 'instanceid' => $category->id)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['filters']); // No filters, all disabled.
$this->assertEmpty($result['warnings']);
@@ -87,7 +88,7 @@ public function test_get_available_in_context_category() {
filter_set_global_state($firstfilter, TEXTFILTER_ON);
$result = external::get_available_in_context(array(array('contextlevel' => 'coursecat', 'instanceid' => $category->id)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled.
$this->assertEquals(TEXTFILTER_INHERIT, $result['filters'][0]['localstate']); // Inherits the parent context status.
@@ -96,7 +97,7 @@ public function test_get_available_in_context_category() {
// Set off the same filter at local context level.
filter_set_local_state($firstfilter, \context_coursecat::instance($category->id)->id, TEXTFILTER_OFF);
$result = external::get_available_in_context(array(array('contextlevel' => 'coursecat', 'instanceid' => $category->id)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled globally.
$this->assertEquals(TEXTFILTER_OFF, $result['filters'][0]['localstate']); // It is not available in this context.
@@ -121,7 +122,7 @@ public function test_get_available_in_context_course() {
}
$result = external::get_available_in_context(array(array('contextlevel' => 'course', 'instanceid' => $course->id)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['filters']); // No filters, all disabled at global level.
$this->assertEmpty($result['warnings']);
@@ -131,7 +132,7 @@ public function test_get_available_in_context_course() {
filter_set_global_state($firstfilter, TEXTFILTER_ON);
$result = external::get_available_in_context(array(array('contextlevel' => 'course', 'instanceid' => $course->id)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled.
$this->assertEquals(TEXTFILTER_INHERIT, $result['filters'][0]['localstate']); // Inherits the parent context status.
@@ -140,7 +141,7 @@ public function test_get_available_in_context_course() {
// Set off the same filter at local context level.
filter_set_local_state($firstfilter, \context_course::instance($course->id)->id, TEXTFILTER_OFF);
$result = external::get_available_in_context(array(array('contextlevel' => 'course', 'instanceid' => $course->id)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled globally.
$this->assertEquals(TEXTFILTER_OFF, $result['filters'][0]['localstate']); // It is not available in this context.
@@ -167,7 +168,7 @@ public function test_get_available_in_context_module() {
}
$result = external::get_available_in_context(array(array('contextlevel' => 'module', 'instanceid' => $forum->cmid)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['filters']); // No filters, all disabled at global level.
$this->assertEmpty($result['warnings']);
@@ -177,7 +178,7 @@ public function test_get_available_in_context_module() {
filter_set_global_state($firstfilter, TEXTFILTER_ON);
$result = external::get_available_in_context(array(array('contextlevel' => 'module', 'instanceid' => $forum->cmid)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled.
$this->assertEquals(TEXTFILTER_INHERIT, $result['filters'][0]['localstate']); // Inherits the parent context status.
@@ -186,7 +187,7 @@ public function test_get_available_in_context_module() {
// Set off the same filter at local context level.
filter_set_local_state($firstfilter, \context_module::instance($forum->cmid)->id, TEXTFILTER_OFF);
$result = external::get_available_in_context(array(array('contextlevel' => 'module', 'instanceid' => $forum->cmid)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertEquals($firstfilter, $result['filters'][0]['filter']); // OK, the filter is enabled globally.
$this->assertEquals(TEXTFILTER_OFF, $result['filters'][0]['localstate']); // It is not available in this context.
@@ -196,7 +197,7 @@ public function test_get_available_in_context_module() {
$user = $this->getDataGenerator()->create_user();
$this->setUser($user);
$result = external::get_available_in_context(array(array('contextlevel' => 'module', 'instanceid' => $forum->cmid)));
- $result = \external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
+ $result = external_api::clean_returnvalue(external::get_available_in_context_returns(), $result);
$this->assertNotEmpty($result['warnings']);
$this->assertEquals('context', $result['warnings'][0]['item']);
$this->assertEquals($forum->cmid, $result['warnings'][0]['itemid']);
diff --git a/grade/classes/external/create_gradecategories.php b/grade/classes/external/create_gradecategories.php
index 924bf4d9eca7a..6c25cc3825229 100644
--- a/grade/classes/external/create_gradecategories.php
+++ b/grade/classes/external/create_gradecategories.php
@@ -16,16 +16,15 @@
namespace core_grades\external;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->libdir/gradelib.php");
require_once("$CFG->dirroot/grade/edit/tree/lib.php");
diff --git a/grade/classes/external/get_enrolled_users_for_search_widget.php b/grade/classes/external/get_enrolled_users_for_search_widget.php
index 91e16f6de88fa..e343793f0e1da 100644
--- a/grade/classes/external/get_enrolled_users_for_search_widget.php
+++ b/grade/classes/external/get_enrolled_users_for_search_widget.php
@@ -16,11 +16,14 @@
namespace core_grades\external;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\restricted_context_exception;
use moodle_url;
use core_user;
@@ -125,16 +128,16 @@ public static function execute(int $courseid, string $actionbaseurl, ?int $group
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'users' => new external_multiple_structure(self::user_description()),
- 'warnings' => new \external_warnings(),
+ 'warnings' => new external_warnings(),
]);
}
/**
* Create user return value description.
*
- * @return \external_description
+ * @return external_description
*/
- public static function user_description(): \external_description {
+ public static function user_description(): external_description {
$userfields = [
'id' => new external_value(core_user::get_property_type('id'), 'ID of the user'),
'profileimage' => new external_value(
diff --git a/grade/classes/external/get_groups_for_search_widget.php b/grade/classes/external/get_groups_for_search_widget.php
index 7ca8230ec63cf..201bc30b562c5 100644
--- a/grade/classes/external/get_groups_for_search_widget.php
+++ b/grade/classes/external/get_groups_for_search_widget.php
@@ -16,22 +16,14 @@
namespace core_grades\external;
-use coding_exception;
use context_course;
-use external_api;
-use external_description;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
-use invalid_parameter_exception;
-use moodle_exception;
-use restricted_context_exception;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once($CFG->libdir.'/externallib.php');
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* External group report API implementation
diff --git a/grade/classes/grades/grader/gradingpanel/point/external/fetch.php b/grade/classes/grades/grader/gradingpanel/point/external/fetch.php
index 4e92b04c9b90a..6571987e2881c 100644
--- a/grade/classes/grades/grader/gradingpanel/point/external/fetch.php
+++ b/grade/classes/grades/grader/gradingpanel/point/external/fetch.php
@@ -28,17 +28,14 @@
use coding_exception;
use context;
-use core_user;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
-use required_capability_exception;
use stdClass;
/**
diff --git a/grade/classes/grades/grader/gradingpanel/point/external/store.php b/grade/classes/grades/grader/gradingpanel/point/external/store.php
index e419832a7ddf2..ed9a15e41da7d 100644
--- a/grade/classes/grades/grader/gradingpanel/point/external/store.php
+++ b/grade/classes/grades/grader/gradingpanel/point/external/store.php
@@ -28,17 +28,13 @@
use coding_exception;
use context;
-use core_user;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use moodle_exception;
-use required_capability_exception;
/**
* External grading panel point API
diff --git a/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php b/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php
index 87f4c0465b68f..43673ba003382 100644
--- a/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php
+++ b/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php
@@ -30,15 +30,13 @@
use context;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use core_user;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
-use required_capability_exception;
use stdClass;
/**
diff --git a/grade/classes/grades/grader/gradingpanel/scale/external/store.php b/grade/classes/grades/grader/gradingpanel/scale/external/store.php
index 751017b10be03..f6349e48b9472 100644
--- a/grade/classes/grades/grader/gradingpanel/scale/external/store.php
+++ b/grade/classes/grades/grader/gradingpanel/scale/external/store.php
@@ -28,17 +28,13 @@
use coding_exception;
use context;
-use core_user;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use moodle_exception;
-use required_capability_exception;
/**
* External grading panel scale API
diff --git a/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php b/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php
index c07cb5c0c604a..17d03ac35c4d1 100644
--- a/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php
+++ b/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php
@@ -33,13 +33,12 @@
use core_user;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use external_api;
-use external_format_value;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
use stdClass;
require_once($CFG->dirroot.'/grade/grading/form/guide/lib.php');
@@ -307,7 +306,15 @@ protected static function get_formatted_text(context $context, int $definitionid
'filter' => true,
];
- [$newtext, ] = external_format_text($text, $format, $context, 'grading', $filearea, $definitionid, $formatoptions);
+ [$newtext] = \core_external\util::format_text(
+ $text,
+ $format,
+ $context,
+ 'grading',
+ $filearea,
+ $definitionid,
+ $formatoptions
+ );
return $newtext;
}
diff --git a/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/store.php b/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/store.php
index 589d9c35109c5..69ff2439855ae 100644
--- a/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/store.php
+++ b/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/store.php
@@ -33,10 +33,10 @@
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
use core_user;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use moodle_exception;
require_once($CFG->dirroot.'/grade/grading/form/guide/lib.php');
diff --git a/grade/grading/form/guide/lib.php b/grade/grading/form/guide/lib.php
index 17e4ac9ce6ede..af90ae4324779 100644
--- a/grade/grading/form/guide/lib.php
+++ b/grade/grading/form/guide/lib.php
@@ -22,6 +22,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_format_value;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/grade/grading/form/lib.php');
diff --git a/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/fetch_test.php b/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/fetch_test.php
index cb86d137668a7..8a7c505d4081e 100644
--- a/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/fetch_test.php
+++ b/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/fetch_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
@@ -34,12 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class fetch_test extends advanced_testcase {
-
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/store_test.php b/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/store_test.php
index 5d64994160833..54b84a2fb55c4 100644
--- a/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/store_test.php
+++ b/grade/grading/form/guide/tests/grades/grader/gradingpanel/external/store_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
@@ -34,12 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class store_test extends advanced_testcase {
-
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php b/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php
index e5081d75864bf..9e231d9afc388 100644
--- a/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php
+++ b/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php
@@ -32,12 +32,12 @@
use context;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use stdClass;
use moodle_exception;
require_once($CFG->dirroot.'/grade/grading/form/rubric/lib.php');
@@ -316,7 +316,15 @@ protected static function get_formatted_text(context $context, int $definitionid
'trusted' => false,
'filter' => true,
];
- [$newtext, ] = external_format_text($text, $format, $context, 'grading', $filearea, $definitionid, $formatoptions);
+ [$newtext] = \core_external\util::format_text(
+ $text,
+ $format,
+ $context,
+ 'grading',
+ $filearea,
+ $definitionid,
+ $formatoptions
+ );
return $newtext;
}
}
diff --git a/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/store.php b/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/store.php
index 6174ce29bc20b..62f651d6e392e 100644
--- a/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/store.php
+++ b/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/store.php
@@ -32,10 +32,10 @@
use context;
use core_grades\component_gradeitem as gradeitem;
use core_grades\component_gradeitems;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use moodle_exception;
require_once($CFG->dirroot.'/grade/grading/form/rubric/lib.php');
diff --git a/grade/grading/form/rubric/lib.php b/grade/grading/form/rubric/lib.php
index a578315664252..5833699418057 100644
--- a/grade/grading/form/rubric/lib.php
+++ b/grade/grading/form/rubric/lib.php
@@ -22,6 +22,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_format_value;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/grade/grading/form/lib.php');
diff --git a/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/fetch_test.php b/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/fetch_test.php
index 68402617c405f..9aa29de660743 100644
--- a/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/fetch_test.php
+++ b/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/fetch_test.php
@@ -22,7 +22,7 @@
use coding_exception;
use core_grades\component_gradeitem;
use core_grades\component_gradeitems;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
@@ -35,12 +35,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class fetch_test extends advanced_testcase {
-
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/store_test.php b/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/store_test.php
index f911134b18ed2..aa0c4134c5fcc 100644
--- a/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/store_test.php
+++ b/grade/grading/form/rubric/tests/grades/grader/gradingpanel/external/store_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
@@ -34,12 +34,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class store_test extends advanced_testcase {
-
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/report/overview/classes/external.php b/grade/report/overview/classes/external.php
index f76ea18a6cc1c..7a27b68039565 100644
--- a/grade/report/overview/classes/external.php
+++ b/grade/report/overview/classes/external.php
@@ -22,9 +22,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->dirroot . '/grade/lib.php');
require_once($CFG->dirroot . '/grade/report/overview/lib.php');
@@ -211,7 +217,7 @@ public static function view_grade_report($courseid, $userid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function view_grade_report_returns() {
diff --git a/grade/report/overview/tests/externallib_test.php b/grade/report/overview/tests/externallib_test.php
index 72f5566e7e9eb..52f3bba04709c 100644
--- a/grade/report/overview/tests/externallib_test.php
+++ b/grade/report/overview/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace gradereport_overview;
+use core_external\external_api;
use externallib_advanced_testcase;
use gradereport_overview_external;
@@ -87,7 +88,7 @@ public function test_get_course_grades_student() {
// A user can see his own grades in both courses.
$this->setUser($this->student1);
$studentgrades = gradereport_overview_external::get_course_grades();
- $studentgrades = \external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
$this->assertCount(0, $studentgrades['warnings']);
$this->assertCount(2, $studentgrades['grades']);
@@ -106,7 +107,7 @@ public function test_get_course_grades_student() {
// Second student, no grade in one course.
$this->setUser($this->student2);
$studentgrades = gradereport_overview_external::get_course_grades();
- $studentgrades = \external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
$this->assertCount(0, $studentgrades['warnings']);
$this->assertCount(2, $studentgrades['grades']);
@@ -132,7 +133,7 @@ public function test_get_course_grades_admin() {
$this->setAdminUser();
$studentgrades = gradereport_overview_external::get_course_grades($this->student1->id);
- $studentgrades = \external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
$this->assertCount(0, $studentgrades['warnings']);
$this->assertCount(2, $studentgrades['grades']);
foreach ($studentgrades['grades'] as $grade) {
@@ -146,13 +147,13 @@ public function test_get_course_grades_admin() {
}
$studentgrades = gradereport_overview_external::get_course_grades($this->student2->id);
- $studentgrades = \external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
$this->assertCount(0, $studentgrades['warnings']);
$this->assertCount(2, $studentgrades['grades']);
// Admins don't see grades.
$studentgrades = gradereport_overview_external::get_course_grades();
- $studentgrades = \external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
$this->assertCount(0, $studentgrades['warnings']);
$this->assertCount(0, $studentgrades['grades']);
}
@@ -165,7 +166,7 @@ public function test_get_course_grades_teacher() {
$this->setUser($this->teacher);
$studentgrades = gradereport_overview_external::get_course_grades();
- $studentgrades = \external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(gradereport_overview_external::get_course_grades_returns(), $studentgrades);
$this->assertCount(0, $studentgrades['warnings']);
$this->assertCount(0, $studentgrades['grades']);
}
@@ -192,7 +193,7 @@ public function test_view_grade_report() {
$this->setUser($this->student1);
$result = gradereport_overview_external::view_grade_report($this->course1->id);
- $result = \external_api::clean_returnvalue(gradereport_overview_external::view_grade_report_returns(), $result);
+ $result = external_api::clean_returnvalue(gradereport_overview_external::view_grade_report_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
@@ -204,7 +205,7 @@ public function test_view_grade_report() {
$this->setUser($this->teacher);
$result = gradereport_overview_external::view_grade_report($this->course1->id, $this->student1->id);
- $result = \external_api::clean_returnvalue(gradereport_overview_external::view_grade_report_returns(), $result);
+ $result = external_api::clean_returnvalue(gradereport_overview_external::view_grade_report_returns(), $result);
$events = $sink->get_events();
$event = reset($events);
$sink->close();
diff --git a/grade/report/singleview/classes/external/singleview.php b/grade/report/singleview/classes/external/singleview.php
index 6a1dd25472b0d..8d9189548af30 100644
--- a/grade/report/singleview/classes/external/singleview.php
+++ b/grade/report/singleview/classes/external/singleview.php
@@ -16,18 +16,14 @@
namespace gradereport_singleview\external;
-use coding_exception;
use context_course;
use core_course_external;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
-use invalid_parameter_exception;
-use moodle_exception;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_url;
-use restricted_context_exception;
use grade_tree;
defined('MOODLE_INTERNAL') || die;
diff --git a/grade/report/user/classes/external/user.php b/grade/report/user/classes/external/user.php
index 650a0b18794ca..1a167ae5e62c8 100644
--- a/grade/report/user/classes/external/user.php
+++ b/grade/report/user/classes/external/user.php
@@ -16,25 +16,22 @@
namespace gradereport_user\external;
-use external_api;
use context_course;
use core_user;
-use external_description;
-use external_format_value;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use grade_plugin_return;
use graded_users_iterator;
use moodle_exception;
use stdClass;
use gradereport_user\report\user as user_report;
-defined('MOODLE_INTERNAL') || die;
-
-require_once($CFG->libdir.'/externallib.php');
require_once($CFG->dirroot.'/grade/lib.php');
/**
@@ -475,7 +472,7 @@ public static function get_grade_items(int $courseid, int $userid = 0, int $grou
foreach ($gradeitems as $gradeitem) {
if (isset($gradeitem['feedback']) && isset($gradeitem['feedbackformat'])) {
list($gradeitem['feedback'], $gradeitem['feedbackformat']) =
- external_format_text($gradeitem['feedback'], $gradeitem['feedbackformat'], $context->id);
+ \core_external\util::format_text($gradeitem['feedback'], $gradeitem['feedbackformat'], $context->id);
}
}
diff --git a/grade/report/user/tests/externallib_test.php b/grade/report/user/tests/externallib_test.php
index d574b6d5ea30b..698a43088295e 100644
--- a/grade/report/user/tests/externallib_test.php
+++ b/grade/report/user/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace gradereport_user;
+use core_external\external_api;
use externallib_advanced_testcase;
use gradereport_user\external\user as user_external;
@@ -101,7 +102,7 @@ public function test_get_grades_table_teacher() {
$this->setUser($teacher);
$studentgrades = user_external::get_grades_table($course->id);
- $studentgrades = \external_api::clean_returnvalue(user_external::get_grades_table_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(user_external::get_grades_table_returns(), $studentgrades);
// No warnings returned.
$this->assertCount(0, $studentgrades['warnings']);
@@ -134,7 +135,7 @@ public function test_get_grades_table_student() {
// A user can see his own grades.
$this->setUser($student1);
$studentgrade = user_external::get_grades_table($course->id, $student1->id);
- $studentgrade = \external_api::clean_returnvalue(user_external::get_grades_table_returns(), $studentgrade);
+ $studentgrade = external_api::clean_returnvalue(user_external::get_grades_table_returns(), $studentgrade);
// No warnings returned.
$this->assertTrue(count($studentgrade['warnings']) == 0);
@@ -185,7 +186,7 @@ public function test_view_grade_report() {
$this->setUser($student1);
$result = user_external::view_grade_report($course->id);
- $result = \external_api::clean_returnvalue(user_external::view_grade_report_returns(), $result);
+ $result = external_api::clean_returnvalue(user_external::view_grade_report_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = reset($events);
@@ -197,7 +198,7 @@ public function test_view_grade_report() {
$this->setUser($teacher);
$result = user_external::view_grade_report($course->id, $student1->id);
- $result = \external_api::clean_returnvalue(user_external::view_grade_report_returns(), $result);
+ $result = external_api::clean_returnvalue(user_external::view_grade_report_returns(), $result);
$events = $sink->get_events();
$event = reset($events);
$sink->close();
@@ -242,7 +243,7 @@ public function test_get_grade_items_teacher() {
grade_set_setting($course->id, 'report_user_showaverage', 1);
$studentgrades = user_external::get_grade_items($course->id);
- $studentgrades = \external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
// No warnings returned.
$this->assertCount(0, $studentgrades['warnings']);
@@ -306,7 +307,7 @@ public function test_get_grade_items_teacher() {
$gradegrade->set_locked(1);
$studentgrades = user_external::get_grade_items($course->id);
- $studentgrades = \external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
// No warnings returned.
$this->assertCount(0, $studentgrades['warnings']);
@@ -339,7 +340,7 @@ public function test_get_grade_items_student() {
$this->setUser($student1);
$studentgrades = user_external::get_grade_items($course->id, $student1->id);
- $studentgrades = \external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
// No warnings returned.
$this->assertCount(0, $studentgrades['warnings']);
@@ -387,7 +388,7 @@ public function test_get_grade_items_student() {
], true);
$gradegrade->set_hidden(1);
$studentgrades = user_external::get_grade_items($course->id, $student1->id);
- $studentgrades = \external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
+ $studentgrades = external_api::clean_returnvalue(user_external::get_grade_items_returns(), $studentgrades);
// Check we get only the course final grade.
$this->assertCount(1, $studentgrades['usergrades']);
diff --git a/grade/tests/external/create_gradecategories_test.php b/grade/tests/external/create_gradecategories_test.php
index ef4295ce4e7b9..87c0b3d0342dd 100644
--- a/grade/tests/external/create_gradecategories_test.php
+++ b/grade/tests/external/create_gradecategories_test.php
@@ -17,7 +17,7 @@
namespace core_grades\external;
use core_grades\external\create_gradecategories;
-use external_api;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die;
diff --git a/grade/tests/grades/grader/gradingpanel/point/external/fetch_test.php b/grade/tests/grades/grader/gradingpanel/point/external/fetch_test.php
index 282d04b399ab6..4d59087527c3a 100644
--- a/grade/tests/grades/grader/gradingpanel/point/external/fetch_test.php
+++ b/grade/tests/grades/grader/gradingpanel/point/external/fetch_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
@@ -35,11 +35,6 @@
*/
class fetch_test extends advanced_testcase {
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/tests/grades/grader/gradingpanel/point/external/store_test.php b/grade/tests/grades/grader/gradingpanel/point/external/store_test.php
index 183d2ea8c96f6..3467230cee9ae 100644
--- a/grade/tests/grades/grader/gradingpanel/point/external/store_test.php
+++ b/grade/tests/grades/grader/gradingpanel/point/external/store_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
use grade_grade;
@@ -37,11 +37,6 @@
*/
class store_test extends advanced_testcase {
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/tests/grades/grader/gradingpanel/scale/external/fetch_test.php b/grade/tests/grades/grader/gradingpanel/scale/external/fetch_test.php
index a4bb51a82da2e..3f16d12ab67a7 100644
--- a/grade/tests/grades/grader/gradingpanel/scale/external/fetch_test.php
+++ b/grade/tests/grades/grader/gradingpanel/scale/external/fetch_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
@@ -35,11 +35,6 @@
*/
class fetch_test extends advanced_testcase {
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/grade/tests/grades/grader/gradingpanel/scale/external/store_test.php b/grade/tests/grades/grader/gradingpanel/scale/external/store_test.php
index 96a0d8fc55855..ec9ddfe0dfa48 100644
--- a/grade/tests/grades/grader/gradingpanel/scale/external/store_test.php
+++ b/grade/tests/grades/grader/gradingpanel/scale/external/store_test.php
@@ -21,7 +21,7 @@
use advanced_testcase;
use coding_exception;
use core_grades\component_gradeitem;
-use external_api;
+use core_external\external_api;
use mod_forum\local\entities\forum as forum_entity;
use moodle_exception;
use grade_grade;
@@ -37,11 +37,6 @@
*/
class store_test extends advanced_testcase {
- public static function setupBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Ensure that an execute with an invalid component is rejected.
*/
diff --git a/group/externallib.php b/group/externallib.php
index 341e72750a886..1e25db334a56e 100644
--- a/group/externallib.php
+++ b/group/externallib.php
@@ -14,19 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
-/**
- * External groups API
- *
- * @package core_group
- * @category external
- * @copyright 2009 Petr Skodak
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Group external functions
@@ -104,7 +99,7 @@ public static function create_groups($groups) {
require_capability('moodle/course:managegroups', $context);
// Validate format.
- $group->descriptionformat = external_validate_format($group->descriptionformat);
+ $group->descriptionformat = util::validate_format($group->descriptionformat);
// finally create the group
$group->id = groups_create_group($group, false);
@@ -126,7 +121,7 @@ public static function create_groups($groups) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function create_groups_returns() {
@@ -188,8 +183,8 @@ public static function get_groups($groupids) {
require_capability('moodle/course:managegroups', $context);
list($group->description, $group->descriptionformat) =
- external_format_text($group->description, $group->descriptionformat,
- $context->id, 'group', 'description', $group->id);
+ \core_external\util::format_text($group->description, $group->descriptionformat,
+ $context, 'group', 'description', $group->id);
$groups[] = (array)$group;
}
@@ -200,7 +195,7 @@ public static function get_groups($groupids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function get_groups_returns() {
@@ -261,8 +256,8 @@ public static function get_course_groups($courseid) {
$groups = array();
foreach ($gs as $group) {
list($group->description, $group->descriptionformat) =
- external_format_text($group->description, $group->descriptionformat,
- $context->id, 'group', 'description', $group->id);
+ \core_external\util::format_text($group->description, $group->descriptionformat,
+ $context, 'group', 'description', $group->id);
$groups[] = (array)$group;
}
@@ -272,7 +267,7 @@ public static function get_course_groups($courseid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function get_course_groups_returns() {
@@ -408,7 +403,7 @@ public static function get_group_members($groupids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function get_group_members_returns() {
@@ -638,7 +633,7 @@ public static function create_groupings($groupings) {
}
require_capability('moodle/course:managegroups', $context);
- $grouping->descriptionformat = external_validate_format($grouping->descriptionformat);
+ $grouping->descriptionformat = util::validate_format($grouping->descriptionformat);
// Finally create the grouping.
$grouping->id = groups_create_grouping($grouping);
@@ -653,7 +648,7 @@ public static function create_groupings($groupings) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function create_groupings_returns() {
@@ -742,7 +737,7 @@ public static function update_groupings($groupings) {
require_capability('moodle/course:managegroups', $context);
// We must force allways FORMAT_HTML.
- $grouping->descriptionformat = external_validate_format($grouping->descriptionformat);
+ $grouping->descriptionformat = util::validate_format($grouping->descriptionformat);
// Finally update the grouping.
groups_update_grouping($grouping);
@@ -756,7 +751,7 @@ public static function update_groupings($groupings) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function update_groupings_returns() {
@@ -814,8 +809,8 @@ public static function get_groupings($groupingids, $returngroups = false) {
require_capability('moodle/course:managegroups', $context);
list($grouping->description, $grouping->descriptionformat) =
- external_format_text($grouping->description, $grouping->descriptionformat,
- $context->id, 'grouping', 'description', $grouping->id);
+ \core_external\util::format_text($grouping->description, $grouping->descriptionformat,
+ $context, 'grouping', 'description', $grouping->id);
$groupingarray = (array)$grouping;
@@ -827,8 +822,8 @@ public static function get_groupings($groupingids, $returngroups = false) {
$groups = array();
foreach ($grouprecords as $grouprecord) {
list($grouprecord->description, $grouprecord->descriptionformat) =
- external_format_text($grouprecord->description, $grouprecord->descriptionformat,
- $context->id, 'group', 'description', $grouprecord->groupid);
+ \core_external\util::format_text($grouprecord->description, $grouprecord->descriptionformat,
+ $context, 'group', 'description', $grouprecord->groupid);
$groups[] = array('id' => $grouprecord->groupid,
'name' => $grouprecord->name,
'idnumber' => $grouprecord->idnumber,
@@ -850,7 +845,7 @@ public static function get_groupings($groupingids, $returngroups = false) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function get_groupings_returns() {
@@ -927,8 +922,8 @@ public static function get_course_groupings($courseid) {
$groupings = array();
foreach ($gs as $grouping) {
list($grouping->description, $grouping->descriptionformat) =
- external_format_text($grouping->description, $grouping->descriptionformat,
- $context->id, 'grouping', 'description', $grouping->id);
+ \core_external\util::format_text($grouping->description, $grouping->descriptionformat,
+ $context, 'grouping', 'description', $grouping->id);
$groupings[] = (array)$grouping;
}
@@ -938,7 +933,7 @@ public static function get_course_groupings($courseid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function get_course_groupings_returns() {
@@ -1013,7 +1008,7 @@ public static function delete_groupings($groupingids) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.3
*/
public static function delete_groupings_returns() {
@@ -1234,7 +1229,7 @@ public static function get_course_user_groups($courseid = 0, $userid = 0, $group
}
// Security checks.
- list($courses, $warnings) = external_util::validate_courses(array_keys($courses), $courses, true);
+ list($courses, $warnings) = util::validate_courses(array_keys($courses), $courses, true);
$usergroups = array();
foreach ($courses as $course) {
@@ -1265,8 +1260,8 @@ public static function get_course_user_groups($courseid = 0, $userid = 0, $group
foreach ($groups as $group) {
list($group->description, $group->descriptionformat) =
- external_format_text($group->description, $group->descriptionformat,
- $course->context->id, 'group', 'description', $group->id);
+ \core_external\util::format_text($group->description, $group->descriptionformat,
+ $course->context, 'group', 'description', $group->id);
$group->courseid = $course->id;
$usergroups[] = $group;
}
@@ -1282,7 +1277,7 @@ public static function get_course_user_groups($courseid = 0, $userid = 0, $group
/**
* Returns description of method result value.
*
- * @return external_description A single structure containing groups and possible warnings.
+ * @return \core_external\external_description A single structure containing groups and possible warnings.
* @since Moodle 2.9
*/
public static function get_course_user_groups_returns() {
@@ -1389,8 +1384,8 @@ public static function get_activity_allowed_groups($cmid, $userid = 0) {
foreach ($groups as $group) {
list($group->description, $group->descriptionformat) =
- external_format_text($group->description, $group->descriptionformat,
- $coursecontext->id, 'group', 'description', $group->id);
+ \core_external\util::format_text($group->description, $group->descriptionformat,
+ $coursecontext, 'group', 'description', $group->id);
$group->courseid = $cm->course;
$usergroups[] = $group;
}
@@ -1407,7 +1402,7 @@ public static function get_activity_allowed_groups($cmid, $userid = 0) {
/**
* Returns description of method result value.
*
- * @return external_description A single structure containing groups and possible warnings.
+ * @return \core_external\external_description A single structure containing groups and possible warnings.
* @since Moodle 3.0
*/
public static function get_activity_allowed_groups_returns() {
@@ -1474,7 +1469,7 @@ public static function get_activity_groupmode($cmid) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_activity_groupmode_returns() {
@@ -1559,7 +1554,7 @@ public static function update_groups($groups) {
require_capability('moodle/course:managegroups', $context);
if (!empty($group->description)) {
- $group->descriptionformat = external_validate_format($group->descriptionformat);
+ $group->descriptionformat = util::validate_format($group->descriptionformat);
}
groups_update_group($group);
diff --git a/group/tests/externallib_test.php b/group/tests/externallib_test.php
index 76ae85aaa317e..719db86305035 100644
--- a/group/tests/externallib_test.php
+++ b/group/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace core_group;
+use core_external\external_api;
use core_group_external;
use externallib_advanced_testcase;
@@ -78,7 +79,7 @@ public function test_create_groups() {
$groups = core_group_external::create_groups(array($group1, $group2));
// We need to execute the return values cleaning process to simulate the web service server.
- $groups = \external_api::clean_returnvalue(core_group_external::create_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::create_groups_returns(), $groups);
// Checks against DB values
$this->assertEquals(2, count($groups));
@@ -230,7 +231,7 @@ public function test_get_groups() {
$groups = core_group_external::get_groups(array($group1->id, $group2->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $groups = \external_api::clean_returnvalue(core_group_external::get_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_groups_returns(), $groups);
// Checks against DB values
$this->assertEquals(2, count($groups));
@@ -397,7 +398,7 @@ public function test_get_groupings() {
// Call the external function without specifying the optional parameter.
$groupings = core_group_external::get_groupings(array($grouping->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $groupings = \external_api::clean_returnvalue(core_group_external::get_groupings_returns(), $groupings);
+ $groupings = external_api::clean_returnvalue(core_group_external::get_groupings_returns(), $groupings);
$this->assertEquals(1, count($groupings));
@@ -421,7 +422,7 @@ public function test_get_groupings() {
// Call the external function specifying that groups are returned.
$groupings = core_group_external::get_groupings(array($grouping->id), true);
// We need to execute the return values cleaning process to simulate the web service server.
- $groupings = \external_api::clean_returnvalue(core_group_external::get_groupings_returns(), $groupings);
+ $groupings = external_api::clean_returnvalue(core_group_external::get_groupings_returns(), $groupings);
$this->assertEquals(1, count($groupings));
$this->assertEquals(2, count($groupings[0]['groups']));
foreach ($groupings[0]['groups'] as $group) {
@@ -563,7 +564,7 @@ public function test_get_course_user_groups() {
$this->setUser($student1);
$groups = core_group_external::get_course_user_groups($course->id, $student1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that I see my groups.
$this->assertCount(2, $groups['groups']);
$this->assertEquals($course->id, $groups['groups'][0]['courseid']);
@@ -571,7 +572,7 @@ public function test_get_course_user_groups() {
// Check that I only see my groups inside the given grouping.
$groups = core_group_external::get_course_user_groups($course->id, $student1->id, $grouping->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that I see my groups in the grouping.
$this->assertCount(1, $groups['groups']);
$this->assertEquals($group1->id, $groups['groups'][0]['id']);
@@ -579,13 +580,13 @@ public function test_get_course_user_groups() {
// Check optional parameters (all student 1 courses and current user).
$groups = core_group_external::get_course_user_groups();
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that I see my groups in all my courses.
$this->assertCount(3, $groups['groups']);
$this->setUser($student2);
$groups = core_group_external::get_course_user_groups($course->id, $student2->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that I see my groups.
$this->assertCount(1, $groups['groups']);
@@ -595,17 +596,17 @@ public function test_get_course_user_groups() {
$this->setUser($teacher);
$groups = core_group_external::get_course_user_groups($course->id, $student1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that a teacher can see student groups in given course.
$this->assertCount(2, $groups['groups']);
$groups = core_group_external::get_course_user_groups($course->id, $student2->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that a teacher can see student groups in given course.
$this->assertCount(1, $groups['groups']);
$groups = core_group_external::get_course_user_groups(0, $student1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that a teacher can see student groups in all the user courses if the teacher is enrolled in the course.
$this->assertCount(2, $groups['groups']); // Teacher only see groups in first course.
$this->assertCount(1, $groups['warnings']); // Enrolment warnings.
@@ -614,7 +615,7 @@ public function test_get_course_user_groups() {
// Enrol teacher in second course.
$this->getDataGenerator()->enrol_user($teacher->id, $anothercourse->id, $teacherrole->id);
$groups = core_group_external::get_course_user_groups(0, $student1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
// Check that a teacher can see student groups in all the user courses if the teacher is enrolled in the course.
$this->assertCount(3, $groups['groups']);
@@ -623,20 +624,20 @@ public function test_get_course_user_groups() {
// Student can's see other students group.
$groups = core_group_external::get_course_user_groups($course->id, $student2->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
$this->assertCount(1, $groups['warnings']);
$this->assertEquals('cannotmanagegroups', $groups['warnings'][0]['warningcode']);
// Not enrolled course.
$groups = core_group_external::get_course_user_groups($emptycourse->id, $student2->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
$this->assertCount(1, $groups['warnings']);
$this->assertEquals('1', $groups['warnings'][0]['warningcode']);
$this->setUser($teacher);
// Check user checking not enrolled in given course.
$groups = core_group_external::get_course_user_groups($emptycourse->id, $student1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_course_user_groups_returns(), $groups);
$this->assertCount(1, $groups['warnings']);
$this->assertEquals('notenrolled', $groups['warnings'][0]['warningcode']);
}
@@ -705,7 +706,7 @@ public function test_get_activity_allowed_groups() {
// Retrieve my groups.
$groups = core_group_external::get_activity_allowed_groups($cm1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
$this->assertCount(2, $groups['groups']);
$this->assertFalse($groups['canaccessallgroups']);
@@ -722,20 +723,20 @@ public function test_get_activity_allowed_groups() {
$this->setUser($teacher);
// Retrieve other users groups.
$groups = core_group_external::get_activity_allowed_groups($cm1->id, $student->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
$this->assertCount(2, $groups['groups']);
// We are checking the $student passed as parameter so this will return false.
$this->assertFalse($groups['canaccessallgroups']);
// Check warnings. Trying to get groups for a user not enrolled in course.
$groups = core_group_external::get_activity_allowed_groups($cm1->id, $otherstudent->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
$this->assertCount(1, $groups['warnings']);
$this->assertFalse($groups['canaccessallgroups']);
// Checking teacher groups.
$groups = core_group_external::get_activity_allowed_groups($cm1->id);
- $groups = \external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
+ $groups = external_api::clean_returnvalue(core_group_external::get_activity_allowed_groups_returns(), $groups);
$this->assertCount(2, $groups['groups']);
// Teachers by default can access all groups.
$this->assertTrue($groups['canaccessallgroups']);
@@ -770,7 +771,7 @@ public function test_get_activity_groupmode() {
$this->setUser($student);
$data = core_group_external::get_activity_groupmode($cm1->id);
- $data = \external_api::clean_returnvalue(core_group_external::get_activity_groupmode_returns(), $data);
+ $data = external_api::clean_returnvalue(core_group_external::get_activity_groupmode_returns(), $data);
$this->assertEquals(VISIBLEGROUPS, $data['groupmode']);
try {
diff --git a/h5p/classes/external.php b/h5p/classes/external.php
index 0cc1ae6be158c..b9cd3fa3ad01d 100644
--- a/h5p/classes/external.php
+++ b/h5p/classes/external.php
@@ -14,30 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external API for this component.
- *
- * @package core_h5p
- * @copyright 2019 Carlos Escobedo
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_h5p;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_files;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* This is the external API for this component.
*
+ * @package core_h5p
* @copyright 2019 Carlos Escobedo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -151,7 +140,7 @@ public static function get_trusted_h5p_file(string $url, int $frame, int $export
* get_trusted_h5p_file return
*
* @since Moodle 3.8
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_trusted_h5p_file_returns() {
return new external_single_structure(
diff --git a/h5p/tests/external/external_test.php b/h5p/tests/external/external_test.php
index dc4c1e9d13026..03736f476ae0e 100644
--- a/h5p/tests/external/external_test.php
+++ b/h5p/tests/external/external_test.php
@@ -32,11 +32,9 @@
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use core_h5p\external;
-use core_h5p\file_storage;
use core_h5p\local\library\autoloader;
/**
@@ -86,7 +84,7 @@ public function test_get_trusted_h5p_file() {
// Call the WS.
$result = external::get_trusted_h5p_file($url->out(false), 0, 0, 0, 0);
- $result = \external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Expected result: Just 1 record on files and none on warnings.
$this->assertCount(1, $result['files']);
$this->assertCount(0, $result['warnings']);
@@ -110,7 +108,7 @@ public function test_h5p_invalid_url() {
// Create an empty url.
$urlempty = '';
$result = external::get_trusted_h5p_file($urlempty, 0, 0, 0, 0);
- $result = \external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Expected result: Just 1 record on warnings and none on files.
$this->assertCount(0, $result['files']);
$this->assertCount(1, $result['warnings']);
@@ -121,7 +119,7 @@ public function test_h5p_invalid_url() {
// Create a non-local URL.
$urlnonlocal = 'http://www.google.com/pluginfile.php/644/block_html/content/arithmetic-quiz-1-1.h5p';
$result = external::get_trusted_h5p_file($urlnonlocal, 0, 0, 0, 0);
- $result = \external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Expected result: Just 1 record on warnings and none on files.
$this->assertCount(0, $result['files']);
$this->assertCount(1, $result['warnings']);
@@ -149,7 +147,7 @@ public function test_h5p_file_not_found() {
);
// Call the ws.
$result = external::get_trusted_h5p_file($filenotfoundurl->out(), 0, 0, 0, 0);
- $result = \external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Expected result: Just 1 record on warnings and none on files.
$this->assertCount(0, $result['files']);
$this->assertCount(1, $result['warnings']);
@@ -189,7 +187,7 @@ public function test_allow_webservice_pluginfile_in_url_param() {
// Call the WS.
$result = external::get_trusted_h5p_file($url->out(), 0, 0, 0, 0);
- $result = \external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Check info export file to compare with the ws's results.
$this->assertEquals($deployedfile['filepath'], $result['files'][0]['filepath']);
@@ -234,7 +232,7 @@ public function test_allow_tokenluginfile_in_url_param() {
// Call the WS.
$result = external::get_trusted_h5p_file($url->out(false), 0, 0, 0, 0);
- $result = \external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
+ $result = \core_external\external_api::clean_returnvalue(external::get_trusted_h5p_file_returns(), $result);
// Expected result: Just 1 record on files and none on warnings.
$this->assertCount(1, $result['files']);
$this->assertCount(0, $result['warnings']);
diff --git a/lib/adminlib.php b/lib/adminlib.php
index d616ec85a5825..36f147d7b9154 100644
--- a/lib/adminlib.php
+++ b/lib/adminlib.php
@@ -205,11 +205,10 @@ function uninstall_plugin($type, $name) {
}
$plugininfo = null;
- // perform clean-up task common for all the plugin/subplugin types
+ // Perform clean-up task common for all the plugin/subplugin types.
- //delete the web service functions and pre-built services
- require_once($CFG->dirroot.'/lib/externallib.php');
- external_delete_descriptions($component);
+ // Delete the web service functions and pre-built services.
+ \core_external\util::delete_service_descriptions($component);
// delete calendar events
$DB->delete_records('event', array('modulename' => $pluginname));
diff --git a/lib/ajax/service.php b/lib/ajax/service.php
index 977b5e4a4b875..001531e78b8b1 100644
--- a/lib/ajax/service.php
+++ b/lib/ajax/service.php
@@ -27,6 +27,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_settings;
+
define('AJAX_SCRIPT', true);
// Services can declare 'readonlysession' in their config located in db/services.php, if not present will default to false.
define('READ_ONLY_SESSION', true);
@@ -36,7 +39,6 @@
}
require_once(__DIR__ . '/../../config.php');
-require_once($CFG->libdir . '/externallib.php');
define('PREFERRED_RENDERER_TARGET', RENDERER_TARGET_GENERAL);
diff --git a/lib/classes/external/dynamic_tabs_get_content.php b/lib/classes/external/dynamic_tabs_get_content.php
index cc78e8826782d..97a36856f6587 100644
--- a/lib/classes/external/dynamic_tabs_get_content.php
+++ b/lib/classes/external/dynamic_tabs_get_content.php
@@ -21,15 +21,10 @@
use coding_exception;
use context_system;
use core\output\dynamic_tabs\base;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* External method for getting tab contents
diff --git a/lib/classes/external/editmode.php b/lib/classes/external/editmode.php
index c48ba9d5238a9..a829f52f5807d 100644
--- a/lib/classes/external/editmode.php
+++ b/lib/classes/external/editmode.php
@@ -16,10 +16,10 @@
namespace core\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Web service to change the edit mode.
diff --git a/lib/classes/external/exporter.php b/lib/classes/external/exporter.php
index 82ff9d9101dbd..960f4970df402 100644
--- a/lib/classes/external/exporter.php
+++ b/lib/classes/external/exporter.php
@@ -22,19 +22,15 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
use stdClass;
use renderer_base;
use context;
-use context_system;
use coding_exception;
-use external_single_structure;
-use external_multiple_structure;
-use external_value;
-use external_format_value;
+use core_external\external_format_value;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Generic exporter to take a stdClass and prepare it for return by webservice, or as the context for a template.
@@ -112,7 +108,7 @@ public function __construct($data, $related = array()) {
/**
* Function to export the renderer data in a format that is suitable for a
* mustache template. This means raw records are generated as in to_record,
- * but all strings are correctly passed through external_format_text (or external_format_string).
+ * but all strings are correctly passed through \core_external\util::format_text (or \core_external\util::format_string).
*
* @param renderer_base $output Used to do a final render of any components that need to be rendered for export.
* @return stdClass
@@ -157,7 +153,7 @@ final public function export(renderer_base $output) {
$formatparams = $this->get_format_parameters($property);
$format = $record->$propertyformat;
- list($text, $format) = external_format_text($data->$property, $format, $formatparams['context'],
+ list($text, $format) = \core_external\util::format_text($data->$property, $format, $formatparams['context'],
$formatparams['component'], $formatparams['filearea'], $formatparams['itemid'], $formatparams['options']);
$data->$property = $text;
@@ -168,11 +164,11 @@ final public function export(renderer_base $output) {
if (!empty($definition['multiple'])) {
foreach ($data->$property as $key => $value) {
- $data->{$property}[$key] = external_format_string($value, $formatparams['context'],
+ $data->{$property}[$key] = \core_external\util::format_string($value, $formatparams['context'],
$formatparams['striplinks'], $formatparams['options']);
}
} else {
- $data->$property = external_format_string($data->$property, $formatparams['context'],
+ $data->$property = \core_external\util::format_string($data->$property, $formatparams['context'],
$formatparams['striplinks'], $formatparams['options']);
}
}
@@ -184,18 +180,20 @@ final public function export(renderer_base $output) {
/**
* Get the format parameters.
*
- * This method returns the parameters to use with the functions external_format_text(), and
- * external_format_string(). To override the default parameters, you can define a protected method
+ * This method returns the parameters to use with the functions \core_external\util::format_text(), and
+ * \core_external\util::format_string(). To override the default parameters, you can define a protected method
* called 'get_format_parameters_for_'. For example, 'get_format_parameters_for_description',
* if your property is 'description'.
*
* Your method must return an array containing any of the following keys:
* - context: The context to use. Defaults to $this->related['context'] if defined, else throws an exception.
- * - component: The component to use with external_format_text(). Defaults to null.
- * - filearea: The filearea to use with external_format_text(). Defaults to null.
- * - itemid: The itemid to use with external_format_text(). Defaults to null.
- * - options: An array of options accepted by external_format_text() or external_format_string(). Defaults to [].
- * - striplinks: Whether to strip the links with external_format_string(). Defaults to true.
+ * - component: The component to use with \core_external\util::format_text(). Defaults to null.
+ * - filearea: The filearea to use with \core_external\util::format_text(). Defaults to null.
+ * - itemid: The itemid to use with \core_external\util::format_text(). Defaults to null.
+ * - options: An array of options accepted by \core_external\util::format_text()
+ * or \core_external\util::format_string().
+ * Defaults to [].
+ * - striplinks: Whether to strip the links with \core_external\util::format_string(). Defaults to true.
*
* @param string $property The property to get the parameters for.
* @return array
diff --git a/lib/classes/external/output/icon_system/load_fontawesome_map.php b/lib/classes/external/output/icon_system/load_fontawesome_map.php
index aafaa4dd7e003..0221979a9b094 100644
--- a/lib/classes/external/output/icon_system/load_fontawesome_map.php
+++ b/lib/classes/external/output/icon_system/load_fontawesome_map.php
@@ -14,22 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * A web service to load the mapping of moodle pix names to fontawesome icon names.
- *
- * @package core
- * @category external
- * @copyright 2020 Andrew Nicols
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core\external\output\icon_system;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use core\output\icon_system_fontawesome;
use theme_config;
@@ -86,7 +77,7 @@ public static function execute(string $themename) {
/**
* Description of the return value for the `execute` function.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function execute_returns() {
return new external_multiple_structure(new external_single_structure([
diff --git a/lib/classes/external/persistent_exporter.php b/lib/classes/external/persistent_exporter.php
index 2fc49f0e7851d..10210f55b4bc6 100644
--- a/lib/classes/external/persistent_exporter.php
+++ b/lib/classes/external/persistent_exporter.php
@@ -22,9 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
use coding_exception;
@@ -81,5 +78,4 @@ protected final static function define_properties() {
protected static function define_class() {
throw new coding_exception('define_class() must be overidden.');
}
-
}
diff --git a/lib/classes/external/record_userfeedback_action.php b/lib/classes/external/record_userfeedback_action.php
index 1066701afa30c..1657f14474254 100644
--- a/lib/classes/external/record_userfeedback_action.php
+++ b/lib/classes/external/record_userfeedback_action.php
@@ -14,27 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External API to record users action on the feedback notification.
- *
- * @package core
- * @copyright 2020 Shamim Rezaie
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
/**
* The external API to record users action on the feedback notification.
*
+ * @package core
* @copyright 2020 Shamim Rezaie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/lib/classes/grades_external.php b/lib/classes/grades_external.php
index 1c85fd215431f..1adca4dafa87f 100644
--- a/lib/classes/grades_external.php
+++ b/lib/classes/grades_external.php
@@ -23,9 +23,15 @@
* @since Moodle 2.7
*/
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->libdir/gradelib.php");
require_once("$CFG->dirroot/grade/edit/tree/lib.php");
require_once("$CFG->dirroot/grade/querylib.php");
@@ -172,7 +178,7 @@ public static function update_grades($source, $courseid, $component, $activityid
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.7
*/
public static function update_grades_returns() {
@@ -268,7 +274,7 @@ public static function create_gradecategory(int $courseid, string $fullname, arr
* @todo MDL-71325 This will be deleted in Moodle 4.3.
* @see core_grades\external\create_gradecategories::create_gradecategories()
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.10
*/
public static function create_gradecategory_returns() {
diff --git a/lib/classes/grading_external.php b/lib/classes/grading_external.php
index 0649ead5c36c9..a5512baa3ea6e 100644
--- a/lib/classes/grading_external.php
+++ b/lib/classes/grading_external.php
@@ -23,9 +23,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/grade/grading/lib.php");
/**
@@ -153,7 +160,7 @@ public static function get_definitions($cmids, $areaname, $activeonly = false) {
$definition['usermodified'] = $def->usermodified;
$definition['timecopied'] = $def->timecopied;
// Format the description text field.
- $formattedtext = external_format_text($definition['description'],
+ $formattedtext = \core_external\util::format_text($definition['description'],
$definition['descriptionformat'],
$context->id,
$componentname,
@@ -180,14 +187,14 @@ public static function get_definitions($cmids, $areaname, $activeonly = false) {
}
/**
- * Recursively processes all elements in an array and runs external_format_text()on
+ * Recursively processes all elements in an array and runs \core_external\util::format_text()on
* all elements which have a text field and associated format field with a key name
* that ends with the text 'format'. The modified array is returned.
* @param array $items the array to be processed
* @param int $contextid
* @param string $componentname
* @param int $itemid
- * @see external_format_text in lib/externallib.php
+ * @see \core_external\util::format_text()
* @return array the input array with all fields formatted
*/
private static function format_text($items, $contextid, $componentname, $itemid) {
@@ -199,9 +206,9 @@ private static function format_text($items, $contextid, $componentname, $itemid)
}
foreach ($formatkeys as $formatkey) {
$descriptionkey = substr($formatkey, 0, -6);
- $formattedtext = external_format_text($items[$descriptionkey],
+ $formattedtext = \core_external\util::format_text($items[$descriptionkey],
$items[$formatkey],
- $contextid,
+ context::instance_by_id($contextid),
$componentname,
'description',
$itemid);
@@ -367,7 +374,7 @@ public static function get_gradingform_instances($definitionid, $since = 0) {
$instance['feedback'] = $activeinstance->get_data('feedback');
$instance['feedbackformat'] = $activeinstance->get_data('feedbackformat');
// Format the feedback text field.
- $formattedtext = external_format_text($activeinstance->get_data('feedback'),
+ $formattedtext = \core_external\util::format_text($activeinstance->get_data('feedback'),
$activeinstance->get_data('feedbackformat'),
$context->id,
$area->component,
diff --git a/lib/classes/output/chooser_item.php b/lib/classes/output/chooser_item.php
index 3e189eeb3cecb..8883b446949f3 100644
--- a/lib/classes/output/chooser_item.php
+++ b/lib/classes/output/chooser_item.php
@@ -23,9 +23,6 @@
*/
namespace core\output;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
use coding_exception;
use context;
@@ -97,7 +94,7 @@ public function export_for_template(renderer_base $output) {
$data->description = '';
if (!empty($this->description)) {
- list($data->description) = external_format_text((string) $this->description, FORMAT_MARKDOWN,
+ list($data->description) = \core_external\util::format_text((string) $this->description, FORMAT_MARKDOWN,
$this->context->id, null, null, null, $options);
}
diff --git a/lib/classes/output/external.php b/lib/classes/output/external.php
index 09a494be04088..b9c24e049c3c2 100644
--- a/lib/classes/output/external.php
+++ b/lib/classes/output/external.php
@@ -14,31 +14,20 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Mustache helper to load strings from string_manager.
- *
- * @package core
- * @category output
- * @copyright 2015 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core\output;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use core_component;
-use moodle_exception;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use context_system;
-use theme_config;
use core\external\output\icon_system\load_fontawesome_map;
/**
* This class contains a list of webservice functions related to output.
*
+ * @package core
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 2.9
@@ -90,7 +79,7 @@ public static function load_template($component, $template, $themename, $include
/**
* Returns description of load_template() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function load_template_returns() {
return new external_value(PARAM_RAW, 'template');
@@ -177,7 +166,7 @@ public static function load_template_with_dependencies(
/**
* Returns description of load_template_with_dependencies() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function load_template_with_dependencies_returns() {
$resourcestructure = new external_single_structure([
@@ -216,7 +205,7 @@ public static function load_fontawesome_icon_map() {
/**
* Returns description of load_icon_map() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function load_fontawesome_icon_map_returns() {
return load_fontawesome_map::execute_returns();
diff --git a/lib/classes/session/external.php b/lib/classes/session/external.php
index e6e0f0e70d6ce..4e1652bd6d007 100644
--- a/lib/classes/session/external.php
+++ b/lib/classes/session/external.php
@@ -24,7 +24,11 @@
namespace core\session;
-defined('MOODLE_INTERNAL') || die();
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* This class contains a list of webservice functions related to session.
@@ -33,7 +37,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since 2.9
*/
-class external extends \external_api {
+class external extends external_api {
/**
* Returns description of touch_session() parameters.
@@ -41,7 +45,7 @@ class external extends \external_api {
* @return external_function_parameters
*/
public static function touch_session_parameters() {
- return new \external_function_parameters([]);
+ return new external_function_parameters([]);
}
/**
@@ -60,7 +64,7 @@ public static function touch_session() {
* @return external_description
*/
public static function touch_session_returns() {
- return new \external_value(PARAM_BOOL, 'result');
+ return new external_value(PARAM_BOOL, 'result');
}
/**
@@ -69,7 +73,7 @@ public static function touch_session_returns() {
* @return external_function_parameters
*/
public static function time_remaining_parameters() {
- return new \external_function_parameters([]);
+ return new external_function_parameters([]);
}
/**
@@ -87,9 +91,9 @@ public static function time_remaining() {
* @return external_description
*/
public static function time_remaining_returns() {
- return new \external_single_structure(array (
- 'userid' => new \external_value(PARAM_INTEGER, 'The current user id.'),
- 'timeremaining' => new \external_value(PARAM_INTEGER, 'The number of seconds remaining in this session.')
- ));
+ return new external_single_structure([
+ 'userid' => new external_value(PARAM_INT, 'The current user id.'),
+ 'timeremaining' => new external_value(PARAM_INT, 'The number of seconds remaining in this session.'),
+ ]);
}
}
diff --git a/lib/classes/task/asynchronous_copy_task.php b/lib/classes/task/asynchronous_copy_task.php
index 0d2b8e45b0311..21aa877b34133 100644
--- a/lib/classes/task/asynchronous_copy_task.php
+++ b/lib/classes/task/asynchronous_copy_task.php
@@ -32,7 +32,6 @@
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/moodle2/backup_plan_builder.class.php');
-require_once($CFG->libdir . '/externallib.php');
/**
* Adhoc task that performs asynchronous course copies.
diff --git a/lib/editor/tiny/plugins/autosave/classes/external/reset_autosave_session.php b/lib/editor/tiny/plugins/autosave/classes/external/reset_autosave_session.php
index 308b0a76c06e0..bcf7e4ff4cc50 100644
--- a/lib/editor/tiny/plugins/autosave/classes/external/reset_autosave_session.php
+++ b/lib/editor/tiny/plugins/autosave/classes/external/reset_autosave_session.php
@@ -16,14 +16,10 @@
namespace tiny_autosave\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("{$CFG->libdir}/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Web Service to reset the autosave session.
diff --git a/lib/editor/tiny/plugins/autosave/classes/external/resume_autosave_session.php b/lib/editor/tiny/plugins/autosave/classes/external/resume_autosave_session.php
index 51a86b84d014b..e3a6cccb1f050 100644
--- a/lib/editor/tiny/plugins/autosave/classes/external/resume_autosave_session.php
+++ b/lib/editor/tiny/plugins/autosave/classes/external/resume_autosave_session.php
@@ -16,14 +16,10 @@
namespace tiny_autosave\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("{$CFG->libdir}/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Web Service to resume an autosave session.
diff --git a/lib/editor/tiny/plugins/autosave/classes/external/update_autosave_session_content.php b/lib/editor/tiny/plugins/autosave/classes/external/update_autosave_session_content.php
index 615b0f3a3f21e..cc27117f62ee8 100644
--- a/lib/editor/tiny/plugins/autosave/classes/external/update_autosave_session_content.php
+++ b/lib/editor/tiny/plugins/autosave/classes/external/update_autosave_session_content.php
@@ -16,14 +16,10 @@
namespace tiny_autosave\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("{$CFG->libdir}/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Web Service to update an autosave session's content.
diff --git a/lib/editor/tiny/plugins/equation/classes/external/filter.php b/lib/editor/tiny/plugins/equation/classes/external/filter.php
index 1912f8b5e36b2..ec4c077e2060a 100644
--- a/lib/editor/tiny/plugins/equation/classes/external/filter.php
+++ b/lib/editor/tiny/plugins/equation/classes/external/filter.php
@@ -14,21 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * TinyMCE Equation external API for filtering the equation.
- *
- * @package tiny_equation
- * @copyright 2022 Huong Nguyen
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace tiny_equation\external;
use context;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use filter_manager;
/**
diff --git a/lib/external/externallib.php b/lib/external/externallib.php
index b9345666b4396..f28f05a137715 100644
--- a/lib/external/externallib.php
+++ b/lib/external/externallib.php
@@ -14,19 +14,11 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
-/**
- * external API for core library
- *
- * @package core_webservice
- * @category external
- * @copyright 2012 Jerome Mouneyrac
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Web service related functions
@@ -60,7 +52,7 @@ public static function format_string_parameters($stringparams) {
// It is a not named string parameter.
$strparams = $stringparam['value'];
}
- } else {
+ } else {
// There are more than one parameter.
foreach ($stringparams as $stringparam) {
@@ -120,7 +112,7 @@ public static function get_string($stringid, $component = 'moodle', $lang = null
/**
* Returns description of get_string() result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.4
*/
public static function get_string_returns() {
@@ -189,7 +181,7 @@ public static function get_strings($strings) {
/**
* Returns description of get_string() result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.4
*/
public static function get_strings_returns() {
@@ -281,7 +273,7 @@ public static function get_user_dates($contextid, $contextlevel, $instanceid, $t
/**
* Returns description of get_user_dates() result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_user_dates_returns() {
return new external_single_structure(
@@ -341,7 +333,7 @@ public static function get_component_strings($component, $lang = null) {
/**
* Returns description of get_component_strings() result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.4
*/
public static function get_component_strings_returns() {
@@ -429,7 +421,7 @@ public static function get_fragment($component, $callback, $contextid, $args = n
/**
* Returns description of get_fragment() result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_fragment_returns() {
@@ -486,7 +478,7 @@ public static function update_inplace_editable($component, $itemtype, $itemid, $
* Return structure for update_inplace_editable()
*
* @since Moodle 3.1
- * @return external_description
+ * @return \core_external\external_description
*/
public static function update_inplace_editable_returns() {
return new external_single_structure(
@@ -526,7 +518,7 @@ public static function fetch_notifications_parameters() {
/**
* Returns description of fetch_notifications() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function fetch_notifications_returns() {
diff --git a/lib/external/tests/external_api_test.php b/lib/external/tests/external_api_test.php
index cad89d4f7119f..5bca4fe5d1916 100644
--- a/lib/external/tests/external_api_test.php
+++ b/lib/external/tests/external_api_test.php
@@ -26,14 +26,6 @@
* @covers \core_external\external_api
*/
class external_api_test extends \advanced_testcase {
- /**
- * Setup the test to include the current externallib.
- */
- public static function setUpBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Test the validate_parameters method.
*
@@ -41,9 +33,9 @@ public static function setUpBeforeClass(): void {
*/
public function test_validate_params(): void {
$params = ['text' => 'aaa', 'someid' => '6'];
- $description = new \external_function_parameters([
- 'someid' => new \external_value(PARAM_INT, 'Some int value'),
- 'text' => new \external_value(PARAM_ALPHA, 'Some text value'),
+ $description = new external_function_parameters([
+ 'someid' => new external_value(PARAM_INT, 'Some int value'),
+ 'text' => new external_value(PARAM_ALPHA, 'Some text value'),
]);
$result = external_api::validate_parameters($description, $params);
$this->assertCount(2, $result);
@@ -56,9 +48,9 @@ public function test_validate_params(): void {
'someids' => ['1', 2, 'a' => '3'],
'scalar' => 666,
];
- $description = new \external_function_parameters([
- 'someids' => new \external_multiple_structure(new \external_value(PARAM_INT, 'Some ID')),
- 'scalar' => new \external_value(PARAM_ALPHANUM, 'Some text value'),
+ $description = new external_function_parameters([
+ 'someids' => new external_multiple_structure(new external_value(PARAM_INT, 'Some ID')),
+ 'scalar' => new external_value(PARAM_ALPHANUM, 'Some text value'),
]);
$result = external_api::validate_parameters($description, $params);
$this->assertCount(2, $result);
@@ -68,9 +60,9 @@ public function test_validate_params(): void {
$this->assertSame('666', $result['scalar']);
$params = ['text' => 'aaa'];
- $description = new \external_function_parameters([
- 'someid' => new \external_value(PARAM_INT, 'Some int value', false),
- 'text' => new \external_value(PARAM_ALPHA, 'Some text value'),
+ $description = new external_function_parameters([
+ 'someid' => new external_value(PARAM_INT, 'Some int value', false),
+ 'text' => new external_value(PARAM_ALPHA, 'Some text value'),
]);
$result = external_api::validate_parameters($description, $params);
$this->assertCount(2, $result);
@@ -80,9 +72,9 @@ public function test_validate_params(): void {
$this->assertSame('aaa', $result['text']);
$params = ['text' => 'aaa'];
- $description = new \external_function_parameters([
- 'someid' => new \external_value(PARAM_INT, 'Some int value', false, 6),
- 'text' => new \external_value(PARAM_ALPHA, 'Some text value'),
+ $description = new external_function_parameters([
+ 'someid' => new external_value(PARAM_INT, 'Some int value', false, 6),
+ 'text' => new external_value(PARAM_ALPHA, 'Some text value'),
]);
$result = external_api::validate_parameters($description, $params);
$this->assertCount(2, $result);
@@ -98,8 +90,8 @@ public function test_validate_params(): void {
* @covers \core_external\external_api::clean_returnvalue
*/
public function test_clean_returnvalue_return_php_type(): void {
- $returndesc = new \external_single_structure([
- 'value' => new \external_value(PARAM_RAW, 'Some text', VALUE_OPTIONAL, null, NULL_NOT_ALLOWED),
+ $returndesc = new external_single_structure([
+ 'value' => new external_value(PARAM_RAW, 'Some text', VALUE_OPTIONAL, null, NULL_NOT_ALLOWED),
]);
// Check return type on exception because the external values does not allow NULL values.
@@ -119,12 +111,12 @@ public function test_clean_returnvalue_return_php_type(): void {
*/
public function test_clean_returnvalue(): void {
// Build some return value decription.
- $returndesc = new \external_multiple_structure(
- new \external_single_structure(
+ $returndesc = new external_multiple_structure(
+ new external_single_structure(
[
- 'object' => new \external_single_structure(
- ['value1' => new \external_value(PARAM_INT, 'this is a int')]),
- 'value2' => new \external_value(PARAM_TEXT, 'some text', VALUE_OPTIONAL),
+ 'object' => new external_single_structure(
+ ['value1' => new external_value(PARAM_INT, 'this is a int')]),
+ 'value2' => new external_value(PARAM_TEXT, 'some text', VALUE_OPTIONAL),
]
));
@@ -296,9 +288,9 @@ public function test_all_external_info(\stdClass $definition): void {
$this->assertNotEmpty($desc->classname);
$this->assertNotEmpty($desc->methodname);
$this->assertEquals($desc->component, clean_param($desc->component, PARAM_COMPONENT));
- $this->assertInstanceOf(\external_function_parameters::class, $desc->parameters_desc);
+ $this->assertInstanceOf(external_function_parameters::class, $desc->parameters_desc);
if ($desc->returns_desc != null) {
- $this->assertInstanceOf(\external_description::class, $desc->returns_desc);
+ $this->assertInstanceOf(external_description::class, $desc->returns_desc);
}
}
diff --git a/lib/external/tests/external_externallib_test.php b/lib/external/tests/external_externallib_test.php
index 2eae46adca78a..3139a21c26cd1 100644
--- a/lib/external/tests/external_externallib_test.php
+++ b/lib/external/tests/external_externallib_test.php
@@ -16,6 +16,7 @@
namespace core;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -50,7 +51,7 @@ public function test_get_string() {
array('name' => 'id', 'value' => $service->id)));
// We need to execute the return values cleaning process to simulate the web service server.
- $returnedstring = \external_api::clean_returnvalue(\core_external::get_string_returns(), $returnedstring);
+ $returnedstring = external_api::clean_returnvalue(\core_external::get_string_returns(), $returnedstring);
$corestring = get_string('addservice', 'webservice', $service);
$this->assertSame($corestring, $returnedstring);
@@ -61,7 +62,7 @@ public function test_get_string() {
array(array('value' => $acapname)));
// We need to execute the return values cleaning process to simulate the web service server.
- $returnedstring = \external_api::clean_returnvalue(\core_external::get_string_returns(), $returnedstring);
+ $returnedstring = external_api::clean_returnvalue(\core_external::get_string_returns(), $returnedstring);
$corestring = get_string('missingrequiredcapability', 'webservice', $acapname);
$this->assertSame($corestring, $returnedstring);
@@ -70,7 +71,7 @@ public function test_get_string() {
$returnedstring = \core_external::get_string('missingpassword', 'webservice');
// We need to execute the return values cleaning process to simulate the web service server.
- $returnedstring = \external_api::clean_returnvalue(\core_external::get_string_returns(), $returnedstring);
+ $returnedstring = external_api::clean_returnvalue(\core_external::get_string_returns(), $returnedstring);
$corestring = get_string('missingpassword', 'webservice');
$this->assertSame($corestring, $returnedstring);
@@ -87,7 +88,7 @@ public function test_get_string() {
*/
public function test_get_string_containing_html() {
$result = \core_external::get_string('registrationinfo');
- $actual = \external_api::clean_returnvalue(\core_external::get_string_returns(), $result);
+ $actual = external_api::clean_returnvalue(\core_external::get_string_returns(), $result);
$expected = get_string('registrationinfo', 'moodle');
$this->assertSame($expected, $actual);
}
@@ -97,7 +98,7 @@ public function test_get_string_containing_html() {
*/
public function test_get_string_with_args_containing_html() {
$result = \core_external::get_string('added', 'moodle', null, [['value' => 'Test']]);
- $actual = \external_api::clean_returnvalue(\core_external::get_string_returns(), $result);
+ $actual = external_api::clean_returnvalue(\core_external::get_string_returns(), $result);
$expected = get_string('added', 'moodle', 'Test');
$this->assertSame($expected, $actual);
}
@@ -127,7 +128,7 @@ public function test_get_strings() {
));
// We need to execute the return values cleaning process to simulate the web service server.
- $returnedstrings = \external_api::clean_returnvalue(\core_external::get_strings_returns(), $returnedstrings);
+ $returnedstrings = external_api::clean_returnvalue(\core_external::get_strings_returns(), $returnedstrings);
foreach($returnedstrings as $returnedstring) {
$corestring = $stringmanager->get_string($returnedstring['stringid'],
@@ -143,7 +144,7 @@ public function test_get_strings() {
*/
public function test_get_strings_containing_html() {
$result = \core_external::get_strings([['stringid' => 'registrationinfo'], ['stringid' => 'loginaspasswordexplain']]);
- $actual = \external_api::clean_returnvalue(\core_external::get_strings_returns(), $result);
+ $actual = external_api::clean_returnvalue(\core_external::get_strings_returns(), $result);
$this->assertSame(get_string('registrationinfo', 'moodle'), $actual[0]['string']);
$this->assertSame(get_string('loginaspasswordexplain', 'moodle'), $actual[1]['string']);
}
@@ -156,7 +157,7 @@ public function test_get_strings_with_args_containing_html() {
['stringid' => 'added', 'stringparams' => [['value' => 'Test']]],
['stringid' => 'loggedinas', 'stringparams' => [['value' => 'Test']]]]
);
- $actual = \external_api::clean_returnvalue(\core_external::get_strings_returns(), $result);
+ $actual = external_api::clean_returnvalue(\core_external::get_strings_returns(), $result);
$this->assertSame(get_string('added', 'moodle', 'Test'), $actual[0]['string']);
$this->assertSame(get_string('loggedinas', 'moodle', 'Test'), $actual[1]['string']);
}
@@ -175,7 +176,7 @@ public function test_get_component_strings() {
$componentstrings = \core_external::get_component_strings('webservice');
// We need to execute the return values cleaning process to simulate the web service server.
- $componentstrings = \external_api::clean_returnvalue(\core_external::get_component_strings_returns(), $componentstrings);
+ $componentstrings = external_api::clean_returnvalue(\core_external::get_component_strings_returns(), $componentstrings);
$this->assertEquals(count($componentstrings), count($wsstrings));
foreach($componentstrings as $string) {
@@ -202,7 +203,7 @@ public function test_update_inplace_editable() {
$this->setAdminUser();
$tag = $this->getDataGenerator()->create_tag();
$res = \core_external::update_inplace_editable('core_tag', 'tagname', $tag->id, 'new tag name');
- $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
+ $res = external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('new tag name', $res['value']);
}
@@ -226,11 +227,11 @@ public function test_update_inplace_editable_with_mathjax() {
// Change the forum name.
$newname = 'New forum name $$(a+b)=2$$';
$res = \core_external::update_inplace_editable('core_course', 'activityname', $forum->cmid, $newname);
- $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
+ $res = external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
// Format original data.
$context = \context_module::instance($forum->cmid);
- $newname = external_format_string($newname, $context->id);
+ $newname = \core_external\util::format_string($newname, $context);
$editlabel = get_string('newactivityname', '', $newname);
// Check editlabel is the same and has mathjax.
@@ -269,7 +270,7 @@ public function test_get_user_dates() {
];
$result = \core_external::get_user_dates($context->id, null, null, $request);
- $result = \external_api::clean_returnvalue(\core_external::get_user_dates_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_external::get_user_dates_returns(), $result);
$this->assertEquals('Saturday, 1 January 2011, 6:00', $result['dates'][0]);
$this->assertEquals('1 01 2011', $result['dates'][1]);
diff --git a/lib/external/tests/external_files_test.php b/lib/external/tests/external_files_test.php
index cb424d37e790f..479ec6dc04181 100644
--- a/lib/external/tests/external_files_test.php
+++ b/lib/external/tests/external_files_test.php
@@ -23,16 +23,16 @@
* @category test
* @copyright 2022 Andrew Lyons
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
- * @covers \core_external\files
+ * @covers \core_external\external_files
*/
class external_files_test extends \advanced_testcase {
/**
* Text external files structure.
*
- * @covers \core_external\files
+ * @covers \core_external\external_files
*/
public function test_files_structure(): void {
- $description = new files();
+ $description = new external_files();
// First check that the expected default values and keys are returned.
$expectedkeys = array_flip([
diff --git a/lib/form/classes/dynamic_form.php b/lib/form/classes/dynamic_form.php
index a60a304a070ad..ad522d4c9f2ff 100644
--- a/lib/form/classes/dynamic_form.php
+++ b/lib/form/classes/dynamic_form.php
@@ -17,6 +17,7 @@
namespace core_form;
use context;
+use core_external\external_api;
use moodle_url;
defined('MOODLE_INTERNAL') || die();
@@ -61,11 +62,10 @@ final public function __construct(
$this->_ajaxformdata = $ajaxformdata;
if ($isajaxsubmission) {
- require_once($CFG->libdir . '/externallib.php');
// This form was created from the WS that needs to validate user access to it and set page context.
// It has to be done before calling parent constructor because elements definitions may need to use
// format_string functions and other methods that expect the page to be set up.
- \external_api::validate_context($this->get_context_for_dynamic_submission());
+ external_api::validate_context($this->get_context_for_dynamic_submission());
$PAGE->set_url($this->get_page_url_for_dynamic_submission());
$this->check_access_for_dynamic_submission();
}
@@ -76,7 +76,7 @@ final public function __construct(
/**
* Returns context where this form is used
*
- * This context is validated in {@see \external_api::validate_context()}
+ * This context is validated in {@see external_api::validate_context()}
*
* If context depends on the form data, it is available in $this->_ajaxformdata or
* by calling $this->optional_param()
diff --git a/lib/form/classes/external.php b/lib/form/classes/external.php
index 40b1c73e73b5c..17f9345d40a8d 100644
--- a/lib/form/classes/external.php
+++ b/lib/form/classes/external.php
@@ -26,15 +26,11 @@
namespace core_form;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir.'/externallib.php');
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Implements the external functions provided by the core_form subsystem.
@@ -48,7 +44,7 @@ class external extends external_api {
/**
* Describes the input paramaters of the get_filetypes_browser_data external function.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_filetypes_browser_data_parameters() {
return new external_function_parameters([
@@ -80,7 +76,7 @@ public static function get_filetypes_browser_data($onlytypes, $allowall, $curren
/**
* Describes the output of the get_filetypes_browser_data external function.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_filetypes_browser_data_returns() {
diff --git a/lib/form/classes/external/dynamic_form.php b/lib/form/classes/external/dynamic_form.php
index 0663123c8f1a4..383f1fafd13a8 100644
--- a/lib/form/classes/external/dynamic_form.php
+++ b/lib/form/classes/external/dynamic_form.php
@@ -16,14 +16,10 @@
namespace core_form\external;
-use core_search\engine_exception;
-use external_api;
-use external_function_parameters;
-use external_value;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir.'/externallib.php');
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Implements the external functions provided by the core_form subsystem.
@@ -91,10 +87,10 @@ public static function execute(string $formclass, string $formdatastr): array {
/**
* Return for modal
- * @return \external_single_structure
+ * @return external_single_structure
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure(
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure(
array(
'submitted' => new external_value(PARAM_BOOL, 'If form was submitted and validated'),
'data' => new external_value(PARAM_RAW, 'JSON-encoded return data from form processing method', VALUE_OPTIONAL),
diff --git a/lib/form/tests/external_test.php b/lib/form/tests/external_test.php
index 3631a8c890ea7..95dfb38332f86 100644
--- a/lib/form/tests/external_test.php
+++ b/lib/form/tests/external_test.php
@@ -26,7 +26,7 @@
namespace core_form;
use advanced_testcase;
-use external_api;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
diff --git a/lib/outputcomponents.php b/lib/outputcomponents.php
index 0facd23c7461c..9d99bfdc47ab0 100644
--- a/lib/outputcomponents.php
+++ b/lib/outputcomponents.php
@@ -3664,20 +3664,16 @@ public function set_url(moodle_url $url) {
* @return array
*/
public function export_for_template(renderer_base $output) {
- global $CFG;
-
- require_once($CFG->libdir . '/externallib.php');
-
$syscontext = context_system::instance();
$context = new stdClass();
$context->moremenuid = uniqid();
- $context->text = external_format_string($this->text, $syscontext->id);
+ $context->text = \core_external\util::format_string($this->text, $syscontext->id);
$context->url = $this->url ? $this->url->out() : null;
// No need for the title if it's the same with text.
if ($this->text !== $this->title) {
// Show the title attribute only if it's different from the text.
- $context->title = external_format_string($this->title, $syscontext->id);
+ $context->title = \core_external\util::format_string($this->title, $syscontext->id);
}
$context->sort = $this->sort;
if (!empty($this->attributes)) {
diff --git a/lib/table/classes/external/dynamic/get.php b/lib/table/classes/external/dynamic/get.php
index 51ad2e4c7c18b..149bcdd3db584 100644
--- a/lib/table/classes/external/dynamic/get.php
+++ b/lib/table/classes/external/dynamic/get.php
@@ -14,23 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Table external API.
- *
- * @package core_table
- * @category external
- * @copyright 2020 Simey Lameze
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_table\external\dynamic;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* Core table external functions.
diff --git a/lib/table/tests/external/dynamic/get_test.php b/lib/table/tests/external/dynamic/get_test.php
index be186e51e1484..898c218d2e686 100644
--- a/lib/table/tests/external/dynamic/get_test.php
+++ b/lib/table/tests/external/dynamic/get_test.php
@@ -39,15 +39,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class get_test extends advanced_testcase {
-
- /**
- * Setup before class.
- */
- public static function setUpBeforeClass(): void {
- global $CFG;
- require_once("{$CFG->libdir}/externallib.php");
- }
-
/**
* Test execute invalid component format.
*/
diff --git a/lib/tests/exporter_test.php b/lib/tests/exporter_test.php
index ead475e86fba2..bbcf5b433319a 100644
--- a/lib/tests/exporter_test.php
+++ b/lib/tests/exporter_test.php
@@ -24,8 +24,11 @@
namespace core;
-defined('MOODLE_INTERNAL') || die();
-global $CFG;
+use core_external\external_format_value;
+use core_external\external_multiple_structure;
+use core_external\external_settings;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Exporter testcase.
@@ -70,21 +73,21 @@ public function setUp(): void {
public function test_get_read_structure() {
$structure = core_testable_exporter::get_read_structure();
- $this->assertInstanceOf('external_single_structure', $structure);
- $this->assertInstanceOf('external_value', $structure->keys['stringA']);
- $this->assertInstanceOf('external_format_value', $structure->keys['stringAformat']);
- $this->assertInstanceOf('external_value', $structure->keys['intB']);
- $this->assertInstanceOf('external_value', $structure->keys['otherstring']);
- $this->assertInstanceOf('external_multiple_structure', $structure->keys['otherstrings']);
+ $this->assertInstanceOf(external_single_structure::class, $structure);
+ $this->assertInstanceOf(external_value::class, $structure->keys['stringA']);
+ $this->assertInstanceOf(external_format_value::class, $structure->keys['stringAformat']);
+ $this->assertInstanceOf(external_value::class, $structure->keys['intB']);
+ $this->assertInstanceOf(external_value::class, $structure->keys['otherstring']);
+ $this->assertInstanceOf(external_multiple_structure::class, $structure->keys['otherstrings']);
}
public function test_get_create_structure() {
$structure = core_testable_exporter::get_create_structure();
- $this->assertInstanceOf('external_single_structure', $structure);
- $this->assertInstanceOf('external_value', $structure->keys['stringA']);
- $this->assertInstanceOf('external_format_value', $structure->keys['stringAformat']);
- $this->assertInstanceOf('external_value', $structure->keys['intB']);
+ $this->assertInstanceOf(external_single_structure::class, $structure);
+ $this->assertInstanceOf(external_value::class, $structure->keys['stringA']);
+ $this->assertInstanceOf(external_format_value::class, $structure->keys['stringAformat']);
+ $this->assertInstanceOf(external_value::class, $structure->keys['intB']);
$this->assertArrayNotHasKey('otherstring', $structure->keys);
$this->assertArrayNotHasKey('otherstrings', $structure->keys);
}
@@ -92,10 +95,10 @@ public function test_get_create_structure() {
public function test_get_update_structure() {
$structure = core_testable_exporter::get_update_structure();
- $this->assertInstanceOf('external_single_structure', $structure);
- $this->assertInstanceOf('external_value', $structure->keys['stringA']);
- $this->assertInstanceOf('external_format_value', $structure->keys['stringAformat']);
- $this->assertInstanceOf('external_value', $structure->keys['intB']);
+ $this->assertInstanceOf(external_single_structure::class, $structure);
+ $this->assertInstanceOf(external_value::class, $structure->keys['stringA']);
+ $this->assertInstanceOf(external_format_value::class, $structure->keys['stringAformat']);
+ $this->assertInstanceOf(external_value::class, $structure->keys['intB']);
$this->assertArrayNotHasKey('otherstring', $structure->keys);
$this->assertArrayNotHasKey('otherstrings', $structure->keys);
}
@@ -152,7 +155,7 @@ public function test_format_text() {
$syscontext = \context_system::instance();
$coursecontext = \context_course::instance($course->id);
- \external_settings::get_instance()->set_filter(true);
+ external_settings::get_instance()->set_filter(true);
filter_set_global_state('urltolink', TEXTFILTER_OFF);
filter_set_local_state('urltolink', $coursecontext->id, TEXTFILTER_ON);
set_config('formats', FORMAT_MARKDOWN, 'filter_urltolink');
diff --git a/lib/tests/external/dynamic_tabs_get_content_test.php b/lib/tests/external/dynamic_tabs_get_content_test.php
index b30fdc1cddb8a..5421b9d9a5916 100644
--- a/lib/tests/external/dynamic_tabs_get_content_test.php
+++ b/lib/tests/external/dynamic_tabs_get_content_test.php
@@ -18,7 +18,7 @@
namespace core\external;
-use external_api;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
diff --git a/lib/tests/external/output/icon_system/load_fontawesome_map_test.php b/lib/tests/external/output/icon_system/load_fontawesome_map_test.php
index 5e970a42f4bb5..eb644c57c8ba7 100644
--- a/lib/tests/external/output/icon_system/load_fontawesome_map_test.php
+++ b/lib/tests/external/output/icon_system/load_fontawesome_map_test.php
@@ -41,18 +41,6 @@
* @coversDefaultClass \core\external\output\icon_system\load_fontawesome_map
*/
class load_fontawesome_map_test extends externallib_advanced_testcase {
-
- /**
- * Perform setup before these tests are run.
- */
- public static function setUpBeforeClass(): void {
- global $CFG;
-
- // In normal operation the external_api classes will have been loaded by the caller.
- // The load_fontawesome_map class should not need to supplement our lack of autoloading of these classes.
- require_once($CFG->libdir . '/externallib.php');
- }
-
/**
* Ensure that a valid theme which uses fontawesome returns a map.
*
diff --git a/lib/tests/fixtures/test_external_function_throwable.php b/lib/tests/fixtures/test_external_function_throwable.php
index b1e975d73ff4c..5ac76c462770e 100644
--- a/lib/tests/fixtures/test_external_function_throwable.php
+++ b/lib/tests/fixtures/test_external_function_throwable.php
@@ -14,6 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+
/**
* An external function that throws an exception, for tests.
*
@@ -22,17 +26,6 @@
* @copyright 2020 Dani Palou
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
-/**
- * Create an external function that throws an exception, for tests.
- *
- * @copyright 2020 Dani Palou
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
class test_external_function_throwable extends external_api {
/**
@@ -58,7 +51,7 @@ public static function throw_exception() {
/**
* Returns description of throw_exception() result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function throw_exception_returns() {
return new external_single_structure(array());
diff --git a/lib/tests/grades_external_test.php b/lib/tests/grades_external_test.php
index e9ffeacd3478b..38d34ed02952b 100644
--- a/lib/tests/grades_external_test.php
+++ b/lib/tests/grades_external_test.php
@@ -17,6 +17,7 @@
namespace core;
use core_grades_external;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
@@ -158,7 +159,7 @@ public function test_update_grades() {
array(),
array('grademax' => $changedmax)
);
- $result = \external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
$this->assertTrue($result == GRADE_UPDATE_OK);
$grades = grade_get_grades($course->id, 'mod', 'assign', $assignment->id);
$this->assertTrue($grades->items[0]->grademax == $changedmax);
@@ -173,7 +174,7 @@ public function test_update_grades() {
0,
array(array('studentid' => $student1->id, 'grade' => $student1grade))
);
- $result = \external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
$this->assertTrue($result == GRADE_UPDATE_OK);
$grades = grade_get_grades($course->id, 'mod', 'assign', $assignment->id, array($student1->id));
$this->assertTrue($grades->items[0]->grades[$student1->id]->grade == $student1grade);
@@ -192,7 +193,7 @@ public function test_update_grades() {
array('studentid' => $student2->id, 'grade' => $student2grade)
)
);
- $result = \external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
$this->assertTrue($result == GRADE_UPDATE_OK);
$grades = grade_get_grades($course->id, 'mod', 'assign', $assignment->id, array($student1->id, $student2->id));
$this->assertTrue($grades->items[0]->grades[$student1->id]->grade == $student1grade);
@@ -268,7 +269,7 @@ public function test_update_grades() {
array(),
array('hidden' => 1)
);
- $result = \external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(core_grades_external::update_grades_returns(), $result);
$this->assertTrue($result == GRADE_UPDATE_OK);
$grades = grade_get_grades($course->id, 'mod', 'assign', $assignment->id);
$this->assertTrue($grades->items[0]->hidden == 1);
diff --git a/lib/tests/grading_external_test.php b/lib/tests/grading_external_test.php
index 2d1ef1f364ddb..1b9d4cfabf80f 100644
--- a/lib/tests/grading_external_test.php
+++ b/lib/tests/grading_external_test.php
@@ -17,6 +17,7 @@
namespace core;
use core_grading_external;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
@@ -145,7 +146,7 @@ public function test_get_definitions() {
$cmids = array ($cm->cmid);
$areaname = 'submissions';
$result = core_grading_external::get_definitions($cmids, $areaname);
- $result = \external_api::clean_returnvalue(core_grading_external::get_definitions_returns(), $result);
+ $result = external_api::clean_returnvalue(core_grading_external::get_definitions_returns(), $result);
$this->assertEquals(1, count($result['areas']));
$this->assertEquals(1, count($result['areas'][0]['definitions']));
@@ -290,7 +291,7 @@ public function test_get_gradingform_instances() {
// Call the external function.
$result = core_grading_external::get_gradingform_instances($definitionid, 0);
- $result = \external_api::clean_returnvalue(core_grading_external::get_gradingform_instances_returns(), $result);
+ $result = external_api::clean_returnvalue(core_grading_external::get_gradingform_instances_returns(), $result);
$this->assertEquals(1, count($result['instances']));
$this->assertEquals($USER->id, $result['instances'][0]['raterid']);
diff --git a/lib/upgradelib.php b/lib/upgradelib.php
index fd04b3a976b61..cb70762d4a725 100644
--- a/lib/upgradelib.php
+++ b/lib/upgradelib.php
@@ -1222,8 +1222,7 @@ function external_update_descriptions($component) {
$defpath = core_component::get_component_directory($component).'/db/services.php';
if (!file_exists($defpath)) {
- require_once($CFG->dirroot.'/lib/externallib.php');
- external_delete_descriptions($component);
+ \core_external\util::delete_service_descriptions($component);
return;
}
diff --git a/lib/xapi/classes/external/post_statement.php b/lib/xapi/classes/external/post_statement.php
index 95118a5233826..0b7af5f1127a9 100644
--- a/lib/xapi/classes/external/post_statement.php
+++ b/lib/xapi/classes/external/post_statement.php
@@ -14,35 +14,22 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external API for generic xAPI handling.
- *
- * @package core_xapi
- * @since Moodle 3.9
- * @copyright 2020 Ferran Recio
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_xapi\external;
use core_xapi\local\statement;
use core_xapi\handler;
use core_xapi\xapi_exception;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_value;
use core_component;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir .'/externallib.php');
-
/**
* This is the external API for generic xAPI handling.
*
+ * @package core_xapi
+ * @since Moodle 3.9
* @copyright 2020 Ferran Recio
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/lib/xapi/tests/external/post_statement_test.php b/lib/xapi/tests/external/post_statement_test.php
index f3986ec77dbfd..1502b6ee098d9 100644
--- a/lib/xapi/tests/external/post_statement_test.php
+++ b/lib/xapi/tests/external/post_statement_test.php
@@ -33,7 +33,7 @@
use core_xapi\local\statement\item_activity;
use externallib_advanced_testcase;
use stdClass;
-use external_api;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
diff --git a/login/tests/login_notifications_test.php b/login/tests/login_notifications_test.php
index eecd58f52e23d..f3d0d898c0284 100644
--- a/login/tests/login_notifications_test.php
+++ b/login/tests/login_notifications_test.php
@@ -16,11 +16,6 @@
namespace core;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->dirroot . '/lib/externallib.php');
-
/**
* Contains tests for course related notifications.
*
@@ -30,15 +25,6 @@
*/
class login_notifications_test extends \advanced_testcase {
- /**
- * Load required classes
- */
- public static function setUpBeforeClass(): void {
- global $CFG;
-
- require_once($CFG->libdir . '/externallib.php');
- }
-
/**
* Test new login notification.
*/
@@ -171,7 +157,7 @@ public function test_mobile_app_login_notification() {
$USER->lastip = '1.2.3.4.6'; // Different ip that current.
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
\core_useragent::instance(true, 'MoodleMobile'); // Force fake mobile app user agent.
// Simulate we are using an new device.
@@ -189,7 +175,7 @@ public function test_mobile_app_login_notification() {
];
$DB->insert_record('user_devices', $fakedevice);
- external_log_token_request($token);
+ \core_external\util::log_token_request($token);
// Redirect messages to sink and stop buffer output from CLI task.
$sink = $this->redirectMessages();
@@ -220,7 +206,7 @@ public function test_mobile_app_login_notification_skip_same_ip() {
// Mock data for test.
$USER->lastip = '0.0.0.0';
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
\core_useragent::instance(true, 'MoodleMobile'); // Force fake mobile app user agent.
// Simulate we are using an new device.
@@ -238,7 +224,7 @@ public function test_mobile_app_login_notification_skip_same_ip() {
];
$DB->insert_record('user_devices', $fakedevice);
- external_log_token_request($token);
+ \core_external\util::log_token_request($token);
// Redirect messages to sink and stop buffer output from CLI task.
$sink = $this->redirectMessages();
@@ -267,10 +253,10 @@ public function test_mobile_app_login_notification_skip_same_device() {
// Mock data for test.
$USER->lastip = '1.2.3.4.6'; // New ip.
$service = $DB->get_record('external_services', array('shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE));
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
\core_useragent::instance(true, 'MoodleMobile'); // Force fake mobile app user agent.
- external_log_token_request($token);
+ \core_external\util::log_token_request($token);
// Redirect messages to sink and stop buffer output from CLI task.
$sink = $this->redirectMessages();
diff --git a/login/token.php b/login/token.php
index 4ba724ead9626..e8e7a90ee5020 100644
--- a/login/token.php
+++ b/login/token.php
@@ -26,7 +26,6 @@
define('NO_MOODLE_COOKIES', true);
require_once(__DIR__ . '/../config.php');
-require_once($CFG->libdir . '/externallib.php');
// Allow CORS requests.
header('Access-Control-Allow-Origin: *');
@@ -94,9 +93,9 @@
}
// Get an existing token or create a new one.
- $token = external_generate_token_for_current_user($service);
+ $token = \core_external\util::generate_token_for_current_user($service);
$privatetoken = $token->privatetoken;
- external_log_token_request($token);
+ \core_external\util::log_token_request($token);
$siteadmin = has_capability('moodle/site:config', $systemcontext, $USER->id);
diff --git a/media/player/videojs/classes/external/get_language.php b/media/player/videojs/classes/external/get_language.php
index 355be4ee89f1f..44b61a3c47c20 100644
--- a/media/player/videojs/classes/external/get_language.php
+++ b/media/player/videojs/classes/external/get_language.php
@@ -14,27 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External API to get language strings for the videojs.
- *
- * @package media_videojs
- * @copyright 2020 Shamim Rezaie
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace media_videojs\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
/**
* The API to get language strings for the videojs.
*
+ * @package media_videojs
* @copyright 2020 Shamim Rezaie
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/message/classes/external/get_unread_notification_count.php b/message/classes/external/get_unread_notification_count.php
index 65e02207c8286..874af68983af5 100644
--- a/message/classes/external/get_unread_notification_count.php
+++ b/message/classes/external/get_unread_notification_count.php
@@ -19,12 +19,11 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/message/lib.php');
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
use context_system;
use core_user;
use moodle_exception;
diff --git a/message/externallib.php b/message/externallib.php
index 6e6bc119497a6..a7a599d82f65e 100644
--- a/message/externallib.php
+++ b/message/externallib.php
@@ -14,7 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
/**
* External message API
*
@@ -24,9 +23,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
+
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . "/message/lib.php");
/**
@@ -102,7 +109,7 @@ public static function send_messages_to_conversation(int $conversationid, array
$message['textformat']);
$createdmessage->text = message_format_message_text((object) [
'smallmessage' => $createdmessage->text,
- 'fullmessageformat' => external_validate_format($message['textformat']),
+ 'fullmessageformat' => util::validate_format($message['textformat']),
'fullmessagetrust' => $createdmessage->fullmessagetrust
]);
$messages[] = $createdmessage;
@@ -114,7 +121,7 @@ public static function send_messages_to_conversation(int $conversationid, array
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.6
*/
public static function send_messages_to_conversation_returns() {
@@ -212,7 +219,7 @@ public static function send_instant_messages($messages = array()) {
if ($success) {
// TODO MDL-31118 performance improvement - edit the function so we can pass an array instead one touser object.
$success = message_post_message($USER, $tousers[$message['touserid']],
- $message['text'], external_validate_format($message['textformat']));
+ $message['text'], util::validate_format($message['textformat']));
}
// Build the resultmsg.
@@ -251,7 +258,7 @@ public static function send_instant_messages($messages = array()) {
$resultmessage['useridfrom'] = $USER->id;
$resultmessage['text'] = message_format_message_text((object) [
'smallmessage' => $messagerecords[$id]->smallmessage,
- 'fullmessageformat' => external_validate_format($messagerecords[$id]->fullmessageformat),
+ 'fullmessageformat' => util::validate_format($messagerecords[$id]->fullmessageformat),
'fullmessagetrust' => $messagerecords[$id]->fullmessagetrust
]);
return $resultmessage;
@@ -264,7 +271,7 @@ public static function send_instant_messages($messages = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function send_instant_messages_returns() {
@@ -346,7 +353,7 @@ public static function delete_contacts($userids, $userid = 0) {
/**
* Delete contacts return description.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function delete_contacts_returns() {
@@ -374,7 +381,7 @@ public static function mute_conversations_parameters() {
*
* @param int $userid The id of the user who is blocking
* @param array $conversationids The list of conversations being muted
- * @return external_description
+ * @return \core_external\external_description
*/
public static function mute_conversations(int $userid, array $conversationids) {
global $CFG, $USER;
@@ -408,7 +415,7 @@ public static function mute_conversations(int $userid, array $conversationids) {
/**
* Mute conversations return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function mute_conversations_returns() {
return new external_warnings();
@@ -466,7 +473,7 @@ public static function unmute_conversations(int $userid, array $conversationids)
/**
* Unmute conversations return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function unmute_conversations_returns() {
return new external_warnings();
@@ -491,7 +498,7 @@ public static function block_user_parameters() {
*
* @param int $userid The id of the user who is blocking
* @param int $blockeduserid The id of the user being blocked
- * @return external_description
+ * @return \core_external\external_description
*/
public static function block_user(int $userid, int $blockeduserid) {
global $CFG, $USER;
@@ -528,7 +535,7 @@ public static function block_user(int $userid, int $blockeduserid) {
/**
* Block user return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function block_user_returns() {
return new external_warnings();
@@ -582,7 +589,7 @@ public static function unblock_user(int $userid, int $unblockeduserid) {
/**
* Unblock user return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function unblock_user_returns() {
return new external_warnings();
@@ -645,7 +652,7 @@ public static function get_contact_requests(int $userid, int $limitfrom = 0, int
/**
* Returns the contact requests return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_contact_requests_returns() {
return new external_multiple_structure(
@@ -778,7 +785,7 @@ public static function get_conversation_members(int $userid, int $conversationid
/**
* Returns the get conversation members return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_conversation_members_returns() {
return new external_multiple_structure(
@@ -852,7 +859,7 @@ public static function create_contact_request(int $userid, int $requesteduserid)
/**
* Creates a contact request return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function create_contact_request_returns() {
return new external_single_structure(
@@ -920,7 +927,7 @@ public static function confirm_contact_request(int $userid, int $requesteduserid
/**
* Confirm a contact request return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function confirm_contact_request_returns() {
return new external_warnings();
@@ -974,7 +981,7 @@ public static function decline_contact_request(int $userid, int $requesteduserid
/**
* Declines a contact request return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function decline_contact_request_returns() {
return new external_warnings();
@@ -1865,7 +1872,7 @@ public static function search_contacts_parameters() {
*
* @param string $searchtext query string.
* @param bool $onlymycourses limit the search to the user's courses only.
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function search_contacts($searchtext, $onlymycourses = false) {
@@ -1930,7 +1937,7 @@ public static function search_contacts($searchtext, $onlymycourses = false) {
/**
* Search contacts return description.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function search_contacts_returns() {
@@ -1987,7 +1994,7 @@ public static function get_messages_parameters() {
* @param bool $newestfirst true for ordering by newest first, false for oldest first
* @param int $limitfrom limit from
* @param int $limitnum limit num
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_messages($useridto, $useridfrom = 0, $type = 'both', $read = MESSAGE_GET_READ,
$newestfirst = true, $limitfrom = 0, $limitnum = 0) {
@@ -2219,7 +2226,7 @@ public static function mark_all_notifications_as_read_parameters() {
* @param int $useridto the user id who received the message
* @param int $useridfrom the user id who send the message. -10 or -20 for no-reply or support user
* @param int $timecreatedto mark message created before this time as read, 0 for all messages
- * @return external_description
+ * @return \core_external\external_description
*/
public static function mark_all_notifications_as_read($useridto, $useridfrom, $timecreatedto = 0) {
global $USER;
@@ -2296,7 +2303,7 @@ public static function get_unread_conversations_count_parameters() {
* @throws invalid_parameter_exception
* @throws moodle_exception
* @param int $useridto the user id who received the message
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_unread_conversations_count($useridto) {
global $USER, $CFG;
@@ -2364,7 +2371,7 @@ public static function get_blocked_users_parameters() {
* Retrieve a list of users blocked
*
* @param int $userid the user whose blocked users we want to retrieve
- * @return external_description
+ * @return \core_external\external_description
* @since 2.9
*/
public static function get_blocked_users($userid) {
@@ -2467,7 +2474,7 @@ public static function mark_message_read_parameters() {
*
* @param int $messageid id of the message (in the message table)
* @param int $timeread timestamp for when the message should be marked read
- * @return external_description
+ * @return \core_external\external_description
* @throws invalid_parameter_exception
* @throws moodle_exception
* @since 2.9
@@ -2533,7 +2540,7 @@ public static function mark_message_read($messageid, $timeread) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 2.9
*/
public static function mark_message_read_returns() {
@@ -2567,7 +2574,7 @@ public static function mark_notification_read_parameters() {
*
* @param int $notificationid id of the notification
* @param int $timeread timestamp for when the notification should be marked read
- * @return external_description
+ * @return \core_external\external_description
* @throws invalid_parameter_exception
* @throws moodle_exception
*/
@@ -2614,7 +2621,7 @@ public static function mark_notification_read($notificationid, $timeread) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function mark_notification_read_returns() {
return new external_single_structure(
@@ -2748,7 +2755,7 @@ public static function delete_conversations_by_id($userid, array $conversationid
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.6
*/
public static function delete_conversations_by_id_returns() {
@@ -2777,7 +2784,7 @@ public static function delete_message_parameters() {
* @param int $messageid the message id
* @param int $userid the user id of who we want to delete the message for
* @param bool $read if is a message read (default to true)
- * @return external_description
+ * @return \core_external\external_description
* @throws moodle_exception
* @since 3.1
*/
@@ -2823,7 +2830,7 @@ public static function delete_message($messageid, $userid, $read = true) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.1
*/
public static function delete_message_returns() {
@@ -2866,7 +2873,7 @@ public static function message_processor_config_form_parameters() {
* @param int $userid the user id
* @param string $name the name of the processor
* @param array $formvalues the form values
- * @return external_description
+ * @return \core_external\external_description
* @throws moodle_exception
* @since 3.2
*/
@@ -2904,7 +2911,7 @@ public static function message_processor_config_form($userid, $name, $formvalues
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.2
*/
public static function message_processor_config_form_returns() {
@@ -2931,7 +2938,7 @@ public static function get_message_processor_parameters() {
*
* @param int $userid
* @param string $name the name of the processor
- * @return external_description
+ * @return \core_external\external_description
* @throws moodle_exception
* @since 3.2
*/
@@ -2970,7 +2977,7 @@ public static function get_message_processor($userid, $name) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.2
*/
public static function get_message_processor_returns() {
@@ -3110,7 +3117,7 @@ public static function get_user_notification_preferences_parameters() {
* Get the notification preferences for a given user.
*
* @param int $userid id of the user, 0 for current user
- * @return external_description
+ * @return \core_external\external_description
* @throws moodle_exception
* @since 3.2
*/
@@ -3142,7 +3149,7 @@ public static function get_user_notification_preferences($userid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.2
*/
public static function get_user_notification_preferences_returns() {
@@ -3172,7 +3179,7 @@ public static function get_user_message_preferences_parameters() {
* Get the notification preferences for a given user.
*
* @param int $userid id of the user, 0 for current user
- * @return external_description
+ * @return \core_external\external_description
* @throws moodle_exception
* @since 3.2
*/
@@ -3220,7 +3227,7 @@ public static function get_user_message_preferences($userid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.2
*/
public static function get_user_message_preferences_returns() {
@@ -3287,7 +3294,7 @@ public static function set_favourite_conversations(int $userid, array $conversat
/**
* Return a description of the returns for the create_user_favourite_conversations() method.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function set_favourite_conversations_returns() {
return new external_warnings();
@@ -3346,7 +3353,7 @@ public static function unset_favourite_conversations(int $userid, array $convers
/**
* Unset favourite conversations return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function unset_favourite_conversations_returns() {
return new external_warnings();
@@ -3418,7 +3425,7 @@ public static function get_member_info(
/**
* Get member info return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_member_info_returns() {
return new external_multiple_structure(
@@ -3483,7 +3490,7 @@ public static function get_conversation_counts(int $userid) {
/**
* Get conversation counts return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_conversation_counts_returns() {
return new external_single_structure(
@@ -3560,7 +3567,7 @@ public static function get_unread_conversation_counts(int $userid) {
/**
* Get unread conversation counts return description.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_unread_conversation_counts_returns() {
return new external_single_structure(
@@ -3599,7 +3606,7 @@ public static function delete_message_for_all_users_parameters() {
*
* @param int $messageid the message id
* @param int $userid the user id of who we want to delete the message for all users, is no longer used.
- * @return external_description
+ * @return \core_external\external_description
* @throws moodle_exception
* @since 3.7
*/
@@ -3636,7 +3643,7 @@ public static function delete_message_for_all_users(int $messageid, int $userid)
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since 3.7
*/
public static function delete_message_for_all_users_returns() {
diff --git a/message/output/airnotifier/externallib.php b/message/output/airnotifier/externallib.php
index a5275ec20221c..696e5f4bc3305 100644
--- a/message/output/airnotifier/externallib.php
+++ b/message/output/airnotifier/externallib.php
@@ -14,19 +14,12 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External functions
- *
- * @package message_airnotifier
- * @category external
- * @copyright 2012 Jerome Mouneyrac
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 2.7
- */
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* External API for airnotifier web services
diff --git a/message/output/airnotifier/tests/externallib_test.php b/message/output/airnotifier/tests/externallib_test.php
index 218c603b11711..406cacb6260b0 100644
--- a/message/output/airnotifier/tests/externallib_test.php
+++ b/message/output/airnotifier/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace message_airnotifier;
+use core_external\external_api;
use externallib_advanced_testcase;
use message_airnotifier_external;
@@ -56,7 +57,7 @@ public function test_is_system_configured() {
// In a clean installation, it should be not configured.
$configured = message_airnotifier_external::is_system_configured();
- $configured = \external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured);
+ $configured = external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured);
$this->assertEquals(0, $configured);
// Fake configuration.
@@ -65,7 +66,7 @@ public function test_is_system_configured() {
$DB->set_field('message_processors', 'enabled', 1, array('name' => 'airnotifier'));
$configured = message_airnotifier_external::is_system_configured();
- $configured = \external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured);
+ $configured = external_api::clean_returnvalue(message_airnotifier_external::is_system_configured_returns(), $configured);
$this->assertEquals(1, $configured);
}
@@ -89,7 +90,7 @@ public function test_are_notification_preferences_configured() {
$preferences = message_airnotifier_external::are_notification_preferences_configured($params);
$returnsdescription = message_airnotifier_external::are_notification_preferences_configured_returns();
- $preferences = \external_api::clean_returnvalue($returnsdescription, $preferences);
+ $preferences = external_api::clean_returnvalue($returnsdescription, $preferences);
$expected = array(
array(
@@ -105,7 +106,7 @@ public function test_are_notification_preferences_configured() {
// Now, remove one user.
delete_user($user2);
$preferences = message_airnotifier_external::are_notification_preferences_configured($params);
- $preferences = \external_api::clean_returnvalue($returnsdescription, $preferences);
+ $preferences = external_api::clean_returnvalue($returnsdescription, $preferences);
$this->assertEquals(1, count($preferences['users']));
$this->assertEquals($expected, $preferences['users']);
$this->assertEquals(2, count($preferences['warnings']));
@@ -113,7 +114,7 @@ public function test_are_notification_preferences_configured() {
// Now, remove one user1 preference (the user still has one preference for airnotifier).
unset_user_preference('message_provider_moodle_instantmessage_enabled', $user1);
$preferences = message_airnotifier_external::are_notification_preferences_configured($params);
- $preferences = \external_api::clean_returnvalue($returnsdescription, $preferences);
+ $preferences = external_api::clean_returnvalue($returnsdescription, $preferences);
$this->assertEquals($expected, $preferences['users']);
}
@@ -129,7 +130,7 @@ public function test_get_user_devices() {
// System not configured.
$devices = message_airnotifier_external::get_user_devices('');
- $devices = \external_api::clean_returnvalue(message_airnotifier_external::get_user_devices_returns(), $devices);
+ $devices = external_api::clean_returnvalue(message_airnotifier_external::get_user_devices_returns(), $devices);
$this->assertCount(1, $devices['warnings']);
$this->assertEquals('systemnotconfigured', $devices['warnings'][0]['warningcode']);
@@ -140,7 +141,7 @@ public function test_get_user_devices() {
// Get devices.
$devices = message_airnotifier_external::get_user_devices('');
- $devices = \external_api::clean_returnvalue(message_airnotifier_external::get_user_devices_returns(), $devices);
+ $devices = external_api::clean_returnvalue(message_airnotifier_external::get_user_devices_returns(), $devices);
$this->assertCount(0, $devices['warnings']);
// No devices, unfortunatelly we cannot create devices (we can't mock airnotifier server).
$this->assertCount(0, $devices['devices']);
@@ -195,13 +196,13 @@ public function test_enable_device() {
// Disable and enable.
$result = message_airnotifier_external::enable_device($airnotifierdevid, false);
- $result = \external_api::clean_returnvalue(message_airnotifier_external::enable_device_returns(), $result);
+ $result = external_api::clean_returnvalue(message_airnotifier_external::enable_device_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertTrue($result['success']);
$this->assertEquals(0, $DB->get_field('message_airnotifier_devices', 'enable', array('id' => $airnotifierdevid)));
$result = message_airnotifier_external::enable_device($airnotifierdevid, true);
- $result = \external_api::clean_returnvalue(message_airnotifier_external::enable_device_returns(), $result);
+ $result = external_api::clean_returnvalue(message_airnotifier_external::enable_device_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertTrue($result['success']);
$this->assertEquals(1, $DB->get_field('message_airnotifier_devices', 'enable', array('id' => $airnotifierdevid)));
diff --git a/message/output/popup/externallib.php b/message/output/popup/externallib.php
index 5925b277b540b..91d654b9f9db3 100644
--- a/message/output/popup/externallib.php
+++ b/message/output/popup/externallib.php
@@ -14,6 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
/**
@@ -25,7 +32,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . "/message/lib.php");
/**
@@ -67,7 +73,7 @@ public static function get_popup_notifications_parameters() {
* @param bool $newestfirst true for ordering by newest first, false for oldest first
* @param int $limit the number of results to return
* @param int $offset offset the result set by a given amount
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_popup_notifications($useridto, $newestfirst, $limit, $offset) {
global $USER, $PAGE;
@@ -196,7 +202,7 @@ public static function get_unread_popup_notification_count_parameters() {
* @throws invalid_parameter_exception
* @throws moodle_exception
* @param int $useridto the user id who received the message
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_unread_popup_notification_count($useridto) {
global $USER;
diff --git a/message/tests/external/get_unread_notification_count_test.php b/message/tests/external/get_unread_notification_count_test.php
index feef3c20f047b..c9dc9502d60d1 100644
--- a/message/tests/external/get_unread_notification_count_test.php
+++ b/message/tests/external/get_unread_notification_count_test.php
@@ -21,7 +21,7 @@
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use \core_message\tests\helper as testhelper;
diff --git a/message/tests/externallib_test.php b/message/tests/externallib_test.php
index 1ff834c6e9d07..8113607ac4300 100644
--- a/message/tests/externallib_test.php
+++ b/message/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace core_message;
+use core_external\external_api;
use core_message\tests\helper as testhelper;
use core_message_external;
use externallib_advanced_testcase;
@@ -125,7 +126,7 @@ public function test_send_instant_messages() {
$messages = array($message1);
$sentmessages = core_message_external::send_instant_messages($messages);
- $sentmessages = \external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$this->assertEquals(
get_string('usercantbemessaged', 'message', fullname(\core_user::get_user($message1['touserid']))),
array_pop($sentmessages)['errormessage']
@@ -137,7 +138,7 @@ public function test_send_instant_messages() {
// Send message again. Now it should work properly.
$sentmessages = core_message_external::send_instant_messages($messages);
// We need to execute the return values cleaning process to simulate the web service server.
- $sentmessages = \external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$sentmessage = reset($sentmessages);
@@ -186,7 +187,7 @@ public function test_send_instant_messages_long_text() {
\core_message\api::add_contact($user1->id, $user2->id);
$sentmessages = core_message_external::send_instant_messages($messages);
- $sentmessages = \external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$this->assertEquals(
get_string('errormessagetoolong', 'message'),
array_pop($sentmessages)['errormessage']
@@ -219,7 +220,7 @@ public function test_send_instant_messages_blocked_user() {
$messages = array($message1);
$sentmessages = core_message_external::send_instant_messages($messages);
- $sentmessages = \external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$sentmessage = reset($sentmessages);
@@ -255,7 +256,7 @@ public function test_send_instant_messages_block_non_contacts() {
$messages = array($message1);
$sentmessages = core_message_external::send_instant_messages($messages);
- $sentmessages = \external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$sentmessage = reset($sentmessages);
@@ -293,7 +294,7 @@ public function test_send_instant_messages_block_non_contacts_but_am_contact() {
$messages = array($message1);
$sentmessages = core_message_external::send_instant_messages($messages);
- $sentmessages = \external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
+ $sentmessages = external_api::clean_returnvalue(core_message_external::send_instant_messages_returns(), $sentmessages);
$sentmessage = reset($sentmessages);
@@ -442,7 +443,7 @@ public function test_get_contact_requests() {
\core_message\api::create_contact_request($user3->id, $user1->id);
$requests = core_message_external::get_contact_requests($user1->id);
- $requests = \external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
+ $requests = external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
$this->assertCount(1, $requests);
@@ -477,7 +478,7 @@ public function test_get_contact_requests_blocked_sender() {
// Verify we don't see the contact request from the blocked user User2 in the requests for User1.
$this->setUser($user1);
$requests = core_message_external::get_contact_requests($user1->id);
- $requests = \external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
+ $requests = external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
$this->assertCount(0, $requests);
}
@@ -493,7 +494,7 @@ public function test_get_contact_requests_no_requests() {
$this->setUser($user1);
$requests = core_message_external::get_contact_requests($user1->id);
- $requests = \external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
+ $requests = external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
$this->assertEmpty($requests);
}
@@ -514,7 +515,7 @@ public function test_get_contact_requests_with_limits() {
\core_message\api::create_contact_request($user3->id, $user1->id);
$requests = core_message_external::get_contact_requests($user1->id, 0, 1);
- $requests = \external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
+ $requests = external_api::clean_returnvalue(core_message_external::get_contact_requests_returns(), $requests);
$this->assertCount(1, $requests);
}
@@ -572,21 +573,21 @@ public function test_get_received_contact_requests_count() {
$this->setUser($user1);
$contactrequestnumber = core_message_external::get_received_contact_requests_count($user1->id);
- $contactrequestnumber = \external_api::clean_returnvalue(
+ $contactrequestnumber = external_api::clean_returnvalue(
core_message_external::get_received_contact_requests_count_returns(), $contactrequestnumber);
$this->assertEquals(0, $contactrequestnumber);
\core_message\api::create_contact_request($user2->id, $user1->id);
$contactrequestnumber = core_message_external::get_received_contact_requests_count($user1->id);
- $contactrequestnumber = \external_api::clean_returnvalue(
+ $contactrequestnumber = external_api::clean_returnvalue(
core_message_external::get_received_contact_requests_count_returns(), $contactrequestnumber);
$this->assertEquals(1, $contactrequestnumber);
\core_message\api::create_contact_request($user3->id, $user1->id);
$contactrequestnumber = core_message_external::get_received_contact_requests_count($user1->id);
- $contactrequestnumber = \external_api::clean_returnvalue(
+ $contactrequestnumber = external_api::clean_returnvalue(
core_message_external::get_received_contact_requests_count_returns(), $contactrequestnumber);
$this->assertEquals(2, $contactrequestnumber);
@@ -594,7 +595,7 @@ public function test_get_received_contact_requests_count() {
// Web service should ignore sent requests.
$contactrequestnumber = core_message_external::get_received_contact_requests_count($user1->id);
- $contactrequestnumber = \external_api::clean_returnvalue(
+ $contactrequestnumber = external_api::clean_returnvalue(
core_message_external::get_received_contact_requests_count_returns(), $contactrequestnumber);
$this->assertEquals(2, $contactrequestnumber);
}
@@ -616,7 +617,7 @@ public function test_get_received_contact_requests_count_blocked_sender() {
// Verify we don't see the contact request from the blocked user User2 in the count for User1.
$this->setUser($user1);
$contactrequestnumber = core_message_external::get_received_contact_requests_count($user1->id);
- $contactrequestnumber = \external_api::clean_returnvalue(
+ $contactrequestnumber = external_api::clean_returnvalue(
core_message_external::get_received_contact_requests_count_returns(), $contactrequestnumber);
$this->assertEquals(0, $contactrequestnumber);
}
@@ -676,7 +677,7 @@ public function test_create_contact_request() {
$CFG->messagingallusers = 1;
$return = core_message_external::create_contact_request($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::create_contact_request_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::create_contact_request_returns(), $return);
$this->assertEquals([], $return['warnings']);
$request = $DB->get_records('message_contact_requests');
@@ -707,7 +708,7 @@ public function test_create_contact_request_not_allowed() {
$CFG->messagingallusers = 0;
$return = core_message_external::create_contact_request($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::create_contact_request_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::create_contact_request_returns(), $return);
$warning = reset($return['warnings']);
@@ -775,7 +776,7 @@ public function test_confirm_contact_request() {
$this->setUser($user2);
$return = core_message_external::confirm_contact_request($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::confirm_contact_request_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::confirm_contact_request_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_contact_requests'));
@@ -848,7 +849,7 @@ public function test_decline_contact_request() {
$this->setUser($user2);
$return = core_message_external::decline_contact_request($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::decline_contact_request_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::decline_contact_request_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_contact_requests'));
@@ -913,7 +914,7 @@ public function test_mute_conversations() {
// Muting a conversation.
$return = core_message_external::mute_conversations($user1->id, [$conversation->id]);
- $return = \external_api::clean_returnvalue(core_message_external::mute_conversations_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::mute_conversations_returns(), $return);
$this->assertEquals(array(), $return);
// Get list of muted conversations.
@@ -925,7 +926,7 @@ public function test_mute_conversations() {
// Muting a conversation that is already muted.
$return = core_message_external::mute_conversations($user1->id, [$conversation->id]);
- $return = \external_api::clean_returnvalue(core_message_external::mute_conversations_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::mute_conversations_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(1, $DB->count_records('message_conversation_actions'));
@@ -998,14 +999,14 @@ public function test_unmute_conversations() {
// Unmuting a conversation.
$return = core_message_external::unmute_conversations($user1->id, [$conversation->id]);
- $return = \external_api::clean_returnvalue(core_message_external::unmute_conversations_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::unmute_conversations_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_conversation_actions'));
// Unmuting a conversation which is already unmuted.
$return = core_message_external::unmute_conversations($user1->id, [$conversation->id]);
- $return = \external_api::clean_returnvalue(core_message_external::unmute_conversations_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::unmute_conversations_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_conversation_actions'));
@@ -1072,7 +1073,7 @@ public function test_block_user() {
// Blocking a user.
$return = core_message_external::block_user($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::block_user_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::block_user_returns(), $return);
$this->assertEquals(array(), $return);
// Get list of blocked users.
@@ -1083,7 +1084,7 @@ public function test_block_user() {
// Blocking a user who is already blocked.
$return = core_message_external::block_user($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::block_user_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::block_user_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(1, $DB->count_records('message_users_blocked'));
@@ -1107,7 +1108,7 @@ public function test_block_user_when_ineffective() {
// Blocking a user.
$return = core_message_external::block_user($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::block_user_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::block_user_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_users_blocked'));
@@ -1171,14 +1172,14 @@ public function test_unblock_user() {
// Unblocking a user.
$return = core_message_external::unblock_user($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::unblock_user_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::unblock_user_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_users_blocked'));
// Unblocking a user who is already unblocked.
$return = core_message_external::unblock_user($user1->id, $user2->id);
- $return = \external_api::clean_returnvalue(core_message_external::unblock_user_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::unblock_user_returns(), $return);
$this->assertEquals(array(), $return);
$this->assertEquals(0, $DB->count_records('message_users_blocked'));
@@ -1263,25 +1264,25 @@ public function test_search_contacts() {
$this->setUser($user1);
$results = core_message_external::search_contacts('r');
- $results = \external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
+ $results = external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
$this->assertCount(5, $results); // Users 2 through 5 + admin
$results = core_message_external::search_contacts('r', true);
- $results = \external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
+ $results = external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
$this->assertCount(2, $results);
$results = core_message_external::search_contacts('Kyle', false);
- $results = \external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
+ $results = external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
$this->assertCount(1, $results);
$result = reset($results);
$this->assertEquals($user4->id, $result['id']);
$results = core_message_external::search_contacts('y', false);
- $results = \external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
+ $results = external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
$this->assertCount(2, $results);
$results = core_message_external::search_contacts('y', true);
- $results = \external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
+ $results = external_api::clean_returnvalue(core_message_external::search_contacts_returns(), $results);
$this->assertCount(1, $results);
$result = reset($results);
$this->assertEquals($user5->id, $result['id']);
@@ -1321,51 +1322,51 @@ public function test_get_messages() {
$this->setUser($user1);
// Get unread conversations from user1 to user2.
$messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['messages']);
$this->assertEquals($im1, $messages['messages'][0]['id']);
// Get read conversations from user1 to user2.
$messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', MESSAGE_GET_READ, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['messages']);
$this->assertEquals($im6, $messages['messages'][0]['id']);
// Get both read and unread conversations from user1 to user2.
$messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', MESSAGE_GET_READ_AND_UNREAD,
true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(2, $messages['messages']);
// Delete an unread message.
\core_message\api::delete_message($user1->id, $im1);
$messages = core_message_external::get_messages($user2->id, $user1->id, 'conversations', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(0, $messages['messages']);
$this->setUser($user2);
// Get unread conversations from any user to user2.
$messages = core_message_external::get_messages($user2->id, 0, 'conversations', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(2, $messages['messages']);
// Conversations from user3 to user2.
$messages = core_message_external::get_messages($user2->id, $user3->id, 'conversations', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['messages']);
// Delete the message.
\core_message\api::delete_message($user2->id, $im4);
$messages = core_message_external::get_messages($user2->id, $user3->id, 'conversations', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(0, $messages['messages']);
$this->setUser($user3);
// Get unread notifications received by user3.
$messages = core_message_external::get_messages($user3->id, 0, 'notifications', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(0, $messages['messages']);
// Now, create some notifications...
@@ -1454,32 +1455,32 @@ public function test_get_messages() {
$this->setUser($user1);
// Get unread notifications from any user to user1.
$messages = core_message_external::get_messages($user1->id, 0, 'notifications', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(3, $messages['messages']);
// Get one unread notifications from any user to user1.
$messages = core_message_external::get_messages($user1->id, 0, 'notifications', MESSAGE_GET_UNREAD, true, 0, 1);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['messages']);
// Get read notifications from any user to user1.
$messages = core_message_external::get_messages($user1->id, 0, 'notifications', MESSAGE_GET_READ, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(0, $messages['messages']);
// Get unread both type of messages from any user to user1.
$messages = core_message_external::get_messages($user1->id, 0, 'both', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(4, $messages['messages']);
// Get unread notifications from no-reply-user to user1.
$messages = core_message_external::get_messages($user1->id, $userfrom->id, 'notifications', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['messages']);
// Get notifications send by user1 to any user.
$messages = core_message_external::get_messages(0, $user1->id, 'notifications', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['messages']);
// Check we receive custom data as a unserialisable json.
$this->assertObjectHasAttribute('datakey', json_decode($messages['messages'][0]['customdata']));
@@ -1492,7 +1493,7 @@ public function test_get_messages() {
$CFG->messaging = 0;
$messages = core_message_external::get_messages(0, $user1->id, 'both', MESSAGE_GET_UNREAD, true, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
$this->assertCount(1, $messages['warnings']);
// Test exceptions.
@@ -1552,7 +1553,7 @@ public function test_get_messages_useridto_all() {
// Get messages sent from user 1.
$messages = core_message_external::get_messages(0, $user1->id, 'conversations', MESSAGE_GET_UNREAD, false, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
// Confirm the data is correct.
$messages = $messages['messages'];
@@ -1586,7 +1587,7 @@ public function test_get_messages_useridfrom_all() {
// Get messages sent to user 1.
$messages = core_message_external::get_messages($user1->id, 0, 'conversations', MESSAGE_GET_UNREAD, false, 0, 0);
- $messages = \external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
+ $messages = external_api::clean_returnvalue(core_message_external::get_messages_returns(), $messages);
// Confirm the data is correct.
$messages = $messages['messages'];
@@ -1631,19 +1632,19 @@ public function test_get_blocked_users() {
// Retrieve the list of blocked users.
$this->setUser($user1);
$blockedusers = core_message_external::get_blocked_users($user1->id);
- $blockedusers = \external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
+ $blockedusers = external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
$this->assertCount(0, $blockedusers['users']);
// Block the $userblocked and retrieve again the list.
\core_message\api::block_user($user1->id, $userblocked->id);
$blockedusers = core_message_external::get_blocked_users($user1->id);
- $blockedusers = \external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
+ $blockedusers = external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
$this->assertCount(1, $blockedusers['users']);
// Remove the $userblocked and check that the list now is empty.
delete_user($userblocked);
$blockedusers = core_message_external::get_blocked_users($user1->id);
- $blockedusers = \external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
+ $blockedusers = external_api::clean_returnvalue(core_message_external::get_blocked_users_returns(), $blockedusers);
$this->assertCount(0, $blockedusers['users']);
}
@@ -1674,7 +1675,7 @@ public function test_mark_message_read() {
$messageids = array();
foreach ($lastmessages as $m) {
$messageid = core_message_external::mark_message_read($m->id, time());
- $messageids[] = \external_api::clean_returnvalue(core_message_external::mark_message_read_returns(), $messageid);
+ $messageids[] = external_api::clean_returnvalue(core_message_external::mark_message_read_returns(), $messageid);
}
// Retrieve all messages sent (they are currently read).
@@ -1733,7 +1734,7 @@ public function test_mark_notification_read() {
$notificationids = array();
foreach ($lastnotifications as $n) {
$notificationid = core_message_external::mark_notification_read($n->id, time());
- $notificationids[] = \external_api::clean_returnvalue(core_message_external::mark_notification_read_returns(),
+ $notificationids[] = external_api::clean_returnvalue(core_message_external::mark_notification_read_returns(),
$notificationid);
}
@@ -1794,7 +1795,7 @@ public function test_delete_message() {
// Delete a message not read, as a user from.
$result = core_message_external::delete_message($m1to2, $user1->id, false);
- $result = \external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
$mua = $DB->get_record('message_user_actions', array('messageid' => $m1to2, 'userid' => $user1->id));
@@ -1802,7 +1803,7 @@ public function test_delete_message() {
// Try to delete the same message again.
$result = core_message_external::delete_message($m1to2, $user1->id, false);
- $result = \external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
$this->assertFalse($result['status']);
// Try to delete a message that does not belong to me.
@@ -1816,7 +1817,7 @@ public function test_delete_message() {
$this->setUser($user3);
// Delete a message not read, as a user to.
$result = core_message_external::delete_message($m2to3, $user3->id, false);
- $result = \external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
$this->assertTrue($DB->record_exists('message_user_actions', array('messageid' => $m2to3, 'userid' => $user3->id,
@@ -1826,7 +1827,7 @@ public function test_delete_message() {
$message = $DB->get_record('messages', ['id' => $m3to2]);
\core_message\api::mark_message_as_read($user3->id, $message, time());
$result = core_message_external::delete_message($m3to2, $user3->id);
- $result = \external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
$this->assertTrue($DB->record_exists('message_user_actions', array('messageid' => $m3to2, 'userid' => $user3->id,
@@ -1860,7 +1861,7 @@ public function test_delete_message() {
// Now, as an admin, try to delete any message.
$this->setAdminUser();
$result = core_message_external::delete_message($m3to4, $user4->id, false);
- $result = \external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::delete_message_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
$this->assertTrue($DB->record_exists('message_user_actions', array('messageid' => $m3to4, 'userid' => $user4->id,
@@ -1983,7 +1984,7 @@ public function test_get_user_notification_preferences() {
set_user_preference('message_provider_mod_assign_assign_notification_enabled', 'popup', $user);
$prefs = core_message_external::get_user_notification_preferences();
- $prefs = \external_api::clean_returnvalue(core_message_external::get_user_notification_preferences_returns(), $prefs);
+ $prefs = external_api::clean_returnvalue(core_message_external::get_user_notification_preferences_returns(), $prefs);
// Check processors.
$this->assertGreaterThanOrEqual(2, count($prefs['preferences']['processors']));
$this->assertEquals($user->id, $prefs['preferences']['userid']);
@@ -2079,7 +2080,7 @@ public function test_message_search_users_messagingallusers_disabled() {
// Perform a search with $CFG->messagingallusers disabled.
set_config('messagingallusers', 0);
$result = core_message_external::message_search_users($users[1]->id, 'search');
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
// Confirm that we returns contacts and non-contacts.
$this->assertArrayHasKey('contacts', $result);
@@ -2175,7 +2176,7 @@ public function test_message_search_users_messagingallusers_enabled() {
// Perform a search with $CFG->messagingallusers enabled.
set_config('messagingallusers', 1);
$result = core_message_external::message_search_users($users[1]->id, 'search');
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
// Confirm that we returns contacts and non-contacts.
$this->assertArrayHasKey('contacts', $result);
@@ -2239,7 +2240,7 @@ public function test_message_search_users_self_conversations() {
// Perform a search as user1.
$this->setUser($user1);
$result = core_message_external::message_search_users($user1->id, 'One');
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
// Check results are empty.
$this->assertCount(0, $result['contacts']);
@@ -2265,7 +2266,7 @@ public function test_message_search_users_with_empty_result() {
// Perform a search as user1.
$this->setUser($user1);
$result = core_message_external::message_search_users($user1->id, 'search');
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
// Check results are empty.
$this->assertCount(0, $result['contacts']);
@@ -2306,7 +2307,7 @@ public function test_message_search_users_limit_offset() {
// Search using a limit of 3.
// This tests the case where we have more results than the limit for both contacts and non-contacts.
$result = core_message_external::message_search_users($users[1]->id, 'search', 0, 3);
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
$contacts = $result['contacts'];
$noncontacts = $result['noncontacts'];
@@ -2326,7 +2327,7 @@ public function test_message_search_users_limit_offset() {
// Now, offset to get the next batch of results.
// We expect to see 2 contacts, and 3 non-contacts.
$result = core_message_external::message_search_users($users[1]->id, 'search', 3, 3);
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
$contacts = $result['contacts'];
$noncontacts = $result['noncontacts'];
$this->assertCount(2, $contacts);
@@ -2341,7 +2342,7 @@ public function test_message_search_users_limit_offset() {
// Now, offset to get the next batch of results.
// We expect to see 0 contacts, and 2 non-contacts.
$result = core_message_external::message_search_users($users[1]->id, 'search', 6, 3);
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
$contacts = $result['contacts'];
$noncontacts = $result['noncontacts'];
$this->assertCount(0, $contacts);
@@ -2390,7 +2391,7 @@ public function test_message_search_users_with_cap() {
// Perform a search with $CFG->messagingallusers disabled.
set_config('messagingallusers', 0);
$result = core_message_external::message_search_users($users[1]->id, 'search');
- $result = \external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::message_search_users_returns(), $result);
$contacts = $result['contacts'];
$noncontacts = $result['noncontacts'];
@@ -2472,7 +2473,7 @@ public function test_messagearea_search_messages() {
$result = core_message_external::data_for_messagearea_search_messages($user1->id, 'o');
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(), $result);
// Confirm the data is correct.
$messages = $result['contacts'];
@@ -2530,7 +2531,7 @@ public function test_messagearea_search_messages_as_other_user() {
$result = core_message_external::data_for_messagearea_search_messages($user1->id, 'o');
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::data_for_messagearea_search_messages_returns(),
$result);
// Confirm the data is correct.
@@ -2644,7 +2645,7 @@ public function test_get_user_contacts() {
$result = core_message_external::get_user_contacts($user1->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(),
$result);
// Confirm the data is correct.
@@ -2709,7 +2710,7 @@ public function test_get_user_contacts_as_other_user() {
$result = core_message_external::get_user_contacts($user1->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(),
$result);
// Confirm the data is correct.
@@ -2785,7 +2786,7 @@ public function test_get_user_contacts_no_results() {
$this->setUser($user1);
$requests = core_message_external::get_user_contacts($user1->id);
- $requests = \external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(), $requests);
+ $requests = external_api::clean_returnvalue(core_message_external::get_user_contacts_returns(), $requests);
$this->assertEmpty($requests);
}
@@ -2823,7 +2824,7 @@ public function test_get_conversation_messages() {
$result = core_message_external::get_conversation_messages($user1->id, $conversation->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(),
$result);
// Check the results are correct.
@@ -2896,7 +2897,7 @@ public function test_get_conversation_messages_timefrom() {
$result = core_message_external::get_conversation_messages($user1->id, $conversation->id, 0, 0, false, $time - 3);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(),
$result);
// Check the results are correct.
@@ -2952,7 +2953,7 @@ public function test_get_conversation_messages_as_other_user() {
$result = core_message_external::get_conversation_messages($user1->id, $conversation->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(),
$result);
// Check the results are correct.
@@ -3224,7 +3225,7 @@ public function test_get_unread_conversations_count() {
$result = core_message_external::get_unread_conversations_count($user1->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_unread_conversations_count_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_unread_conversations_count_returns(),
$result);
$this->assertEquals(3, $result);
@@ -3264,7 +3265,7 @@ public function test_get_unread_conversations_count_as_other_user() {
$result = core_message_external::get_unread_conversations_count($user1->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_unread_conversations_count_returns(),
+ $result = external_api::clean_returnvalue(core_message_external::get_unread_conversations_count_returns(),
$result);
$this->assertEquals(3, $result);
@@ -3471,7 +3472,7 @@ public function test_get_message_processor() {
$result = core_message_external::get_message_processor($user1->id, 'popup');
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_message_processor_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_message_processor_returns(), $result);
$this->assertNotEmpty($result['systemconfigured']);
$this->assertNotEmpty($result['userconfigured']);
@@ -3494,7 +3495,7 @@ public function test_get_user_message_preferences() {
set_user_preference('message_blocknoncontacts', \core_message\api::MESSAGE_PRIVACY_SITE, $user);
$prefs = core_message_external::get_user_message_preferences();
- $prefs = \external_api::clean_returnvalue(core_message_external::get_user_message_preferences_returns(), $prefs);
+ $prefs = external_api::clean_returnvalue(core_message_external::get_user_message_preferences_returns(), $prefs);
$this->assertEquals($user->id, $prefs['preferences']['userid']);
// Check components.
@@ -3587,7 +3588,7 @@ public function test_set_favourite_conversations_basic() {
$result = core_message_external::set_favourite_conversations($user1->id, [$conversation1, $conversation2]);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::set_favourite_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::set_favourite_conversations_returns(), $result);
$this->assertCount(0, $result);
}
@@ -3705,7 +3706,7 @@ public function test_unset_favourite_conversations_basic() {
$result = core_message_external::unset_favourite_conversations($user1->id, [$conversation1, $conversation2]);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::unset_favourite_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::unset_favourite_conversations_returns(), $result);
$this->assertCount(0, $result);
}
@@ -3842,7 +3843,7 @@ public function test_get_conversations_no_restrictions() {
// Get all conversations for user1.
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$selfconversation = \core_message\api::get_self_conversation($user1->id);
@@ -3924,7 +3925,7 @@ public function test_get_conversations_message_format() {
// Verify the format of the html message.
$expectedmessagetext = message_format_message_text($message);
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$messages = $conversations[0]['messages'];
$this->assertEquals($expectedmessagetext, $messages[0]['text']);
@@ -3945,7 +3946,7 @@ public function test_get_conversations_limit_offset() {
// Get all conversations for user1.
$result = core_message_external::get_conversations($user1->id, 0, 1);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
// Verify the first conversation.
@@ -3955,21 +3956,21 @@ public function test_get_conversations_limit_offset() {
// Verify the next conversation.
$result = core_message_external::get_conversations($user1->id, 1, 1);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(1, $conversations);
$this->assertEquals($gc2->id, $conversations[0]['id']);
// Verify the next conversation.
$result = core_message_external::get_conversations($user1->id, 2, 1);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(1, $conversations);
$this->assertEquals($ic2->id, $conversations[0]['id']);
// Skip one and get both empty conversations.
$result = core_message_external::get_conversations($user1->id, 4, 2);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(2, $conversations);
$this->assertEquals($gc5->id, $conversations[0]['id']);
@@ -3998,14 +3999,14 @@ public function test_get_conversations_type_filter() {
// Verify we can ask for only individual conversations.
$result = core_message_external::get_conversations($user1->id, 0, 20,
\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(2, $conversations);
// Verify we can ask for only group conversations.
$result = core_message_external::get_conversations($user1->id, 0, 20,
\core_message\api::MESSAGE_CONVERSATION_TYPE_GROUP);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(4, $conversations);
@@ -4036,7 +4037,7 @@ public function test_get_conversations_self_conversations() {
// Verify this conversation is returned by the method.
$this->setUser($user1);
$result = core_message_external::get_conversations($user1->id, 0, 20);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(1, $conversations);
}
@@ -4061,7 +4062,7 @@ public function test_get_conversations_deleted_user() {
// Group conversations are also present, albeit with less members.
delete_user($user2);
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(7, $conversations);
$this->assertEquals($gc3->id, $conversations[0]['id']);
@@ -4078,7 +4079,7 @@ public function test_get_conversations_deleted_user() {
// This user will still be present in the members array, as will the message in the messages array.
delete_user($user4);
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(7, $conversations);
$this->assertEquals($gc2->id, $conversations[1]['id']);
@@ -4092,7 +4093,7 @@ public function test_get_conversations_deleted_user() {
// Group conversations are also present, albeit with less members.
delete_user($user3);
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(7, $conversations);
$this->assertEquals($gc3->id, $conversations[0]['id']);
@@ -4150,7 +4151,7 @@ public function test_get_conversations_deleted_user_from_database() {
delete_user($user2);
$DB->delete_records('user', ['id' => $user2->id]);
$result = core_message_external::get_conversations($user1->id, 0, 20, 1, false);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversation = $result['conversations'];
@@ -4180,13 +4181,13 @@ public function test_get_conversations_favourite_conversations() {
// Try to get ONLY favourite conversations, when no favourites exist.
$result = core_message_external::get_conversations($user1->id, 0, 20, null, true);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertEquals([], $conversations);
// Try to get NO favourite conversations, when no favourites exist.
$result = core_message_external::get_conversations($user1->id, 0, 20, null, false);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
// Consider first conversations is self-conversation.
$this->assertCount(7, $conversations);
@@ -4198,7 +4199,7 @@ public function test_get_conversations_favourite_conversations() {
// Get the conversations, first with no restrictions, confirming the favourite status of the conversations.
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(7, $conversations);
foreach ($conversations as $conv) {
@@ -4209,7 +4210,7 @@ public function test_get_conversations_favourite_conversations() {
// Now, get ONLY favourite conversations.
$result = core_message_external::get_conversations($user1->id, 0, 20, null, true);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(3, $conversations);
foreach ($conversations as $conv) {
@@ -4226,7 +4227,7 @@ public function test_get_conversations_favourite_conversations() {
// And NO favourite conversations.
$result = core_message_external::get_conversations($user1->id, 0, 20, null, false);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(4, $conversations);
foreach ($conversations as $conv) {
@@ -4264,7 +4265,7 @@ public function test_get_conversations_group_linked() {
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user2->id));
$result = core_message_external::get_conversations($user1->id, 0, 20, null, false);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertEquals(2, $conversations[0]['membercount']);
@@ -4275,7 +4276,7 @@ public function test_get_conversations_group_linked() {
// Now, disable the conversation linked to the group and verify it's no longer returned.
$DB->set_field('message_conversations', 'enabled', 0, ['id' => $conversations[0]['id']]);
$result = core_message_external::get_conversations($user1->id, 0, 20, null, false);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$this->assertCount(0, $conversations);
}
@@ -4314,13 +4315,13 @@ public function test_get_conversations_group_with_mathjax() {
// Call the WebService.
$result = core_message_external::get_conversations($user1->id, 0, 20, null, false);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
// Format original data.
$coursecontext = \context_course::instance($course1->id);
- $coursename = external_format_string($coursename, $coursecontext->id);
- $groupname = external_format_string($groupname, $coursecontext->id);
+ $coursename = \core_external\util::format_string($coursename, $coursecontext->id);
+ $groupname = \core_external\util::format_string($groupname, $coursecontext->id);
$this->assertStringContainsString('', $conversations[0]['name']);
$this->assertStringContainsString('', $conversations[0]['subname']);
@@ -4367,7 +4368,7 @@ public function test_get_conversations_user_in_group_and_individual_chat() {
$this->setUser($user2);
$result = core_message_external::get_conversations($user2->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
$groupconversation = array_shift($conversations);
@@ -4421,7 +4422,7 @@ public function test_get_conversations_some_muted() {
$this->setUser($user1);
$result = core_message_external::get_conversations($user1->id);
- $result = \external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversations_returns(), $result);
$conversations = $result['conversations'];
usort($conversations, function($first, $second){
@@ -4509,7 +4510,7 @@ public function test_get_conversation_members() {
$this->setAdminUser();
$members = core_message_external::get_conversation_members($user1->id, $conversationid, false);
- \external_api::clean_returnvalue(core_message_external::get_conversation_members_returns(), $members);
+ external_api::clean_returnvalue(core_message_external::get_conversation_members_returns(), $members);
// Sort them by id.
ksort($members);
@@ -4587,7 +4588,7 @@ public function test_get_conversation_members_with_contact_requests() {
$this->setAdminUser();
$members = core_message_external::get_conversation_members($user1->id, $conversationid, true);
- \external_api::clean_returnvalue(core_message_external::get_conversation_members_returns(), $members);
+ external_api::clean_returnvalue(core_message_external::get_conversation_members_returns(), $members);
// Sort them by id.
ksort($members);
@@ -4707,7 +4708,7 @@ public function test_send_messages_to_conversation_individual() {
$sink = $this->redirectMessages();
$writtenmessages = core_message_external::send_messages_to_conversation($ic1->id, $messages);
- \external_api::clean_returnvalue(core_message_external::send_messages_to_conversation_returns(), $writtenmessages);
+ external_api::clean_returnvalue(core_message_external::send_messages_to_conversation_returns(), $writtenmessages);
$this->assertCount(2, $writtenmessages);
$this->assertObjectHasAttribute('id', $writtenmessages[0]);
@@ -4759,7 +4760,7 @@ public function test_send_messages_to_conversation_group() {
$sink = $this->redirectMessages();
$writtenmessages = core_message_external::send_messages_to_conversation($gc2->id, $messages);
- \external_api::clean_returnvalue(core_message_external::send_messages_to_conversation_returns(), $writtenmessages);
+ external_api::clean_returnvalue(core_message_external::send_messages_to_conversation_returns(), $writtenmessages);
$this->assertCount(2, $writtenmessages);
$this->assertObjectHasAttribute('id', $writtenmessages[0]);
@@ -4892,7 +4893,7 @@ public function test_get_conversation_no_conversation() {
$this->expectException('moodle_exception');
$conv = core_message_external::get_conversation($user1->id, $conversationid + 1);
- \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
}
/**
@@ -4920,13 +4921,13 @@ public function test_get_conversation_favourited() {
// Get the conversation for user1 and confirm it's favourited.
$this->setUser($user1);
$conv = core_message_external::get_conversation($user1->id, $conversation->id);
- $conv = \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ $conv = external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$this->assertTrue($conv['isfavourite']);
// Get the conversation for user2 and confirm it's NOT favourited.
$this->setUser($user2);
$conv = core_message_external::get_conversation($user2->id, $conversation->id);
- $conv = \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ $conv = external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$this->assertFalse($conv['isfavourite']);
}
@@ -4968,13 +4969,13 @@ public function test_get_conversation_favourited_group_linked() {
// Get the conversation for user1 and confirm it's favourited.
$this->setUser($user1);
$conv = core_message_external::get_conversation($user1->id, $conversationrecord->id);
- $conv = \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ $conv = external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$this->assertTrue($conv['isfavourite']);
// Get the conversation for user2 and confirm it's NOT favourited.
$this->setUser($user2);
$conv = core_message_external::get_conversation($user2->id, $conversationrecord->id);
- $conv = \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ $conv = external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$this->assertFalse($conv['isfavourite']);
}
@@ -5001,7 +5002,7 @@ public function test_get_conversation_no_messages() {
$this->setUser($user1);
$conv = core_message_external::get_conversation($user1->id, $conversationid);
- \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$conv = (array) $conv;
$this->assertEquals($conversationid, $conv['id']);
@@ -5077,7 +5078,7 @@ public function test_get_conversation_with_messages() {
0,
true
);
- \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$conv = (array) $conv;
$this->assertEquals(false, $conv['isread']);
@@ -5102,7 +5103,7 @@ public function test_get_conversation_with_messages() {
0,
false
);
- \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$conv = (array) $conv;
$this->assertCount(3, $conv['messages']);
@@ -5125,7 +5126,7 @@ public function test_get_conversation_with_messages() {
1,
true
);
- \external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
+ external_api::clean_returnvalue(core_message_external::get_conversation_returns(), $conv);
$conv = (array) $conv;
$this->assertCount(1, $conv['messages']);
@@ -5582,7 +5583,7 @@ public function test_get_conversation_counts(
}
$counts = core_message_external::get_conversation_counts(...$arguments);
- $counts = \external_api::clean_returnvalue(core_message_external::get_conversation_counts_returns(), $counts);
+ $counts = external_api::clean_returnvalue(core_message_external::get_conversation_counts_returns(), $counts);
$this->assertEquals($expectedcounts['favourites'], $counts['favourites']);
$this->assertEquals($expectedcounts['types'][\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL],
@@ -5668,7 +5669,7 @@ public function test_get_unread_conversation_counts(
}
$counts = core_message_external::get_unread_conversation_counts(...$arguments);
- $counts = \external_api::clean_returnvalue(core_message_external::get_unread_conversation_counts_returns(), $counts);
+ $counts = external_api::clean_returnvalue(core_message_external::get_unread_conversation_counts_returns(), $counts);
$this->assertEquals($expectedunreadcounts['favourites'], $counts['favourites']);
$this->assertEquals($expectedunreadcounts['types'][\core_message\api::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL],
@@ -5703,7 +5704,7 @@ public function test_delete_message_for_all_users() {
// Now, user1 deletes message for all users.
$return = core_message_external::delete_message_for_all_users($messageid1, $user1->id);
- $return = \external_api::clean_returnvalue(core_message_external::delete_message_for_all_users_returns(), $return);
+ $return = external_api::clean_returnvalue(core_message_external::delete_message_for_all_users_returns(), $return);
// Check if everything is ok.
$this->assertEquals(array(), $return);
@@ -5830,7 +5831,7 @@ public function test_get_conversation_messages_timefrom_higher_than_last_timecre
$result = core_message_external::get_conversation_messages($user1->id, $conversation->id, 0, 0, '', $time + 5);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(), $result);
+ $result = external_api::clean_returnvalue(core_message_external::get_conversation_messages_returns(), $result);
// Check the results are correct.
$this->assertEquals($conversation->id, $result['id']);
diff --git a/mod/assign/classes/external/external_api.php b/mod/assign/classes/external/external_api.php
index e8e9c83462024..1be7efd0f26e2 100644
--- a/mod/assign/classes/external/external_api.php
+++ b/mod/assign/classes/external/external_api.php
@@ -20,7 +20,6 @@
global $CFG;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/mod/assign/locallib.php");
/**
@@ -31,7 +30,7 @@
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class external_api extends \external_api {
+class external_api extends \core_external\external_api {
/**
* Generate a warning in a standard structure for a known failure.
diff --git a/mod/assign/classes/external/start_submission.php b/mod/assign/classes/external/start_submission.php
index 669a475676423..35424a94f7997 100644
--- a/mod/assign/classes/external/start_submission.php
+++ b/mod/assign/classes/external/start_submission.php
@@ -16,6 +16,11 @@
namespace mod_assign\external;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+
/**
* External function to notify Moodle that an assignment submission is starting.
*
@@ -29,12 +34,12 @@ class start_submission extends external_api {
/**
* Describes the parameters for submission_start.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
* @since Moodle 4.0
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters ([
- 'assignid' => new \external_value(PARAM_INT, 'Assignment instance id'),
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters ([
+ 'assignid' => new external_value(PARAM_INT, 'Assignment instance id'),
]
);
}
@@ -101,13 +106,13 @@ public static function execute(int $assignid): array {
/**
* Describes the submission_start return value.
*
- * @return \external_single_structure
+ * @return external_single_structure
* @since Moodle 4.0
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure([
- 'submissionid' => new \external_value(PARAM_INT, 'New submission ID.'),
- 'warnings' => new \external_warnings(),
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure([
+ 'submissionid' => new external_value(PARAM_INT, 'New submission ID.'),
+ 'warnings' => new external_warnings(),
]);
}
}
diff --git a/mod/assign/externallib.php b/mod/assign/externallib.php
index fa2b761c36a4d..04105c0cb58b2 100644
--- a/mod/assign/externallib.php
+++ b/mod/assign/externallib.php
@@ -23,9 +23,17 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util as external_util;
+
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/user/externallib.php");
require_once("$CFG->dirroot/mod/assign/locallib.php");
@@ -404,7 +412,7 @@ public static function get_assignments($courseids = array(), $capabilities = arr
'id' => $module->assignmentid,
'cmid' => $module->id,
'course' => $module->course,
- 'name' => external_format_string($module->name, $context),
+ 'name' => \core_external\util::format_string($module->name, $context),
'nosubmissions' => $module->nosubmissions,
'submissiondrafts' => $module->submissiondrafts,
'sendnotifications' => $module->sendnotifications,
@@ -437,9 +445,15 @@ public static function get_assignments($courseids = array(), $capabilities = arr
// Return or not intro and file attachments depending on the plugin settings.
if ($assign->show_intro()) {
$options = array('noclean' => true);
- list($assignment['intro'], $assignment['introformat']) =
- external_format_text($module->intro, $module->introformat, $context->id, 'mod_assign', 'intro', null,
- $options);
+ [$assignment['intro'], $assignment['introformat']] = \core_external\util::format_text(
+ $module->intro,
+ $module->introformat,
+ $context,
+ 'mod_assign',
+ 'intro',
+ null,
+ $options
+ );
$assignment['introfiles'] = external_util::get_area_files($context->id, 'mod_assign', 'intro', false,
false);
if ($assign->should_provide_intro_attachments($USER->id)) {
@@ -454,27 +468,33 @@ public static function get_assignments($courseids = array(), $capabilities = arr
// Single submission.
if (!$module->teamsubmission) {
list($assignment['submissionstatement'], $assignment['submissionstatementformat']) =
- external_format_text($adminconfig->submissionstatement, FORMAT_MOODLE, $context->id,
+ \core_external\util::format_text($adminconfig->submissionstatement, FORMAT_MOODLE, $context->id,
'mod_assign', '', 0);
} else { // Team submission.
// One user can submit for the whole team.
if (!empty($adminconfig->submissionstatementteamsubmission) && !$module->requireallteammemberssubmit) {
list($assignment['submissionstatement'], $assignment['submissionstatementformat']) =
- external_format_text($adminconfig->submissionstatementteamsubmission,
+ \core_external\util::format_text($adminconfig->submissionstatementteamsubmission,
FORMAT_MOODLE, $context->id, 'mod_assign', '', 0);
} else if (!empty($adminconfig->submissionstatementteamsubmissionallsubmit) &&
$module->requireallteammemberssubmit) {
// All team members must submit.
list($assignment['submissionstatement'], $assignment['submissionstatementformat']) =
- external_format_text($adminconfig->submissionstatementteamsubmissionallsubmit,
+ \core_external\util::format_text($adminconfig->submissionstatementteamsubmissionallsubmit,
FORMAT_MOODLE, $context->id, 'mod_assign', '', 0);
}
}
}
if ($module->activity && $assign->submissions_open($USER->id, true)) {
- list($assignment['activity'], $assignment['activityformat']) = external_format_text($module->activity,
- $module->activityformat, $context->id, 'mod_assign', ASSIGN_ACTIVITYATTACHMENT_FILEAREA, 0);
+ list($assignment['activity'], $assignment['activityformat']) = \core_external\util::format_text(
+ $module->activity,
+ $module->activityformat,
+ $context,
+ 'mod_assign',
+ ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
+ 0
+ );
$assignment['activityattachments'] = external_util::get_area_files($context->id, 'mod_assign',
ASSIGN_ACTIVITYATTACHMENT_FILEAREA, 0);
}
@@ -484,8 +504,8 @@ public static function get_assignments($courseids = array(), $capabilities = arr
}
$coursearray[]= array(
'id' => $courses[$id]->id,
- 'fullname' => external_format_string($courses[$id]->fullname, $course->contextid),
- 'shortname' => external_format_string($courses[$id]->shortname, $course->contextid),
+ 'fullname' => \core_external\util::format_string($courses[$id]->fullname, $course->contextid),
+ 'shortname' => \core_external\util::format_string($courses[$id]->shortname, $course->contextid),
'timemodified' => $courses[$id]->timemodified,
'assignments' => $assignmentarray
);
@@ -658,8 +678,8 @@ private static function get_plugins_data($assign, $assignplugins, $item) {
// Now format the text.
foreach ($fileareas as $filearea => $name) {
- list($editorfieldinfo['text'], $editorfieldinfo['format']) = external_format_text(
- $editorfieldinfo['text'], $editorfieldinfo['format'], $assign->get_context()->id,
+ list($editorfieldinfo['text'], $editorfieldinfo['format']) = \core_external\util::format_text(
+ $editorfieldinfo['text'], $editorfieldinfo['format'], $assign->get_context(),
$component, $filearea, $item->id);
}
@@ -2228,16 +2248,14 @@ public static function view_grading_table($assignid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_grading_table_returns() {
- return new external_single_structure(
- array(
- 'status' => new external_value(PARAM_BOOL, 'status: true if success'),
- 'warnings' => new external_warnings()
- )
- );
+ return new external_single_structure([
+ 'status' => new external_value(PARAM_BOOL, 'status: true if success'),
+ 'warnings' => new external_warnings()
+ ]);
}
/**
@@ -2247,11 +2265,9 @@ public static function view_grading_table_returns() {
* @since Moodle 3.1
*/
public static function view_submission_status_parameters() {
- return new external_function_parameters (
- array(
- 'assignid' => new external_value(PARAM_INT, 'assign instance id'),
- )
- );
+ return new external_function_parameters ([
+ 'assignid' => new external_value(PARAM_INT, 'assign instance id'),
+ ]);
}
/**
@@ -2498,8 +2514,14 @@ function($e){
ASSIGN_INTROATTACHMENT_FILEAREA, 0);
}
if ($instance->activity && ($lastattempt || $assign->submissions_open($user->id, true))) {
- list($assignmentdata['activity'], $assignmentdata['activityformat']) = external_format_text($instance->activity,
- $instance->activityformat, $context->id, 'mod_assign', ASSIGN_ACTIVITYATTACHMENT_FILEAREA, 0);
+ [$assignmentdata['activity'], $assignmentdata['activityformat']] = \core_external\util::format_text(
+ $instance->activity,
+ $instance->activityformat,
+ $context,
+ 'mod_assign',
+ ASSIGN_ACTIVITYATTACHMENT_FILEAREA,
+ 0
+ );
$attachments['activity'] = external_util::get_area_files($context->id, 'mod_assign',
ASSIGN_ACTIVITYATTACHMENT_FILEAREA, 0);
}
@@ -2728,7 +2750,7 @@ public static function list_participants($assignid, $groupid, $filter, $skip,
/**
* Returns the description of the results of the mod_assign_external::list_participants() method.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function list_participants_returns() {
@@ -2887,7 +2909,7 @@ public static function get_participant($assignid, $userid, $embeduser) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_participant_returns() {
diff --git a/mod/assign/feedback/comments/locallib.php b/mod/assign/feedback/comments/locallib.php
index 6bd4466e2ced6..9cfd0ee3493aa 100644
--- a/mod/assign/feedback/comments/locallib.php
+++ b/mod/assign/feedback/comments/locallib.php
@@ -22,6 +22,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
// File component for feedback comments.
@@ -615,7 +618,7 @@ public function get_file_areas() {
/**
* Return a description of external params suitable for uploading an feedback comment from a webservice.
*
- * @return external_description|null
+ * @return \core_external\external_description|null
*/
public function get_external_parameters() {
$editorparams = array('text' => new external_value(PARAM_RAW, 'The text for this feedback.'),
diff --git a/mod/assign/feedback/file/locallib.php b/mod/assign/feedback/file/locallib.php
index 30c2821116bd8..2bf0d9cf8aa8c 100644
--- a/mod/assign/feedback/file/locallib.php
+++ b/mod/assign/feedback/file/locallib.php
@@ -25,7 +25,8 @@
defined('MOODLE_INTERNAL') || die();
-use \mod_assign\output\assign_header;
+use mod_assign\output\assign_header;
+use core_external\external_value;
// File areas for file feedback assignment.
define('ASSIGNFEEDBACK_FILE_FILEAREA', 'feedback_files');
@@ -693,7 +694,7 @@ public function get_grading_actions() {
/**
* Return a description of external params suitable for uploading a feedback file from a webservice.
*
- * @return external_description|null
+ * @return \core_external\external_description|null
*/
public function get_external_parameters() {
return array(
diff --git a/mod/assign/submission/file/locallib.php b/mod/assign/submission/file/locallib.php
index 382c3b31e2f61..804ec66205f31 100644
--- a/mod/assign/submission/file/locallib.php
+++ b/mod/assign/submission/file/locallib.php
@@ -24,7 +24,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+use core_external\external_value;
// File areas for file submission assignment.
define('ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES', 5);
@@ -595,7 +595,7 @@ public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmis
/**
* Return a description of external params suitable for uploading a file submission from a webservice.
*
- * @return external_description|null
+ * @return \core_external\external_description|null
*/
public function get_external_parameters() {
return array(
diff --git a/mod/assign/submission/onlinetext/locallib.php b/mod/assign/submission/onlinetext/locallib.php
index c2bb02aa08a86..30fd3d26faa29 100644
--- a/mod/assign/submission/onlinetext/locallib.php
+++ b/mod/assign/submission/onlinetext/locallib.php
@@ -24,6 +24,9 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
// File area for online text submission assignment.
define('ASSIGNSUBMISSION_ONLINETEXT_FILEAREA', 'submissions_onlinetext');
@@ -678,7 +681,7 @@ public function copy_submission(stdClass $sourcesubmission, stdClass $destsubmis
/**
* Return a description of external params suitable for uploading an onlinetext submission from a webservice.
*
- * @return external_description|null
+ * @return \core_external\external_description|null
*/
public function get_external_parameters() {
$editorparams = array('text' => new external_value(PARAM_RAW, 'The text for this submission.'),
@@ -725,5 +728,3 @@ public function get_config_for_external() {
return (array) $this->get_config();
}
}
-
-
diff --git a/mod/assign/tests/externallib_test.php b/mod/assign/tests/externallib_test.php
index fa4a3ebce3188..7976256a1cc02 100644
--- a/mod/assign/tests/externallib_test.php
+++ b/mod/assign/tests/externallib_test.php
@@ -16,6 +16,8 @@
namespace mod_assign;
+use core_external\external_api;
+use core_external\external_settings;
use core_user_external;
use mod_assign_external;
use mod_assign_testable_assign;
@@ -125,7 +127,7 @@ public function test_get_grades() {
$result = mod_assign_external::get_grades($assignmentids);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_grades_returns(), $result);
// Check that the correct grade information for the student is returned.
$this->assertEquals(1, count($result['assignments']));
@@ -151,7 +153,7 @@ public function test_get_assignments() {
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', 1);
// Set WS filtering.
- $wssettings = \external_settings::get_instance();
+ $wssettings = external_settings::get_instance();
$wssettings->set_filter(true);
$category = self::getDataGenerator()->create_category(array(
@@ -161,8 +163,8 @@ public function test_get_assignments() {
// Create a course.
$course1 = self::getDataGenerator()->create_course(array(
'idnumber' => 'idnumbercourse1',
- 'fullname' => 'Lightwork Course 1', // Adding tags here to check that external_format_string works.
- 'shortname' => 'Lightwork Course 1', // Adding tags here to check that external_format_string works.
+ 'fullname' => 'Lightwork Course 1', // Adding tags here to check that \core_external\util::format_string works.
+ 'shortname' => 'Lightwork Course 1', // Adding tags here to check that \core_external\util::format_string works.
'summary' => 'Lightwork Course 1 description',
'summaryformat' => FORMAT_MOODLE,
'category' => $category->id
@@ -228,7 +230,7 @@ public function test_get_assignments() {
$result = mod_assign_external::get_assignments();
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
// Check the course and assignment are returned.
$this->assertEquals(1, count($result['courses']));
@@ -264,7 +266,7 @@ public function test_get_assignments() {
$result = mod_assign_external::get_assignments(array($course1->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
@@ -283,7 +285,7 @@ public function test_get_assignments() {
$result = mod_assign_external::get_assignments(array($course2->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertEquals(0, count($result['courses']));
$this->assertEquals(1, count($result['warnings']));
@@ -291,18 +293,18 @@ public function test_get_assignments() {
// Test with non-enrolled user, but with view capabilities.
$this->setAdminUser();
$result = mod_assign_external::get_assignments();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertEquals(0, count($result['courses']));
$this->assertEquals(0, count($result['warnings']));
// Expect no courses, because we are not using the special flag.
$result = mod_assign_external::get_assignments(array($course1->id));
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertCount(0, $result['courses']);
// Now use the special flag to return courses where you are not enroled in.
$result = mod_assign_external::get_assignments(array($course1->id), array(), true);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertCount(1, $result['courses']);
$course = $result['courses'][0];
@@ -350,7 +352,7 @@ public function test_get_assignments_with_submissionstatement() {
$result = mod_assign_external::get_assignments();
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
// Check that the amount of courses and assignments is right.
$this->assertCount(1, $result['courses']);
@@ -411,7 +413,7 @@ public function test_get_assignments_when_submissionattachments_is_enabled() {
// We need to execute the return values cleaning process to simulate the web service server.
$result = mod_assign_external::get_assignments();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
@@ -426,7 +428,7 @@ public function test_get_assignments_when_submissionattachments_is_enabled() {
// We need to execute the return values cleaning process to simulate the web service server.
$result = mod_assign_external::get_assignments();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
@@ -439,7 +441,7 @@ public function test_get_assignments_when_submissionattachments_is_enabled() {
// We need to execute the return values cleaning process to simulate the web service server.
$result = mod_assign_external::get_assignments();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_assignments_returns(), $result);
$this->assertEquals(1, count($result['courses']));
$course = $result['courses'][0];
@@ -511,7 +513,7 @@ public function test_get_submissions() {
$assignmentids[] = $assign1->id;
$result = mod_assign_external::get_submissions($assignmentids);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
// Check the online text submission is NOT returned because the student is not yet enrolled in the course.
$this->assertEquals(1, count($result['assignments']));
@@ -524,7 +526,7 @@ public function test_get_submissions() {
$this->getDataGenerator()->enrol_user($student->id, $course1->id, $studentrole->id);
$result = mod_assign_external::get_submissions($assignmentids);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
$this->assertEquals(1, count($result['assignments']));
$assignment = $result['assignments'][0];
@@ -545,7 +547,7 @@ public function test_get_submissions() {
$this->setUser($teacher);
$assignmentids[] = $assign1->id;
$result = mod_assign_external::get_submissions($assignmentids);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
$this->assertEquals(1, count($result['assignments']));
}
@@ -582,7 +584,7 @@ public function test_get_submissions_group_submission() {
$assignmentids[] = $assignmodule->id;
$result = mod_assign_external::get_submissions($assignmentids);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
$this->assertEquals(1, count($result['assignments']));
$assignment = $result['assignments'][0];
@@ -662,7 +664,7 @@ public function test_get_submissions_group_submission_attemptnumber() {
$this->setUser($teacher);
$result = mod_assign_external::get_submissions([$assignmodule->id]);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
$this->assertEquals(1, count($result['assignments']));
[$assignment] = $result['assignments'];
@@ -729,7 +731,7 @@ public function test_get_user_flags() {
$result = mod_assign_external::get_user_flags($assignmentids);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_user_flags_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_user_flags_returns(), $result);
// Check that the correct user flag information for the student is returned.
$this->assertEquals(1, count($result['assignments']));
@@ -795,7 +797,7 @@ public function test_get_user_mappings() {
$result = mod_assign_external::get_user_mappings($assignmentids);
// We need to execute the return values cleaning process to simulate the web service server.
- $result = \external_api::clean_returnvalue(mod_assign_external::get_user_mappings_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_user_mappings_returns(), $result);
// Check that the correct user mapping information for the student is returned.
$this->assertEquals(1, count($result['assignments']));
@@ -851,7 +853,7 @@ public function test_lock_submissions() {
$this->setUser($teacher);
$students = array($student1->id, $student2->id);
$result = mod_assign_external::lock_submissions($instance->id, $students);
- $result = \external_api::clean_returnvalue(mod_assign_external::lock_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::lock_submissions_returns(), $result);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
@@ -912,13 +914,13 @@ public function test_unlock_submissions() {
$this->setUser($teacher);
$students = array($student1->id, $student2->id);
$result = mod_assign_external::lock_submissions($instance->id, $students);
- $result = \external_api::clean_returnvalue(mod_assign_external::lock_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::lock_submissions_returns(), $result);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
$result = mod_assign_external::unlock_submissions($instance->id, $students);
- $result = \external_api::clean_returnvalue(mod_assign_external::unlock_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::unlock_submissions_returns(), $result);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
@@ -974,13 +976,13 @@ public function test_submit_for_grading() {
$plugin->save($submission, $data);
$result = mod_assign_external::submit_for_grading($instance->id, false);
- $result = \external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
// Should be 1 fail because the submission statement was not aceptted.
$this->assertEquals(1, count($result));
$result = mod_assign_external::submit_for_grading($instance->id, true);
- $result = \external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
@@ -1027,34 +1029,34 @@ public function test_save_user_extensions() {
$this->setUser($student1);
$result = mod_assign_external::submit_for_grading($instance->id, true);
- $result = \external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
// Check for 0 warnings.
$this->assertEquals(1, count($result));
$this->setUser($teacher);
$result = mod_assign_external::save_user_extensions($instance->id, array($student1->id), array($now, $tomorrow));
- $result = \external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
$this->assertEquals(1, count($result));
$this->setUser($teacher);
$result = mod_assign_external::save_user_extensions($instance->id, array($student1->id), array($yesterday - 10));
- $result = \external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
$this->assertEquals(1, count($result));
$this->setUser($teacher);
$result = mod_assign_external::save_user_extensions($instance->id, array($student1->id), array($tomorrow));
- $result = \external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
$this->assertEquals(0, count($result));
$this->setUser($student1);
$result = mod_assign_external::submit_for_grading($instance->id, true);
- $result = \external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
$this->assertEquals(0, count($result));
$this->setUser($student1);
$result = mod_assign_external::save_user_extensions($instance->id, array($student1->id), array($now, $tomorrow));
- $result = \external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_user_extensions_returns(), $result);
}
/**
@@ -1090,13 +1092,13 @@ public function test_reveal_identities() {
$this->setUser($student1);
$this->expectException(\required_capability_exception::class);
$result = mod_assign_external::reveal_identities($instance->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
$this->assertEquals(1, count($result));
$this->assertEquals(true, $assign->is_blind_marking());
$this->setUser($teacher);
$result = mod_assign_external::reveal_identities($instance->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
$this->assertEquals(0, count($result));
$this->assertEquals(false, $assign->is_blind_marking());
@@ -1111,7 +1113,7 @@ public function test_reveal_identities() {
$assign = new \assign($context, $cm, $course);
$result = mod_assign_external::reveal_identities($instance->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::reveal_identities_returns(), $result);
$this->assertEquals(1, count($result));
$this->assertEquals(false, $assign->is_blind_marking());
@@ -1151,14 +1153,14 @@ public function test_revert_submissions_to_draft() {
// Simulate a submission.
$this->setUser($student1);
$result = mod_assign_external::submit_for_grading($instance->id, true);
- $result = \external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::submit_for_grading_returns(), $result);
$this->assertEquals(0, count($result));
// Ready to test.
$this->setUser($teacher);
$students = array($student1->id, $student2->id);
$result = mod_assign_external::revert_submissions_to_draft($instance->id, array($student1->id));
- $result = \external_api::clean_returnvalue(mod_assign_external::revert_submissions_to_draft_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::revert_submissions_to_draft_returns(), $result);
// Check for 0 warnings.
$this->assertEquals(0, count($result));
@@ -1239,7 +1241,7 @@ public function test_save_submission() {
'itemid' => $draftidonlinetext);
$submissionpluginparams['onlinetext_editor'] = $onlinetexteditorparams;
$result = mod_assign_external::save_submission($instance->id, $submissionpluginparams);
- $result = \external_api::clean_returnvalue(mod_assign_external::save_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_submission_returns(), $result);
$this->assertEquals(0, count($result));
@@ -1249,7 +1251,7 @@ public function test_save_submission() {
$DB->update_record('assign', $instance);
$result = mod_assign_external::save_submission($instance->id, $submissionpluginparams);
- $result = \external_api::clean_returnvalue(mod_assign_external::save_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_submission_returns(), $result);
$this->assertCount(1, $result);
$this->assertEquals(get_string('duedatereached', 'assign'), $result[0]['item']);
@@ -1327,7 +1329,7 @@ public function test_save_grade() {
$this->assertNull($result);
$result = mod_assign_external::get_grades(array($instance->id));
- $result = \external_api::clean_returnvalue(mod_assign_external::get_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_grades_returns(), $result);
$this->assertEquals((float)$result['assignments'][0]['grades'][0]['grade'], '50.0');
}
@@ -1569,7 +1571,7 @@ public function test_save_grades_with_group_submission() {
// Expect an exception since 2 grades have been submitted for the same team.
$this->expectException(\invalid_parameter_exception::class);
$result = mod_assign_external::save_grades($instance->id, true, $grades1);
- $result = \external_api::clean_returnvalue(mod_assign_external::save_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_grades_returns(), $result);
$grades2 = array();
$student3gradeinfo = array();
@@ -1590,7 +1592,7 @@ public function test_save_grades_with_group_submission() {
$student4gradeinfo['plugindata'] = $feedbackpluginparams;
$grades2[] = $student4gradeinfo;
$result = mod_assign_external::save_grades($instance->id, true, $grades2);
- $result = \external_api::clean_returnvalue(mod_assign_external::save_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_grades_returns(), $result);
// There should be no warnings.
$this->assertEquals(0, count($result));
@@ -1646,7 +1648,7 @@ public function test_copy_previous_attempt() {
$submissionpluginparams['onlinetext_editor'] = $onlinetexteditorparams;
$submissionpluginparams['files_filemanager'] = file_get_unused_draft_itemid();
$result = mod_assign_external::save_submission($instance->id, $submissionpluginparams);
- $result = \external_api::clean_returnvalue(mod_assign_external::save_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::save_submission_returns(), $result);
$this->setUser($teacher);
// Add a grade and reopen the attempt.
@@ -1669,13 +1671,13 @@ public function test_copy_previous_attempt() {
$this->setUser($student1);
// Now copy the previous attempt.
$result = mod_assign_external::copy_previous_attempt($instance->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::copy_previous_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::copy_previous_attempt_returns(), $result);
// No warnings.
$this->assertEquals(0, count($result));
$this->setUser($teacher);
$result = mod_assign_external::get_submissions(array($instance->id));
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submissions_returns(), $result);
// Check we are now on the second attempt.
$this->assertEquals($result['assignments'][0]['submissions'][0]['attemptnumber'], 1);
@@ -1733,7 +1735,7 @@ public function test_set_user_flags() {
$createduserflags = mod_assign_external::set_user_flags($assign->id, $userflags);
// We need to execute the return values cleaning process to simulate the web service server.
- $createduserflags = \external_api::clean_returnvalue(mod_assign_external::set_user_flags_returns(), $createduserflags);
+ $createduserflags = external_api::clean_returnvalue(mod_assign_external::set_user_flags_returns(), $createduserflags);
$this->assertEquals($student->id, $createduserflags[0]['userid']);
$createduserflag = $DB->get_record('assign_user_flags', array('id' => $createduserflags[0]['id']));
@@ -1755,7 +1757,7 @@ public function test_set_user_flags() {
$updateduserflags = mod_assign_external::set_user_flags($assign->id, $userflags);
// We need to execute the return values cleaning process to simulate the web service server.
- $updateduserflags = \external_api::clean_returnvalue(mod_assign_external::set_user_flags_returns(), $updateduserflags);
+ $updateduserflags = external_api::clean_returnvalue(mod_assign_external::set_user_flags_returns(), $updateduserflags);
$this->assertEquals($student->id, $updateduserflags[0]['userid']);
$updateduserflag = $DB->get_record('assign_user_flags', array('id' => $updateduserflags[0]['id']));
@@ -1835,7 +1837,7 @@ public function test_view_grading_table_correct() {
$sink = $this->redirectEvents();
$result = mod_assign_external::view_grading_table($assign->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::view_grading_table_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::view_grading_table_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -1966,7 +1968,7 @@ public function test_view_submission_status() {
$sink = $this->redirectEvents();
$result = mod_assign_external::view_submission_status($assign->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::view_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::view_submission_status_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -2007,7 +2009,7 @@ public function test_get_submission_status_in_draft_status() {
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
// The submission is now in draft mode.
$this->assertCount(0, $result['warnings']);
@@ -2041,8 +2043,15 @@ public function test_get_submission_status_in_draft_status() {
// Format expected online text.
$onlinetext = 'Submission text with a link';
- list($expectedtext, $expectedformat) = external_format_text($onlinetext, FORMAT_HTML, $assign->get_context()->id,
- 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $studentsubmission->id);
+ list($expectedtext,
+ $expectedformat) = \core_external\util::format_text(
+ $onlinetext,
+ FORMAT_HTML,
+ $assign->get_context(),
+ 'assignsubmission_onlinetext',
+ ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
+ $studentsubmission->id
+ );
$this->assertEquals($expectedtext, $submissionplugins['onlinetext']['editorfields'][0]['text']);
$this->assertEquals($expectedformat, $submissionplugins['onlinetext']['editorfields'][0]['format']);
@@ -2064,7 +2073,7 @@ public function test_get_submission_status_in_submission_status() {
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertFalse(isset($result['gradingsummary']));
@@ -2101,7 +2110,7 @@ public function test_get_submission_status_in_submission_status_for_teacher() {
$result = mod_assign_external::get_submission_status($assign->get_instance()->id, 0, $g1->id);
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertFalse(isset($result['lastattempt']));
@@ -2118,7 +2127,7 @@ public function test_get_submission_status_in_submission_status_for_teacher() {
// Second group.
$result = mod_assign_external::get_submission_status($assign->get_instance()->id, 0, $g2->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $result['gradingsummary']['participantcount']);
$this->assertEquals(0, $result['gradingsummary']['submissionssubmittedcount']); // G2 students didn't submit yet.
@@ -2126,7 +2135,7 @@ public function test_get_submission_status_in_submission_status_for_teacher() {
// Should not return information for all users (missing access to all groups capability for non-editing teacher).
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertFalse(isset($result['gradingsummary']));
@@ -2137,7 +2146,7 @@ public function test_get_submission_status_in_submission_status_for_teacher() {
accesslib_clear_all_caches_for_unit_testing();
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(2, $result['gradingsummary']['participantcount']);
$this->assertEquals(0, $result['gradingsummary']['submissiondraftscount']);
@@ -2148,7 +2157,7 @@ public function test_get_submission_status_in_submission_status_for_teacher() {
list($assign, $instance, $student1, $student2, $teacher, $g1, $g2) = $this->create_submission_for_testing_status(false);
$this->setUser($teacher);
$result = mod_assign_external::get_submission_status($assign->get_instance()->id, 0, $g1->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $result['gradingsummary']['participantcount']);
$this->assertEquals(1, $result['gradingsummary']['submissiondraftscount']); // We have a draft submission.
@@ -2194,7 +2203,7 @@ public function test_get_submission_status_in_reopened_status() {
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertFalse(isset($result['gradingsummary']));
@@ -2243,8 +2252,14 @@ public function test_get_submission_status_in_reopened_status() {
}
// Format expected online text.
$onlinetext = 'Submission text with a link';
- list($expectedtext, $expectedformat) = external_format_text($onlinetext, FORMAT_HTML, $assign->get_context()->id,
- 'assignsubmission_onlinetext', ASSIGNSUBMISSION_ONLINETEXT_FILEAREA, $studentsubmission->id);
+ list($expectedtext, $expectedformat) = \core_external\util::format_text(
+ $onlinetext,
+ FORMAT_HTML,
+ $assign->get_context(),
+ 'assignsubmission_onlinetext',
+ ASSIGNSUBMISSION_ONLINETEXT_FILEAREA,
+ $studentsubmission->id
+ );
$this->assertEquals($expectedtext, $submissionplugins['onlinetext']['editorfields'][0]['text']);
$this->assertEquals($expectedformat, $submissionplugins['onlinetext']['editorfields'][0]['format']);
@@ -2294,7 +2309,7 @@ public function test_get_submission_status_hidden_grader() {
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertTrue(isset($result['feedback']));
$this->assertTrue(isset($result['feedback']['grade']));
@@ -2312,7 +2327,7 @@ public function test_get_submission_status_hidden_grader() {
// Check that the student cannot see the grader anymore.
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertTrue(isset($result['feedback']));
$this->assertTrue(isset($result['feedback']['grade']));
@@ -2322,7 +2337,7 @@ public function test_get_submission_status_hidden_grader() {
$this->setUser($teacher);
$result = mod_assign_external::get_submission_status($assign->get_instance()->id, $student1->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertTrue(isset($result['feedback']));
$this->assertTrue(isset($result['feedback']['grade']));
@@ -2351,7 +2366,7 @@ public function test_get_submission_status_with_override() {
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertFalse(isset($result['gradingsummary']));
@@ -2372,7 +2387,7 @@ public function test_get_submission_status_with_override() {
$this->setUser($student2);
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
// The submission is now in draft mode.
$this->assertCount(0, $result['warnings']);
@@ -2437,7 +2452,7 @@ public function test_get_submission_status_with_time_limit_enabled() {
$result = mod_assign_external::get_submission_status($assign->get_instance()->id);
// We expect debugging because of the $PAGE object, this won't happen in a normal WS request.
$this->assertDebuggingCalled();
- $result = \external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_submission_status_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertFalse(isset($result['gradingsummary']));
@@ -2542,7 +2557,7 @@ public function test_get_participant_no_participant() {
$this->expectException(\moodle_exception::class);
$result = mod_assign_external::get_participant($assign->id, $student->id, false);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
}
/**
@@ -2564,7 +2579,7 @@ public function test_get_participant_blind_marking() {
$this->setUser($teacher);
$result = mod_assign_external::get_participant($assign->id, $student->id, true);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
$this->assertEquals($student->id, $result['id']);
$this->assertFalse(fullname($student) == $result['fullname']);
$this->assertFalse($result['submitted']);
@@ -2619,7 +2634,7 @@ public function test_get_participant_no_user() {
$this->setUser($teacher);
$result = mod_assign_external::get_participant($assignmodule->id, $student->id, false);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
$this->assertEquals($student->id, $result['id']);
$this->assertEquals(fullname($student), $result['fullname']);
$this->assertTrue($result['submitted']);
@@ -2649,7 +2664,7 @@ public function test_get_participant_full_details() {
$this->setUser($teacher);
$result = mod_assign_external::get_participant($assign->id, $student->id, true);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
// Check some of the extended properties we get when requesting the user.
$this->assertEquals($student->id, $result['id']);
// We should get user infomation back.
@@ -2701,7 +2716,7 @@ public function test_get_participant_group_submission() {
$this->setUser($teacher);
$result = mod_assign_external::get_participant($assignmodule->id, $student->id, false);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
// Check some of the extended properties we get when not requesting a summary.
$this->assertEquals($student->id, $result['id']);
$this->assertEquals($group->id, $result['groupid']);
@@ -2737,7 +2752,7 @@ public function test_get_participant_relative_dates(array $courseconfig, array $
$this->setUser($teacher);
$result = mod_assign_external::get_participant($assign->get_instance()->id, $user->id, false);
- $result = \external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::get_participant_returns(), $result);
foreach ($expectedproperties as $propertyname => $propertyval) {
$this->assertEquals($propertyval, $result[$propertyname]);
@@ -2796,11 +2811,11 @@ public function test_list_participants_user_info_with_special_characters() {
$this->setUser($teacher);
$participants = mod_assign_external::list_participants($assignment->id, 0, '', 0, 0, false, true, true);
- $participants = \external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
+ $participants = external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
$this->assertCount(1, $participants);
// Asser that we have a valid response data.
- $response = \external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
+ $response = external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
$this->assertEquals($response, $participants);
// Check participant data.
@@ -2815,7 +2830,7 @@ public function test_list_participants_user_info_with_special_characters() {
$this->assertArrayHasKey('enrolledcourses', $participant);
$participants = mod_assign_external::list_participants($assignment->id, 0, '', 0, 0, false, false, true);
- $participants = \external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
+ $participants = external_api::clean_returnvalue(mod_assign_external::list_participants_returns(), $participants);
// Check that the list of courses the participant is enrolled is not returned.
$participant = $participants[0];
$this->assertArrayNotHasKey('enrolledcourses', $participant);
@@ -2872,7 +2887,7 @@ public function test_view_assign() {
$cm = get_coursemodule_from_instance('assign', $assign->id);
$result = mod_assign_external::view_assign($assign->id);
- $result = \external_api::clean_returnvalue(mod_assign_external::view_assign_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_assign_external::view_assign_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEmpty($result['warnings']);
diff --git a/mod/bigbluebuttonbn/classes/external/can_join.php b/mod/bigbluebuttonbn/classes/external/can_join.php
index b81fc4df57c60..fb1b94bb277b4 100644
--- a/mod/bigbluebuttonbn/classes/external/can_join.php
+++ b/mod/bigbluebuttonbn/classes/external/can_join.php
@@ -15,18 +15,14 @@
// along with Moodle. If not, see .
namespace mod_bigbluebuttonbn\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\meeting;
-use restricted_context_exception;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
/**
* External service to check whether a user can join a meeting.
diff --git a/mod/bigbluebuttonbn/classes/external/completion_validate.php b/mod/bigbluebuttonbn/classes/external/completion_validate.php
index 599c531b0cd2d..5866ff36f9bc9 100644
--- a/mod/bigbluebuttonbn/classes/external/completion_validate.php
+++ b/mod/bigbluebuttonbn/classes/external/completion_validate.php
@@ -16,18 +16,14 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* External service to validate completion.
*
@@ -108,8 +104,7 @@ public static function execute(
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
- 'warnings' => new \external_warnings()
- ]
- );
+ 'warnings' => new external_warnings(),
+ ]);
}
}
diff --git a/mod/bigbluebuttonbn/classes/external/end_meeting.php b/mod/bigbluebuttonbn/classes/external/end_meeting.php
index c89d929049a40..fca145e9ea9f4 100644
--- a/mod/bigbluebuttonbn/classes/external/end_meeting.php
+++ b/mod/bigbluebuttonbn/classes/external/end_meeting.php
@@ -17,21 +17,16 @@
namespace mod_bigbluebuttonbn\external;
use core\notification;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
-use mod_bigbluebuttonbn\local\bigbluebutton;
use mod_bigbluebuttonbn\local\exceptions\bigbluebutton_exception;
use mod_bigbluebuttonbn\logger;
use mod_bigbluebuttonbn\meeting;
-use restricted_context_exception;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
/**
* External service to end a meeting.
@@ -125,7 +120,7 @@ public static function execute(
*/
public static function execute_returns(): external_single_structure {
return new external_single_structure([
- 'warnings' => new \external_warnings()
+ 'warnings' => new external_warnings(),
]);
}
}
diff --git a/mod/bigbluebuttonbn/classes/external/get_bigbluebuttonbns_by_courses.php b/mod/bigbluebuttonbn/classes/external/get_bigbluebuttonbns_by_courses.php
index c347a9c16ccb3..945534afc776b 100644
--- a/mod/bigbluebuttonbn/classes/external/get_bigbluebuttonbns_by_courses.php
+++ b/mod/bigbluebuttonbn/classes/external/get_bigbluebuttonbns_by_courses.php
@@ -16,22 +16,14 @@
namespace mod_bigbluebuttonbn\external;
-use context_module;
use core_course\external\helper_for_get_mods_by_courses;
-use external_api;
-use external_files;
-use external_format_value;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_util;
-use external_value;
-use external_warnings;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util as external_util;
/**
* External service to get activity per course
diff --git a/mod/bigbluebuttonbn/classes/external/get_join_url.php b/mod/bigbluebuttonbn/classes/external/get_join_url.php
index 8a2b8fe49d4b3..f3064fe36dccf 100644
--- a/mod/bigbluebuttonbn/classes/external/get_join_url.php
+++ b/mod/bigbluebuttonbn/classes/external/get_join_url.php
@@ -16,19 +16,15 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\exceptions\meeting_join_exception;
use mod_bigbluebuttonbn\meeting;
-use restricted_context_exception;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
/**
* External service to create the meeting (if needed), check user limit, and return the join URL when we can join.
@@ -109,7 +105,7 @@ public static function execute(
public static function execute_returns(): external_single_structure {
return new external_single_structure([
'join_url' => new external_value(PARAM_RAW, 'Can join session', VALUE_OPTIONAL),
- 'warnings' => new \external_warnings()
+ 'warnings' => new external_warnings(),
]);
}
}
diff --git a/mod/bigbluebuttonbn/classes/external/get_recordings.php b/mod/bigbluebuttonbn/classes/external/get_recordings.php
index 989135eec2fb5..dcaa29419b41d 100644
--- a/mod/bigbluebuttonbn/classes/external/get_recordings.php
+++ b/mod/bigbluebuttonbn/classes/external/get_recordings.php
@@ -16,21 +16,16 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_data;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
-use restricted_context_exception;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
/**
* External service to fetch a list of recordings from the BBB service.
diff --git a/mod/bigbluebuttonbn/classes/external/get_recordings_to_import.php b/mod/bigbluebuttonbn/classes/external/get_recordings_to_import.php
index 9d780d99013cf..8886dc8427680 100644
--- a/mod/bigbluebuttonbn/classes/external/get_recordings_to_import.php
+++ b/mod/bigbluebuttonbn/classes/external/get_recordings_to_import.php
@@ -16,21 +16,16 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_data;
use mod_bigbluebuttonbn\recording;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* External service to fetch a list of recordings from the BBB service.
*
diff --git a/mod/bigbluebuttonbn/classes/external/meeting_info.php b/mod/bigbluebuttonbn/classes/external/meeting_info.php
index b61be8fd5d8a4..d48b1f97fc6c4 100644
--- a/mod/bigbluebuttonbn/classes/external/meeting_info.php
+++ b/mod/bigbluebuttonbn/classes/external/meeting_info.php
@@ -16,19 +16,15 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\restricted_context_exception;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\proxy\bigbluebutton_proxy;
use mod_bigbluebuttonbn\meeting;
-use restricted_context_exception;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
/**
* External service to fetch meeting information.
@@ -132,7 +128,7 @@ public static function execute_returns(): external_single_structure {
'participantplural' => new external_value(PARAM_BOOL, 'Several participants ?', VALUE_OPTIONAL),
'canjoin' => new external_value(PARAM_BOOL, 'Can join'),
'ismoderator' => new external_value(PARAM_BOOL, 'Is moderator'),
- 'presentations' => new \external_multiple_structure(
+ 'presentations' => new external_multiple_structure(
new external_single_structure([
'url' => new external_value(PARAM_URL, 'presentation URL'),
'iconname' => new external_value(PARAM_RAW, 'icon name'),
@@ -144,7 +140,7 @@ public static function execute_returns(): external_single_structure {
'guestaccessenabled' => new external_value(PARAM_BOOL, 'Guest access enabled', VALUE_OPTIONAL),
'guestjoinurl' => new external_value(PARAM_URL, 'Guest URL', VALUE_OPTIONAL),
'guestpassword' => new external_value(PARAM_RAW, 'Guest join password', VALUE_OPTIONAL),
- 'features' => new \external_multiple_structure(
+ 'features' => new external_multiple_structure(
new external_single_structure([
'name' => new external_value(PARAM_ALPHA, 'Feature name.'),
'isenabled' => new external_value(PARAM_BOOL, 'Whether the feature is enabled.'),
diff --git a/mod/bigbluebuttonbn/classes/external/update_recording.php b/mod/bigbluebuttonbn/classes/external/update_recording.php
index be22cc4a4901a..6ba0bc05a49d0 100644
--- a/mod/bigbluebuttonbn/classes/external/update_recording.php
+++ b/mod/bigbluebuttonbn/classes/external/update_recording.php
@@ -17,20 +17,14 @@
namespace mod_bigbluebuttonbn\external;
use coding_exception;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_action;
-use mod_bigbluebuttonbn\local\bigbluebutton\recordings\recording_helper;
use mod_bigbluebuttonbn\recording;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* External service to update the details of one recording.
*
diff --git a/mod/bigbluebuttonbn/classes/external/view_bigbluebuttonbn.php b/mod/bigbluebuttonbn/classes/external/view_bigbluebuttonbn.php
index 176bcd42ab2ff..6b92cc1b57b42 100644
--- a/mod/bigbluebuttonbn/classes/external/view_bigbluebuttonbn.php
+++ b/mod/bigbluebuttonbn/classes/external/view_bigbluebuttonbn.php
@@ -17,19 +17,13 @@
namespace mod_bigbluebuttonbn\external;
use context_module;
-use external_api;
-use external_description;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_bigbluebuttonbn\instance;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* External service to trigger the course module viewed event and update the module completion status
*
@@ -101,7 +95,7 @@ public static function execute($instanceid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function execute_returns() {
diff --git a/mod/bigbluebuttonbn/tests/external/can_join_test.php b/mod/bigbluebuttonbn/tests/external/can_join_test.php
index 477e1bf84c477..8fe1d7080eeb3 100644
--- a/mod/bigbluebuttonbn/tests/external/can_join_test.php
+++ b/mod/bigbluebuttonbn/tests/external/can_join_test.php
@@ -16,7 +16,7 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use moodle_exception;
diff --git a/mod/bigbluebuttonbn/tests/external/completion_validate_test.php b/mod/bigbluebuttonbn/tests/external/completion_validate_test.php
index 1183a60eaecc2..df6524095a05c 100644
--- a/mod/bigbluebuttonbn/tests/external/completion_validate_test.php
+++ b/mod/bigbluebuttonbn/tests/external/completion_validate_test.php
@@ -16,7 +16,7 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use require_login_exception;
diff --git a/mod/bigbluebuttonbn/tests/external/end_meeting_test.php b/mod/bigbluebuttonbn/tests/external/end_meeting_test.php
index 491b886746832..d3fd82e482208 100644
--- a/mod/bigbluebuttonbn/tests/external/end_meeting_test.php
+++ b/mod/bigbluebuttonbn/tests/external/end_meeting_test.php
@@ -16,13 +16,13 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\meeting;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use moodle_exception;
use require_login_exception;
-use restricted_context_exception;
+use core_external\restricted_context_exception;
defined('MOODLE_INTERNAL') || die();
diff --git a/mod/bigbluebuttonbn/tests/external/get_bigbluebuttons_by_courses_test.php b/mod/bigbluebuttonbn/tests/external/get_bigbluebuttons_by_courses_test.php
index ac4f22ac4fe40..cd0db47400870 100644
--- a/mod/bigbluebuttonbn/tests/external/get_bigbluebuttons_by_courses_test.php
+++ b/mod/bigbluebuttonbn/tests/external/get_bigbluebuttons_by_courses_test.php
@@ -16,7 +16,7 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use moodle_exception;
diff --git a/mod/bigbluebuttonbn/tests/external/get_join_url_test.php b/mod/bigbluebuttonbn/tests/external/get_join_url_test.php
index 3bdd93242a4f1..9036916d61e5d 100644
--- a/mod/bigbluebuttonbn/tests/external/get_join_url_test.php
+++ b/mod/bigbluebuttonbn/tests/external/get_join_url_test.php
@@ -16,9 +16,8 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
-use mod_bigbluebuttonbn\local\config;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use moodle_exception;
diff --git a/mod/bigbluebuttonbn/tests/external/get_recordings_test.php b/mod/bigbluebuttonbn/tests/external/get_recordings_test.php
index b1040873e3cf9..96b85bc481615 100644
--- a/mod/bigbluebuttonbn/tests/external/get_recordings_test.php
+++ b/mod/bigbluebuttonbn/tests/external/get_recordings_test.php
@@ -16,7 +16,7 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
use require_login_exception;
diff --git a/mod/bigbluebuttonbn/tests/external/view_bigbluebuttonbn_test.php b/mod/bigbluebuttonbn/tests/external/view_bigbluebuttonbn_test.php
index 3cfbb90efa08b..31e0ca4574bd9 100644
--- a/mod/bigbluebuttonbn/tests/external/view_bigbluebuttonbn_test.php
+++ b/mod/bigbluebuttonbn/tests/external/view_bigbluebuttonbn_test.php
@@ -16,10 +16,9 @@
namespace mod_bigbluebuttonbn\external;
-use external_api;
+use core_external\external_api;
use mod_bigbluebuttonbn\instance;
use mod_bigbluebuttonbn\test\testcase_helper_trait;
-use moodle_exception;
use require_login_exception;
defined('MOODLE_INTERNAL') || die();
diff --git a/mod/book/classes/external.php b/mod/book/classes/external.php
index 7a26c0b36a4cc..ee22e0ed42a6b 100644
--- a/mod/book/classes/external.php
+++ b/mod/book/classes/external.php
@@ -25,10 +25,13 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Book external functions
@@ -139,7 +142,7 @@ public static function view_book($bookid, $chapterid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_book_returns() {
@@ -191,7 +194,7 @@ public static function get_books_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $courses);
// Get the books in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
diff --git a/mod/book/tests/externallib_test.php b/mod/book/tests/externallib_test.php
index 9508f647e57c6..106f1ec169dfa 100644
--- a/mod/book/tests/externallib_test.php
+++ b/mod/book/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_book;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_book_external;
@@ -81,7 +82,7 @@ public function test_view_book() {
$sink = $this->redirectEvents();
$result = mod_book_external::view_book($book->id, 0);
- $result = \external_api::clean_returnvalue(mod_book_external::view_book_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_book_external::view_book_returns(), $result);
$events = $sink->get_events();
$this->assertCount(2, $events);
@@ -100,7 +101,7 @@ public function test_view_book() {
$this->assertEquals($chapter->id, $event->objectid);
$result = mod_book_external::view_book($book->id, $chapter->id);
- $result = \external_api::clean_returnvalue(mod_book_external::view_book_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_book_external::view_book_returns(), $result);
$events = $sink->get_events();
// We expect a total of 3 events.
@@ -156,7 +157,7 @@ public function test_get_books_by_courses() {
$books = mod_book_external::get_books_by_courses();
// We need to execute the return values cleaning process to simulate the web service server.
- $books = \external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
+ $books = external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
$this->assertCount(1, $books['books']);
$this->assertEquals('First Book', $books['books'][0]['name']);
// We see 10 fields.
@@ -168,7 +169,7 @@ public function test_get_books_by_courses() {
// Student1 is not enrolled in course2. The webservice will return a warning!
$books = mod_book_external::get_books_by_courses(array($course2->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $books = \external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
+ $books = external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
$this->assertCount(0, $books['books']);
$this->assertEquals(1, $books['warnings'][0]['warningcode']);
@@ -177,7 +178,7 @@ public function test_get_books_by_courses() {
// As Admin we can see this book.
$books = mod_book_external::get_books_by_courses(array($course2->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $books = \external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
+ $books = external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
$this->assertCount(1, $books['books']);
$this->assertEquals('Second Book', $books['books'][0]['name']);
@@ -190,7 +191,7 @@ public function test_get_books_by_courses() {
self::getDataGenerator()->enrol_user($student1->id, $course2->id, $studentrole->id);
$this->setUser($student1);
$books = mod_book_external::get_books_by_courses();
- $books = \external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
+ $books = external_api::clean_returnvalue(mod_book_external::get_books_by_courses_returns(), $books);
$this->assertCount(2, $books['books']);
}
diff --git a/mod/book/tests/lib_test.php b/mod/book/tests/lib_test.php
index b679aaa34e9a8..2493ce156e106 100644
--- a/mod/book/tests/lib_test.php
+++ b/mod/book/tests/lib_test.php
@@ -24,6 +24,8 @@
*/
namespace mod_book;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -90,7 +92,7 @@ public function test_export_contents() {
// Now, test the function via the external API.
$contents = \core_course_external::get_course_contents($course->id, array());
- $contents = \external_api::clean_returnvalue(\core_course_external::get_course_contents_returns(), $contents);
+ $contents = external_api::clean_returnvalue(\core_course_external::get_course_contents_returns(), $contents);
$this->assertCount(4, $contents[0]['modules'][0]['contents']);
@@ -145,7 +147,7 @@ public function test_export_contents() {
// Now, test the function via the external API.
$contents = \core_course_external::get_course_contents($course->id, array());
- $contents = \external_api::clean_returnvalue(\core_course_external::get_course_contents_returns(), $contents);
+ $contents = external_api::clean_returnvalue(\core_course_external::get_course_contents_returns(), $contents);
$this->assertCount(5, $contents[0]['modules'][0]['contents']);
diff --git a/mod/chat/classes/external.php b/mod/chat/classes/external.php
index 14876c7044ba7..5f75d30b9e8cf 100644
--- a/mod/chat/classes/external.php
+++ b/mod/chat/classes/external.php
@@ -26,10 +26,16 @@
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/chat/lib.php');
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
use mod_chat\external\chat_message_exporter;
/**
@@ -121,7 +127,7 @@ public static function login_user($chatid, $groupid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function login_user_returns() {
@@ -204,7 +210,7 @@ public static function get_chat_users($chatsid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_chat_users_returns() {
@@ -300,7 +306,7 @@ public static function send_chat_message($chatsid, $messagetext, $beepid = '') {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function send_chat_message_returns() {
@@ -378,10 +384,15 @@ public static function get_chat_latest_messages($chatsid, $chatlasttime = 0) {
$returnedmessages = array();
foreach ($messages as $message) {
-
// FORMAT_MOODLE is mandatory in the chat plugin.
- list($messageformatted, $format) = external_format_text($message->message, FORMAT_MOODLE, $context->id, 'mod_chat',
- '', 0);
+ [$messageformatted] = \core_external\util::format_text(
+ $message->message,
+ FORMAT_MOODLE,
+ $context->id,
+ 'mod_chat',
+ '',
+ 0
+ );
$returnedmessages[] = array(
'id' => $message->id,
@@ -405,7 +416,7 @@ public static function get_chat_latest_messages($chatsid, $chatlasttime = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_chat_latest_messages_returns() {
@@ -481,7 +492,7 @@ public static function view_chat($chatid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_chat_returns() {
@@ -535,7 +546,7 @@ public static function get_chats_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $courses);
// Get the chats in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -687,7 +698,7 @@ public static function get_sessions($chatid, $groupid = 0, $showall = false) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_sessions_returns() {
@@ -806,7 +817,7 @@ public static function get_session_messages($chatid, $sessionstart, $sessionend,
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_session_messages_returns() {
diff --git a/mod/chat/tests/backup/restore_date_test.php b/mod/chat/tests/backup/restore_date_test.php
index 89c9e0e54593d..07b732d876ec0 100644
--- a/mod/chat/tests/backup/restore_date_test.php
+++ b/mod/chat/tests/backup/restore_date_test.php
@@ -16,6 +16,8 @@
namespace mod_chat\backup;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -35,11 +37,11 @@ public function test_restore_dates() {
list($course, $chat) = $this->create_course_and_module('chat');
$result = \mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(\mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(\mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
$result = \mod_chat_external::send_chat_message($chatsid, 'hello!');
- $result = \external_api::clean_returnvalue(\mod_chat_external::send_chat_message_returns(), $result);
+ $result = external_api::clean_returnvalue(\mod_chat_external::send_chat_message_returns(), $result);
$message = $DB->get_record('chat_messages', ['id' => $result['messageid']]);
$timestamp = 1000;
$DB->set_field('chat_messages', 'timestamp', $timestamp);
diff --git a/mod/chat/tests/externallib_test.php b/mod/chat/tests/externallib_test.php
index 3219c8da2cd13..723bd42228ada 100644
--- a/mod/chat/tests/externallib_test.php
+++ b/mod/chat/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_chat;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_chat_external;
@@ -55,7 +56,7 @@ public function test_login_user() {
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
// Test session started.
$sid = $DB->get_field('chat_users', 'sid', array('userid' => $user->id, 'chatid' => $chat->id));
@@ -85,15 +86,15 @@ public function test_get_chat_users() {
$this->getDataGenerator()->enrol_user($user2->id, $course->id, $studentrole->id);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$this->setUser($user2);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
// Get users.
$result = mod_chat_external::get_chat_users($result['chatsid']);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_chat_users_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_chat_users_returns(), $result);
// Check correct users.
$this->assertCount(2, $result['users']);
@@ -126,16 +127,16 @@ public function test_send_get_chat_message() {
$this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
$result = mod_chat_external::send_chat_message($chatsid, 'hello!');
- $result = \external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
// Test messages received.
$result = mod_chat_external::get_chat_latest_messages($chatsid, 0);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_chat_latest_messages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_chat_latest_messages_returns(), $result);
foreach ($result['messages'] as $message) {
// Ommit system messages, like user just joined in.
@@ -187,7 +188,7 @@ public function test_view_chat() {
$sink = $this->redirectEvents();
$result = mod_chat_external::view_chat($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::view_chat_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::view_chat_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -246,7 +247,7 @@ public function test_get_chats_by_courses() {
$chats = mod_chat_external::get_chats_by_courses();
// We need to execute the return values cleaning process to simulate the web service server.
- $chats = \external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
+ $chats = external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
$this->assertCount(1, $chats['chats']);
$this->assertEquals('First Chat', $chats['chats'][0]['name']);
// We see 12 fields.
@@ -258,7 +259,7 @@ public function test_get_chats_by_courses() {
// Student1 is not enrolled in course2. The webservice will return a warning!
$chats = mod_chat_external::get_chats_by_courses(array($course2->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $chats = \external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
+ $chats = external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
$this->assertCount(0, $chats['chats']);
$this->assertEquals(1, $chats['warnings'][0]['warningcode']);
@@ -267,7 +268,7 @@ public function test_get_chats_by_courses() {
// As Admin we can see this chat.
$chats = mod_chat_external::get_chats_by_courses(array($course2->id));
// We need to execute the return values cleaning process to simulate the web service server.
- $chats = \external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
+ $chats = external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
$this->assertCount(1, $chats['chats']);
$this->assertEquals('Second Chat', $chats['chats'][0]['name']);
@@ -281,7 +282,7 @@ public function test_get_chats_by_courses() {
self::getDataGenerator()->enrol_user($student1->id, $course2->id, $studentrole->id);
$this->setUser($student1);
$chats = mod_chat_external::get_chats_by_courses();
- $chats = \external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
+ $chats = external_api::clean_returnvalue(mod_chat_external::get_chats_by_courses_returns(), $chats);
$this->assertCount(2, $chats['chats']);
}
@@ -300,7 +301,7 @@ public function test_get_sessions_empty_chat() {
$chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id));
$result = mod_chat_external::get_sessions($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
$this->assertEmpty($result['sessions']);
$this->assertEmpty($result['warnings']);
}
@@ -321,7 +322,7 @@ public function test_get_sessions_no_permissions_for_student() {
$chat = $this->getDataGenerator()->create_module('chat', array('course' => $course->id, 'studentlogs' => 0));
// The admin has permissions to check logs.
$result = mod_chat_external::get_sessions($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
$this->assertEmpty($result['sessions']);
$this->assertEmpty($result['warnings']);
@@ -357,20 +358,20 @@ public function test_get_sessions_not_completed_session() {
// Start a chat and send just one message.
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
$result = mod_chat_external::send_chat_message($chatsid, 'hello!');
- $result = \external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
// Check session is not marked as completed so it is not returned.
$result = mod_chat_external::get_sessions($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
$this->assertEmpty($result['sessions']);
$this->assertEmpty($result['warnings']);
// Pass showall parameter to indicate that we want not completed sessions.
$result = mod_chat_external::get_sessions($chat->id, 0, true);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
$this->assertCount(1, $result['sessions']); // One session.
$this->assertFalse($result['sessions'][0]['iscomplete']); // Session not complete.
$this->assertEmpty($result['warnings']);
@@ -398,16 +399,16 @@ public function test_get_sessions_completed_session() {
// Start a chat and completeit.
$this->setUser($user1);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
$result = mod_chat_external::send_chat_message($chatsid, 'hello!');
- $result = \external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
$this->setUser($user2);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
$result = mod_chat_external::send_chat_message($chatsid, 'hello to you!');
- $result = \external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::send_chat_message_returns(), $result);
// Need to change first messages and last message times to mark the session completed.
// We receive 4 messages (2 system messages that indicates user joined and the 2 messages sent by the users).
$messages = $DB->get_records('chat_messages', array('chatid' => $chat->id));
@@ -420,7 +421,7 @@ public function test_get_sessions_completed_session() {
}
// Check session is completed.
$result = mod_chat_external::get_sessions($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
$this->assertCount(1, $result['sessions']); // One session.
$this->assertTrue($result['sessions'][0]['iscomplete']); // Session complete.
// The session started when user1 entered the chat.
@@ -450,26 +451,26 @@ public function test_get_session_messages() {
// Start a chat and send a few messages.
$this->setUser($user1);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
mod_chat_external::send_chat_message($chatsid, 'hello!');
mod_chat_external::send_chat_message($chatsid, 'bye bye!');
$this->setUser($user2);
$result = mod_chat_external::login_user($chat->id);
- $result = \external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::login_user_returns(), $result);
$chatsid = $result['chatsid'];
mod_chat_external::send_chat_message($chatsid, 'greetings!');
// Pass showall parameter to indicate that we want not completed sessions.
$result = mod_chat_external::get_sessions($chat->id, 0, true);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_sessions_returns(), $result);
$this->assertCount(1, $result['sessions']); // One session.
$sessionstart = $result['sessions'][0]['sessionstart'];
$sessionend = $result['sessions'][0]['sessionend'];
$result = mod_chat_external::get_session_messages($chat->id, $sessionstart, $sessionend);
- $result = \external_api::clean_returnvalue(mod_chat_external::get_session_messages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_chat_external::get_session_messages_returns(), $result);
$this->assertCount(5, $result['messages']); // 2 system + 3 personal messages.
$found = 0;
foreach ($result['messages'] as $message) {
diff --git a/mod/choice/classes/external.php b/mod/choice/classes/external.php
index 1612e44dc895f..f451d793fadab 100644
--- a/mod/choice/classes/external.php
+++ b/mod/choice/classes/external.php
@@ -25,9 +25,15 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/choice/lib.php');
/**
@@ -115,7 +121,7 @@ public static function get_choice_results($choiceid) {
}
$options[] = array('id' => $optionid,
- 'text' => external_format_string($option->text, $context->id),
+ 'text' => \core_external\util::format_string($option->text, $context->id),
'maxanswer' => $option->maxanswer,
'userresponses' => $userresponses,
'numberofuser' => $numberofuser,
@@ -228,7 +234,7 @@ public static function get_choice_options($choiceid) {
foreach ($options['options'] as $option) {
$optionarr = array();
$optionarr['id'] = $option->attributes->value;
- $optionarr['text'] = external_format_string($option->text, $context->id);
+ $optionarr['text'] = \core_external\util::format_string($option->text, $context->id);
$optionarr['maxanswers'] = $option->maxanswers;
$optionarr['displaylayout'] = $option->displaylayout;
$optionarr['countanswers'] = $option->countanswers;
@@ -436,7 +442,7 @@ public static function view_choice($choiceid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_choice_returns() {
@@ -487,7 +493,7 @@ public static function get_choices_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $courses);
// Get the choices in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
diff --git a/mod/choice/tests/externallib_test.php b/mod/choice/tests/externallib_test.php
index 561ec87fdb972..57bc4079bafba 100644
--- a/mod/choice/tests/externallib_test.php
+++ b/mod/choice/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_choice;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_choice_external;
@@ -71,7 +72,7 @@ public function test_get_choice_results() {
choice_user_submit_response($myanswer, $choice, $student1->id, $course, $cm);
$results = mod_choice_external::get_choice_results($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
// Create an array with optionID as Key.
$resultsarr = array();
@@ -87,7 +88,7 @@ public function test_get_choice_results() {
$this->setUser($student2);
$results = mod_choice_external::get_choice_results($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
// We do not retrieve any response!
foreach ($results['options'] as $option) {
$this->assertCount(0, $option['userresponses']);
@@ -103,7 +104,7 @@ public function test_get_choice_results() {
$results = mod_choice_external::get_choice_results($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
// We do not retrieve any response (activity is still open).
foreach ($results['options'] as $option) {
$this->assertCount(0, $option['userresponses']);
@@ -115,7 +116,7 @@ public function test_get_choice_results() {
// Now as Stundent2 we will see results!
$results = mod_choice_external::get_choice_results($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
// Create an array with optionID as Key.
$resultsarr = array();
foreach ($results['options'] as $option) {
@@ -131,7 +132,7 @@ public function test_get_choice_results() {
$DB->update_record('choice', $choice);
$results = mod_choice_external::get_choice_results($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_results_returns(), $results);
// Create an array with optionID as Key.
$resultsarr = array();
// Does not show any user response!
@@ -177,7 +178,7 @@ public function test_get_choice_options() {
$results = mod_choice_external::get_choice_options($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
// We should retrieve all options.
$this->assertCount(count($possibleoptions), $results['options']);
@@ -188,7 +189,7 @@ public function test_get_choice_options() {
$results = mod_choice_external::get_choice_options($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
// We should retrieve no options.
$this->assertCount(0, $results['options']);
$this->assertEquals($notopenyet, $results['warnings'][0]['warningcode']);
@@ -198,7 +199,7 @@ public function test_get_choice_options() {
$DB->update_record('choice', $choice);
$results = mod_choice_external::get_choice_options($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
// We should retrieve all options.
$this->assertCount(count($possibleoptions), $results['options']);
@@ -225,7 +226,7 @@ public function test_get_choice_options() {
$results = mod_choice_external::get_choice_options($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
// We should retrieve all options.
$this->assertCount(count($possibleoptions), $results['options']);
foreach ($results['options'] as $option) {
@@ -245,7 +246,7 @@ public function test_get_choice_options() {
$DB->update_record('choice', $choice);
$results = mod_choice_external::get_choice_options($choice->id);
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::get_choice_options_returns(), $results);
// We should retrieve no options.
$this->assertCount(0, $results['options']);
$this->assertEquals($expired, $results['warnings'][0]['warningcode']);
@@ -282,7 +283,7 @@ public function test_submit_choice_response() {
$myresponse = $options[2];
$results = mod_choice_external::submit_choice_response($choice->id, array($myresponse));
// We need to execute the return values cleaning process to simulate the web service server.
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
$myanswers = $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $student1->id));
$myanswer = reset($myanswers);
$this->assertEquals($results['answers'][0]['id'], $myanswer->id);
@@ -331,7 +332,7 @@ public function test_view_choice() {
$sink = $this->redirectEvents();
$result = mod_choice_external::view_choice($choice->id);
- $result = \external_api::clean_returnvalue(mod_choice_external::view_choice_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_choice_external::view_choice_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -377,7 +378,7 @@ public function test_get_choices_by_courses() {
$this->setUser($student1);
$choices = mod_choice_external::get_choices_by_courses(array());
- $choices = \external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
+ $choices = external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
$this->assertCount(1, $choices['choices']);
$this->assertEquals('First IMSCP', $choices['choices'][0]['name']);
// As Student you cannot see some IMSCP properties like 'section'.
@@ -386,7 +387,7 @@ public function test_get_choices_by_courses() {
// Student1 is not enrolled in this Course.
// The webservice will give a warning!
$choices = mod_choice_external::get_choices_by_courses(array($course2->id));
- $choices = \external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
+ $choices = external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
$this->assertCount(0, $choices['choices']);
$this->assertEquals(1, $choices['warnings'][0]['warningcode']);
@@ -394,7 +395,7 @@ public function test_get_choices_by_courses() {
$this->setAdminUser();
// As Admin we can see this IMSCP.
$choices = mod_choice_external::get_choices_by_courses(array($course2->id));
- $choices = \external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
+ $choices = external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
$this->assertCount(1, $choices['choices']);
$this->assertEquals('Second IMSCP', $choices['choices'][0]['name']);
// As an Admin you can see some IMSCP properties like 'section'.
@@ -408,7 +409,7 @@ public function test_get_choices_by_courses() {
accesslib_clear_all_caches_for_unit_testing();
$choices = mod_choice_external::get_choices_by_courses(array($course1->id));
- $choices = \external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
+ $choices = external_api::clean_returnvalue(mod_choice_external::get_choices_by_courses_returns(), $choices);
$this->assertFalse(isset($choices['choices'][0]['timeopen']));
}
@@ -442,7 +443,7 @@ public function test_delete_choice_responses() {
$this->setUser($student);
$results = mod_choice_external::submit_choice_response($choice->id, array($options[1], $options[2]));
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
$myresponses = array_keys(choice_get_my_response($choice));
@@ -467,7 +468,7 @@ public function test_delete_choice_responses() {
// Reset time close. We should be able now to delete all the responses.
$DB->set_field('choice', 'timeclose', 0, array('id' => $choice->id));
$results = mod_choice_external::delete_choice_responses($choice->id, array($myresponses[0], $myresponses[1]));
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
$this->assertCount(0, $results['warnings']);
@@ -476,12 +477,12 @@ public function test_delete_choice_responses() {
// Submit again the responses.
$results = mod_choice_external::submit_choice_response($choice->id, array($options[1], $options[2]));
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
$myresponses = array_keys(choice_get_my_response($choice));
// Delete only one response.
$results = mod_choice_external::delete_choice_responses($choice->id, array($myresponses[0]));
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
$this->assertCount(0, $results['warnings']);
// Now, in the DB 1 response still.
@@ -490,7 +491,7 @@ public function test_delete_choice_responses() {
// Delete the remaining response, passing 2 invalid responses ids.
$results = mod_choice_external::delete_choice_responses($choice->id, array($myresponses[1], $myresponses[0] + 2,
$myresponses[0] + 3));
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
// 2 warnings, 2 invalid responses.
$this->assertCount(2, $results['warnings']);
@@ -501,7 +502,7 @@ public function test_delete_choice_responses() {
$this->setUser($student);
// Submit again the responses.
$results = mod_choice_external::submit_choice_response($choice->id, array($options[1], $options[2]));
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
$studentresponses = array_keys(choice_get_my_response($choice));
$this->setAdminUser();
@@ -509,7 +510,7 @@ public function test_delete_choice_responses() {
$DB->set_field('choice', 'timeclose', time() - DAYSECS, array('id' => $choice->id));
$results = mod_choice_external::delete_choice_responses($choice->id, array($studentresponses[0], $studentresponses[1]));
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
$this->assertCount(0, $results['warnings']);
@@ -518,12 +519,12 @@ public function test_delete_choice_responses() {
$this->setUser($student);
$DB->set_field('choice', 'timeclose', 0, array('id' => $choice->id));
$results = mod_choice_external::submit_choice_response($choice->id, array($options[1], $options[2]));
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
// Test admin try to delete his own responses (he didn't respond so nothing should be deleted).
$this->setAdminUser();
$results = mod_choice_external::delete_choice_responses($choice->id);
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertFalse($results['status']);
$this->assertCount(0, $results['warnings']);
$allresponses = choice_get_all_responses($choice);
@@ -531,12 +532,12 @@ public function test_delete_choice_responses() {
// Now admin submit a couple of responses more.
$results = mod_choice_external::submit_choice_response($choice->id, array($options[1], $options[2]));
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
$allresponses = choice_get_all_responses($choice);
$this->assertCount(4, $allresponses);
// Admin responses are deleted when passing an empty array.
$results = mod_choice_external::delete_choice_responses($choice->id);
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
$this->assertCount(0, $results['warnings']);
$allresponses = choice_get_all_responses($choice);
@@ -544,7 +545,7 @@ public function test_delete_choice_responses() {
// Now admin will delete all the other users responses.
$results = mod_choice_external::delete_choice_responses($choice->id, array_keys($allresponses));
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
$this->assertCount(0, $results['warnings']);
@@ -553,7 +554,7 @@ public function test_delete_choice_responses() {
// Admin try do delete an invalid response.
$results = mod_choice_external::delete_choice_responses($choice->id, array(-1));
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertFalse($results['status']);
$this->assertCount(1, $results['warnings']);
@@ -565,11 +566,11 @@ public function test_delete_choice_responses() {
$DB->set_field('choice', 'allowupdate', 1, array('id' => $choice->id));
$DB->set_field('choice', 'timeclose', 0, array('id' => $choice->id));
$results = mod_choice_external::submit_choice_response($choice->id, array($options[1], $options[2]));
- $results = \external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::submit_choice_response_returns(), $results);
// Delete all responses.
$results = mod_choice_external::delete_choice_responses($choice->id);
- $results = \external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
+ $results = external_api::clean_returnvalue(mod_choice_external::delete_choice_responses_returns(), $results);
$this->assertTrue($results['status']);
$this->assertCount(0, $results['warnings']);
diff --git a/mod/data/classes/external.php b/mod/data/classes/external.php
index e4e22192ea7e8..5432d218060d0 100644
--- a/mod/data/classes/external.php
+++ b/mod/data/classes/external.php
@@ -26,12 +26,17 @@
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . "/mod/data/locallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
use mod_data\external\database_summary_exporter;
use mod_data\external\record_exporter;
-use mod_data\external\content_exporter;
use mod_data\external\field_exporter;
use mod_data\manager;
@@ -89,7 +94,7 @@ public static function get_databases_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($dbcourses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($dbcourses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the databases in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -127,7 +132,7 @@ public static function get_databases_by_courses($courseids = array()) {
}
$exporter = new database_summary_exporter($database, array('context' => $context));
$data = $exporter->export($PAGE->get_renderer('core'));
- $data->name = external_format_string($data->name, $context);
+ $data->name = \core_external\util::format_string($data->name, $context);
$arrdatabases[] = $data;
}
}
@@ -220,7 +225,7 @@ public static function view_database($databaseid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function view_database_returns() {
@@ -307,7 +312,7 @@ public static function get_data_access_information($databaseid, $groupid = 0) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function get_data_access_information_returns() {
@@ -461,7 +466,7 @@ public static function get_entries($databaseid, $groupid = 0, $returncontents =
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function get_entries_returns() {
@@ -557,7 +562,7 @@ public static function get_entry($entryid, $returncontents = false) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function get_entry_returns() {
@@ -631,7 +636,7 @@ public static function get_fields($databaseid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function get_fields_returns() {
@@ -796,7 +801,7 @@ public static function search_entries($databaseid, $groupid = 0, $returncontents
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function search_entries_returns() {
@@ -866,7 +871,7 @@ public static function approve_entry($entryid, $approve = true) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function approve_entry_returns() {
@@ -926,7 +931,7 @@ public static function delete_entry($entryid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function delete_entry_returns() {
@@ -1048,7 +1053,7 @@ public static function add_entry($databaseid, $groupid, $data) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function add_entry_returns() {
@@ -1162,7 +1167,7 @@ public static function update_entry($entryid, $data) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.3
*/
public static function update_entry_returns() {
diff --git a/mod/data/classes/external/content_exporter.php b/mod/data/classes/external/content_exporter.php
index 3e41e9e6ce8d9..0617dacd5b3c4 100644
--- a/mod/data/classes/external/content_exporter.php
+++ b/mod/data/classes/external/content_exporter.php
@@ -26,8 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_files;
-use external_util;
+use core_external\external_files;
+use core_external\util as external_util;
/**
* Class for exporting content associated to a record.
diff --git a/mod/data/classes/external/database_summary_exporter.php b/mod/data/classes/external/database_summary_exporter.php
index ec85060293419..ab85cc8a6caa0 100644
--- a/mod/data/classes/external/database_summary_exporter.php
+++ b/mod/data/classes/external/database_summary_exporter.php
@@ -26,8 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_files;
-use external_util;
+use core_external\external_files;
+use core_external\util as external_util;
/**
* Class for exporting partial database data (some fields are only viewable by admins).
diff --git a/mod/data/classes/external/delete_saved_preset.php b/mod/data/classes/external/delete_saved_preset.php
index e6a4e52e50a8b..6903e8d9b7d9f 100644
--- a/mod/data/classes/external/delete_saved_preset.php
+++ b/mod/data/classes/external/delete_saved_preset.php
@@ -17,14 +17,15 @@
namespace mod_data\external;
use core\notification;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_data\manager;
use mod_data\preset;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* This is the external method for deleting a saved preset.
*
@@ -33,17 +34,17 @@
* @copyright 2022 Amaia Anabitarte
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class delete_saved_preset extends \external_api {
+class delete_saved_preset extends external_api {
/**
* Parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters([
- 'dataid' => new \external_value(PARAM_INT, 'Id of the data activity', VALUE_REQUIRED),
- 'presetnames' => new \external_multiple_structure(
- new \external_value(PARAM_TEXT, 'The preset name to delete', VALUE_REQUIRED)
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters([
+ 'dataid' => new external_value(PARAM_INT, 'Id of the data activity', VALUE_REQUIRED),
+ 'presetnames' => new external_multiple_structure(
+ new external_value(PARAM_TEXT, 'The preset name to delete', VALUE_REQUIRED)
)
]);
}
@@ -111,12 +112,12 @@ public static function execute(int $dataid, array $presetnames): array {
/**
* Return.
*
- * @return \external_single_structure
+ * @return external_single_structure
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure([
- 'result' => new \external_value(PARAM_BOOL, 'The processing result'),
- 'warnings' => new \external_warnings()
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure([
+ 'result' => new external_value(PARAM_BOOL, 'The processing result'),
+ 'warnings' => new external_warnings()
]);
}
}
diff --git a/mod/data/classes/external/get_mapping_information.php b/mod/data/classes/external/get_mapping_information.php
index 0051456d760ae..89552aa08759e 100644
--- a/mod/data/classes/external/get_mapping_information.php
+++ b/mod/data/classes/external/get_mapping_information.php
@@ -17,14 +17,14 @@
namespace mod_data\external;
use core\notification;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_data\local\importer\preset_importer;
use mod_data\manager;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* This is the external method for deleting a saved preset.
*
@@ -33,16 +33,16 @@
* @copyright 2022 Amaia Anabitarte
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class get_mapping_information extends \external_api {
+class get_mapping_information extends external_api {
/**
* Parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters([
- 'cmid' => new \external_value(PARAM_INT, 'Id of the data activity', VALUE_REQUIRED),
- 'importedpreset' => new \external_value(PARAM_TEXT, 'Preset to be imported'),
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters([
+ 'cmid' => new external_value(PARAM_INT, 'Id of the data activity', VALUE_REQUIRED),
+ 'importedpreset' => new external_value(PARAM_TEXT, 'Preset to be imported'),
]);
}
@@ -81,17 +81,17 @@ public static function execute(int $cmid, string $importedpreset): array {
/**
* Return.
*
- * @return \external_single_structure
+ * @return external_single_structure
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure([
- 'data' => new \external_single_structure([
- 'needsmapping' => new \external_value(PARAM_BOOL, 'Whether the importing needs mapping or not'),
- 'presetname' => new \external_value(PARAM_TEXT, 'Name of the applied preset'),
- 'fieldstocreate' => new \external_value(PARAM_TEXT, 'List of field names to create'),
- 'fieldstoremove' => new \external_value(PARAM_TEXT, 'List of field names to remove'),
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure([
+ 'data' => new external_single_structure([
+ 'needsmapping' => new external_value(PARAM_BOOL, 'Whether the importing needs mapping or not'),
+ 'presetname' => new external_value(PARAM_TEXT, 'Name of the applied preset'),
+ 'fieldstocreate' => new external_value(PARAM_TEXT, 'List of field names to create'),
+ 'fieldstoremove' => new external_value(PARAM_TEXT, 'List of field names to remove'),
], 'Information to import if everything went fine', VALUE_OPTIONAL),
- 'warnings' => new \external_warnings(),
+ 'warnings' => new external_warnings(),
]);
}
}
diff --git a/mod/data/tests/external/delete_saved_preset_test.php b/mod/data/tests/external/delete_saved_preset_test.php
index e36ae5e036484..a1a40276d3c2d 100644
--- a/mod/data/tests/external/delete_saved_preset_test.php
+++ b/mod/data/tests/external/delete_saved_preset_test.php
@@ -22,7 +22,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use externallib_advanced_testcase;
-use external_api;
+use core_external\external_api;
use mod_data\manager;
/**
diff --git a/mod/data/tests/external/get_mapping_information_test.php b/mod/data/tests/external/get_mapping_information_test.php
index cbadf5966b2ae..b521875004481 100644
--- a/mod/data/tests/external/get_mapping_information_test.php
+++ b/mod/data/tests/external/get_mapping_information_test.php
@@ -21,7 +21,7 @@
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use mod_data\manager;
/**
diff --git a/mod/data/tests/externallib_test.php b/mod/data/tests/externallib_test.php
index 11213856b7f55..9e0cefd55943a 100644
--- a/mod/data/tests/externallib_test.php
+++ b/mod/data/tests/externallib_test.php
@@ -18,6 +18,8 @@
use externallib_advanced_testcase;
use mod_data_external;
+use core_external\external_api;
+use core_external\external_settings;
defined('MOODLE_INTERNAL') || die();
@@ -133,8 +135,7 @@ protected function add_test_field(): \data_field_base {
* Test get databases by courses
*/
public function test_mod_data_get_databases_by_courses() {
- global $DB, $CFG;
- require_once($CFG->libdir . '/externallib.php');
+ global $DB;
$this->resetAfterTest(true);
@@ -187,7 +188,7 @@ public function test_mod_data_get_databases_by_courses() {
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
// Set WS filtering.
- $wssettings = \external_settings::get_instance();
+ $wssettings = external_settings::get_instance();
$wssettings->set_filter(true);
// Create what we expect to be returned when querying the two courses.
@@ -228,12 +229,12 @@ public function test_mod_data_get_databases_by_courses() {
// Call the external function passing course ids.
$result = mod_data_external::get_databases_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
$this->assertEquals($expecteddatabases, $result['databases']);
// Call the external function without passing course id.
$result = mod_data_external::get_databases_by_courses();
- $result = \external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
$this->assertEquals($expecteddatabases, $result['databases']);
// Unenrol user from second course and alter expected databases.
@@ -242,7 +243,7 @@ public function test_mod_data_get_databases_by_courses() {
// Call the external function without passing course id.
$result = mod_data_external::get_databases_by_courses();
- $result = \external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
$this->assertEquals($expecteddatabases, $result['databases']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -263,14 +264,14 @@ public function test_mod_data_get_databases_by_courses() {
$expecteddatabases[0][$field] = $database1->{$field};
}
$result = mod_data_external::get_databases_by_courses();
- $result = \external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
$this->assertEquals($expecteddatabases, $result['databases']);
// Admin should get all the information.
self::setAdminUser();
$result = mod_data_external::get_databases_by_courses(array($course1->id));
- $result = \external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_databases_by_courses_returns(), $result);
$this->assertEquals($expecteddatabases, $result['databases']);
}
@@ -321,7 +322,7 @@ public function test_view_database() {
$sink = $this->redirectEvents();
$result = mod_data_external::view_database($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::view_database_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::view_database_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -355,7 +356,7 @@ public function test_get_data_access_information_student() {
$this->setUser($this->student1);
$result = mod_data_external::get_data_access_information($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
$this->assertEquals($this->group1->id, $result['groupid']);
@@ -388,7 +389,7 @@ public function test_get_data_access_information_teacher() {
$this->setUser($this->teacher);
$result = mod_data_external::get_data_access_information($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
$this->assertEquals(0, $result['groupid']);
@@ -417,7 +418,7 @@ public function test_get_data_access_information_groups() {
$this->setUser($this->student1);
$result = mod_data_external::get_data_access_information($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
$this->assertEquals($this->group1->id, $result['groupid']); // My group is correctly found.
$this->assertFalse($result['canmanageentries']);
@@ -431,7 +432,7 @@ public function test_get_data_access_information_groups() {
// Check the other course group in visible groups mode.
$result = mod_data_external::get_data_access_information($this->database->id, $this->group2->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_data_access_information_returns(), $result);
$this->assertEquals($this->group2->id, $result['groupid']); // The group is correctly found.
$this->assertFalse($result['canmanageentries']);
@@ -517,11 +518,11 @@ public function test_get_entries() {
// Check the behaviour when the database has no entries.
$result = mod_data_external::get_entries($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertEmpty($result['entries']);
$result = mod_data_external::get_entries($this->database->id, 0, true);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertEmpty($result['entries']);
$this->assertEmpty($result['listviewcontents']);
@@ -532,7 +533,7 @@ public function test_get_entries() {
// We may expect entries without group also.
$this->setUser($this->student1);
$result = mod_data_external::get_entries($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
@@ -554,7 +555,7 @@ public function test_get_entries() {
// Other user in same group.
$this->setUser($this->student2);
$result = mod_data_external::get_entries($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(4, $result['entries']); // I can see my entry is pending approval.
$this->assertEquals(4, $result['totalcount']);
@@ -562,7 +563,7 @@ public function test_get_entries() {
// Now try with the user in the second group that must see only two entries (his group entry and the one without group).
$this->setUser($this->student3);
$result = mod_data_external::get_entries($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['entries']);
$this->assertEquals(2, $result['totalcount']);
@@ -578,7 +579,7 @@ public function test_get_entries() {
// Now, as teacher we should see all (we have permissions to view all groups).
$this->setUser($this->teacher);
$result = mod_data_external::get_entries($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(5, $result['entries']); // I can see the not approved one.
$this->assertEquals(5, $result['totalcount']);
@@ -594,7 +595,7 @@ public function test_get_entries() {
// Basic test passing the parameter (instead having to calculate it).
$this->setUser($this->student1);
$result = mod_data_external::get_entries($this->database->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
@@ -602,7 +603,7 @@ public function test_get_entries() {
// Test ordering (reverse).
$this->setUser($this->student1);
$result = mod_data_external::get_entries($this->database->id, $this->group1->id, false, null, 'DESC');
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
@@ -611,14 +612,14 @@ public function test_get_entries() {
// Test pagination.
$this->setUser($this->student1);
$result = mod_data_external::get_entries($this->database->id, $this->group1->id, false, null, null, 0, 1);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
$this->assertEquals($entry11, $result['entries'][0]['id']);
$result = mod_data_external::get_entries($this->database->id, $this->group1->id, false, null, null, 1, 1);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
@@ -627,7 +628,7 @@ public function test_get_entries() {
// Now test the return contents.
data_generate_default_template($this->database, 'listtemplate', 0, false, true); // Generate a default list template.
$result = mod_data_external::get_entries($this->database->id, $this->group1->id, true, null, null, 0, 2);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entries_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
@@ -653,7 +654,7 @@ public function test_get_entry_visible_groups() {
// Check I can see my approved group entries.
$this->setUser($this->student1);
$result = mod_data_external::get_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($entry11, $result['entry']['id']);
$this->assertTrue($result['entry']['approved']);
@@ -661,7 +662,7 @@ public function test_get_entry_visible_groups() {
// Entry from other group.
$result = mod_data_external::get_entry($entry21);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($entry21, $result['entry']['id']);
}
@@ -676,7 +677,7 @@ public function test_get_entry_separated_groups() {
// Check I can see my approved group entries.
$this->setUser($this->student1);
$result = mod_data_external::get_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($entry11, $result['entry']['id']);
$this->assertTrue($result['entry']['approved']);
@@ -685,7 +686,7 @@ public function test_get_entry_separated_groups() {
// Retrieve contents.
data_generate_default_template($this->database, 'singletemplate', 0, false, true);
$result = mod_data_external::get_entry($entry11, true);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(9, $result['entry']['contents']);
$this->assertTrue(strpos($result['entryviewcontents'], 'opt1') !== false);
@@ -696,7 +697,7 @@ public function test_get_entry_separated_groups() {
// This is in my group but I'm not the author.
$result = mod_data_external::get_entry($entry12);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($entry12, $result['entry']['id']);
$this->assertTrue($result['entry']['approved']);
@@ -704,7 +705,7 @@ public function test_get_entry_separated_groups() {
$this->setUser($this->student3);
$result = mod_data_external::get_entry($entry21);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($entry21, $result['entry']['id']);
$this->assertTrue($result['entry']['approved']);
@@ -713,19 +714,19 @@ public function test_get_entry_separated_groups() {
// As teacher I should be able to see all the entries.
$this->setUser($this->teacher);
$result = mod_data_external::get_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($entry11, $result['entry']['id']);
$result = mod_data_external::get_entry($entry12);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($entry12, $result['entry']['id']);
// This is the not approved one.
$result = mod_data_external::get_entry($entry13);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($entry13, $result['entry']['id']);
$result = mod_data_external::get_entry($entry21);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($entry21, $result['entry']['id']);
// Now, try to get a pending approval.
@@ -755,7 +756,7 @@ public function test_get_fields() {
$this->setUser($this->student1);
$result = mod_data_external::get_fields($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_fields_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_fields_returns(), $result);
// Basically compare we retrieve all the fields and the correct values.
$fields = $DB->get_records('data_fields', array('dataid' => $this->database->id), 'id');
@@ -771,7 +772,7 @@ public function test_get_fields_database_without_fields() {
$this->setUser($this->student1);
$result = mod_data_external::get_fields($this->database->id);
- $result = \external_api::clean_returnvalue(mod_data_external::get_fields_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_fields_returns(), $result);
$this->assertEmpty($result['fields']);
}
@@ -786,19 +787,19 @@ public function test_search_entries() {
$this->setUser($this->student1);
// Empty search, it should return all the visible entries.
$result = mod_data_external::search_entries($this->database->id, 0, false);
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(3, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
// Search for something that does not exists.
$result = mod_data_external::search_entries($this->database->id, 0, false, 'abc');
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(0, $result['entries']);
$this->assertEquals(0, $result['totalcount']);
// Search by text matching all the entries.
$result = mod_data_external::search_entries($this->database->id, 0, false, 'text');
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(3, $result['entries']);
$this->assertEquals(3, $result['totalcount']);
$this->assertEquals(3, $result['maxcount']);
@@ -806,7 +807,7 @@ public function test_search_entries() {
// Now as the other student I should receive my not approved entry. Apply ordering here.
$this->setUser($this->student2);
$result = mod_data_external::search_entries($this->database->id, 0, false, 'text', [], DATA_APPROVED, 'ASC');
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(4, $result['entries']);
$this->assertEquals(4, $result['totalcount']);
$this->assertEquals(4, $result['maxcount']);
@@ -816,7 +817,7 @@ public function test_search_entries() {
// Now as the other group student.
$this->setUser($this->student3);
$result = mod_data_external::search_entries($this->database->id, 0, false, 'text');
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(2, $result['entries']);
$this->assertEquals(2, $result['totalcount']);
$this->assertEquals(2, $result['maxcount']);
@@ -826,7 +827,7 @@ public function test_search_entries() {
// Same normal text search as teacher.
$this->setUser($this->teacher);
$result = mod_data_external::search_entries($this->database->id, 0, false, 'text');
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(5, $result['entries']); // I can see all groups and non approved.
$this->assertEquals(5, $result['totalcount']);
$this->assertEquals(5, $result['maxcount']);
@@ -834,7 +835,7 @@ public function test_search_entries() {
// Pagination.
$this->setUser($this->teacher);
$result = mod_data_external::search_entries($this->database->id, 0, false, 'text', [], DATA_TIMEADDED, 'ASC', 0, 2);
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(2, $result['entries']); // Only 2 per page.
$this->assertEquals(5, $result['totalcount']);
$this->assertEquals(5, $result['maxcount']);
@@ -845,7 +846,7 @@ public function test_search_entries() {
['name' => 'fn', 'value' => json_encode($this->student2->firstname)]
];
$result = mod_data_external::search_entries($this->database->id, 0, false, '', $advsearch);
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(2, $result['entries']);
$this->assertEquals(2, $result['totalcount']);
$this->assertEquals(3, $result['maxcount']);
@@ -857,7 +858,7 @@ public function test_search_entries() {
['name' => 'f_' . $field->id , 'value' => 'sampleurl']
];
$result = mod_data_external::search_entries($this->database->id, 0, false, '', $advsearch);
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(3, $result['entries']); // Found two entries matching this.
$this->assertEquals(3, $result['totalcount']);
$this->assertEquals(3, $result['maxcount']);
@@ -870,7 +871,7 @@ public function test_search_entries() {
['name' => 'ln', 'value' => json_encode($this->student2->lastname)]
];
$result = mod_data_external::search_entries($this->database->id, 0, false, '', $advsearch);
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(2, $result['entries']); // Only one matching everything.
$this->assertEquals(2, $result['totalcount']);
$this->assertEquals(3, $result['maxcount']);
@@ -882,7 +883,7 @@ public function test_search_entries() {
['name' => 'f_' . $field2->id , 'value' => '98780333'], // Non existent number.
];
$result = mod_data_external::search_entries($this->database->id, 0, false, '', $advsearch);
- $result = \external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::search_entries_returns(), $result);
$this->assertCount(0, $result['entries']); // Only one matching everything.
$this->assertEquals(0, $result['totalcount']);
$this->assertEquals(3, $result['maxcount']);
@@ -898,7 +899,7 @@ public function test_approve_entry() {
$this->setUser($this->teacher);
$this->assertEquals(0, $DB->get_field('data_records', 'approved', array('id' => $entry13)));
$result = mod_data_external::approve_entry($entry13);
- $result = \external_api::clean_returnvalue(mod_data_external::approve_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::approve_entry_returns(), $result);
$this->assertEquals(1, $DB->get_field('data_records', 'approved', array('id' => $entry13)));
}
@@ -912,7 +913,7 @@ public function test_unapprove_entry() {
$this->setUser($this->teacher);
$this->assertEquals(1, $DB->get_field('data_records', 'approved', array('id' => $entry11)));
$result = mod_data_external::approve_entry($entry11, false);
- $result = \external_api::clean_returnvalue(mod_data_external::approve_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::approve_entry_returns(), $result);
$this->assertEquals(0, $DB->get_field('data_records', 'approved', array('id' => $entry11)));
}
@@ -937,12 +938,12 @@ public function test_delete_entry_as_teacher() {
$this->setUser($this->teacher);
$result = mod_data_external::delete_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::delete_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::delete_entry_returns(), $result);
$this->assertEquals(0, $DB->count_records('data_records', array('id' => $entry11)));
// Entry in other group.
$result = mod_data_external::delete_entry($entry21);
- $result = \external_api::clean_returnvalue(mod_data_external::delete_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::delete_entry_returns(), $result);
$this->assertEquals(0, $DB->count_records('data_records', array('id' => $entry21)));
}
@@ -955,7 +956,7 @@ public function test_delete_entry_as_student() {
$this->setUser($this->student1);
$result = mod_data_external::delete_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::delete_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::delete_entry_returns(), $result);
$this->assertEquals(0, $DB->count_records('data_records', array('id' => $entry11)));
}
@@ -1062,11 +1063,11 @@ public function test_add_entry() {
];
}
$result = mod_data_external::add_entry($this->database->id, 0, $newentrydata);
- $result = \external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
$newentryid = $result['newentryid'];
$result = mod_data_external::get_entry($newentryid, true);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($this->student1->id, $result['entry']['userid']);
$this->assertCount(9, $result['entry']['contents']);
foreach ($result['entry']['contents'] as $content) {
@@ -1119,7 +1120,7 @@ public function test_add_entry() {
// Now, try to add another entry but removing some required data.
unset($newentrydata[0]);
$result = mod_data_external::add_entry($this->database->id, 0, $newentrydata);
- $result = \external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
$this->assertEquals(0, $result['newentryid']);
$this->assertCount(0, $result['generalnotifications']);
$this->assertCount(1, $result['fieldnotifications']);
@@ -1136,7 +1137,7 @@ public function test_add_entry_empty_form() {
$this->add_test_field();
$result = mod_data_external::add_entry($this->database->id, 0, []);
- $result = \external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::add_entry_returns(), $result);
$this->assertEquals(0, $result['newentryid']);
$this->assertCount(1, $result['generalnotifications']);
$this->assertCount(0, $result['fieldnotifications']);
@@ -1275,13 +1276,13 @@ public function test_update_entry() {
];
}
$result = mod_data_external::update_entry($entry11, $newentrydata);
- $result = \external_api::clean_returnvalue(mod_data_external::update_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::update_entry_returns(), $result);
$this->assertTrue($result['updated']);
$this->assertCount(0, $result['generalnotifications']);
$this->assertCount(0, $result['fieldnotifications']);
$result = mod_data_external::get_entry($entry11, true);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertEquals($this->student1->id, $result['entry']['userid']);
$this->assertCount(9, $result['entry']['contents']);
foreach ($result['entry']['contents'] as $content) {
@@ -1334,7 +1335,7 @@ public function test_update_entry() {
// Now, try to update the entry but removing some required data.
unset($newentrydata[0]);
$result = mod_data_external::update_entry($entry11, $newentrydata);
- $result = \external_api::clean_returnvalue(mod_data_external::update_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::update_entry_returns(), $result);
$this->assertFalse($result['updated']);
$this->assertCount(0, $result['generalnotifications']);
$this->assertCount(1, $result['fieldnotifications']);
@@ -1350,7 +1351,7 @@ public function test_update_entry_empty_data() {
$this->setUser($this->student1);
$result = mod_data_external::update_entry($entry11, []);
- $result = \external_api::clean_returnvalue(mod_data_external::update_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::update_entry_returns(), $result);
$this->assertFalse($result['updated']);
$this->assertCount(1, $result['generalnotifications']);
$this->assertCount(9, $result['fieldnotifications']);
@@ -1431,7 +1432,7 @@ public function test_get_entry_rating_information() {
// As student, retrieve ratings information.
$this->setUser($this->student2);
$result = mod_data_external::get_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(1, $result['ratinginfo']['ratings']);
$this->assertFalse($result['ratinginfo']['ratings'][0]['canviewaggregate']);
$this->assertFalse($result['ratinginfo']['canviewall']);
@@ -1441,7 +1442,7 @@ public function test_get_entry_rating_information() {
// Now, as teacher, I should see the info correctly.
$this->setUser($this->teacher);
$result = mod_data_external::get_entry($entry11);
- $result = \external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_data_external::get_entry_returns(), $result);
$this->assertCount(1, $result['ratinginfo']['ratings']);
$this->assertTrue($result['ratinginfo']['ratings'][0]['canviewaggregate']);
$this->assertTrue($result['ratinginfo']['canviewall']);
diff --git a/mod/feedback/classes/external.php b/mod/feedback/classes/external.php
index 9642de3afc2a5..f4da1ba53405d 100644
--- a/mod/feedback/classes/external.php
+++ b/mod/feedback/classes/external.php
@@ -14,26 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Feedback external API
- *
- * @package mod_feedback
- * @category external
- * @copyright 2017 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 3.3
- */
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
-
use mod_feedback\external\feedback_summary_exporter;
use mod_feedback\external\feedback_completedtmp_exporter;
use mod_feedback\external\feedback_item_exporter;
use mod_feedback\external\feedback_valuetmp_exporter;
use mod_feedback\external\feedback_value_exporter;
use mod_feedback\external\feedback_completed_exporter;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Feedback external functions
@@ -90,7 +83,7 @@ public static function get_feedbacks_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
$output = $PAGE->get_renderer('core');
// Get the feedbacks in this course, this function checks users visibility permissions.
diff --git a/mod/feedback/classes/external/feedback_item_exporter.php b/mod/feedback/classes/external/feedback_item_exporter.php
index 0c7c1ad367fa8..f45a5dc273813 100644
--- a/mod/feedback/classes/external/feedback_item_exporter.php
+++ b/mod/feedback/classes/external/feedback_item_exporter.php
@@ -24,7 +24,6 @@
namespace mod_feedback\external;
defined('MOODLE_INTERNAL') || die();
-use mod_feedback\feedback;
use core\external\exporter;
use renderer_base;
use core_files\external\stored_file_exporter;
diff --git a/mod/feedback/classes/external/feedback_summary_exporter.php b/mod/feedback/classes/external/feedback_summary_exporter.php
index 08f07fde4e6b6..7b620d89a01a0 100644
--- a/mod/feedback/classes/external/feedback_summary_exporter.php
+++ b/mod/feedback/classes/external/feedback_summary_exporter.php
@@ -14,26 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Class for exporting partial feedback data.
- *
- * @package mod_feedback
- * @copyright 2017 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace mod_feedback\external;
-defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
-use external_util;
-use external_files;
+use core_external\util as external_util;
+use core_external\external_files;
/**
* Class for exporting partial feedback data (some fields are only viewable by admins).
*
* @copyright 2017 Juan Leyva
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @package mod_feedback
*/
class feedback_summary_exporter extends exporter {
diff --git a/mod/feedback/tests/external/external_test.php b/mod/feedback/tests/external/external_test.php
index df8e12b5dbd2f..85f7603156034 100644
--- a/mod/feedback/tests/external/external_test.php
+++ b/mod/feedback/tests/external/external_test.php
@@ -26,10 +26,10 @@
namespace mod_feedback\external;
+use core_external\external_api;
use externallib_advanced_testcase;
use feedback_item_multichoice;
use mod_feedback_external;
-
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -163,14 +163,14 @@ public function test_mod_feedback_get_feedbacks_by_courses() {
// Call the external function passing course ids.
$result = mod_feedback_external::get_feedbacks_by_courses(array($course2->id, $this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfeedbacks, $result['feedbacks']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_feedback_external::get_feedbacks_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfeedbacks, $result['feedbacks']);
$this->assertCount(0, $result['warnings']);
@@ -180,7 +180,7 @@ public function test_mod_feedback_get_feedbacks_by_courses() {
// Call the external function without passing course id.
$result = mod_feedback_external::get_feedbacks_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfeedbacks, $result['feedbacks']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -206,14 +206,14 @@ public function test_mod_feedback_get_feedbacks_by_courses() {
$expectedfeedbacks[0]['page_after_submitformat'] = 1;
$result = mod_feedback_external::get_feedbacks_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfeedbacks, $result['feedbacks']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_feedback_external::get_feedbacks_by_courses(array($this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfeedbacks, $result['feedbacks']);
}
@@ -224,7 +224,7 @@ public function test_get_feedback_access_information_student() {
self::setUser($this->student);
$result = mod_feedback_external::get_feedback_access_information($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
$this->assertFalse($result['canviewanalysis']);
$this->assertFalse($result['candeletesubmissions']);
@@ -245,7 +245,7 @@ public function test_get_feedback_access_information_teacher() {
self::setUser($this->teacher);
$result = mod_feedback_external::get_feedback_access_information($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
$this->assertTrue($result['canviewanalysis']);
$this->assertTrue($result['canviewreports']);
@@ -261,7 +261,7 @@ public function test_get_feedback_access_information_teacher() {
// Add some items to the feedback and check is not empty any more.
self::populate_feedback($this->feedback);
$result = mod_feedback_external::get_feedback_access_information($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
$this->assertFalse($result['isempty']);
}
@@ -302,7 +302,7 @@ public function test_view_feedback() {
// Trigger and capture the event.
$sink = $this->redirectEvents();
$result = mod_feedback_external::view_feedback($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::view_feedback_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::view_feedback_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
$event = array_shift($events);
@@ -339,7 +339,7 @@ public function test_get_current_completed_tmp() {
$this->setUser($this->student);
$result = mod_feedback_external::get_current_completed_tmp($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_current_completed_tmp_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_current_completed_tmp_returns(), $result);
$this->assertEquals($record['id'], $result['feedback']['id']);
}
@@ -354,7 +354,7 @@ public function test_get_items() {
$itemscreated = self::populate_feedback($this->feedback, 2);
$result = mod_feedback_external::get_items($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_items_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_items_returns(), $result);
$this->assertCount(count($itemscreated), $result['items']);
$index = 1;
foreach ($result['items'] as $key => $item) {
@@ -388,7 +388,7 @@ public function test_launch_feedback() {
// First try a feedback we didn't attempt.
$result = mod_feedback_external::launch_feedback($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::launch_feedback_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::launch_feedback_returns(), $result);
$this->assertEquals(0, $result['gopage']);
// Now, try a feedback that we attempted.
@@ -425,7 +425,7 @@ public function test_launch_feedback() {
$DB->insert_record('feedback_valuetmp', (object) $response);
$result = mod_feedback_external::launch_feedback($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::launch_feedback_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::launch_feedback_returns(), $result);
$this->assertEquals(1, $result['gopage']);
}
@@ -441,14 +441,14 @@ public function test_get_page_items() {
// Retrieve first page.
$result = mod_feedback_external::get_page_items($this->feedback->id, 0);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_page_items_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_page_items_returns(), $result);
$this->assertCount(3, $result['items']); // The first page has 3 items.
$this->assertTrue($result['hasnextpage']);
$this->assertFalse($result['hasprevpage']);
// Retrieve second page.
$result = mod_feedback_external::get_page_items($this->feedback->id, 1);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_page_items_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_page_items_returns(), $result);
$this->assertCount(5, $result['items']); // The second page has 5 items (page break doesn't count).
$this->assertFalse($result['hasnextpage']);
$this->assertTrue($result['hasprevpage']);
@@ -501,14 +501,14 @@ public function test_process_page() {
// Process first page.
$firstpagedata = [$data[0], $data[1]];
$result = mod_feedback_external::process_page($this->feedback->id, 0, $firstpagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertEquals(1, $result['jumpto']);
$this->assertFalse($result['completed']);
// Now, process the second page. But first we are going back to the first page.
$secondpagedata = [$data[2], $data[3], $data[4], $data[5], $data[6]];
$result = mod_feedback_external::process_page($this->feedback->id, 1, $secondpagedata, true);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertFalse($result['completed']);
$this->assertEquals(0, $result['jumpto']); // We jumped to the first page.
// Check the values were correctly saved.
@@ -517,7 +517,7 @@ public function test_process_page() {
// Go forward again (sending the same data).
$result = mod_feedback_external::process_page($this->feedback->id, 0, $firstpagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertEquals(1, $result['jumpto']);
$this->assertFalse($result['completed']);
$tmpitems = $DB->get_records('feedback_valuetmp');
@@ -528,7 +528,7 @@ public function test_process_page() {
$data[2]['value'] = 2; // 2 is value of the option 'b'.
$secondpagedata = [$data[2], $data[3], $data[4], $data[5], $data[6]];
$result = mod_feedback_external::process_page($this->feedback->id, 1, $secondpagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
$this->assertTrue(strpos($result['completionpagecontents'], $pagecontents) !== false);
// Check all the items were saved.
@@ -606,7 +606,7 @@ public function test_process_page_site_feedback() {
// Process first page.
$firstpagedata = [$data[0], $data[1]];
$result = mod_feedback_external::process_page($this->feedback->id, 0, $firstpagedata, false, $this->course->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertEquals(1, $result['jumpto']);
$this->assertFalse($result['completed']);
@@ -614,7 +614,7 @@ public function test_process_page_site_feedback() {
$data[2]['value'] = 2; // 2 is value of the option 'b';
$secondpagedata = [$data[2], $data[3], $data[4], $data[5], $data[6]];
$result = mod_feedback_external::process_page($this->feedback->id, 1, $secondpagedata, false, $this->course->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
$this->assertTrue(strpos($result['completionpagecontents'], $pagecontents) !== false);
// Check all the items were saved.
@@ -653,13 +653,13 @@ public function test_get_analysis() {
];
// Process the feedback, there is only one page so the feedback will be completed.
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
// Retrieve analysis.
$this->setUser($this->teacher);
$result = mod_feedback_external::get_analysis($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_analysis_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_analysis_returns(), $result);
$this->assertEquals(1, $result['completedcount']); // 1 feedback completed.
$this->assertEquals(2, $result['itemscount']); // 2 items in the feedback.
$this->assertCount(2, $result['itemsdata']);
@@ -681,13 +681,13 @@ public function test_get_analysis() {
// Process the feedback, there is only one page so the feedback will be completed.
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
// Retrieve analysis.
$this->setUser($this->teacher);
$result = mod_feedback_external::get_analysis($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_analysis_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_analysis_returns(), $result);
$this->assertEquals(2, $result['completedcount']); // 2 feedback completed.
$this->assertEquals(2, $result['itemscount']);
$this->assertCount(2, $result['itemsdata'][0]['data']); // There are 2 responses per item.
@@ -715,12 +715,12 @@ public function test_get_unfinished_responses() {
];
// Process the feedback, there are two pages so the feedback will be unfinished yet.
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertFalse($result['completed']);
// Retrieve the unfinished responses.
$result = mod_feedback_external::get_unfinished_responses($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_unfinished_responses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_unfinished_responses_returns(), $result);
// Check that ids and responses match.
foreach ($result['responses'] as $r) {
if ($r['item'] == $numericitem->id) {
@@ -751,12 +751,12 @@ public function test_get_finished_responses() {
// Process the feedback, there is only one page so the feedback will be completed.
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
// Retrieve the responses.
$result = mod_feedback_external::get_finished_responses($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_finished_responses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_finished_responses_returns(), $result);
// Check that ids and responses match.
foreach ($result['responses'] as $r) {
if ($r['item'] == $numericitem->id) {
@@ -814,13 +814,13 @@ public function test_get_non_respondents() {
// Process the feedback, there is only one page so the feedback will be completed.
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
// Retrieve the non-respondent users.
$this->setUser($this->teacher);
$result = mod_feedback_external::get_non_respondents($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['users']);
$this->assertEquals($anotherstudent->id, $result['users'][0]['userid']);
@@ -831,13 +831,13 @@ public function test_get_non_respondents() {
$this->setUser($anotherstudent2);
$this->setUser($this->teacher);
$result = mod_feedback_external::get_non_respondents($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['users']);
// Test pagination.
$result = mod_feedback_external::get_non_respondents($this->feedback->id, 0, 'lastaccess', 0, 1);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_non_respondents_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['users']);
}
@@ -884,7 +884,7 @@ protected function complete_basic_feedback() {
// Process the feedback, there is only one page so the feedback will be completed.
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
$this->setUser($anotherstudent1);
@@ -895,7 +895,7 @@ protected function complete_basic_feedback() {
];
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
$this->setUser($anotherstudent2);
@@ -906,7 +906,7 @@ protected function complete_basic_feedback() {
];
$result = mod_feedback_external::process_page($this->feedback->id, 0, $pagedata);
- $result = \external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::process_page_returns(), $result);
$this->assertTrue($result['completed']);
}
@@ -919,7 +919,7 @@ public function test_get_responses_analysis_anonymous() {
// Retrieve the responses analysis.
$this->setUser($this->teacher);
$result = mod_feedback_external::get_responses_analysis($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_responses_analysis_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_responses_analysis_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(0, $result['totalattempts']);
$this->assertEquals(2, $result['totalanonattempts']); // Only see my groups.
@@ -942,7 +942,7 @@ public function test_get_responses_analysis_non_anonymous() {
// Retrieve the responses analysis.
$this->setUser($this->teacher);
$result = mod_feedback_external::get_responses_analysis($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_responses_analysis_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_responses_analysis_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(2, $result['totalattempts']);
$this->assertEquals(0, $result['totalanonattempts']); // Only see my groups.
@@ -1018,7 +1018,7 @@ public function test_get_last_completed_not_anonymous_completed() {
// Test user with full capabilities.
$this->setUser($this->student);
$result = mod_feedback_external::get_last_completed($this->feedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_last_completed_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_last_completed_returns(), $result);
$this->assertEquals($record, $result['completed']);
}
@@ -1048,13 +1048,13 @@ public function test_get_feedback_access_information_for_site_feedback() {
$this->setUser($this->student);
// Access the site feedback via the site activity.
$result = mod_feedback_external::get_feedback_access_information($sitefeedback->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
$this->assertTrue($result['cancomplete']);
$this->assertTrue($result['cansubmit']);
// Access the site feedback via course where I'm enrolled.
$result = mod_feedback_external::get_feedback_access_information($sitefeedback->id, $this->course->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
$this->assertTrue($result['cancomplete']);
$this->assertTrue($result['cansubmit']);
@@ -1077,7 +1077,7 @@ public function test_get_feedback_access_information_for_site_feedback_mapped()
// Access the site feedback via course where I'm enrolled and mapped.
$result = mod_feedback_external::get_feedback_access_information($sitefeedback->id, $this->course->id);
- $result = \external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_feedback_external::get_feedback_access_information_returns(), $result);
$this->assertTrue($result['cancomplete']);
$this->assertTrue($result['cansubmit']);
diff --git a/mod/folder/classes/external.php b/mod/folder/classes/external.php
index 946e39cd98608..209a15da7ec8c 100644
--- a/mod/folder/classes/external.php
+++ b/mod/folder/classes/external.php
@@ -14,21 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * folder external API
- *
- * @package mod_folder
- * @category external
- * @copyright 2015 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 3.0
- */
-
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* folder external functions
@@ -94,7 +87,7 @@ public static function view_folder($folderid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_folder_returns() {
@@ -149,7 +142,7 @@ public static function get_folders_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the folders in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
diff --git a/mod/folder/tests/externallib_test.php b/mod/folder/tests/externallib_test.php
index 1a0b0a63df518..31488a3c2758c 100644
--- a/mod/folder/tests/externallib_test.php
+++ b/mod/folder/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_folder;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_folder_external;
@@ -77,7 +78,7 @@ public function test_view_folder() {
$sink = $this->redirectEvents();
$result = mod_folder_external::view_folder($folder->id);
- $result = \external_api::clean_returnvalue(mod_folder_external::view_folder_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_folder_external::view_folder_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -181,14 +182,14 @@ public function test_mod_folder_get_folders_by_courses() {
// Call the external function passing course ids.
$result = mod_folder_external::get_folders_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfolders, $result['folders']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_folder_external::get_folders_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfolders, $result['folders']);
$this->assertCount(0, $result['warnings']);
@@ -208,7 +209,7 @@ public function test_mod_folder_get_folders_by_courses() {
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_folder_external::get_folders_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['folders'][0]['introfiles']);
$this->assertEquals($fileintroname, $result['folders'][0]['introfiles'][0]['filename']);
@@ -219,7 +220,7 @@ public function test_mod_folder_get_folders_by_courses() {
// Call the external function without passing course id.
$result = mod_folder_external::get_folders_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedfolders, $result['folders']);
diff --git a/mod/forum/classes/local/exporters/post.php b/mod/forum/classes/local/exporters/post.php
index 7137510e4e8bf..a336f55174060 100644
--- a/mod/forum/classes/local/exporters/post.php
+++ b/mod/forum/classes/local/exporters/post.php
@@ -523,7 +523,7 @@ protected static function define_related() {
/**
* This method returns the parameters for the post's message to
- * use with the function external_format_text().
+ * use with the function \core_external\util::format_text().
*
* @return array
*/
diff --git a/mod/forum/externallib.php b/mod/forum/externallib.php
index b019ab3e73547..6885c52e9b86c 100644
--- a/mod/forum/externallib.php
+++ b/mod/forum/externallib.php
@@ -15,6 +15,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use mod_forum\local\exporters\post as post_exporter;
+use mod_forum\local\exporters\discussion as discussion_exporter;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util as external_util;
+
/**
* External forum API
*
@@ -22,14 +34,6 @@
* @copyright 2012 Mark Nelson
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
-
-use mod_forum\local\exporters\post as post_exporter;
-use mod_forum\local\exporters\discussion as discussion_exporter;
-
class mod_forum_external extends external_api {
/**
@@ -91,11 +95,18 @@ public static function get_forums_by_courses($courseids = array()) {
continue;
}
- $forum->name = external_format_string($forum->name, $context->id);
+ $forum->name = \core_external\util::format_string($forum->name, $context);
// Format the intro before being returning using the format setting.
$options = array('noclean' => true);
- list($forum->intro, $forum->introformat) =
- external_format_text($forum->intro, $forum->introformat, $context->id, 'mod_forum', 'intro', null, $options);
+ [$forum->intro, $forum->introformat] = \core_external\util::format_text(
+ $forum->intro,
+ $forum->introformat,
+ $context,
+ 'mod_forum',
+ 'intro',
+ null,
+ $options
+ );
$forum->introfiles = external_util::get_area_files($context->id, 'mod_forum', 'intro', false, false);
$forum->lang = clean_param($forum->lang, PARAM_LANG);
@@ -415,13 +426,13 @@ public static function get_forum_discussions_paginated($forumid, $sortby = 'time
$discussion->numreplies = (int) $replies[$discussion->discussion]->replies;
}
- $discussion->name = external_format_string($discussion->name, $modcontext->id);
- $discussion->subject = external_format_string($discussion->subject, $modcontext->id);
+ $discussion->name = \core_external\util::format_string($discussion->name, $modcontext);
+ $discussion->subject = \core_external\util::format_string($discussion->subject, $modcontext);
// Rewrite embedded images URLs.
$options = array('trusted' => $discussion->messagetrust);
list($discussion->message, $discussion->messageformat) =
- external_format_text($discussion->message, $discussion->messageformat,
- $modcontext->id, 'mod_forum', 'post', $discussion->id, $options);
+ \core_external\util::format_text($discussion->message, $discussion->messageformat,
+ $modcontext, 'mod_forum', 'post', $discussion->id, $options);
// List attachments.
if (!empty($discussion->attachment)) {
@@ -715,13 +726,13 @@ public static function get_forum_discussions(int $forumid, ?int $sortorder = -1,
$discussionobject->numreplies = (int) $replies[$discussion->get_id()];
}
- $discussionobject->name = external_format_string($discussion->get_name(), $modcontext->id);
- $discussionobject->subject = external_format_string($discussionobject->subject, $modcontext->id);
+ $discussionobject->name = \core_external\util::format_string($discussion->get_name(), $modcontext);
+ $discussionobject->subject = \core_external\util::format_string($discussionobject->subject, $modcontext);
// Rewrite embedded images URLs.
$options = array('trusted' => $discussionobject->messagetrust);
list($discussionobject->message, $discussionobject->messageformat) =
- external_format_text($discussionobject->message, $discussionobject->messageformat,
- $modcontext->id, 'mod_forum', 'post', $discussionobject->id, $options);
+ \core_external\util::format_text($discussionobject->message, $discussionobject->messageformat,
+ $modcontext, 'mod_forum', 'post', $discussionobject->id, $options);
// List attachments.
if (!empty($discussionobject->attachment)) {
@@ -877,7 +888,7 @@ public static function view_forum($forumid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function view_forum_returns() {
@@ -948,7 +959,7 @@ public static function view_forum_discussion($discussionid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function view_forum_discussion_returns() {
@@ -1185,7 +1196,7 @@ public static function add_discussion_post($postid, $subject, $message, $options
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function add_discussion_post_returns() {
@@ -1257,7 +1268,7 @@ public static function toggle_favourite_state($discussionid, $targetstate) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function toggle_favourite_state_returns() {
@@ -1460,7 +1471,7 @@ public static function add_discussion($forumid, $subject, $message, $groupid = 0
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function add_discussion_returns() {
@@ -1528,7 +1539,7 @@ public static function can_add_discussion($forumid, $groupid = null) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function can_add_discussion_returns() {
@@ -1691,7 +1702,7 @@ public static function set_subscription_state_parameters() {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function set_subscription_state_returns() {
return discussion_exporter::get_read_structure();
@@ -1759,7 +1770,7 @@ public static function set_lock_state_parameters() {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function set_lock_state_returns() {
return new external_single_structure([
@@ -1930,7 +1941,7 @@ public static function delete_post($postid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function delete_post_returns() {
@@ -2167,7 +2178,7 @@ public static function get_discussion_post($postid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function get_discussion_post_returns() {
@@ -2321,7 +2332,7 @@ public static function prepare_draft_area_for_post($postid, $area, $draftitemid
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function prepare_draft_area_for_post_returns() {
@@ -2535,7 +2546,7 @@ public static function update_discussion_post($postid, $subject = '', $message =
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function update_discussion_post_returns() {
diff --git a/mod/forum/tests/externallib_test.php b/mod/forum/tests/externallib_test.php
index 5de6f02ffeb4a..40147eda8c805 100644
--- a/mod/forum/tests/externallib_test.php
+++ b/mod/forum/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_forum;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_forum_external;
@@ -194,7 +195,7 @@ public function test_mod_forum_get_forums_by_courses() {
// Call the external function passing course ids.
$forums = mod_forum_external::get_forums_by_courses(array($course1->id, $course2->id));
- $forums = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
+ $forums = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
$this->assertCount(2, $forums);
foreach ($forums as $forum) {
$this->assertEquals($expectedforums[$forum['id']], $forum);
@@ -202,7 +203,7 @@ public function test_mod_forum_get_forums_by_courses() {
// Call the external function without passing course id.
$forums = mod_forum_external::get_forums_by_courses();
- $forums = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
+ $forums = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
$this->assertCount(2, $forums);
foreach ($forums as $forum) {
$this->assertEquals($expectedforums[$forum['id']], $forum);
@@ -214,7 +215,7 @@ public function test_mod_forum_get_forums_by_courses() {
// Call the external function without passing course id.
$forums = mod_forum_external::get_forums_by_courses();
- $forums = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
+ $forums = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
$this->assertCount(1, $forums);
$this->assertEquals($expectedforums[$forum1->id], $forums[0]);
$this->assertTrue($forums[0]['cancreatediscussions']);
@@ -222,12 +223,12 @@ public function test_mod_forum_get_forums_by_courses() {
// Change the type of the forum, the user shouldn't be able to add discussions.
$DB->set_field('forum', 'type', 'news', array('id' => $forum1->id));
$forums = mod_forum_external::get_forums_by_courses();
- $forums = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
+ $forums = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
$this->assertFalse($forums[0]['cancreatediscussions']);
// Call for the second course we unenrolled the user from.
$forums = mod_forum_external::get_forums_by_courses(array($course2->id));
- $forums = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
+ $forums = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $forums);
$this->assertCount(0, $forums);
}
@@ -264,11 +265,11 @@ public function test_mod_forum_toggle_favourite_state() {
$discussion1 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$response = mod_forum_external::toggle_favourite_state($discussion1->id, 1);
- $response = \external_api::clean_returnvalue(mod_forum_external::toggle_favourite_state_returns(), $response);
+ $response = external_api::clean_returnvalue(mod_forum_external::toggle_favourite_state_returns(), $response);
$this->assertTrue($response['userstate']['favourited']);
$response = mod_forum_external::toggle_favourite_state($discussion1->id, 0);
- $response = \external_api::clean_returnvalue(mod_forum_external::toggle_favourite_state_returns(), $response);
+ $response = external_api::clean_returnvalue(mod_forum_external::toggle_favourite_state_returns(), $response);
$this->assertFalse($response['userstate']['favourited']);
$this->setUser(0);
@@ -317,11 +318,11 @@ public function test_mod_forum_set_pin_state() {
self::setAdminUser();
$response = mod_forum_external::set_pin_state($discussion1->id, 1);
- $response = \external_api::clean_returnvalue(mod_forum_external::set_pin_state_returns(), $response);
+ $response = external_api::clean_returnvalue(mod_forum_external::set_pin_state_returns(), $response);
$this->assertTrue($response['pinned']);
$response = mod_forum_external::set_pin_state($discussion1->id, 0);
- $response = \external_api::clean_returnvalue(mod_forum_external::set_pin_state_returns(), $response);
+ $response = external_api::clean_returnvalue(mod_forum_external::set_pin_state_returns(), $response);
$this->assertFalse($response['pinned']);
}
@@ -493,7 +494,7 @@ public function test_mod_forum_get_discussion_posts() {
'subject' => $discussion1reply2->subject,
'replysubject' => get_string('re', 'mod_forum') . " {$discussion1reply2->subject}",
'message' => $message,
- 'messageformat' => 1, // This value is usually changed by external_format_text() function.
+ 'messageformat' => 1, // This value is usually changed by \core_external\util::format_text() function.
'unread' => null,
'isdeleted' => false,
'isprivatereply' => false,
@@ -552,7 +553,7 @@ public function test_mod_forum_get_discussion_posts() {
'subject' => $discussion1reply1->subject,
'replysubject' => get_string('re', 'mod_forum') . " {$discussion1reply1->subject}",
'message' => $message,
- 'messageformat' => 1, // This value is usually changed by external_format_text() function.
+ 'messageformat' => 1, // This value is usually changed by \core_external\util::format_text() function.
'unread' => null,
'isdeleted' => false,
'isprivatereply' => false,
@@ -600,7 +601,7 @@ public function test_mod_forum_get_discussion_posts() {
// Test a discussion with two additional posts (total 3 posts).
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'DESC', true);
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(3, count($posts['posts']));
// Unset the initial discussion post.
@@ -610,7 +611,7 @@ public function test_mod_forum_get_discussion_posts() {
// Check we receive the unread count correctly on tracked forum.
forum_tp_count_forum_unread_posts($forum2cm, $course1, true); // Reset static cache.
$result = mod_forum_external::get_forums_by_courses(array($course1->id));
- $result = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
foreach ($result as $f) {
if ($f['id'] == $forum2->id) {
$this->assertEquals(1, $f['unreadpostscount']);
@@ -619,31 +620,31 @@ public function test_mod_forum_get_discussion_posts() {
// Test discussion without additional posts. There should be only one post (the one created by the discussion).
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(1, count($posts['posts']));
// Test discussion tracking on not tracked forum.
$result = mod_forum_external::view_forum_discussion($discussion1->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::view_forum_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::view_forum_discussion_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEmpty($result['warnings']);
// Test posts have not been marked as read.
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
foreach ($posts['posts'] as $post) {
$this->assertNull($post['unread']);
}
// Test discussion tracking on tracked forum.
$result = mod_forum_external::view_forum_discussion($discussion3->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::view_forum_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::view_forum_discussion_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEmpty($result['warnings']);
// Test posts have been marked as read.
$posts = mod_forum_external::get_discussion_posts($discussion3->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
foreach ($posts['posts'] as $post) {
$this->assertFalse($post['unread']);
}
@@ -651,7 +652,7 @@ public function test_mod_forum_get_discussion_posts() {
// Check we receive 0 unread posts.
forum_tp_count_forum_unread_posts($forum2cm, $course1, true); // Reset static cache.
$result = mod_forum_external::get_forums_by_courses(array($course1->id));
- $result = \external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_forums_by_courses_returns(), $result);
foreach ($result as $f) {
if ($f['id'] == $forum2->id) {
$this->assertEquals(0, $f['unreadpostscount']);
@@ -722,7 +723,7 @@ public function test_mod_forum_get_discussion_posts_deleted() {
// Test where some posts have been marked as deleted.
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$deletedsubject = get_string('forumsubjectdeleted', 'mod_forum');
$deletedmessage = get_string('forumbodydeleted', 'mod_forum');
@@ -801,14 +802,14 @@ public function test_mod_forum_get_discussion_posts_inline_attachments() {
-1, $options);
$posts = mod_forum_external::get_discussion_posts($discussion['discussionid'], 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$post = $posts['posts'][0];
$this->assertCount(0, $post['messageinlinefiles']);
$this->assertEmpty($post['messageinlinefiles']);
$posts = mod_forum_external::get_discussion_posts($discussion['discussionid'], 'modified', 'DESC',
true);
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$post = $posts['posts'][0];
$this->assertCount(1, $post['messageinlinefiles']);
$this->assertEquals('fakeimage.png', $post['messageinlinefiles'][0]['filename']);
@@ -857,7 +858,7 @@ public function test_mod_forum_get_discussion_posts_qanda() {
// We still see only the original post.
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(1, count($posts['posts']));
// Add a new reply, the user is going to be able to see only the original post and their new post.
@@ -868,7 +869,7 @@ public function test_mod_forum_get_discussion_posts_qanda() {
$discussion1reply2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(2, count($posts['posts']));
// Now, we can fake the time of the user post, so he can se the rest of the discussion posts.
@@ -876,7 +877,7 @@ public function test_mod_forum_get_discussion_posts_qanda() {
$DB->update_record('forum_posts', $discussion1reply2);
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(3, count($posts['posts']));
}
@@ -995,7 +996,7 @@ public function test_mod_forum_get_forum_discussions_paginated() {
// Call the external function passing forum id.
$discussions = mod_forum_external::get_forum_discussions_paginated($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$expectedreturn = array(
'discussions' => array($expecteddiscussions),
'warnings' => array()
@@ -1034,7 +1035,7 @@ public function test_mod_forum_get_forum_discussions_paginated() {
$this->setAdminUser();
$discussions = mod_forum_external::get_forum_discussions_paginated($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertTrue($discussions['discussions'][0]['canlock']);
}
@@ -1066,7 +1067,7 @@ public function test_mod_forum_get_forum_discussions_paginated_qanda() {
self::setAdminUser();
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(1, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -1075,7 +1076,7 @@ public function test_mod_forum_get_forum_discussions_paginated_qanda() {
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(1, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -1199,7 +1200,7 @@ public function test_mod_forum_get_forum_discussions() {
// Call the external function passing forum id.
$discussions = mod_forum_external::get_forum_discussions($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
$expectedreturn = array(
'discussions' => array($expecteddiscussions),
'warnings' => array()
@@ -1220,7 +1221,7 @@ public function test_mod_forum_get_forum_discussions() {
$t = mod_forum_external::toggle_favourite_state($discussion1->id, 1);
$expectedreturn['discussions'][0]['starred'] = true;
$discussions = mod_forum_external::get_forum_discussions($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
$this->assertEquals($expectedreturn, $discussions);
// Call without required view discussion capability.
@@ -1245,7 +1246,7 @@ public function test_mod_forum_get_forum_discussions() {
$this->setAdminUser();
$discussions = mod_forum_external::get_forum_discussions($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
$this->assertTrue($discussions['discussions'][0]['canlock']);
}
@@ -1363,7 +1364,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id.
$discussions = mod_forum_external::get_forum_discussions($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by last post date in descending order by default.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion3->id);
$this->assertEquals($discussions['discussions'][1]['discussion'], $discussion2->id);
@@ -1374,7 +1375,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id and sort order parameter.
$discussions = mod_forum_external::get_forum_discussions($forum1->id, $discussionlistvault::SORTORDER_LASTPOST_ASC);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by last post date in ascending order.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion1->id);
$this->assertEquals($discussions['discussions'][1]['discussion'], $discussion2->id);
@@ -1382,7 +1383,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id and sort order parameter.
$discussions = mod_forum_external::get_forum_discussions($forum1->id, $discussionlistvault::SORTORDER_CREATED_DESC);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by discussion creation date in descending order.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion3->id);
$this->assertEquals($discussions['discussions'][1]['discussion'], $discussion2->id);
@@ -1390,7 +1391,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id and sort order parameter.
$discussions = mod_forum_external::get_forum_discussions($forum1->id, $discussionlistvault::SORTORDER_CREATED_ASC);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by discussion creation date in ascending order.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion1->id);
$this->assertEquals($discussions['discussions'][1]['discussion'], $discussion2->id);
@@ -1398,7 +1399,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id and sort order parameter.
$discussions = mod_forum_external::get_forum_discussions($forum1->id, $discussionlistvault::SORTORDER_REPLIES_DESC);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by the number of replies in descending order.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion1->id);
$this->assertEquals($discussions['discussions'][1]['discussion'], $discussion3->id);
@@ -1406,7 +1407,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id and sort order parameter.
$discussions = mod_forum_external::get_forum_discussions($forum1->id, $discussionlistvault::SORTORDER_REPLIES_ASC);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by the number of replies in ascending order.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion2->id);
$this->assertEquals($discussions['discussions'][1]['discussion'], $discussion3->id);
@@ -1418,7 +1419,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id.
$discussions = mod_forum_external::get_forum_discussions($forum1->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by last post date in descending order by default.
// Pinned discussions should be at the top of the list.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion2->id);
@@ -1427,7 +1428,7 @@ public function test_mod_forum_get_forum_discussions_sorting() {
// Call the external function passing forum id and sort order parameter.
$discussions = mod_forum_external::get_forum_discussions($forum1->id, $discussionlistvault::SORTORDER_LASTPOST_ASC);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
// Discussions should be ordered by last post date in ascending order.
// Pinned discussions should be at the top of the list.
$this->assertEquals($discussions['discussions'][0]['discussion'], $discussion2->id);
@@ -1478,10 +1479,10 @@ public function test_add_discussion_post() {
$this->getDataGenerator()->enrol_user($otheruser->id, $course->id);
$createdpost = mod_forum_external::add_discussion_post($discussion->firstpost, 'some subject', 'some text here...');
- $createdpost = \external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
+ $createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// We receive the discussion and the post.
$this->assertEquals(2, count($posts['posts']));
@@ -1505,7 +1506,7 @@ public function test_add_discussion_post() {
foreach ($formats as $format) {
$createdpost = mod_forum_external::add_discussion_post($discussion->firstpost,
'with some format', 'some formatted here...', $options, $format);
- $createdpost = \external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
+ $createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
$dbformat = $DB->get_field('forum_posts', 'messageformat', ['id' => $createdpost['postid']]);
$this->assertEquals($format, $dbformat);
}
@@ -1516,7 +1517,7 @@ public function test_add_discussion_post() {
$options = [['name' => 'topreferredformat', 'value' => true]];
$createdpost = mod_forum_external::add_discussion_post($discussion->firstpost,
'interesting subject', 'with some https://example.com link', $options, FORMAT_MOODLE);
- $createdpost = \external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
+ $createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
$dbpost = $DB->get_record('forum_posts', ['id' => $createdpost['postid']]);
// Format HTML and content converted, we should get.
$this->assertEquals(FORMAT_HTML, $dbpost->messageformat);
@@ -1557,10 +1558,10 @@ public function test_add_discussion_post() {
. '" alt="inlineimage">.';
$createdpost = mod_forum_external::add_discussion_post($discussion->firstpost, 'new post inline attachment',
$dummytext, $options);
- $createdpost = \external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
+ $createdpost = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $createdpost);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// We receive the discussion and the post.
// Can't guarantee order of posts during tests.
$postfound = false;
@@ -1635,7 +1636,7 @@ public function test_add_discussion_post_subscribe_discussion() {
mod_forum_external::add_discussion_post($discussion1->firstpost, 'some subject', 'some text here...');
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// We receive the discussion and the post.
$this->assertEquals(2, count($posts['posts']));
// The user should be subscribed to the discussion after adding a discussion post.
@@ -1648,7 +1649,7 @@ public function test_add_discussion_post_subscribe_discussion() {
mod_forum_external::add_discussion_post($discussion1->firstpost, 'some subject 1', 'some text here 1...');
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// We receive the discussion and the post.
$this->assertEquals(3, count($posts['posts']));
// The user should still be subscribed to the discussion after adding a discussion post.
@@ -1659,7 +1660,7 @@ public function test_add_discussion_post_subscribe_discussion() {
mod_forum_external::add_discussion_post($discussion2->firstpost, 'some subject 2', 'some text here 2...');
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// We receive the discussion and the post.
$this->assertEquals(2, count($posts['posts']));
// The user should still not be subscribed to the discussion after adding a discussion post.
@@ -1675,7 +1676,7 @@ public function test_add_discussion_post_subscribe_discussion() {
$options);
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// We receive the discussion and the post.
$this->assertEquals(3, count($posts['posts']));
// The user should now be subscribed to the discussion after adding a discussion post.
@@ -1713,10 +1714,10 @@ public function test_add_discussion() {
self::setAdminUser();
$createddiscussion = mod_forum_external::add_discussion($forum->id, 'the subject', 'some text here...');
- $createddiscussion = \external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $createddiscussion);
+ $createddiscussion = external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $createddiscussion);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(1, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -1731,7 +1732,7 @@ public function test_add_discussion() {
'value' => true)));
$discussion3 = mod_forum_external::add_discussion($forum->id, 'the non pinnedsubject', 'some 3 text here...');
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(3, $discussions['discussions']);
$this->assertEquals($discussion2pinned['discussionid'], $discussions['discussions'][0]['discussion']);
@@ -1773,10 +1774,10 @@ public function test_add_discussion() {
array('name' => 'attachmentsid', 'value' => $draftidattach));
$createddiscussion = mod_forum_external::add_discussion($forum->id, 'the inline attachment subject',
$dummytext, -1, $options);
- $createddiscussion = \external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $createddiscussion);
+ $createddiscussion = external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $createddiscussion);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(4, $discussions['discussions']);
$this->assertCount(0, $createddiscussion['warnings']);
@@ -1857,10 +1858,10 @@ public function test_add_discussion_in_course_with_groups() {
// Nost add the discussion using a valid group.
$discussion = mod_forum_external::add_discussion($forum->id, 'the subject', 'some text here...', $group->id);
- $discussion = \external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $discussion);
+ $discussion = external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $discussion);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(1, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -1869,10 +1870,10 @@ public function test_add_discussion_in_course_with_groups() {
// Now add a discussions without indicating a group. The function should guess the correct group.
$discussion = mod_forum_external::add_discussion($forum->id, 'the subject', 'some text here...');
- $discussion = \external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $discussion);
+ $discussion = external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $discussion);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(2, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -1885,10 +1886,10 @@ public function test_add_discussion_in_course_with_groups() {
// Now add a discussions without indicating a group. The function should guess the correct group (the first one).
$discussion = mod_forum_external::add_discussion($forum->id, 'the subject', 'some text here...');
- $discussion = \external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $discussion);
+ $discussion = external_api::clean_returnvalue(mod_forum_external::add_discussion_returns(), $discussion);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(3, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -1937,13 +1938,13 @@ public function test_set_lock_state() {
// Set the lock.
self::setAdminUser();
$result = mod_forum_external::set_lock_state($forum->id, $discussion->id, 0);
- $result = \external_api::clean_returnvalue(mod_forum_external::set_lock_state_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::set_lock_state_returns(), $result);
$this->assertTrue($result['locked']);
$this->assertNotEquals(0, $result['times']['locked']);
// Unset the lock.
$result = mod_forum_external::set_lock_state($forum->id, $discussion->id, time());
- $result = \external_api::clean_returnvalue(mod_forum_external::set_lock_state_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::set_lock_state_returns(), $result);
$this->assertFalse($result['locked']);
$this->assertEquals('0', $result['times']['locked']);
}
@@ -1971,7 +1972,7 @@ public function test_can_add_discussion() {
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$result = mod_forum_external::can_add_discussion($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
$this->assertFalse($result['status']);
$this->assertFalse($result['canpindiscussions']);
$this->assertTrue($result['cancreateattachment']);
@@ -1979,7 +1980,7 @@ public function test_can_add_discussion() {
// Disable attachments.
$DB->set_field('forum', 'maxattachments', 0, array('id' => $forum->id));
$result = mod_forum_external::can_add_discussion($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
$this->assertFalse($result['status']);
$this->assertFalse($result['canpindiscussions']);
$this->assertFalse($result['cancreateattachment']);
@@ -1987,7 +1988,7 @@ public function test_can_add_discussion() {
self::setAdminUser();
$result = mod_forum_external::can_add_discussion($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
$this->assertTrue($result['status']);
$this->assertTrue($result['canpindiscussions']);
$this->assertTrue($result['cancreateattachment']);
@@ -2012,12 +2013,12 @@ public function test_can_add_discussion_after_cutoff() {
$this->getDataGenerator()->enrol_user($user->id, $course->id);
$result = mod_forum_external::can_add_discussion($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
$this->assertFalse($result['status']);
self::setAdminUser();
$result = mod_forum_external::can_add_discussion($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::can_add_discussion_returns(), $result);
$this->assertTrue($result['status']);
}
@@ -2093,7 +2094,7 @@ public function test_mod_forum_get_discussion_rating_information() {
// Retrieve the rating for the post as student.
$this->setUser($user1);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertCount(1, $posts['ratinginfo']['ratings']);
$this->assertTrue($posts['ratinginfo']['ratings'][0]['canviewaggregate']);
$this->assertFalse($posts['ratinginfo']['canviewall']);
@@ -2104,7 +2105,7 @@ public function test_mod_forum_get_discussion_rating_information() {
// Retrieve the rating for the post as teacher.
$this->setUser($teacher);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertCount(1, $posts['ratinginfo']['ratings']);
$this->assertTrue($posts['ratinginfo']['ratings'][0]['canviewaggregate']);
$this->assertTrue($posts['ratinginfo']['canviewall']);
@@ -2133,7 +2134,7 @@ public function test_mod_forum_get_forum_access_information() {
self::setUser($student);
$result = mod_forum_external::get_forum_access_information($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_forum_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_forum_access_information_returns(), $result);
// Check default values for capabilities.
$enabledcaps = array('canviewdiscussion', 'canstartdiscussion', 'canreplypost', 'canviewrating', 'cancreateattachment',
@@ -2155,7 +2156,7 @@ public function test_mod_forum_get_forum_access_information() {
accesslib_clear_all_caches_for_unit_testing();
$result = mod_forum_external::get_forum_access_information($forum->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_forum_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_forum_access_information_returns(), $result);
unset($result['warnings']);
foreach ($result as $capname => $capvalue) {
if (in_array($capname, $enabledcaps)) {
@@ -2213,7 +2214,7 @@ public function test_add_discussion_post_private() {
'value' => true,
],
]);
- $post = \external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $post);
+ $post = external_api::clean_returnvalue(mod_forum_external::add_discussion_post_returns(), $post);
$privatereply = $DB->get_record('forum_posts', array('id' => $post['postid']));
$this->assertEquals($student1->id, $privatereply->privatereplyto);
// Bump the time of the private reply to ensure order.
@@ -2224,28 +2225,28 @@ public function test_add_discussion_post_private() {
// The teacher will receive their private reply.
self::setUser($teacher1);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(2, count($posts['posts']));
$this->assertTrue($posts['posts'][0]['isprivatereply']);
// Another teacher on the course will also receive the private reply.
self::setUser($teacher2);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(2, count($posts['posts']));
$this->assertTrue($posts['posts'][0]['isprivatereply']);
// The student will receive the private reply.
self::setUser($student1);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(2, count($posts['posts']));
$this->assertTrue($posts['posts'][0]['isprivatereply']);
// Another student will not receive the private reply.
self::setUser($student2);
$posts = mod_forum_external::get_discussion_posts($discussion->id, 'id', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
$this->assertEquals(1, count($posts['posts']));
$this->assertFalse($posts['posts'][0]['isprivatereply']);
@@ -2298,7 +2299,7 @@ public function test_trusted_text_enabled() {
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($discussionrecord);
$discussions = mod_forum_external::get_forum_discussions_paginated($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_paginated_returns(), $discussions);
$this->assertCount(2, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -2311,12 +2312,12 @@ public function test_trusted_text_enabled() {
// Get posts now.
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'DESC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// Admin message is fully trusted.
$this->assertEquals($dangeroustext, $posts['posts'][0]['message']);
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// Student message is not trusted.
$this->assertEquals($cleantext, $posts['posts'][0]['message']);
}
@@ -2359,7 +2360,7 @@ public function test_trusted_text_disabled() {
$discussion2 = self::getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($discussionrecord);
$discussions = mod_forum_external::get_forum_discussions($forum->id);
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_forum_discussions_returns(), $discussions);
$this->assertCount(2, $discussions['discussions']);
$this->assertCount(0, $discussions['warnings']);
@@ -2372,12 +2373,12 @@ public function test_trusted_text_disabled() {
// Get posts now.
$posts = mod_forum_external::get_discussion_posts($discussion2->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// Admin message is not trusted because enabletrusttext is disabled.
$this->assertEquals($cleantext, $posts['posts'][0]['message']);
$posts = mod_forum_external::get_discussion_posts($discussion1->id, 'modified', 'ASC');
- $posts = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
+ $posts = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $posts);
// Student message is not trusted.
$this->assertEquals($cleantext, $posts['posts'][0]['message']);
}
@@ -2405,7 +2406,7 @@ public function test_delete_post_discussion() {
$this->setUser($user);
$result = mod_forum_external::delete_post($discussion->firstpost);
- $result = \external_api::clean_returnvalue(mod_forum_external::delete_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::delete_post_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEquals(0, $DB->count_records('forum_posts', array('id' => $discussion->firstpost)));
$this->assertEquals(0, $DB->count_records('forum_discussions', array('id' => $discussion->id)));
@@ -2444,7 +2445,7 @@ public function test_delete_post_post() {
$this->setUser($user);
$result = mod_forum_external::delete_post($post->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::delete_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::delete_post_returns(), $result);
$this->assertTrue($result['status']);
$this->assertEquals(1, $DB->count_records('forum_posts', array('discussion' => $discussion->id)));
$this->assertEquals(1, $DB->count_records('forum_discussions', array('id' => $discussion->id)));
@@ -2647,7 +2648,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'replysubject' => get_string('re', 'mod_forum') . " {$discussion1reply1->subject}",
'message' => file_rewrite_pluginfile_urls($discussion1reply1->message, 'pluginfile.php',
$forum1context->id, 'mod_forum', 'post', $discussion1reply1->id),
- 'messageformat' => 1, // This value is usually changed by external_format_text() function.
+ 'messageformat' => 1, // This value is usually changed by \core_external\util::format_text() function.
'unread' => null,
'isdeleted' => false,
'isprivatereply' => false,
@@ -2713,7 +2714,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'replysubject' => get_string('re', 'mod_forum') . " {$discussion1firstpostobject->subject}",
'message' => file_rewrite_pluginfile_urls($discussion1firstpostobject->message, 'pluginfile.php',
$forum1context->id, 'mod_forum', 'post', $discussion1firstpostobject->id),
- 'messageformat' => 1, // This value is usually changed by external_format_text() function.
+ 'messageformat' => 1, // This value is usually changed by \core_external\util::format_text() function.
'unread' => null,
'isdeleted' => false,
'isprivatereply' => false,
@@ -2790,7 +2791,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'replysubject' => get_string('re', 'mod_forum') . " {$discussion2reply1->subject}",
'message' => file_rewrite_pluginfile_urls($discussion2reply1->message, 'pluginfile.php',
$forum1context->id, 'mod_forum', 'post', $discussion2reply1->id),
- 'messageformat' => 1, // This value is usually changed by external_format_text() function.
+ 'messageformat' => 1, // This value is usually changed by \core_external\util::format_text() function.
'unread' => null,
'isdeleted' => false,
'isprivatereply' => false,
@@ -2856,7 +2857,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
'replysubject' => get_string('re', 'mod_forum') . " {$discussion2firstpostobject->subject}",
'message' => file_rewrite_pluginfile_urls($discussion2firstpostobject->message, 'pluginfile.php',
$forum1context->id, 'mod_forum', 'post', $discussion2firstpostobject->id),
- 'messageformat' => 1, // This value is usually changed by external_format_text() function.
+ 'messageformat' => 1, // This value is usually changed by \core_external\util::format_text() function.
'unread' => null,
'isdeleted' => false,
'isprivatereply' => false,
@@ -2914,7 +2915,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
// Test discussions with one additional post each (total 2 posts).
// Also testing that we get the parent posts too.
$discussions = mod_forum_external::get_discussion_posts_by_userid($user2->id, $forum1->cmid, 'modified', 'DESC');
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_by_userid_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_by_userid_returns(), $discussions);
$this->assertEquals(2, count($discussions['discussions']));
@@ -2941,7 +2942,7 @@ public function test_mod_forum_get_discussion_posts_by_userid() {
groups_add_member($group2->id, $teacher->id);
self::setUser($teacher);
$discussions = mod_forum_external::get_discussion_posts_by_userid($user2->id, $forum1->cmid, 'modified', 'DESC');
- $discussions = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_by_userid_returns(), $discussions);
+ $discussions = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_by_userid_returns(), $discussions);
// Discussion is only 1 record (group 2).
$this->assertEquals(1, count($discussions['discussions']));
$this->assertEquals($expectedposts['discussions'][1], $discussions['discussions'][0]);
@@ -2967,7 +2968,7 @@ public function test_get_discussion_post_discussion() {
$discussion = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_discussion($record);
$this->setUser($user);
$result = mod_forum_external::get_discussion_post($discussion->firstpost);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
$this->assertEquals($discussion->firstpost, $result['post']['id']);
$this->assertFalse($result['post']['hasparent']);
$this->assertEquals($discussion->message, $result['post']['message']);
@@ -3002,7 +3003,7 @@ public function test_get_discussion_post_post() {
$post = $this->getDataGenerator()->get_plugin_generator('mod_forum')->create_post($record);
$this->setUser($user);
$result = mod_forum_external::get_discussion_post($post->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
$this->assertEquals($post->id, $result['post']['id']);
$this->assertTrue($result['post']['hasparent']);
$this->assertEquals($post->message, $result['post']['message']);
@@ -3040,7 +3041,7 @@ public function test_get_discussion_post_other_user_post() {
// Check other user post.
$this->setUser($otheruser);
$result = mod_forum_external::get_discussion_post($post->id);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
$this->assertEquals($post->id, $result['post']['id']);
$this->assertTrue($result['post']['hasparent']);
$this->assertEquals($post->message, $result['post']['message']);
@@ -3093,7 +3094,7 @@ public function test_prepare_draft_area_for_post() {
// Check attachment area.
$result = mod_forum_external::prepare_draft_area_for_post($post->id, 'attachment');
- $result = \external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
$this->assertCount(2, $result['files']);
$this->assertEquals($filename, $result['files'][0]['filename']);
$this->assertCount(5, $result['areaoptions']);
@@ -3101,13 +3102,13 @@ public function test_prepare_draft_area_for_post() {
// Check again using existing draft item id.
$result = mod_forum_external::prepare_draft_area_for_post($post->id, 'attachment', $result['draftitemid']);
- $result = \external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
$this->assertCount(2, $result['files']);
// Keep only certain files in the area.
$filestokeep = array(array('filename' => $filename, 'filepath' => '/'));
$result = mod_forum_external::prepare_draft_area_for_post($post->id, 'attachment', $result['draftitemid'], $filestokeep);
- $result = \external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
$this->assertCount(1, $result['files']);
$this->assertEquals($filename, $result['files'][0]['filename']);
@@ -3116,7 +3117,7 @@ public function test_prepare_draft_area_for_post() {
$filerecordinline['filename'] = 'fakeimage.png';
$fs->create_file_from_string($filerecordinline, 'fake image.');
$result = mod_forum_external::prepare_draft_area_for_post($post->id, 'post');
- $result = \external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::prepare_draft_area_for_post_returns(), $result);
$this->assertCount(1, $result['files']);
$this->assertEquals($filerecordinline['filename'], $result['files'][0]['filename']);
$this->assertCount(5, $result['areaoptions']);
@@ -3152,12 +3153,12 @@ public function test_update_discussion_post_discussion() {
$result = mod_forum_external::update_discussion_post($discussion->firstpost, $subject, $message, $messageformat,
$options);
- $result = \external_api::clean_returnvalue(mod_forum_external::update_discussion_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::update_discussion_post_returns(), $result);
$this->assertTrue($result['status']);
// Get the post from WS.
$result = mod_forum_external::get_discussion_post($discussion->firstpost);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_discussion_post_returns(), $result);
$this->assertEquals($subject, $result['post']['subject']);
$this->assertEquals($message, $result['post']['message']);
$this->assertEquals($messageformat, $result['post']['messageformat']);
@@ -3236,14 +3237,14 @@ public function test_update_discussion_post_post() {
];
$result = mod_forum_external::update_discussion_post($newpost->id, '', $message, $messageformat, $options);
- $result = \external_api::clean_returnvalue(mod_forum_external::update_discussion_post_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::update_discussion_post_returns(), $result);
$this->assertTrue($result['status']);
// Check subscription status.
$this->assertFalse(\mod_forum\subscriptions::is_subscribed($user->id, $forum, $discussion->id, $cm));
// Get the post from WS.
$result = mod_forum_external::get_discussion_posts($discussion->id, 'modified', 'DESC', true);
- $result = \external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_forum_external::get_discussion_posts_returns(), $result);
$found = false;
foreach ($result['posts'] as $post) {
if ($post['id'] == $newpost->id) {
@@ -3320,7 +3321,7 @@ public function test_update_discussion_post_set_subject_to_zero(): void {
]);
// Update discussion post subject.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
mod_forum_external::update_discussion_post_returns(),
mod_forum_external::update_discussion_post($discussion->firstpost, '0')
);
@@ -3353,7 +3354,7 @@ public function test_update_discussion_post_set_message_to_zero(): void {
]);
// Update discussion post message.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
mod_forum_external::update_discussion_post_returns(),
mod_forum_external::update_discussion_post($discussion->firstpost, '', '0', FORMAT_HTML)
);
@@ -3386,7 +3387,7 @@ public function test_update_discussion_post_set_message_format_moodle(): void {
]);
// Update discussion post message & messageformat.
- $result = \external_api::clean_returnvalue(
+ $result = external_api::clean_returnvalue(
mod_forum_external::update_discussion_post_returns(),
mod_forum_external::update_discussion_post($discussion->firstpost, '', 'Update discussion message', FORMAT_MOODLE)
);
diff --git a/mod/glossary/classes/external.php b/mod/glossary/classes/external.php
index 27a1ee9e064fa..60803cbd4a3fd 100644
--- a/mod/glossary/classes/external.php
+++ b/mod/glossary/classes/external.php
@@ -25,10 +25,18 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/glossary/lib.php');
/**
@@ -133,9 +141,15 @@ protected static function fill_entry_details($entry, $context) {
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
// Format concept and definition.
- $entry->concept = external_format_string($entry->concept, $context->id);
- list($entry->definition, $entry->definitionformat) = external_format_text($entry->definition, $entry->definitionformat,
- $context->id, 'mod_glossary', 'entry', $entry->id);
+ $entry->concept = \core_external\util::format_string($entry->concept, $context);
+ [$entry->definition, $entry->definitionformat] = \core_external\util::format_text(
+ $entry->definition,
+ $entry->definitionformat,
+ $context,
+ 'mod_glossary',
+ 'entry',
+ $entry->id
+ );
// Author details.
$user = mod_glossary_entry_query_builder::get_user_from_record($entry);
@@ -148,9 +162,9 @@ protected static function fill_entry_details($entry, $context) {
$entry->attachment = !empty($entry->attachment) ? 1 : 0;
$entry->attachments = array();
if ($entry->attachment) {
- $entry->attachments = external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
+ $entry->attachments = util::get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
}
- $definitioninlinefiles = external_util::get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
+ $definitioninlinefiles = util::get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
if (!empty($definitioninlinefiles)) {
$entry->definitioninlinefiles = $definitioninlinefiles;
}
@@ -218,7 +232,7 @@ public static function get_glossaries_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($courseids)) {
- list($courses, $warnings) = external_util::validate_courses($courseids, $courses);
+ list($courses, $warnings) = util::validate_courses($courseids, $courses);
// Get the glossaries in these courses, this function checks users visibility permissions.
$glossaries = get_all_instances_in_courses('glossary', $courses);
@@ -349,7 +363,7 @@ public static function view_glossary($id, $mode) {
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function view_glossary_returns() {
@@ -407,7 +421,7 @@ public static function view_entry($id) {
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function view_entry_returns() {
@@ -491,7 +505,7 @@ public static function get_entries_by_letter($id, $letter, $from, $limit, $optio
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_letter_returns() {
@@ -590,7 +604,7 @@ public static function get_entries_by_date($id, $order, $sort, $from, $limit, $o
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_date_returns() {
@@ -646,7 +660,7 @@ public static function get_categories($id, $from, $limit) {
$categories = array();
list($records, $count) = glossary_get_categories($glossary, $from, $limit);
foreach ($records as $category) {
- $category->name = external_format_string($category->name, $context->id);
+ $category->name = \core_external\util::format_string($category->name, $context);
$categories[] = $category;
}
@@ -660,7 +674,7 @@ public static function get_categories($id, $from, $limit) {
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_categories_returns() {
@@ -753,7 +767,7 @@ public static function get_entries_by_category($id, $categoryid, $from, $limit,
$record->categoryid = GLOSSARY_SHOW_NOT_CATEGORISED;
}
if (isset($record->categoryname)) {
- $record->categoryname = external_format_string($record->categoryname, $context->id);
+ $record->categoryname = \core_external\util::format_string($record->categoryname, $context);
}
$entries[] = $record;
}
@@ -769,7 +783,7 @@ public static function get_entries_by_category($id, $categoryid, $from, $limit,
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_category_returns() {
@@ -856,7 +870,7 @@ public static function get_authors($id, $from, $limit, $options) {
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_authors_returns() {
@@ -965,7 +979,7 @@ public static function get_entries_by_author($id, $letter, $field, $sort, $from,
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_author_returns() {
@@ -1070,7 +1084,7 @@ public static function get_entries_by_author_id($id, $authorid, $order, $sort, $
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_author_id_returns() {
@@ -1173,7 +1187,7 @@ public static function get_entries_by_search($id, $query, $fullsearch, $order, $
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_search_returns() {
@@ -1255,7 +1269,7 @@ public static function get_entries_by_term($id, $term, $from, $limit, $options)
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_by_term_returns() {
@@ -1343,7 +1357,7 @@ public static function get_entries_to_approve($id, $letter, $order, $sort, $from
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entries_to_approve_returns() {
@@ -1414,7 +1428,7 @@ public static function get_entry_by_id($id) {
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_entry_by_id_returns() {
@@ -1554,7 +1568,7 @@ public static function add_entry($glossaryid, $concept, $definition, $definition
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.2
*/
public static function add_entry_returns() {
diff --git a/mod/glossary/classes/external/delete_entry.php b/mod/glossary/classes/external/delete_entry.php
index 7551c43c86ab9..285dace3ccdb2 100644
--- a/mod/glossary/classes/external/delete_entry.php
+++ b/mod/glossary/classes/external/delete_entry.php
@@ -28,15 +28,13 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/glossary/lib.php');
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* This is the external method for deleting a content.
diff --git a/mod/glossary/classes/external/prepare_entry.php b/mod/glossary/classes/external/prepare_entry.php
index 77134f4897d1d..22e59844c002f 100644
--- a/mod/glossary/classes/external/prepare_entry.php
+++ b/mod/glossary/classes/external/prepare_entry.php
@@ -28,15 +28,14 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/glossary/lib.php');
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
/**
* This is the external method for preparing a entry for edition.
diff --git a/mod/glossary/classes/external/update_entry.php b/mod/glossary/classes/external/update_entry.php
index 695fbb72d3ee0..f52a08e9928ae 100644
--- a/mod/glossary/classes/external/update_entry.php
+++ b/mod/glossary/classes/external/update_entry.php
@@ -28,16 +28,15 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/glossary/lib.php');
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_format_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use core_text;
use moodle_exception;
diff --git a/mod/glossary/tests/external/delete_entry.php b/mod/glossary/tests/external/delete_entry.php
index df56e078d4739..3e2c07041da01 100644
--- a/mod/glossary/tests/external/delete_entry.php
+++ b/mod/glossary/tests/external/delete_entry.php
@@ -31,7 +31,7 @@
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
/**
diff --git a/mod/glossary/tests/external/external_test.php b/mod/glossary/tests/external/external_test.php
index 181cc074d777c..0350afd2212c5 100644
--- a/mod/glossary/tests/external/external_test.php
+++ b/mod/glossary/tests/external/external_test.php
@@ -25,6 +25,8 @@
namespace mod_glossary\external;
+use core_external\external_api;
+use core_external\util as external_util;
use externallib_advanced_testcase;
use mod_glossary_external;
@@ -62,7 +64,7 @@ public function test_get_glossaries_by_courses() {
// Check results where student is enrolled.
$this->setUser($s1);
$glossaries = mod_glossary_external::get_glossaries_by_courses(array());
- $glossaries = \external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
+ $glossaries = external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
$this->assertCount(2, $glossaries['glossaries']);
$this->assertEquals('First Glossary', $glossaries['glossaries'][0]['name']);
@@ -72,7 +74,7 @@ public function test_get_glossaries_by_courses() {
// Check results with specific course IDs.
$glossaries = mod_glossary_external::get_glossaries_by_courses(array($c1->id, $c2->id));
- $glossaries = \external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
+ $glossaries = external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
$this->assertCount(2, $glossaries['glossaries']);
$this->assertEquals('First Glossary', $glossaries['glossaries'][0]['name']);
@@ -87,7 +89,7 @@ public function test_get_glossaries_by_courses() {
$this->setAdminUser();
$glossaries = mod_glossary_external::get_glossaries_by_courses(array($c2->id));
- $glossaries = \external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
+ $glossaries = external_api::clean_returnvalue(mod_glossary_external::get_glossaries_by_courses_returns(), $glossaries);
$this->assertCount(1, $glossaries['glossaries']);
$this->assertEquals('Third Glossary', $glossaries['glossaries'][0]['name']);
@@ -106,7 +108,7 @@ public function test_view_glossary() {
$sink = $this->redirectEvents();
$this->setUser($u1);
$return = mod_glossary_external::view_glossary($g1->id, 'letter');
- $return = \external_api::clean_returnvalue(mod_glossary_external::view_glossary_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::view_glossary_returns(), $return);
$events = $sink->get_events();
// Assertion.
@@ -160,7 +162,7 @@ public function test_view_entry() {
// Test readable entry.
$sink = $this->redirectEvents();
$return = mod_glossary_external::view_entry($e1->id);
- $return = \external_api::clean_returnvalue(mod_glossary_external::view_entry_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::view_entry_returns(), $return);
$events = $sink->get_events();
$this->assertTrue($return['status']);
$this->assertEmpty($return['warnings']);
@@ -170,7 +172,7 @@ public function test_view_entry() {
// Test non-approved of self.
$return = mod_glossary_external::view_entry($e2->id);
- $return = \external_api::clean_returnvalue(mod_glossary_external::view_entry_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::view_entry_returns(), $return);
$events = $sink->get_events();
$this->assertTrue($return['status']);
$this->assertEmpty($return['warnings']);
@@ -214,7 +216,7 @@ public function test_get_entries_by_letter() {
// Just a normal request from admin user.
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1c->id, $return['entries'][0]['id']);
@@ -225,7 +227,7 @@ public function test_get_entries_by_letter() {
// An admin user requesting all the entries.
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 20, array('includenotapproved' => 1));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
@@ -236,7 +238,7 @@ public function test_get_entries_by_letter() {
// A normal user.
$this->setUser($u1);
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
@@ -245,7 +247,7 @@ public function test_get_entries_by_letter() {
// A normal user requesting to view all non approved entries.
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 20, array('includenotapproved' => 1));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
@@ -272,14 +274,14 @@ public function test_get_entries_by_letter_with_parameters() {
// Requesting a single letter.
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'b', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e1b->id, $return['entries'][0]['id']);
// Requesting special letters.
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'SPECIAL', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
@@ -287,12 +289,12 @@ public function test_get_entries_by_letter_with_parameters() {
// Requesting with limit.
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
$return = mod_glossary_external::get_entries_by_letter($g1->id, 'ALL', 1, 2, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_letter_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1c->id, $return['entries'][0]['id']);
@@ -327,7 +329,7 @@ public function test_get_entries_by_date() {
// Ordering by time modified descending.
$return = mod_glossary_external::get_entries_by_date($g1->id, 'UPDATE', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
@@ -338,7 +340,7 @@ public function test_get_entries_by_date() {
// Ordering by time modified ascending.
$return = mod_glossary_external::get_entries_by_date($g1->id, 'UPDATE', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1b->id, $return['entries'][0]['id']);
@@ -347,7 +349,7 @@ public function test_get_entries_by_date() {
// Ordering by time created asc.
$return = mod_glossary_external::get_entries_by_date($g1->id, 'CREATION', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
@@ -356,7 +358,7 @@ public function test_get_entries_by_date() {
// Ordering by time created descending.
$return = mod_glossary_external::get_entries_by_date($g1->id, 'CREATION', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1b->id, $return['entries'][0]['id']);
@@ -366,7 +368,7 @@ public function test_get_entries_by_date() {
// Ordering including to approve.
$return = mod_glossary_external::get_entries_by_date($g1->id, 'CREATION', 'ASC', 0, 20,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
@@ -377,14 +379,14 @@ public function test_get_entries_by_date() {
// Ordering including to approve and pagination.
$return = mod_glossary_external::get_entries_by_date($g1->id, 'CREATION', 'ASC', 0, 2,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
$this->assertEquals($e1c->id, $return['entries'][1]['id']);
$return = mod_glossary_external::get_entries_by_date($g1->id, 'CREATION', 'ASC', 2, 2,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_date_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
@@ -405,7 +407,7 @@ public function test_get_categories() {
$cat2a = $gg->create_category($g2);
$return = mod_glossary_external::get_categories($g1->id, 0, 20);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_categories_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_categories_returns(), $return);
$this->assertCount(3, $return['categories']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($cat1a->id, $return['categories'][0]['id']);
@@ -413,7 +415,7 @@ public function test_get_categories() {
$this->assertEquals($cat1c->id, $return['categories'][2]['id']);
$return = mod_glossary_external::get_categories($g1->id, 1, 2);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_categories_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_categories_returns(), $return);
$this->assertCount(2, $return['categories']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($cat1b->id, $return['categories'][0]['id']);
@@ -449,7 +451,7 @@ public function test_get_entries_by_category() {
// Browse one category.
$return = mod_glossary_external::get_entries_by_category($g1->id, $cat1a->id, 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a1->id, $return['entries'][0]['id']);
@@ -460,7 +462,7 @@ public function test_get_entries_by_category() {
// Browse all categories.
$return = mod_glossary_external::get_entries_by_category($g1->id, GLOSSARY_SHOW_ALL_CATEGORIES, 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
$this->assertCount(5, $return['entries']);
$this->assertEquals(5, $return['count']);
$this->assertEquals($e1b1->id, $return['entries'][0]['id']);
@@ -471,7 +473,7 @@ public function test_get_entries_by_category() {
// Browse uncategorised.
$return = mod_glossary_external::get_entries_by_category($g1->id, GLOSSARY_SHOW_NOT_CATEGORISED, 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e1x1->id, $return['entries'][0]['id']);
@@ -479,7 +481,7 @@ public function test_get_entries_by_category() {
// Including to approve.
$return = mod_glossary_external::get_entries_by_category($g1->id, $cat1b->id, 0, 20,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
$this->assertEquals($e1b1->id, $return['entries'][0]['id']);
@@ -488,7 +490,7 @@ public function test_get_entries_by_category() {
// Using limit.
$return = mod_glossary_external::get_entries_by_category($g1->id, GLOSSARY_SHOW_ALL_CATEGORIES, 0, 3,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1b1->id, $return['entries'][0]['id']);
@@ -496,7 +498,7 @@ public function test_get_entries_by_category() {
$this->assertEquals($e1a1->id, $return['entries'][2]['id']);
$return = mod_glossary_external::get_entries_by_category($g1->id, GLOSSARY_SHOW_ALL_CATEGORIES, 3, 2,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_category_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1a2->id, $return['entries'][0]['id']);
@@ -527,7 +529,7 @@ public function test_get_authors() {
// Simple request.
$return = mod_glossary_external::get_authors($g1->id, 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_authors_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_authors_returns(), $return);
$this->assertCount(2, $return['authors']);
$this->assertEquals(2, $return['count']);
$this->assertEquals($u2->id, $return['authors'][0]['id']);
@@ -535,7 +537,7 @@ public function test_get_authors() {
// Include users with entries pending approval.
$return = mod_glossary_external::get_authors($g1->id, 0, 20, array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_authors_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_authors_returns(), $return);
$this->assertCount(3, $return['authors']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($u2->id, $return['authors'][0]['id']);
@@ -544,7 +546,7 @@ public function test_get_authors() {
// Pagination.
$return = mod_glossary_external::get_authors($g1->id, 1, 1, array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_authors_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_authors_returns(), $return);
$this->assertCount(1, $return['authors']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($u3->id, $return['authors'][0]['id']);
@@ -578,7 +580,7 @@ public function test_get_entries_by_author() {
// Requesting a single letter.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'u', 'LASTNAME', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1b2->id, $return['entries'][0]['id']);
@@ -590,19 +592,19 @@ public function test_get_entries_by_author() {
// Requesting special letters.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'SPECIAL', 'LASTNAME', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
// Requesting with limit.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 1, 2, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1c1->id, $return['entries'][0]['id']);
@@ -612,7 +614,7 @@ public function test_get_entries_by_author() {
$this->setAdminUser();
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'ASC', 0, 20,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(7, $return['entries']);
$this->assertEquals(7, $return['count']);
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
@@ -625,28 +627,28 @@ public function test_get_entries_by_author() {
// Changing order.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'LASTNAME', 'DESC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1a1->id, $return['entries'][0]['id']);
// Sorting by firstname.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'FIRSTNAME', 'ASC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1b2->id, $return['entries'][0]['id']);
// Sorting by firstname descending.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'ALL', 'FIRSTNAME', 'DESC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(6, $return['count']);
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
// Filtering by firstname descending.
$return = mod_glossary_external::get_entries_by_author($g1->id, 'z', 'FIRSTNAME', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1d1->id, $return['entries'][0]['id']);
@@ -657,7 +659,7 @@ public function test_get_entries_by_author() {
// Test with a deleted user.
delete_user($u2);
$return = mod_glossary_external::get_entries_by_author($g1->id, 'u', 'LASTNAME', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1b2->id, $return['entries'][0]['id']);
@@ -694,7 +696,7 @@ public function test_get_entries_by_author_id() {
// Standard request.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a2->id, $return['entries'][0]['id']);
@@ -703,7 +705,7 @@ public function test_get_entries_by_author_id() {
// Standard request descending.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a1->id, $return['entries'][0]['id']);
@@ -712,7 +714,7 @@ public function test_get_entries_by_author_id() {
// Requesting ordering by time created.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CREATION', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a3->id, $return['entries'][0]['id']);
@@ -721,7 +723,7 @@ public function test_get_entries_by_author_id() {
// Requesting ordering by time created descending.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CREATION', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a2->id, $return['entries'][0]['id']);
@@ -730,7 +732,7 @@ public function test_get_entries_by_author_id() {
// Requesting ordering by time modified.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'UPDATE', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a1->id, $return['entries'][0]['id']);
@@ -739,7 +741,7 @@ public function test_get_entries_by_author_id() {
// Requesting ordering by time modified descending.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'UPDATE', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1a2->id, $return['entries'][0]['id']);
@@ -749,7 +751,7 @@ public function test_get_entries_by_author_id() {
// Including non approved.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'ASC', 0, 20,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1a2->id, $return['entries'][0]['id']);
@@ -760,14 +762,14 @@ public function test_get_entries_by_author_id() {
// Pagination.
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'ASC', 0, 2,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1a2->id, $return['entries'][0]['id']);
$this->assertEquals($e1a4->id, $return['entries'][1]['id']);
$return = mod_glossary_external::get_entries_by_author_id($g1->id, $u1->id, 'CONCEPT', 'ASC', 1, 2,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_author_id_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1a4->id, $return['entries'][0]['id']);
@@ -803,7 +805,7 @@ public function test_get_entries_by_search() {
// Test simple query.
$query = 'hero';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'CONCEPT', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e3->id, $return['entries'][0]['id']);
@@ -813,7 +815,7 @@ public function test_get_entries_by_search() {
// Enabling full search.
$query = 'hero';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, true, 'CONCEPT', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
$this->assertEquals($e5->id, $return['entries'][0]['id']);
@@ -822,7 +824,7 @@ public function test_get_entries_by_search() {
// Concept descending.
$query = 'hero';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, true, 'CONCEPT', 'DESC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
$this->assertEquals($e3->id, $return['entries'][0]['id']);
@@ -831,12 +833,12 @@ public function test_get_entries_by_search() {
// Search on alias.
$query = 'couscous';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'CONCEPT', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e7->id, $return['entries'][0]['id']);
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, true, 'CONCEPT', 'ASC', 0, 20, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e7->id, $return['entries'][0]['id']);
@@ -844,12 +846,12 @@ public function test_get_entries_by_search() {
// Pagination and ordering on created date.
$query = 'ou';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'CREATION', 'ASC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e7->id, $return['entries'][0]['id']);
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'CREATION', 'DESC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e1->id, $return['entries'][0]['id']);
@@ -857,12 +859,12 @@ public function test_get_entries_by_search() {
// Ordering on updated date.
$query = 'ou';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'UPDATE', 'ASC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e2->id, $return['entries'][0]['id']);
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'UPDATE', 'DESC', 0, 1, array());
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(3, $return['count']);
$this->assertEquals($e7->id, $return['entries'][0]['id']);
@@ -871,7 +873,7 @@ public function test_get_entries_by_search() {
$query = 'ou';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, false, 'CONCEPT', 'ASC', 0, 20,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1->id, $return['entries'][0]['id']);
@@ -883,7 +885,7 @@ public function test_get_entries_by_search() {
$query = '+Heroes -Abcd';
$return = mod_glossary_external::get_entries_by_search($g1->id, $query, true, 'CONCEPT', 'ASC', 0, 20,
array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_search_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
$this->assertEquals($e6->id, $return['entries'][0]['id']);
@@ -913,7 +915,7 @@ public function test_get_entries_by_term() {
// Search concept + alias.
$return = mod_glossary_external::get_entries_by_term($g1->id, 'cat', 0, 20, array('includenotapproved' => false));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
// Compare ids, ignore ordering of array, using canonicalize parameter of assertEquals.
@@ -932,7 +934,7 @@ public function test_get_entries_by_term() {
// Search alias.
$return = mod_glossary_external::get_entries_by_term($g1->id, 'dog', 0, 20, array('includenotapproved' => false));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(2, $return['count']);
@@ -943,7 +945,7 @@ public function test_get_entries_by_term() {
// Search including not approved.
$return = mod_glossary_external::get_entries_by_term($g1->id, 'dog', 0, 20, array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
$this->assertCount(3, $return['entries']);
$this->assertEquals(3, $return['count']);
// Compare ids, ignore ordering of array, using canonicalize parameter of assertEquals.
@@ -953,13 +955,13 @@ public function test_get_entries_by_term() {
// Pagination.
$return = mod_glossary_external::get_entries_by_term($g1->id, 'dog', 0, 1, array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
$this->assertCount(1, $return['entries']);
// We don't compare the returned entry id because it may be different depending on the DBMS,
// for example, Postgres does a random sorting in this case.
$this->assertEquals(3, $return['count']);
$return = mod_glossary_external::get_entries_by_term($g1->id, 'dog', 1, 1, array('includenotapproved' => true));
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(3, $return['count']);
}
@@ -989,7 +991,7 @@ public function test_get_entries_to_approve() {
// Simple listing.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'ASC', 0, 20);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
@@ -999,7 +1001,7 @@ public function test_get_entries_to_approve() {
// Revert ordering of concept.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'DESC', 0, 20);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(4, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1b->id, $return['entries'][0]['id']);
@@ -1009,27 +1011,27 @@ public function test_get_entries_to_approve() {
// Filtering by letter.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'a', 'CONCEPT', 'ASC', 0, 20);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e1c->id, $return['entries'][0]['id']);
// Filtering by special.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'SPECIAL', 'CONCEPT', 'ASC', 0, 20);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(1, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
// Pagination.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'ASC', 0, 2);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
$this->assertEquals($e1c->id, $return['entries'][1]['id']);
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'ASC', 1, 2);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(2, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1c->id, $return['entries'][0]['id']);
@@ -1037,28 +1039,28 @@ public function test_get_entries_to_approve() {
// Ordering by creation date.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CREATION', 'ASC', 0, 1);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1b->id, $return['entries'][0]['id']);
// Ordering by creation date desc.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CREATION', 'DESC', 0, 1);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1a->id, $return['entries'][0]['id']);
// Ordering by update date.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'UPDATE', 'ASC', 0, 1);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1c->id, $return['entries'][0]['id']);
// Ordering by update date desc.
$return = mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'UPDATE', 'DESC', 0, 1);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_to_approve_returns(), $return);
$this->assertCount(1, $return['entries']);
$this->assertEquals(4, $return['count']);
$this->assertEquals($e1d->id, $return['entries'][0]['id']);
@@ -1107,7 +1109,7 @@ public function test_get_entry_by_id() {
$this->setUser($u1);
$return = mod_glossary_external::get_entry_by_id($e1->id);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
$this->assertEquals($e1->id, $return['entry']['id']);
$this->assertEquals('Cats', $return['entry']['tags'][0]['rawname']);
$this->assertEquals('Dogs', $return['entry']['tags'][1]['rawname']);
@@ -1115,7 +1117,7 @@ public function test_get_entry_by_id() {
$this->assertTrue($return['permissions']['candelete']);
$return = mod_glossary_external::get_entry_by_id($e2->id);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
$this->assertEquals($e2->id, $return['entry']['id']);
$this->assertTrue($return['permissions']['candelete']);
@@ -1136,14 +1138,14 @@ public function test_get_entry_by_id() {
// An admin can see other's entries to be approved.
$this->setAdminUser();
$return = mod_glossary_external::get_entry_by_id($e3->id);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
$this->assertEquals($e3->id, $return['entry']['id']);
$this->assertTrue($return['permissions']['candelete']);
// Students can see other students approved entries but they will not be able to delete them.
$this->setUser($u3);
$return = mod_glossary_external::get_entry_by_id($e1->id);
- $return = \external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
$this->assertEquals($e1->id, $return['entry']['id']);
$this->assertFalse($return['permissions']['candelete']);
}
@@ -1159,7 +1161,7 @@ public function test_add_entry_without_optional_settings() {
$concept = 'A concept';
$definition = 'A definition
';
$return = mod_glossary_external::add_entry($glossary->id, $concept, $definition, FORMAT_HTML);
- $return = \external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
// Get entry from DB.
$entry = $DB->get_record('glossary_entries', array('id' => $return['entryid']));
@@ -1191,7 +1193,7 @@ public function test_add_entry_with_aliases() {
)
);
$return = mod_glossary_external::add_entry($glossary->id, $concept, $definition, FORMAT_HTML, $options);
- $return = \external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
$aliases = $DB->get_records('glossary_alias', array('entryid' => $return['entryid']));
$this->assertCount(3, $aliases);
@@ -1221,7 +1223,7 @@ public function test_add_entry_in_categories() {
)
);
$return = mod_glossary_external::add_entry($glossary->id, $concept, $definition, FORMAT_HTML, $options);
- $return = \external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
$categories = $DB->get_records('glossary_entries_categories', array('entryid' => $return['entryid']));
$this->assertCount(2, $categories);
@@ -1275,10 +1277,10 @@ public function test_add_entry_with_attachments() {
)
);
$return = mod_glossary_external::add_entry($glossary->id, $concept, $definition, FORMAT_HTML, $options);
- $return = \external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
+ $return = external_api::clean_returnvalue(mod_glossary_external::add_entry_returns(), $return);
- $editorfiles = \external_util::get_area_files($context->id, 'mod_glossary', 'entry', $return['entryid']);
- $attachmentfiles = \external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $return['entryid']);
+ $editorfiles = external_util::get_area_files($context->id, 'mod_glossary', 'entry', $return['entryid']);
+ $attachmentfiles = external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $return['entryid']);
$this->assertCount(1, $editorfiles);
$this->assertCount(1, $attachmentfiles);
@@ -1354,7 +1356,7 @@ public function test_get_entry_rating_information() {
// As student, retrieve ratings information.
$this->setUser($user1);
$result = mod_glossary_external::get_entry_by_id($entry->id);
- $result = \external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $result);
$this->assertCount(1, $result['ratinginfo']['ratings']);
$this->assertFalse($result['ratinginfo']['ratings'][0]['canviewaggregate']);
$this->assertFalse($result['ratinginfo']['canviewall']);
@@ -1364,7 +1366,7 @@ public function test_get_entry_rating_information() {
// Now, as teacher, I should see the info correctly.
$this->setUser($teacher);
$result = mod_glossary_external::get_entry_by_id($entry->id);
- $result = \external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $result);
$this->assertCount(1, $result['ratinginfo']['ratings']);
$this->assertTrue($result['ratinginfo']['ratings'][0]['canviewaggregate']);
$this->assertTrue($result['ratinginfo']['canviewall']);
diff --git a/mod/glossary/tests/external/prepare_entry.php b/mod/glossary/tests/external/prepare_entry.php
index b5870a5cc957d..1ba657a88045f 100644
--- a/mod/glossary/tests/external/prepare_entry.php
+++ b/mod/glossary/tests/external/prepare_entry.php
@@ -31,12 +31,8 @@
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
-use mod_glossary_external;
-use context_module;
-use context_user;
-use external_util;
/**
* External function test for prepare_entry.
diff --git a/mod/glossary/tests/external/update_entry.php b/mod/glossary/tests/external/update_entry.php
index ed6ffc52e66b0..bb5d862c0384b 100644
--- a/mod/glossary/tests/external/update_entry.php
+++ b/mod/glossary/tests/external/update_entry.php
@@ -31,12 +31,12 @@
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_glossary_external;
use context_module;
use context_user;
-use external_util;
+use core_external\util as external_util;
/**
* External function test for update_entry.
diff --git a/mod/h5pactivity/classes/external/get_attempts.php b/mod/h5pactivity/classes/external/get_attempts.php
index d1f9aecf6cfba..8cfff5a8641a7 100644
--- a/mod/h5pactivity/classes/external/get_attempts.php
+++ b/mod/h5pactivity/classes/external/get_attempts.php
@@ -14,38 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for getting the information needed to present an attempts report.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.9
- * @copyright 2020 Ferran Recio
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_h5pactivity\local\manager;
use mod_h5pactivity\local\attempt;
use mod_h5pactivity\local\report\attempts as report_attempts;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_multiple_structure;
-use external_single_structure;
-use external_warnings;
-use moodle_exception;
use context_module;
use stdClass;
/**
* This is the external method for getting the information needed to present an attempts report.
*
+ * @package mod_h5pactivity
+ * @since Moodle 3.9
* @copyright 2020 Ferran Recio
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/mod/h5pactivity/classes/external/get_h5pactivities_by_courses.php b/mod/h5pactivity/classes/external/get_h5pactivities_by_courses.php
index e1546dd102984..adf69ae8bc127 100644
--- a/mod/h5pactivity/classes/external/get_h5pactivities_by_courses.php
+++ b/mod/h5pactivity/classes/external/get_h5pactivities_by_courses.php
@@ -14,28 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for returning a list of h5p activities.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.9
- * @copyright 2020 Carlos Escobedo
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_util;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_module;
use core_h5p\factory;
@@ -90,7 +76,7 @@ public static function execute(array $courseids): array {
$factory = new factory();
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = \core_external\util::validate_courses($params['courseids'], $mycourses);
$output = $PAGE->get_renderer('core');
// Get the h5p activities in this course, this function checks users visibility permissions.
@@ -133,4 +119,4 @@ public static function execute_returns() {
]
);
}
-}
\ No newline at end of file
+}
diff --git a/mod/h5pactivity/classes/external/get_h5pactivity_access_information.php b/mod/h5pactivity/classes/external/get_h5pactivity_access_information.php
index 20e80122fe26e..0567cfc671c47 100644
--- a/mod/h5pactivity/classes/external/get_h5pactivity_access_information.php
+++ b/mod/h5pactivity/classes/external/get_h5pactivity_access_information.php
@@ -14,26 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for getting access information for a h5p activity.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.9
- * @copyright 2020 Carlos Escobedo
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_module;
use mod_h5pactivity\local\manager;
@@ -119,4 +106,4 @@ public static function execute_returns() {
return new external_single_structure($structure);
}
-}
\ No newline at end of file
+}
diff --git a/mod/h5pactivity/classes/external/get_results.php b/mod/h5pactivity/classes/external/get_results.php
index 633631f703935..8e93e3ab75497 100644
--- a/mod/h5pactivity/classes/external/get_results.php
+++ b/mod/h5pactivity/classes/external/get_results.php
@@ -14,36 +14,24 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for getting the information needed to present a results report.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.9
- * @copyright 2020 Ferran Recio
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
use mod_h5pactivity\local\manager;
use mod_h5pactivity\local\report\results as report_results;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_multiple_structure;
-use external_single_structure;
-use external_warnings;
-use moodle_exception;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_module;
use stdClass;
/**
* This is the external method for getting the information needed to present a results report.
*
+ * @package mod_h5pactivity
+ * @since Moodle 3.9
* @copyright 2020 Ferran Recio
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/mod/h5pactivity/classes/external/get_user_attempts.php b/mod/h5pactivity/classes/external/get_user_attempts.php
index 8a27f821bc37f..e10163af3ac8e 100644
--- a/mod/h5pactivity/classes/external/get_user_attempts.php
+++ b/mod/h5pactivity/classes/external/get_user_attempts.php
@@ -14,32 +14,18 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method to return the information needed to list all enrolled user attempts.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.11
- * @copyright 2020 Ilya Tregubov
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
use mod_h5pactivity\local\manager;
use mod_h5pactivity\local\attempt;
use mod_h5pactivity\local\report;
use mod_h5pactivity\local\report\attempts as report_attempts;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_multiple_structure;
-use external_single_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use moodle_exception;
use context_module;
use stdClass;
@@ -47,6 +33,8 @@
/**
* This is the external method to return the information needed to list all enrolled user attempts.
*
+ * @package mod_h5pactivity
+ * @since Moodle 3.11
* @copyright 2020 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
diff --git a/mod/h5pactivity/classes/external/h5pactivity_summary_exporter.php b/mod/h5pactivity/classes/external/h5pactivity_summary_exporter.php
index 493fa1f79dbaa..1714b628dea82 100644
--- a/mod/h5pactivity/classes/external/h5pactivity_summary_exporter.php
+++ b/mod/h5pactivity/classes/external/h5pactivity_summary_exporter.php
@@ -26,9 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_util;
-use external_files;
-use core_h5p\factory;
+use core_external\util as external_util;
+use core_external\external_files;
use core_h5p\api;
/**
diff --git a/mod/h5pactivity/classes/external/log_report_viewed.php b/mod/h5pactivity/classes/external/log_report_viewed.php
index 7e182b5d78031..c6faad1353346 100644
--- a/mod/h5pactivity/classes/external/log_report_viewed.php
+++ b/mod/h5pactivity/classes/external/log_report_viewed.php
@@ -14,38 +14,25 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for logging that the h5pactivity was viewed.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.11
- * @copyright 2021 Ilya Tregubov
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
-
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use mod_h5pactivity\local\manager;
use mod_h5pactivity\event\report_viewed;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_warnings;
-use moodle_exception;
use context_module;
use stdClass;
/**
* This is the external method for logging that the h5pactivity was viewed.
*
+ * @package mod_h5pactivity
* @copyright 2021 Ilya Tregubov
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * @since Moodle 3.11
*/
class log_report_viewed extends external_api {
diff --git a/mod/h5pactivity/classes/external/view_h5pactivity.php b/mod/h5pactivity/classes/external/view_h5pactivity.php
index 3b33183514c19..663de693ef7e3 100644
--- a/mod/h5pactivity/classes/external/view_h5pactivity.php
+++ b/mod/h5pactivity/classes/external/view_h5pactivity.php
@@ -14,26 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external method for triggering the course module viewed event.
- *
- * @package mod_h5pactivity
- * @since Moodle 3.9
- * @copyright 2020 Carlos Escobedo
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace mod_h5pactivity\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
use context_module;
use mod_h5pactivity\local\manager;
diff --git a/mod/h5pactivity/tests/external/get_attempts_test.php b/mod/h5pactivity/tests/external/get_attempts_test.php
index 86b5a108b456e..37529651fadd5 100644
--- a/mod/h5pactivity/tests/external/get_attempts_test.php
+++ b/mod/h5pactivity/tests/external/get_attempts_test.php
@@ -32,7 +32,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use mod_h5pactivity\local\manager;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
/**
diff --git a/mod/h5pactivity/tests/external/get_h5pactivities_by_courses_test.php b/mod/h5pactivity/tests/external/get_h5pactivities_by_courses_test.php
index 3972354e4dfee..e8170526c52d4 100644
--- a/mod/h5pactivity/tests/external/get_h5pactivities_by_courses_test.php
+++ b/mod/h5pactivity/tests/external/get_h5pactivities_by_courses_test.php
@@ -32,9 +32,8 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
-use stdClass;
use context_module;
/**
diff --git a/mod/h5pactivity/tests/external/get_h5pactivity_access_information_test.php b/mod/h5pactivity/tests/external/get_h5pactivity_access_information_test.php
index 6f7be0dd8b385..25760d2920003 100644
--- a/mod/h5pactivity/tests/external/get_h5pactivity_access_information_test.php
+++ b/mod/h5pactivity/tests/external/get_h5pactivity_access_information_test.php
@@ -32,7 +32,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use dml_missing_record_exception;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
/**
diff --git a/mod/h5pactivity/tests/external/get_results_test.php b/mod/h5pactivity/tests/external/get_results_test.php
index 081501e522996..fffa4f3a16df5 100644
--- a/mod/h5pactivity/tests/external/get_results_test.php
+++ b/mod/h5pactivity/tests/external/get_results_test.php
@@ -32,7 +32,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use mod_h5pactivity\local\manager;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use dml_missing_record_exception;
diff --git a/mod/h5pactivity/tests/external/get_user_attempts_test.php b/mod/h5pactivity/tests/external/get_user_attempts_test.php
index faff92273f40a..2f0a344d7cb69 100644
--- a/mod/h5pactivity/tests/external/get_user_attempts_test.php
+++ b/mod/h5pactivity/tests/external/get_user_attempts_test.php
@@ -32,7 +32,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use mod_h5pactivity\local\manager;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
/**
diff --git a/mod/h5pactivity/tests/external/log_report_viewed.php b/mod/h5pactivity/tests/external/log_report_viewed.php
index 2372a229d7c4b..b05ef119b98be 100644
--- a/mod/h5pactivity/tests/external/log_report_viewed.php
+++ b/mod/h5pactivity/tests/external/log_report_viewed.php
@@ -32,7 +32,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
use mod_h5pactivity\local\manager;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
/**
diff --git a/mod/h5pactivity/tests/external/view_h5pactivity_test.php b/mod/h5pactivity/tests/external/view_h5pactivity_test.php
index 487f7538f60b8..d4b54ace1c14c 100644
--- a/mod/h5pactivity/tests/external/view_h5pactivity_test.php
+++ b/mod/h5pactivity/tests/external/view_h5pactivity_test.php
@@ -32,7 +32,7 @@
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use stdClass;
use context_module;
diff --git a/mod/imscp/classes/external.php b/mod/imscp/classes/external.php
index d89120f7e8685..9acd41bbba5c4 100644
--- a/mod/imscp/classes/external.php
+++ b/mod/imscp/classes/external.php
@@ -25,10 +25,13 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* IMSCP external functions
@@ -94,7 +97,7 @@ public static function view_imscp($imscpid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_imscp_returns() {
@@ -147,7 +150,7 @@ public static function get_imscps_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $courses);
// Get the imscps in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
diff --git a/mod/imscp/tests/externallib_test.php b/mod/imscp/tests/externallib_test.php
index 3900a4e68720a..3e74afc8177c1 100644
--- a/mod/imscp/tests/externallib_test.php
+++ b/mod/imscp/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_imscp;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_imscp_external;
@@ -77,7 +78,7 @@ public function test_view_imscp() {
$sink = $this->redirectEvents();
$result = mod_imscp_external::view_imscp($imscp->id);
- $result = \external_api::clean_returnvalue(mod_imscp_external::view_imscp_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_imscp_external::view_imscp_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -137,7 +138,7 @@ public function test_get_imscps_by_courses() {
$this->setUser($student1);
$imscps = mod_imscp_external::get_imscps_by_courses(array());
- $imscps = \external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
+ $imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(1, $imscps['imscps']);
$this->assertEquals('First IMSCP', $imscps['imscps'][0]['name']);
// As Student you cannot see some IMSCP properties like 'section'.
@@ -146,7 +147,7 @@ public function test_get_imscps_by_courses() {
// Student1 is not enrolled in this Course.
// The webservice will give a warning!
$imscps = mod_imscp_external::get_imscps_by_courses(array($course2->id));
- $imscps = \external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
+ $imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(0, $imscps['imscps']);
$this->assertEquals(1, $imscps['warnings'][0]['warningcode']);
@@ -154,7 +155,7 @@ public function test_get_imscps_by_courses() {
$this->setAdminUser();
// As Admin we can see this IMSCP.
$imscps = mod_imscp_external::get_imscps_by_courses(array($course2->id));
- $imscps = \external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
+ $imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(1, $imscps['imscps']);
$this->assertEquals('Second IMSCP', $imscps['imscps'][0]['name']);
// As an Admin you can see some IMSCP properties like 'section'.
@@ -170,7 +171,7 @@ public function test_get_imscps_by_courses() {
\course_modinfo::clear_instance_cache();
$imscps = mod_imscp_external::get_imscps_by_courses(array($course1->id));
- $imscps = \external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
+ $imscps = external_api::clean_returnvalue(mod_imscp_external::get_imscps_by_courses_returns(), $imscps);
$this->assertCount(0, $imscps['imscps']);
}
}
diff --git a/mod/label/classes/external.php b/mod/label/classes/external.php
index 5ed11d6cdf768..ebdf78fb912db 100644
--- a/mod/label/classes/external.php
+++ b/mod/label/classes/external.php
@@ -25,10 +25,13 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Label external functions
@@ -84,7 +87,7 @@ public static function get_labels_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the labels in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
diff --git a/mod/label/tests/externallib_test.php b/mod/label/tests/externallib_test.php
index 0a36608c0767a..768cf0900003d 100644
--- a/mod/label/tests/externallib_test.php
+++ b/mod/label/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_label;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_label_external;
@@ -108,14 +109,14 @@ public function test_mod_label_get_labels_by_courses() {
// Call the external function passing course ids.
$result = mod_label_external::get_labels_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlabels, $result['labels']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_label_external::get_labels_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlabels, $result['labels']);
$this->assertCount(0, $result['warnings']);
@@ -134,7 +135,7 @@ public function test_mod_label_get_labels_by_courses() {
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_label_external::get_labels_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['labels'][0]['introfiles']);
$this->assertEquals($filename, $result['labels'][0]['introfiles'][0]['filename']);
@@ -145,7 +146,7 @@ public function test_mod_label_get_labels_by_courses() {
// Call the external function without passing course id.
$result = mod_label_external::get_labels_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlabels, $result['labels']);
// Call for the second course we unenrolled the user from, expected warning.
diff --git a/mod/lesson/classes/external.php b/mod/lesson/classes/external.php
index 2d1e648717d33..e45baabf670e9 100644
--- a/mod/lesson/classes/external.php
+++ b/mod/lesson/classes/external.php
@@ -26,10 +26,18 @@
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/lesson/locallib.php');
use mod_lesson\external\lesson_summary_exporter;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Lesson external functions
@@ -129,7 +137,7 @@ public static function get_lessons_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the lessons in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -145,7 +153,7 @@ public static function get_lessons_by_courses($courseids = array()) {
$exporter = new lesson_summary_exporter($lessonrecord, array('context' => $context));
$lesson = $exporter->export($PAGE->get_renderer('core'));
- $lesson->name = external_format_string($lesson->name, $context);
+ $lesson->name = \core_external\util::format_string($lesson->name, $context);
$returnedlessons[] = $lesson;
}
}
@@ -225,7 +233,7 @@ protected static function validate_attempt(lesson $lesson, $params, $return = fa
// Password protected lesson code.
if ($passwordrestriction = $lesson->get_password_restriction_status($params['password'])) {
- $error = ["passwordprotectedlesson" => external_format_string($lesson->name, $lesson->context->id)];
+ $error = ["passwordprotectedlesson" => \core_external\util::format_string($lesson->name, $lesson->context)];
if (!$return) {
throw new moodle_exception(key($error), 'lesson', '', current($error));
}
@@ -994,13 +1002,18 @@ protected static function get_page_fields(lesson_page $page, $returncontents = f
$canmanage = $lesson->can_manage();
// If we are managers or the menu block is enabled and is a content page visible always return contents.
if ($returncontents || $canmanage || (lesson_displayleftif($lesson) && $page->displayinmenublock && $page->display)) {
- $pagedata->title = external_format_string($page->title, $context->id);
+ $pagedata->title = \core_external\util::format_string($page->title, $context);
$options = array('noclean' => true);
- list($pagedata->contents, $pagedata->contentsformat) =
- external_format_text($page->contents, $page->contentsformat, $context->id, 'mod_lesson', 'page_contents', $page->id,
- $options);
-
+ [$pagedata->contents, $pagedata->contentsformat] = \core_external\util::format_text(
+ $page->contents,
+ $page->contentsformat,
+ $context,
+ 'mod_lesson',
+ 'page_contents',
+ $page->id,
+ $options
+ );
}
return $pagedata;
}
@@ -1295,7 +1308,7 @@ public static function get_page_data($lessonid, $pageid, $password = '', $revie
$pagedata = self::get_page_fields($page, true);
// Files.
- $contentfiles = external_util::get_area_files($context->id, 'mod_lesson', 'page_contents', $page->id);
+ $contentfiles = util::get_area_files($context->id, 'mod_lesson', 'page_contents', $page->id);
// Answers.
$answers = array();
@@ -1303,8 +1316,8 @@ public static function get_page_data($lessonid, $pageid, $password = '', $revie
foreach ($pageanswers as $a) {
$answer = array(
'id' => $a->id,
- 'answerfiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_answers', $a->id),
- 'responsefiles' => external_util::get_area_files($context->id, 'mod_lesson', 'page_responses', $a->id),
+ 'answerfiles' => util::get_area_files($context->id, 'mod_lesson', 'page_answers', $a->id),
+ 'responsefiles' => util::get_area_files($context->id, 'mod_lesson', 'page_responses', $a->id),
);
// For managers, return all the information (including correct answers, jumps).
// If the teacher enabled offline attempts, this information will be downloaded too.
@@ -1315,12 +1328,24 @@ public static function get_page_data($lessonid, $pageid, $password = '', $revie
}
$options = array('noclean' => true);
- list($answer['answer'], $answer['answerformat']) =
- external_format_text($a->answer, $a->answerformat, $context->id, 'mod_lesson', 'page_answers', $a->id,
- $options);
- list($answer['response'], $answer['responseformat']) =
- external_format_text($a->response, $a->responseformat, $context->id, 'mod_lesson', 'page_responses',
- $a->id, $options);
+ [$answer['answer'], $answer['answerformat']] = \core_external\util::format_text(
+ $a->answer,
+ $a->answerformat,
+ $context,
+ 'mod_lesson',
+ 'page_answers',
+ $a->id,
+ $options
+ );
+ [$answer['response'], $answer['responseformat']] = \core_external\util::format_text(
+ $a->response,
+ $a->responseformat,
+ $context,
+ 'mod_lesson',
+ 'page_responses',
+ $a->id,
+ $options
+ );
}
$answers[] = $answer;
}
diff --git a/mod/lesson/classes/external/lesson_summary_exporter.php b/mod/lesson/classes/external/lesson_summary_exporter.php
index a5b30448ae632..87b41cc214aae 100644
--- a/mod/lesson/classes/external/lesson_summary_exporter.php
+++ b/mod/lesson/classes/external/lesson_summary_exporter.php
@@ -26,8 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_files;
-use external_util;
+use core_external\external_files;
+use core_external\util as external_util;
/**
* Class for exporting partial lesson data (some fields are only viewable by admins).
diff --git a/mod/lesson/tests/backup/restore_date_test.php b/mod/lesson/tests/backup/restore_date_test.php
index 08bf6f6f594a3..a8d50cc983f33 100644
--- a/mod/lesson/tests/backup/restore_date_test.php
+++ b/mod/lesson/tests/backup/restore_date_test.php
@@ -16,6 +16,8 @@
namespace mod_lesson\backup;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -75,7 +77,7 @@ protected function create_attempt($lesson, $page, $correct = true, $finished = f
)
);
$result = \mod_lesson_external::process_page($lesson->id, $page->id, $data);
- $result = \external_api::clean_returnvalue(\mod_lesson_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(\mod_lesson_external::process_page_returns(), $result);
// Create attempt.
$newpageattempt = [
@@ -92,7 +94,7 @@ protected function create_attempt($lesson, $page, $correct = true, $finished = f
if ($finished) {
$result = \mod_lesson_external::finish_attempt($lesson->id);
- $result = \external_api::clean_returnvalue(\mod_lesson_external::finish_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(\mod_lesson_external::finish_attempt_returns(), $result);
}
return $result;
}
diff --git a/mod/lesson/tests/external/external_test.php b/mod/lesson/tests/external/external_test.php
index 74a369650d67a..b933833dc05ce 100644
--- a/mod/lesson/tests/external/external_test.php
+++ b/mod/lesson/tests/external/external_test.php
@@ -29,6 +29,8 @@
use externallib_advanced_testcase;
use mod_lesson_external;
use lesson;
+use core_external\external_api;
+use core_external\external_settings;
defined('MOODLE_INTERNAL') || die();
@@ -105,8 +107,7 @@ public function setUp(): void {
* Test test_mod_lesson_get_lessons_by_courses
*/
public function test_mod_lesson_get_lessons_by_courses() {
- global $DB, $CFG;
- require_once($CFG->libdir . '/externallib.php');
+ global $DB;
// Create additional course.
$course2 = self::getDataGenerator()->create_course();
@@ -135,7 +136,7 @@ public function test_mod_lesson_get_lessons_by_courses() {
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
// Set WS filtering.
- $wssettings = \external_settings::get_instance();
+ $wssettings = external_settings::get_instance();
$wssettings->set_filter(true);
$returndescription = mod_lesson_external::get_lessons_by_courses_returns();
@@ -180,14 +181,14 @@ public function test_mod_lesson_get_lessons_by_courses() {
// Call the external function passing course ids.
$result = mod_lesson_external::get_lessons_by_courses(array($course2->id, $this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlessons, $result['lessons']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_lesson_external::get_lessons_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlessons, $result['lessons']);
$this->assertCount(0, $result['warnings']);
@@ -197,7 +198,7 @@ public function test_mod_lesson_get_lessons_by_courses() {
// Call the external function without passing course id.
$result = mod_lesson_external::get_lessons_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlessons, $result['lessons']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -217,14 +218,14 @@ public function test_mod_lesson_get_lessons_by_courses() {
}
$result = mod_lesson_external::get_lessons_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlessons, $result['lessons']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_lesson_external::get_lessons_by_courses(array($this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlessons, $result['lessons']);
// Now, add a restriction.
@@ -233,7 +234,7 @@ public function test_mod_lesson_get_lessons_by_courses() {
$DB->set_field('lesson', 'password', 'abc', array('id' => $lesson1->id));
$lessons = mod_lesson_external::get_lessons_by_courses(array($this->course->id));
- $lessons = \external_api::clean_returnvalue(mod_lesson_external::get_lessons_by_courses_returns(), $lessons);
+ $lessons = external_api::clean_returnvalue(mod_lesson_external::get_lessons_by_courses_returns(), $lessons);
$this->assertFalse(isset($lessons['lessons'][0]['intro']));
}
@@ -351,7 +352,7 @@ public function test_get_lesson_access_information() {
$DB->insert_record('lesson_grades', (object) $record);
$result = mod_lesson_external::get_lesson_access_information($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_lesson_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_access_information_returns(), $result);
$this->assertFalse($result['canmanage']);
$this->assertFalse($result['cangrade']);
$this->assertFalse($result['canviewreports']);
@@ -369,7 +370,7 @@ public function test_get_lesson_access_information() {
// Now check permissions as admin.
$this->setAdminUser();
$result = mod_lesson_external::get_lesson_access_information($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_lesson_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_access_information_returns(), $result);
$this->assertTrue($result['canmanage']);
$this->assertTrue($result['cangrade']);
$this->assertTrue($result['canviewreports']);
@@ -405,7 +406,7 @@ public function test_view_lesson_user_student() {
$sink = $this->redirectEvents();
$result = mod_lesson_external::view_lesson($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::view_lesson_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::view_lesson_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -448,7 +449,7 @@ public function test_get_questions_attempts() {
// Test lesson without page attempts.
$result = mod_lesson_external::get_questions_attempts($this->lesson->id, $attemptnumber);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['attempts']);
@@ -469,7 +470,7 @@ public function test_get_questions_attempts() {
$DB->insert_record('lesson_attempts', (object) $newpageattempt);
$result = mod_lesson_external::get_questions_attempts($this->lesson->id, $attemptnumber);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['attempts']);
@@ -478,20 +479,20 @@ public function test_get_questions_attempts() {
// Test filtering. Only correct.
$result = mod_lesson_external::get_questions_attempts($this->lesson->id, $attemptnumber, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['attempts']);
// Test filtering. Only correct only for page 2.
$result = mod_lesson_external::get_questions_attempts($this->lesson->id, $attemptnumber, true, $this->page2->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['attempts']);
// Teacher retrieve student page attempts.
$this->setUser($this->teacher);
$result = mod_lesson_external::get_questions_attempts($this->lesson->id, $attemptnumber, false, null, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_questions_attempts_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['attempts']);
@@ -530,7 +531,7 @@ public function test_get_user_grade() {
// Test lesson without multiple attemps. The first result must be returned.
$result = mod_lesson_external::get_user_grade($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(50, $result['grade']);
$this->assertEquals('50.00', $result['formattedgrade']);
@@ -538,7 +539,7 @@ public function test_get_user_grade() {
// With retakes. By default average.
$DB->set_field('lesson', 'retake', 1, array('id' => $this->lesson->id));
$result = mod_lesson_external::get_user_grade($this->lesson->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(75, $result['grade']);
$this->assertEquals('75.00', $result['formattedgrade']);
@@ -546,7 +547,7 @@ public function test_get_user_grade() {
// With retakes. With max grade setting.
$DB->set_field('lesson', 'usemaxgrade', 1, array('id' => $this->lesson->id));
$result = mod_lesson_external::get_user_grade($this->lesson->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(100, $result['grade']);
$this->assertEquals('100.00', $result['formattedgrade']);
@@ -554,7 +555,7 @@ public function test_get_user_grade() {
// Test as teacher we get the same result.
$this->setUser($this->teacher);
$result = mod_lesson_external::get_user_grade($this->lesson->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_grade_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(100, $result['grade']);
$this->assertEquals('100.00', $result['formattedgrade']);
@@ -592,7 +593,7 @@ public function test_get_user_attempt_grade() {
$DB->set_field('lesson', 'custom', 0, array('id' => $this->lesson->id));
$this->setUser($this->student);
$result = mod_lesson_external::get_user_attempt_grade($this->lesson->id, $attemptnumber, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_grade_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $result['grade']['nquestions']);
$this->assertEquals(1, $result['grade']['attempts']);
@@ -605,7 +606,7 @@ public function test_get_user_attempt_grade() {
// With custom scoring, in this case, we don't retrieve any values since we are using questions without particular score.
$DB->set_field('lesson', 'custom', 1, array('id' => $this->lesson->id));
$result = mod_lesson_external::get_user_attempt_grade($this->lesson->id, $attemptnumber, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_grade_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $result['grade']['nquestions']);
$this->assertEquals(1, $result['grade']['attempts']);
@@ -648,7 +649,7 @@ public function test_get_content_pages_viewed() {
// Test first attempt.
$result = mod_lesson_external::get_content_pages_viewed($this->lesson->id, 1, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_content_pages_viewed_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_content_pages_viewed_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['pages']);
foreach ($result['pages'] as $page) {
@@ -661,7 +662,7 @@ public function test_get_content_pages_viewed() {
// Attempt without pages viewed.
$result = mod_lesson_external::get_content_pages_viewed($this->lesson->id, 3, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_content_pages_viewed_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_content_pages_viewed_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['pages']);
}
@@ -693,7 +694,7 @@ public function test_get_user_timers() {
// Test retrieve timers.
$result = mod_lesson_external::get_user_timers($this->lesson->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_timers_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_timers_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['timers']);
foreach ($result['timers'] as $timer) {
@@ -745,7 +746,7 @@ public function test_get_pages() {
}
$result = mod_lesson_external::get_pages($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['pages']);
@@ -765,7 +766,7 @@ public function test_get_pages() {
$this->setUser($this->student);
$DB->set_field('lesson', 'displayleft', 0, array('id' => $this->lesson->id));
$result = mod_lesson_external::get_pages($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['pages']);
@@ -795,7 +796,7 @@ public function test_launch_attempt() {
unset($SESSION->lesson_messages);
$result = mod_lesson_external::launch_attempt($this->lesson->id, '', 1);
- $result = \external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['messages']);
@@ -826,7 +827,7 @@ public function test_launch_attempt_not_finished_in_review_mode() {
unset($SESSION->lesson_messages);
$this->setUser($this->teacher);
$result = mod_lesson_external::launch_attempt($this->lesson->id, '', 1, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
// Everything ok as teacher.
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['messages']);
@@ -879,7 +880,7 @@ public function test_launch_attempt_just_finished_in_review_mode() {
$this->setUser($this->student);
$result = mod_lesson_external::launch_attempt($this->lesson->id, '', $this->page2->id, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
// Everything ok as student.
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['messages']);
@@ -906,7 +907,7 @@ public function test_launch_attempt_not_just_finished_in_review_mode() {
// Everything ok as teacher.
$this->setUser($this->teacher);
$result = mod_lesson_external::launch_attempt($this->lesson->id, '', 1, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::launch_attempt_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['messages']);
@@ -924,7 +925,7 @@ public function test_get_page_data() {
// Test a content page first (page1).
$result = mod_lesson_external::get_page_data($this->lesson->id, $this->page1->id, '', false, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_page_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_page_data_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(0, $result['answers']); // No answers, auto-generated content page.
@@ -944,7 +945,7 @@ public function test_get_page_data() {
// Check now a page with answers (true / false) and with menu available.
$DB->set_field('lesson', 'displayleft', 1, array('id' => $this->lesson->id));
$result = mod_lesson_external::get_page_data($this->lesson->id, $this->page2->id, '', false, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_page_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_page_data_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['answers']); // One for true, one for false.
// Check menu availability.
@@ -966,7 +967,7 @@ public function test_get_page_data_student() {
// First we need to launch the lesson so the timer is on.
mod_lesson_external::launch_attempt($this->lesson->id);
$result = mod_lesson_external::get_page_data($this->lesson->id, $this->page2->id, '', false, true);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_page_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_page_data_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['answers']); // One for true, one for false.
// Check contents.
@@ -1032,11 +1033,11 @@ protected function create_attempt($user, $correct = true, $finished = false) {
)
);
$result = mod_lesson_external::process_page($this->lesson->id, $this->page2->id, $data);
- $result = \external_api::clean_returnvalue(mod_lesson_external::process_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::process_page_returns(), $result);
if ($finished) {
$result = mod_lesson_external::finish_attempt($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::finish_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::finish_attempt_returns(), $result);
}
return $result;
}
@@ -1073,7 +1074,7 @@ public function test_finish_attempt_not_doing_anything() {
mod_lesson_external::launch_attempt($this->lesson->id);
$result = mod_lesson_external::finish_attempt($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::finish_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::finish_attempt_returns(), $result);
$this->assertCount(0, $result['warnings']);
$returneddata = [];
@@ -1133,7 +1134,7 @@ public function test_get_attempts_overview() {
$this->setAdminUser();
$result = mod_lesson_external::get_attempts_overview($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
// One attempt, 0 for grade (incorrect response) in overal statistics.
$this->assertEquals(1, $result['data']['numofattempts']);
@@ -1160,7 +1161,7 @@ public function test_get_attempts_overview() {
$this->setAdminUser();
$result = mod_lesson_external::get_attempts_overview($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
// Two attempts with maximum grade.
$this->assertEquals(2, $result['data']['numofattempts']);
@@ -1189,7 +1190,7 @@ public function test_get_attempts_overview() {
// Now check we have two students and the statistics changed.
$this->setAdminUser();
$result = mod_lesson_external::get_attempts_overview($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
// Total of 3 attempts with maximum grade.
$this->assertEquals(3, $result['data']['numofattempts']);
@@ -1206,7 +1207,7 @@ public function test_get_attempts_overview() {
public function test_get_attempts_overview_no_attempts() {
$this->setAdminUser();
$result = mod_lesson_external::get_attempts_overview($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertArrayNotHasKey('data', $result);
}
@@ -1228,7 +1229,7 @@ public function test_get_user_attempt() {
$this->setAdminUser();
// Test first attempt finished.
$result = mod_lesson_external::get_user_attempt($this->lesson->id, $this->student->id, 0);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
$this->assertCount(2, $result['answerpages']); // 2 pages in the lesson.
$this->assertCount(2, $result['answerpages'][0]['answerdata']['answers']); // 2 possible answers in true/false.
@@ -1246,7 +1247,7 @@ public function test_get_user_attempt() {
// Test second attempt unfinished.
$result = mod_lesson_external::get_user_attempt($this->lesson->id, $this->student->id, 1);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
$this->assertCount(2, $result['answerpages']); // 2 pages in the lesson.
$this->assertCount(2, $result['answerpages'][0]['answerdata']['answers']); // 2 possible answers in true/false.
@@ -1256,7 +1257,7 @@ public function test_get_user_attempt() {
$this->setUser($this->student);
// Test first attempt finished.
$result = mod_lesson_external::get_user_attempt($this->lesson->id, $this->student->id, 0);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_user_attempt_returns(), $result);
$this->assertCount(2, $result['answerpages']); // 2 pages in the lesson.
$this->assertCount(2, $result['answerpages'][0]['answerdata']['answers']); // 2 possible answers in true/false.
@@ -1274,7 +1275,7 @@ public function test_get_user_attempt() {
public function test_get_pages_possible_jumps() {
$this->setAdminUser();
$result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['jumps']); // 3 jumps, 2 from the question page and 1 from the content.
@@ -1297,7 +1298,7 @@ public function test_get_pages_possible_jumps() {
public function test_get_pages_possible_jumps_with_offlineattemps_disabled() {
$this->setUser($this->student->id);
$result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
$this->assertCount(0, $result['jumps']);
}
@@ -1310,7 +1311,7 @@ public function test_get_pages_possible_jumps_with_offlineattemps_enabled() {
$DB->set_field('lesson', 'allowofflineattempts', 1, array('id' => $this->lesson->id));
$this->setUser($this->student->id);
$result = mod_lesson_external::get_pages_possible_jumps($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_pages_possible_jumps_returns(), $result);
$this->assertCount(3, $result['jumps']);
}
@@ -1323,7 +1324,7 @@ public function test_get_lesson_user_student() {
// Lesson not using password.
$result = mod_lesson_external::get_lesson($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
$this->assertCount(37, $result['lesson']); // Expect most of the fields.
$this->assertFalse(isset($result['password']));
}
@@ -1341,7 +1342,7 @@ public function test_get_lesson_user_student_with_missing_password() {
// Lesson not using password.
$result = mod_lesson_external::get_lesson($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
$this->assertCount(7, $result['lesson']); // Expect just this few fields.
$this->assertFalse(isset($result['intro']));
}
@@ -1359,7 +1360,7 @@ public function test_get_lesson_user_student_with_correct_password() {
// Lesson not using password.
$result = mod_lesson_external::get_lesson($this->lesson->id, $password);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
$this->assertCount(37 , $result['lesson']);
$this->assertFalse(isset($result['intro']));
}
@@ -1377,7 +1378,7 @@ public function test_get_lesson_teacher() {
// Lesson not passing a valid password (but we are teachers, we should see all the info).
$result = mod_lesson_external::get_lesson($this->lesson->id);
- $result = \external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lesson_external::get_lesson_returns(), $result);
$this->assertCount(46, $result['lesson']); // Expect all the fields.
$this->assertEquals($result['lesson']['password'], $password);
}
diff --git a/mod/lti/classes/external.php b/mod/lti/classes/external.php
index 422251607649f..53f727a38591b 100644
--- a/mod/lti/classes/external.php
+++ b/mod/lti/classes/external.php
@@ -25,10 +25,16 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/lti/lib.php');
require_once($CFG->dirroot . '/mod/lti/locallib.php');
@@ -157,7 +163,7 @@ public static function get_tool_proxies($orphanedonly) {
/**
* Returns description of method result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_tool_proxies_returns() {
@@ -228,7 +234,7 @@ public static function get_tool_launch_data($toolid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_tool_launch_data_returns() {
@@ -289,7 +295,7 @@ public static function get_ltis_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the ltis in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -431,7 +437,7 @@ public static function view_lti($ltiid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_lti_returns() {
@@ -529,7 +535,7 @@ public static function create_tool_proxy($name, $registrationurl, $capabilityoff
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function create_tool_proxy_returns() {
@@ -579,7 +585,7 @@ public static function delete_tool_proxy($id) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function delete_tool_proxy_returns() {
@@ -626,7 +632,7 @@ public static function get_tool_proxy_registration_request($id) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_tool_proxy_registration_request_returns() {
@@ -691,7 +697,7 @@ public static function get_tool_types($toolproxyid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function get_tool_types_returns() {
@@ -780,7 +786,7 @@ public static function create_tool_type($cartridgeurl, $key, $secret) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function create_tool_type_returns() {
@@ -863,7 +869,7 @@ public static function update_tool_type($id, $name, $description, $state) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function update_tool_type_returns() {
@@ -922,7 +928,7 @@ public static function delete_tool_type($id) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function delete_tool_type_returns() {
@@ -974,7 +980,7 @@ public static function is_cartridge($url) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function is_cartridge_returns() {
diff --git a/mod/lti/classes/external/get_tool_types_and_proxies.php b/mod/lti/classes/external/get_tool_types_and_proxies.php
index 40d2cfd1a8bab..f3c554f54884c 100644
--- a/mod/lti/classes/external/get_tool_types_and_proxies.php
+++ b/mod/lti/classes/external/get_tool_types_and_proxies.php
@@ -16,7 +16,10 @@
namespace mod_lti\external;
-defined('MOODLE_INTERNAL') || die();
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* External function for fetching all tool types and proxies.
@@ -26,26 +29,42 @@
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class get_tool_types_and_proxies extends \external_api {
+class get_tool_types_and_proxies extends external_api {
/**
* Get parameter definition for get_tool_types_and_proxies().
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters(
- [
- 'toolproxyid' => new \external_value(PARAM_INT, 'Tool proxy id',
- VALUE_DEFAULT, 0),
- 'orphanedonly' => new \external_value(PARAM_BOOL, 'Orphaned tool types only',
- VALUE_DEFAULT, 0),
- 'limit' => new \external_value(PARAM_INT, 'How many tool types displayed per page',
- VALUE_DEFAULT, 60, NULL_NOT_ALLOWED),
- 'offset' => new \external_value(PARAM_INT, 'Current offset of tool elements',
- VALUE_DEFAULT, 0, NULL_NOT_ALLOWED),
- ]
- );
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters([
+ 'toolproxyid' => new external_value(
+ PARAM_INT,
+ 'Tool proxy id',
+ VALUE_DEFAULT,
+ 0
+ ),
+ 'orphanedonly' => new external_value(
+ PARAM_BOOL,
+ 'Orphaned tool types only',
+ VALUE_DEFAULT,
+ 0
+ ),
+ 'limit' => new external_value(
+ PARAM_INT,
+ 'How many tool types displayed per page',
+ VALUE_DEFAULT,
+ 60,
+ NULL_NOT_ALLOWED
+ ),
+ 'offset' => new external_value(
+ PARAM_INT,
+ 'Current offset of tool elements',
+ VALUE_DEFAULT,
+ 0,
+ NULL_NOT_ALLOWED
+ ),
+ ]);
}
/**
@@ -58,13 +77,12 @@ public static function execute_parameters(): \external_function_parameters {
* @return array
*/
public static function execute($toolproxyid, $orphanedonly, $limit, $offset): array {
- $params = self::validate_parameters(self::execute_parameters(),
- [
- 'toolproxyid' => $toolproxyid,
- 'orphanedonly' => $orphanedonly,
- 'limit' => $limit,
- 'offset' => $offset,
- ]);
+ $params = self::validate_parameters(self::execute_parameters(), [
+ 'toolproxyid' => $toolproxyid,
+ 'orphanedonly' => $orphanedonly,
+ 'limit' => $limit,
+ 'offset' => $offset,
+ ]);
$toolproxyid = $params['toolproxyid'] !== null ? $params['toolproxyid'] : 0;
$orphanedonly = $params['orphanedonly'] !== null ? $params['orphanedonly'] : false;
$limit = $params['limit'] !== null ? $params['limit'] : 0;
@@ -74,7 +92,7 @@ public static function execute($toolproxyid, $orphanedonly, $limit, $offset): ar
self::validate_context($context);
require_capability('moodle/site:config', $context);
- list($proxies, $types) = lti_get_lti_types_and_proxies($limit, $offset, $orphanedonly, $toolproxyid);
+ [$proxies, $types] = lti_get_lti_types_and_proxies($limit, $offset, $orphanedonly, $toolproxyid);
return [
'types' => $types,
@@ -87,14 +105,14 @@ public static function execute($toolproxyid, $orphanedonly, $limit, $offset): ar
/**
* Get return definition for get_tool_types_and_proxies.
*
- * @return \external_single_structure
+ * @return external_single_structure
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure([
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure([
'types' => \mod_lti_external::get_tool_types_returns(),
'proxies' => \mod_lti_external::get_tool_proxies_returns(),
- 'limit' => new \external_value(PARAM_INT, 'Limit of how many tool types to show', VALUE_OPTIONAL),
- 'offset' => new \external_value(PARAM_INT, 'Offset of tool types', VALUE_OPTIONAL),
+ 'limit' => new external_value(PARAM_INT, 'Limit of how many tool types to show', VALUE_OPTIONAL),
+ 'offset' => new external_value(PARAM_INT, 'Offset of tool types', VALUE_OPTIONAL),
]);
}
}
diff --git a/mod/lti/classes/external/get_tool_types_and_proxies_count.php b/mod/lti/classes/external/get_tool_types_and_proxies_count.php
index d11031d574bbf..50883c9be5709 100644
--- a/mod/lti/classes/external/get_tool_types_and_proxies_count.php
+++ b/mod/lti/classes/external/get_tool_types_and_proxies_count.php
@@ -16,6 +16,11 @@
namespace mod_lti\external;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -30,18 +35,18 @@
* @copyright 2021 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class get_tool_types_and_proxies_count extends \external_api {
+class get_tool_types_and_proxies_count extends external_api {
/**
* Get parameter definition for get_tool_types_and_proxies_count().
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters(
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters(
[
- 'toolproxyid' => new \external_value(PARAM_INT, 'Tool proxy id', VALUE_DEFAULT, 0),
- 'orphanedonly' => new \external_value(PARAM_BOOL, 'Orphaned tool types only', VALUE_DEFAULT, 0),
+ 'toolproxyid' => new external_value(PARAM_INT, 'Tool proxy id', VALUE_DEFAULT, 0),
+ 'orphanedonly' => new external_value(PARAM_BOOL, 'Orphaned tool types only', VALUE_DEFAULT, 0),
]
);
}
@@ -74,11 +79,11 @@ public static function execute($toolproxyid, $orphanedonly): array {
/**
* Get return definition for get_tool_types_and_proxies_count.
*
- * @return \external_single_structure
+ * @return external_single_structure
*/
- public static function execute_returns(): \external_single_structure {
- return new \external_single_structure([
- 'count' => new \external_value(PARAM_INT, 'Total number of tool types and proxies', VALUE_REQUIRED),
+ public static function execute_returns(): external_single_structure {
+ return new external_single_structure([
+ 'count' => new external_value(PARAM_INT, 'Total number of tool types and proxies', VALUE_REQUIRED),
]);
}
}
diff --git a/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php b/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php
index 41b308bb753ee..b6c408ffa24a5 100644
--- a/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php
+++ b/mod/lti/tests/external/get_tool_types_and_proxies_count_test.php
@@ -16,6 +16,8 @@
namespace mod_lti\external;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -50,7 +52,7 @@ public function test_mod_lti_get_tool_types_and_proxies_count() {
}
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
- $data = \external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
+ $data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(20, $data['count']);
}
@@ -60,7 +62,7 @@ public function test_mod_lti_get_tool_types_and_proxies_count() {
*/
public function test_mod_lti_get_tool_types_and_proxies_count_with_no_tools_configured() {
$data = \mod_lti\external\get_tool_types_and_proxies_count::execute(0, false);
- $data = \external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
+ $data = external_api::clean_returnvalue(\mod_lti\external\get_tool_types_and_proxies_count::execute_returns(), $data);
$this->assertEquals(0, $data['count']);
}
diff --git a/mod/lti/tests/external/get_tool_types_and_proxies_test.php b/mod/lti/tests/external/get_tool_types_and_proxies_test.php
index f38068fe82ac1..a482db767e8a6 100644
--- a/mod/lti/tests/external/get_tool_types_and_proxies_test.php
+++ b/mod/lti/tests/external/get_tool_types_and_proxies_test.php
@@ -16,6 +16,8 @@
namespace mod_lti\external;
+use core_external\external_api;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
@@ -48,7 +50,7 @@ public function test_mod_lti_get_tool_types_and_proxies() {
$this->generate_tool_type(1, $proxy->id);
$data = get_tool_types_and_proxies::execute(0, false, 50, 0);
- $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(1, $data['types']);
$type = $data['types'][0];
@@ -71,7 +73,7 @@ public function test_mod_lti_get_tool_types_and_proxies_with_multiple_pages() {
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 0);
- $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(3, $data['proxies']);
@@ -89,7 +91,7 @@ public function test_mod_lti_get_tool_types_and_proxies_with_multiple_pages_last
}
$data = get_tool_types_and_proxies::execute(0, false, 5, 10);
- $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(2, $data['types']);
$this->assertCount(0, $data['proxies']);
@@ -107,7 +109,7 @@ public function test_mod_lti_get_tool_types_and_proxies_without_pagination() {
}
$data = get_tool_types_and_proxies::execute(0, false, 0, 0);
- $data = \external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
+ $data = external_api::clean_returnvalue(get_tool_types_and_proxies::execute_returns(), $data);
$this->assertCount(10, $data['types']);
$this->assertCount(10, $data['proxies']);
diff --git a/mod/lti/tests/externallib_test.php b/mod/lti/tests/externallib_test.php
index 62fa2f692d749..4cee9bb25a201 100644
--- a/mod/lti/tests/externallib_test.php
+++ b/mod/lti/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_lti;
+use core_external\external_api;
use mod_lti_external;
use mod_lti_testcase;
@@ -96,7 +97,7 @@ public function test_mod_lti_get_tool_proxies() {
// Fetch all proxies.
$proxies = mod_lti_external::get_tool_proxies(false);
- $proxies = \external_api::clean_returnvalue(mod_lti_external::get_tool_proxies_returns(), $proxies);
+ $proxies = external_api::clean_returnvalue(mod_lti_external::get_tool_proxies_returns(), $proxies);
$this->assertCount(2, $proxies);
$this->assertEqualsCanonicalizing([(array) $proxy, (array) $orphanedproxy], $proxies);
@@ -114,7 +115,7 @@ public function test_mod_lti_get_orphaned_tool_proxies() {
// Fetch all proxies.
$proxies = mod_lti_external::get_tool_proxies(true);
- $proxies = \external_api::clean_returnvalue(mod_lti_external::get_tool_proxies_returns(), $proxies);
+ $proxies = external_api::clean_returnvalue(mod_lti_external::get_tool_proxies_returns(), $proxies);
$this->assertCount(1, $proxies);
$this->assertEqualsCanonicalizing([(array) $orphanedproxy], $proxies);
@@ -132,7 +133,7 @@ public function test_get_tool_launch_data() {
] = $this->setup_test_data();
$result = mod_lti_external::get_tool_launch_data($lti->id);
- $result = \external_api::clean_returnvalue(mod_lti_external::get_tool_launch_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lti_external::get_tool_launch_data_returns(), $result);
// Basic test, the function returns what it's expected.
self::assertEquals($lti->toolurl, $result['endpoint']);
@@ -226,14 +227,14 @@ public function test_mod_lti_get_ltis_by_courses() {
// Call the external function passing course ids.
$result = mod_lti_external::get_ltis_by_courses(array($course2->id, $course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedltis, $result['ltis']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_lti_external::get_ltis_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedltis, $result['ltis']);
$this->assertCount(0, $result['warnings']);
@@ -243,12 +244,12 @@ public function test_mod_lti_get_ltis_by_courses() {
// Call the external function without passing course id.
$result = mod_lti_external::get_ltis_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedltis, $result['ltis']);
// Call for the second course we unenrolled the user from, expected warning.
$result = mod_lti_external::get_ltis_by_courses(array($course2->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('1', $result['warnings'][0]['warningcode']);
$this->assertEquals($course2->id, $result['warnings'][0]['itemid']);
@@ -266,14 +267,14 @@ public function test_mod_lti_get_ltis_by_courses() {
}
$result = mod_lti_external::get_ltis_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedltis, $result['ltis']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_lti_external::get_ltis_by_courses(array($course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedltis, $result['ltis']);
// Now, prohibit capabilities.
@@ -286,7 +287,7 @@ public function test_mod_lti_get_ltis_by_courses() {
\course_modinfo::clear_instance_cache();
$ltis = mod_lti_external::get_ltis_by_courses(array($course->id));
- $ltis = \external_api::clean_returnvalue(mod_lti_external::get_ltis_by_courses_returns(), $ltis);
+ $ltis = external_api::clean_returnvalue(mod_lti_external::get_ltis_by_courses_returns(), $ltis);
$this->assertCount(0, $ltis['ltis']);
}
@@ -356,7 +357,7 @@ public function test_view_lti() {
$result = mod_lti_external::view_lti($lti->id);
// The value of the result isn't needed but validation is.
- \external_api::clean_returnvalue(mod_lti_external::view_lti_returns(), $result);
+ external_api::clean_returnvalue(mod_lti_external::view_lti_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -378,7 +379,7 @@ public function test_mod_lti_create_tool_proxy() {
$this->setAdminUser();
$capabilities = ['AA', 'BB'];
$proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), $capabilities, []);
- $proxy = (object) \external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
+ $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
$this->assertEquals('Test proxy', $proxy->name);
$this->assertEquals($this->getExternalTestFileUrl('/test.html'), $proxy->regurl);
@@ -414,11 +415,11 @@ public function test_mod_lti_create_tool_proxy_without_capability() {
public function test_mod_lti_delete_tool_proxy() {
$this->setAdminUser();
$proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
- $proxy = (object) \external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
+ $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
$this->assertNotEmpty(lti_get_tool_proxy($proxy->id));
$proxy = mod_lti_external::delete_tool_proxy($proxy->id);
- $proxy = (object) \external_api::clean_returnvalue(mod_lti_external::delete_tool_proxy_returns(), $proxy);
+ $proxy = (object) external_api::clean_returnvalue(mod_lti_external::delete_tool_proxy_returns(), $proxy);
$this->assertEquals('Test proxy', $proxy->name);
$this->assertEquals($this->getExternalTestFileUrl('/test.html'), $proxy->regurl);
@@ -432,10 +433,10 @@ public function test_mod_lti_delete_tool_proxy() {
public function test_mod_lti_get_tool_proxy_registration_request() {
$this->setAdminUser();
$proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
- $proxy = (object) \external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
+ $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
$request = mod_lti_external::get_tool_proxy_registration_request($proxy->id);
- $request = \external_api::clean_returnvalue(mod_lti_external::get_tool_proxy_registration_request_returns(),
+ $request = external_api::clean_returnvalue(mod_lti_external::get_tool_proxy_registration_request_returns(),
$request);
$this->assertEquals('ToolProxyRegistrationRequest', $request['lti_message_type']);
@@ -448,7 +449,7 @@ public function test_mod_lti_get_tool_proxy_registration_request() {
public function test_mod_lti_get_tool_types() {
$this->setAdminUser();
$proxy = mod_lti_external::create_tool_proxy('Test proxy', $this->getExternalTestFileUrl('/test.html'), array(), array());
- $proxy = (object) \external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
+ $proxy = (object) external_api::clean_returnvalue(mod_lti_external::create_tool_proxy_returns(), $proxy);
// Create a tool type, associated with that proxy.
$type = new \stdClass();
@@ -461,7 +462,7 @@ public function test_mod_lti_get_tool_types() {
lti_add_type($type, $data);
$types = mod_lti_external::get_tool_types($proxy->id);
- $types = \external_api::clean_returnvalue(mod_lti_external::get_tool_types_returns(), $types);
+ $types = external_api::clean_returnvalue(mod_lti_external::get_tool_types_returns(), $types);
$this->assertCount(1, $types);
$type = $types[0];
@@ -475,7 +476,7 @@ public function test_mod_lti_get_tool_types() {
public function test_mod_lti_create_tool_type() {
$this->setAdminUser();
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
- $type = \external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
+ $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
$this->assertEquals('Example tool', $type['name']);
$this->assertEquals('Example tool description', $type['description']);
@@ -522,10 +523,10 @@ public function test_mod_lti_create_tool_type_without_capability() {
public function test_mod_lti_update_tool_type() {
$this->setAdminUser();
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
- $type = \external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
+ $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
$type = mod_lti_external::update_tool_type($type['id'], 'New name', 'New description', LTI_TOOL_STATE_PENDING);
- $type = \external_api::clean_returnvalue(mod_lti_external::update_tool_type_returns(), $type);
+ $type = external_api::clean_returnvalue(mod_lti_external::update_tool_type_returns(), $type);
$this->assertEquals('New name', $type['name']);
$this->assertEquals('New description', $type['description']);
@@ -538,11 +539,11 @@ public function test_mod_lti_update_tool_type() {
public function test_mod_lti_delete_tool_type() {
$this->setAdminUser();
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
- $type = \external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
+ $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
$this->assertNotEmpty(lti_get_type($type['id']));
$type = mod_lti_external::delete_tool_type($type['id']);
- $type = \external_api::clean_returnvalue(mod_lti_external::delete_tool_type_returns(), $type);
+ $type = external_api::clean_returnvalue(mod_lti_external::delete_tool_type_returns(), $type);
$this->assertEmpty(lti_get_type($type['id']));
}
@@ -552,7 +553,7 @@ public function test_mod_lti_delete_tool_type() {
public function test_mod_lti_delete_tool_type_without_capability() {
$this->setAdminUser();
$type = mod_lti_external::create_tool_type($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'), '', '');
- $type = \external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
+ $type = external_api::clean_returnvalue(mod_lti_external::create_tool_type_returns(), $type);
$this->assertNotEmpty(lti_get_type($type['id']));
$course = $this->getDataGenerator()->create_course();
@@ -568,11 +569,11 @@ public function test_mod_lti_delete_tool_type_without_capability() {
public function test_mod_lti_is_cartridge() {
$this->setAdminUser();
$result = mod_lti_external::is_cartridge($this->getExternalTestFileUrl('/ims_cartridge_basic_lti_link.xml'));
- $result = \external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
$this->assertTrue($result['iscartridge']);
$result = mod_lti_external::is_cartridge($this->getExternalTestFileUrl('/test.html'));
- $result = \external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_lti_external::is_cartridge_returns(), $result);
$this->assertFalse($result['iscartridge']);
}
}
diff --git a/mod/page/classes/external.php b/mod/page/classes/external.php
index 01566bb0418fc..b406946529409 100644
--- a/mod/page/classes/external.php
+++ b/mod/page/classes/external.php
@@ -25,10 +25,15 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Page external functions
@@ -94,7 +99,7 @@ public static function view_page($pageid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_page_returns() {
@@ -149,7 +154,7 @@ public static function get_pages_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the pages in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -158,10 +163,10 @@ public static function get_pages_by_courses($courseids = array()) {
helper_for_get_mods_by_courses::format_name_and_intro($page, 'mod_page');
$context = context_module::instance($page->coursemodule);
- list($page->content, $page->contentformat) = external_format_text(
+ list($page->content, $page->contentformat) = \core_external\util::format_text(
$page->content, $page->contentformat,
- $context->id, 'mod_page', 'content', $page->revision, ['noclean' => true]);
- $page->contentfiles = external_util::get_area_files($context->id, 'mod_page', 'content');
+ $context, 'mod_page', 'content', $page->revision, ['noclean' => true]);
+ $page->contentfiles = util::get_area_files($context->id, 'mod_page', 'content');
$returnedpages[] = $page;
}
diff --git a/mod/page/tests/externallib_test.php b/mod/page/tests/externallib_test.php
index 92fdad8246837..666b1b0206e19 100644
--- a/mod/page/tests/externallib_test.php
+++ b/mod/page/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_page;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_page_external;
@@ -76,7 +77,7 @@ public function test_view_page() {
$sink = $this->redirectEvents();
$result = mod_page_external::view_page($page->id);
- $result = \external_api::clean_returnvalue(mod_page_external::view_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_page_external::view_page_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -183,14 +184,14 @@ public function test_mod_page_get_pages_by_courses() {
// Call the external function passing course ids.
$result = mod_page_external::get_pages_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedpages, $result['pages']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_page_external::get_pages_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedpages, $result['pages']);
$this->assertCount(0, $result['warnings']);
@@ -209,7 +210,7 @@ public function test_mod_page_get_pages_by_courses() {
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_page_external::get_pages_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['pages'][0]['introfiles']);
$this->assertEquals($filename, $result['pages'][0]['introfiles'][0]['filename']);
@@ -220,7 +221,7 @@ public function test_mod_page_get_pages_by_courses() {
// Call the external function without passing course id.
$result = mod_page_external::get_pages_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedpages, $result['pages']);
// Call for the second course we unenrolled the user from, expected warning.
diff --git a/mod/quiz/accessrule/seb/classes/external/validate_quiz_keys.php b/mod/quiz/accessrule/seb/classes/external/validate_quiz_keys.php
index def7a16b3f428..6ee0fa352752d 100644
--- a/mod/quiz/accessrule/seb/classes/external/validate_quiz_keys.php
+++ b/mod/quiz/accessrule/seb/classes/external/validate_quiz_keys.php
@@ -20,17 +20,15 @@
global $CFG;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use invalid_parameter_exception;
use mod_quiz\quiz_settings;
use quizaccess_seb\event\access_prevented;
use quizaccess_seb\seb_access_manager;
-require_once($CFG->libdir . '/externallib.php');
-
/**
* Validate browser exam key and config key.
*
@@ -150,4 +148,3 @@ private static function get_quiz_id(string $cmid): int {
return $quizid;
}
}
-
diff --git a/mod/quiz/accessrule/seb/tests/external/validate_quiz_access_test.php b/mod/quiz/accessrule/seb/tests/external/validate_quiz_access_test.php
index b9c5b3b9a14f2..cf0982064dbd1 100644
--- a/mod/quiz/accessrule/seb/tests/external/validate_quiz_access_test.php
+++ b/mod/quiz/accessrule/seb/tests/external/validate_quiz_access_test.php
@@ -16,13 +16,11 @@
namespace quizaccess_seb\external;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-
use quizaccess_seb\seb_quiz_settings;
-require_once($CFG->libdir . '/externallib.php');
+defined('MOODLE_INTERNAL') || die();
+
+require_once(__DIR__ . '/../test_helper_trait.php');
/**
* PHPUnit tests for external function.
@@ -115,7 +113,7 @@ public function test_invalid_parameters($cmid, $url, $configkey, $messageregex)
$this->expectException(\invalid_parameter_exception::class);
$this->expectExceptionMessageMatches($messageregex);
- \external_api::validate_parameters(validate_quiz_keys::execute_parameters(), $params);
+ \core_external\external_api::validate_parameters(validate_quiz_keys::execute_parameters(), $params);
}
/**
diff --git a/mod/quiz/classes/external.php b/mod/quiz/classes/external.php
index 26bf39486fcdb..73e4f49b0d366 100644
--- a/mod/quiz/classes/external.php
+++ b/mod/quiz/classes/external.php
@@ -25,13 +25,21 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
use mod_quiz\access_manager;
use mod_quiz\quiz_attempt;
use mod_quiz\quiz_settings;
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
/**
@@ -89,7 +97,7 @@ public static function get_quizzes_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the quizzes in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -105,7 +113,7 @@ public static function get_quizzes_by_courses($courseids = array()) {
$quiz, 'mod_quiz', 'mod/quiz:view', 'mod/quiz:view');
if (has_capability('mod/quiz:view', $context)) {
- $quizdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_quiz', 'intro', false, false);
+ $quizdetails['introfiles'] = util::get_area_files($context->id, 'mod_quiz', 'intro', false, false);
$viewablefields = array('timeopen', 'timeclose', 'attempts', 'timelimit', 'grademethod', 'decimalpoints',
'questiondecimalpoints', 'sumgrades', 'grade', 'preferredbehaviour');
@@ -1726,11 +1734,17 @@ public static function get_quiz_feedback_for_grade($quizid, $grade) {
$feedback = quiz_feedback_record_for_grade($params['grade'], $quiz);
if (!empty($feedback->feedbacktext)) {
- list($text, $format) = external_format_text($feedback->feedbacktext, $feedback->feedbacktextformat, $context->id,
- 'mod_quiz', 'feedback', $feedback->id);
+ list($text, $format) = \core_external\util::format_text(
+ $feedback->feedbacktext,
+ $feedback->feedbacktextformat,
+ $context,
+ 'mod_quiz',
+ 'feedback',
+ $feedback->id
+ );
$result['feedbacktext'] = $text;
$result['feedbacktextformat'] = $format;
- $feedbackinlinefiles = external_util::get_area_files($context->id, 'mod_quiz', 'feedback', $feedback->id);
+ $feedbackinlinefiles = util::get_area_files($context->id, 'mod_quiz', 'feedback', $feedback->id);
if (!empty($feedbackinlinefiles)) {
$result['feedbackinlinefiles'] = $feedbackinlinefiles;
}
diff --git a/mod/quiz/classes/external/submit_question_version.php b/mod/quiz/classes/external/submit_question_version.php
index dea250868f8c7..788e10f757356 100644
--- a/mod/quiz/classes/external/submit_question_version.php
+++ b/mod/quiz/classes/external/submit_question_version.php
@@ -18,16 +18,14 @@
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/question/engine/lib.php');
require_once($CFG->dirroot . '/question/engine/datalib.php');
require_once($CFG->libdir . '/questionlib.php');
-use external_api;
-use external_description;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use stdClass;
/**
@@ -43,15 +41,13 @@ class submit_question_version extends external_api {
/**
* Parameters for the submit_question_version.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function execute_parameters(): external_function_parameters {
- return new external_function_parameters (
- [
- 'slotid' => new external_value(PARAM_INT, ''),
- 'newversion' => new external_value(PARAM_INT, '')
- ]
- );
+ return new external_function_parameters([
+ 'slotid' => new external_value(PARAM_INT, ''),
+ 'newversion' => new external_value(PARAM_INT, '')
+ ]);
}
/**
@@ -94,13 +90,12 @@ public static function execute(int $slotid, int $newversion): array {
/**
* Define the webservice response.
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function execute_returns() {
- return new external_single_structure(
- [
- 'result' => new external_value(PARAM_BOOL, '')
- ]
- );
+ return new external_single_structure([
+ 'result' => new external_value(PARAM_BOOL, '')
+
+ ]);
}
}
diff --git a/mod/quiz/tests/external/external_test.php b/mod/quiz/tests/external/external_test.php
index 5b6de7293b959..381894dbd6f2d 100644
--- a/mod/quiz/tests/external/external_test.php
+++ b/mod/quiz/tests/external/external_test.php
@@ -26,12 +26,13 @@
namespace mod_quiz\external;
+use core_external\external_api;
use externallib_advanced_testcase;
+use mod_quiz\question\display_options;
use mod_quiz\quiz_attempt;
+use mod_quiz\quiz_settings;
use mod_quiz_external;
-use mod_quiz\question\display_options;
use moodle_exception;
-use mod_quiz\quiz_settings;
defined('MOODLE_INTERNAL') || die();
@@ -264,14 +265,14 @@ public function test_mod_quiz_get_quizzes_by_courses() {
// Call the external function passing course ids.
$result = mod_quiz_external::get_quizzes_by_courses(array($course2->id, $this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedquizzes, $result['quizzes']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_quiz_external::get_quizzes_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedquizzes, $result['quizzes']);
$this->assertCount(0, $result['warnings']);
@@ -281,7 +282,7 @@ public function test_mod_quiz_get_quizzes_by_courses() {
// Call the external function without passing course id.
$result = mod_quiz_external::get_quizzes_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedquizzes, $result['quizzes']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -298,14 +299,14 @@ public function test_mod_quiz_get_quizzes_by_courses() {
}
$result = mod_quiz_external::get_quizzes_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedquizzes, $result['quizzes']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_quiz_external::get_quizzes_by_courses(array($this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedquizzes, $result['quizzes']);
// Now, prevent access.
@@ -317,7 +318,7 @@ public function test_mod_quiz_get_quizzes_by_courses() {
$DB->update_record('quiz', $quiz2);
$result = mod_quiz_external::get_quizzes_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(2, $result['quizzes']);
// We only see a limited set of fields.
$this->assertCount(5, $result['quizzes'][0]);
@@ -362,7 +363,7 @@ public function test_view_quiz() {
$sink = $this->redirectEvents();
$result = mod_quiz_external::view_quiz($this->quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::view_quiz_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::view_quiz_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -403,7 +404,7 @@ public function test_get_user_attempts() {
$this->setUser($this->student);
$result = mod_quiz_external::get_user_attempts($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
$this->assertEquals($attempt->id, $result['attempts'][0]['id']);
@@ -415,21 +416,21 @@ public function test_get_user_attempts() {
// Test filters. Only finished.
$result = mod_quiz_external::get_user_attempts($quiz->id, 0, 'finished', false);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
$this->assertEquals($attempt->id, $result['attempts'][0]['id']);
// Test filters. All attempts.
$result = mod_quiz_external::get_user_attempts($quiz->id, 0, 'all', false);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
$this->assertEquals($attempt->id, $result['attempts'][0]['id']);
// Test filters. Unfinished.
$result = mod_quiz_external::get_user_attempts($quiz->id, 0, 'unfinished', false);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(0, $result['attempts']);
@@ -444,26 +445,26 @@ public function test_get_user_attempts() {
// Test filters. All attempts.
$result = mod_quiz_external::get_user_attempts($quiz->id, 0, 'all', false);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(2, $result['attempts']);
// Test filters. Unfinished.
$result = mod_quiz_external::get_user_attempts($quiz->id, 0, 'unfinished', false);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
// Test manager can see user attempts.
$this->setUser($this->teacher);
$result = mod_quiz_external::get_user_attempts($quiz->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
$this->assertEquals($this->student->id, $result['attempts'][0]['userid']);
$result = mod_quiz_external::get_user_attempts($quiz->id, $this->student->id, 'all');
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(2, $result['attempts']);
$this->assertEquals($this->student->id, $result['attempts'][0]['userid']);
@@ -489,7 +490,7 @@ public function test_get_user_attempts_with_marks_hidden() {
// Student cannot see the grades.
$this->setUser($this->student);
$result = mod_quiz_external::get_user_attempts($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
$this->assertEquals($attempt->id, $result['attempts'][0]['id']);
@@ -502,7 +503,7 @@ public function test_get_user_attempts_with_marks_hidden() {
// Test manager can see user grades.
$this->setUser($this->teacher);
$result = mod_quiz_external::get_user_attempts($quiz->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_attempts_returns(), $result);
$this->assertCount(1, $result['attempts']);
$this->assertEquals($attempt->id, $result['attempts'][0]['id']);
@@ -580,7 +581,7 @@ public function test_get_user_best_grade() {
$this->setUser($this->student);
$result = mod_quiz_external::get_user_best_grade($quizapi1->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
// No grades yet.
$this->assertFalse($result['hasgrade']);
@@ -600,7 +601,7 @@ public function test_get_user_best_grade() {
$attemptobj->process_finish($timenow, false);
$result = mod_quiz_external::get_user_best_grade($quizapi1->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
// Now I have grades.
$this->assertTrue($result['hasgrade']);
@@ -622,7 +623,7 @@ public function test_get_user_best_grade() {
$this->setUser($this->teacher);
$result = mod_quiz_external::get_user_best_grade($quizapi1->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
$this->assertTrue($result['hasgrade']);
$this->assertEquals(100.0, $result['grade']);
@@ -642,7 +643,7 @@ public function test_get_user_best_grade() {
$this->setUser($this->student);
$result = mod_quiz_external::get_user_best_grade($quizapi2->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
// No grades yet.
$this->assertFalse($result['hasgrade']);
@@ -662,7 +663,7 @@ public function test_get_user_best_grade() {
$attemptobj->process_finish($timenow, false);
$result = mod_quiz_external::get_user_best_grade($quizapi2->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
// Now I have grades but I will not be allowed to see it.
$this->assertFalse($result['hasgrade']);
@@ -672,7 +673,7 @@ public function test_get_user_best_grade() {
$this->setUser($this->teacher);
$result = mod_quiz_external::get_user_best_grade($quizapi2->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_user_best_grade_returns(), $result);
$this->assertTrue($result['hasgrade']);
$this->assertEquals(100.0, $result['grade']);
@@ -720,7 +721,7 @@ public function test_get_combined_review_options() {
$this->setUser($this->student);
$result = mod_quiz_external::get_combined_review_options($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
// Expected values.
$expected = array(
@@ -767,7 +768,7 @@ public function test_get_combined_review_options() {
// We should see now the overall feedback.
$result = mod_quiz_external::get_combined_review_options($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
$this->assertEquals($expected, $result);
// Start a new attempt, but not finish it.
@@ -797,14 +798,14 @@ public function test_get_combined_review_options() {
);
$result = mod_quiz_external::get_combined_review_options($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
$this->assertEquals($expected, $result);
// Teacher, for see student options.
$this->setUser($this->teacher);
$result = mod_quiz_external::get_combined_review_options($quiz->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_combined_review_options_returns(), $result);
$this->assertEquals($expected, $result);
@@ -833,7 +834,7 @@ public function test_start_attempt() {
$quiz->timeclose = time() - DAYSECS;
$DB->update_record('quiz', $quiz);
$result = mod_quiz_external::start_attempt($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
$this->assertEquals([], $result['attempt']);
$this->assertCount(1, $result['warnings']);
@@ -853,7 +854,7 @@ public function test_start_attempt() {
// Now, try everything correct.
$result = mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc')));
- $result = \external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
$this->assertEquals(1, $result['attempt']['attempt']);
$this->assertEquals($this->student->id, $result['attempt']['userid']);
@@ -885,7 +886,7 @@ public function test_start_attempt() {
// We should be able to start a new attempt.
$result = mod_quiz_external::start_attempt($quiz->id, array(array("name" => "quizpassword", "value" => 'abc')));
- $result = \external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::start_attempt_returns(), $result);
$this->assertEquals(2, $result['attempt']['attempt']);
$this->assertEquals($this->student->id, $result['attempt']['userid']);
@@ -1039,7 +1040,7 @@ public function test_get_attempt_data() {
// We receive one question per page.
$result = mod_quiz_external::get_attempt_data($attempt->id, 0);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
$this->assertEquals($attempt, (object) $result['attempt']);
$this->assertEquals(1, $result['nextpage']);
@@ -1060,7 +1061,7 @@ public function test_get_attempt_data() {
// Now try the last page.
$result = mod_quiz_external::get_attempt_data($attempt->id, 1);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
$this->assertEquals($attempt, (object) $result['attempt']);
$this->assertEquals(-1, $result['nextpage']);
@@ -1082,7 +1083,7 @@ public function test_get_attempt_data() {
// Now we should receive the question state.
$result = mod_quiz_external::get_attempt_review($attempt->id, 1);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_review_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_review_returns(), $result);
$this->assertEquals('gaveup', $result['questions'][0]['state']);
// Change setting and expect two pages.
@@ -1101,7 +1102,7 @@ public function test_get_attempt_data() {
// We receive two questions per page.
$result = mod_quiz_external::get_attempt_data($attempt->id, 0);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
$this->assertCount(2, $result['questions']);
$this->assertEquals(-1, $result['nextpage']);
@@ -1145,7 +1146,7 @@ public function test_get_attempt_data_with_blocked_questions() {
// We receive one question per page.
$result = mod_quiz_external::get_attempt_data($attempt->id, 0);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
$this->assertEquals($attempt, (object) $result['attempt']);
$this->assertCount(1, $result['questions']);
@@ -1155,7 +1156,7 @@ public function test_get_attempt_data_with_blocked_questions() {
// Now try the last page.
$result = mod_quiz_external::get_attempt_data($attempt->id, 1);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_data_returns(), $result);
$this->assertEquals($attempt, (object) $result['attempt']);
$this->assertCount(1, $result['questions']);
@@ -1175,7 +1176,7 @@ public function test_get_attempt_summary() {
$this->setUser($this->student);
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
// Check the state, flagged and mark data is correct.
$this->assertEquals('todo', $result['questions'][0]['state']);
@@ -1202,7 +1203,7 @@ public function test_get_attempt_summary() {
$tosubmit = array(1 => array('answer' => '3.14'));
$attemptobj->process_submitted_actions(time(), false, $tosubmit);
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
// Check it's marked as completed only the first one.
$this->assertEquals('complete', $result['questions'][0]['state']);
@@ -1243,12 +1244,12 @@ public function test_save_attempt() {
$this->setUser($this->student);
$result = mod_quiz_external::save_attempt($attempt->id, $data);
- $result = \external_api::clean_returnvalue(mod_quiz_external::save_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::save_attempt_returns(), $result);
$this->assertTrue($result['status']);
// Now, get the summary.
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
// Check it's marked as completed only the first one.
$this->assertEquals('complete', $result['questions'][0]['state']);
@@ -1276,12 +1277,12 @@ public function test_save_attempt() {
);
$result = mod_quiz_external::save_attempt($attempt->id, $data);
- $result = \external_api::clean_returnvalue(mod_quiz_external::save_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::save_attempt_returns(), $result);
$this->assertTrue($result['status']);
// Now, get the summary.
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
// Check it's marked as completed only the first one.
$this->assertEquals('complete', $result['questions'][0]['state']);
@@ -1314,14 +1315,14 @@ public function test_process_attempt() {
$this->setUser($this->student);
$result = mod_quiz_external::process_attempt($attempt->id, $data);
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::IN_PROGRESS, $result['state']);
$result = mod_quiz_external::get_attempt_data($attempt->id, 2);
// Now, get the summary.
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
// Check it's marked as completed only the first one.
$this->assertEquals('complete', $result['questions'][0]['state']);
@@ -1350,12 +1351,12 @@ public function test_process_attempt() {
);
$result = mod_quiz_external::process_attempt($attempt->id, $data);
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::IN_PROGRESS, $result['state']);
// Now, get the summary.
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
// Check it's marked as completed the two first questions.
$this->assertEquals('complete', $result['questions'][0]['state']);
@@ -1388,12 +1389,12 @@ public function test_process_attempt() {
);
$result = mod_quiz_external::process_attempt($attempt->id, $data);
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::IN_PROGRESS, $result['state']);
// Now, get the summary.
$result = mod_quiz_external::get_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_summary_returns(), $result);
$this->assertEquals('complete', $result['questions'][0]['state']);
$this->assertEquals('complete', $result['questions'][1]['state']);
@@ -1411,7 +1412,7 @@ public function test_process_attempt() {
// Finish the attempt.
$sink = $this->redirectMessages();
$result = mod_quiz_external::process_attempt($attempt->id, array(), true);
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::FINISHED, $result['state']);
$messages = $sink->get_messages();
$message = reset($messages);
@@ -1441,7 +1442,7 @@ public function test_process_attempt() {
$DB->update_record('quiz', $quiz);
$result = mod_quiz_external::process_attempt($attempt->id, array());
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::OVERDUE, $result['state']);
// Force grace period for time limit.
@@ -1459,7 +1460,7 @@ public function test_process_attempt() {
quiz_attempt_save_started($quizobj, $quba, $attempt);
$result = mod_quiz_external::process_attempt($attempt->id, array());
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::OVERDUE, $result['state']);
// New attempt.
@@ -1475,7 +1476,7 @@ public function test_process_attempt() {
$DB->update_record('quiz', $quiz);
$result = mod_quiz_external::process_attempt($attempt->id, array());
- $result = \external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::process_attempt_returns(), $result);
$this->assertEquals(quiz_attempt::ABANDONED, $result['state']);
}
@@ -1559,7 +1560,7 @@ public function test_get_attempt_review() {
$feedback->id = $DB->insert_record('quiz_feedback', $feedback);
$result = mod_quiz_external::get_attempt_review($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_review_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_review_returns(), $result);
// Two questions, one completed and correct, the other gave up.
$this->assertEquals(50, $result['grade']);
@@ -1579,7 +1580,7 @@ public function test_get_attempt_review() {
// Only first page.
$result = mod_quiz_external::get_attempt_review($attempt->id, 0);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_review_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_review_returns(), $result);
$this->assertEquals(50, $result['grade']);
$this->assertEquals(1, $result['attempt']['attempt']);
@@ -1612,7 +1613,7 @@ public function test_view_attempt() {
$sink = $this->redirectEvents();
$result = mod_quiz_external::view_attempt($attempt->id, 0);
- $result = \external_api::clean_returnvalue(mod_quiz_external::view_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::view_attempt_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -1633,7 +1634,7 @@ public function test_view_attempt() {
// See next page.
$result = mod_quiz_external::view_attempt($attempt->id, 1, $preflightdata);
- $result = \external_api::clean_returnvalue(mod_quiz_external::view_attempt_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::view_attempt_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -1665,7 +1666,7 @@ public function test_view_attempt_summary() {
$sink = $this->redirectEvents();
$result = mod_quiz_external::view_attempt_summary($attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::view_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::view_attempt_summary_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -1685,7 +1686,7 @@ public function test_view_attempt_summary() {
$preflightdata = array(array("name" => "quizpassword", "value" => 'abcdef'));
$result = mod_quiz_external::view_attempt_summary($attempt->id, $preflightdata);
- $result = \external_api::clean_returnvalue(mod_quiz_external::view_attempt_summary_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::view_attempt_summary_returns(), $result);
$this->assertTrue($result['status']);
}
@@ -1706,7 +1707,7 @@ public function test_view_attempt_review() {
$sink = $this->redirectEvents();
$result = mod_quiz_external::view_attempt_review($attempt->id, 0);
- $result = \external_api::clean_returnvalue(mod_quiz_external::view_attempt_review_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::view_attempt_review_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -1757,18 +1758,18 @@ public function test_get_quiz_feedback_for_grade() {
$feedback->id = $DB->insert_record('quiz_feedback', $feedback);
$result = mod_quiz_external::get_quiz_feedback_for_grade($this->quiz->id, 50);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
$this->assertEquals('Feedback text 1', $result['feedbacktext']);
$this->assertEquals($filename, $result['feedbackinlinefiles'][0]['filename']);
$this->assertEquals(FORMAT_HTML, $result['feedbacktextformat']);
$result = mod_quiz_external::get_quiz_feedback_for_grade($this->quiz->id, 30);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
$this->assertEquals('Feedback text 2', $result['feedbacktext']);
$this->assertEquals(FORMAT_HTML, $result['feedbacktextformat']);
$result = mod_quiz_external::get_quiz_feedback_for_grade($this->quiz->id, 10);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_feedback_for_grade_returns(), $result);
$this->assertEquals('', $result['feedbacktext']);
$this->assertEquals(FORMAT_MOODLE, $result['feedbacktextformat']);
}
@@ -1788,7 +1789,7 @@ public function test_get_quiz_access_information() {
// Default restrictions (none).
$result = mod_quiz_external::get_quiz_access_information($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result);
$expected = array(
'canattempt' => true,
@@ -1808,7 +1809,7 @@ public function test_get_quiz_access_information() {
// Now teacher, different privileges.
$this->setUser($this->teacher);
$result = mod_quiz_external::get_quiz_access_information($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result);
$expected['canmanage'] = true;
$expected['canpreview'] = true;
@@ -1826,7 +1827,7 @@ public function test_get_quiz_access_information() {
$DB->update_record('quiz', $quiz);
$result = mod_quiz_external::get_quiz_access_information($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_access_information_returns(), $result);
// Access is limited by time and password, but only the password limit has a description.
$this->assertCount(1, $result['accessrules']);
@@ -1878,7 +1879,7 @@ public function test_get_attempt_access_information() {
// Default restrictions (none).
$result = mod_quiz_external::get_attempt_access_information($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result);
$expected = array(
'isfinished' => false,
@@ -1913,7 +1914,7 @@ public function test_get_attempt_access_information() {
// Can we start a new attempt? We shall not!
$result = mod_quiz_external::get_attempt_access_information($quiz->id, $attempt->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_attempt_access_information_returns(), $result);
// Now new attemps allowed.
$this->assertCount(1, $result['preventnewattemptreasons']);
@@ -1952,7 +1953,7 @@ public function test_get_quiz_required_qtypes() {
$this->setUser($this->student);
$result = mod_quiz_external::get_quiz_required_qtypes($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
$expected = array(
'questiontypes' => ['essay', 'numerical', 'shortanswer', 'truefalse'],
@@ -1992,7 +1993,7 @@ public function test_get_quiz_required_qtypes_random() {
$this->setUser($this->student);
$result = mod_quiz_external::get_quiz_required_qtypes($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
$expected = ['numerical', 'shortanswer', 'truefalse'];
ksort($result['questiontypes']);
@@ -2005,7 +2006,7 @@ public function test_get_quiz_required_qtypes_random() {
$this->setUser($this->student);
$result = mod_quiz_external::get_quiz_required_qtypes($quiz->id);
- $result = \external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_quiz_external::get_quiz_required_qtypes_returns(), $result);
// The new question from the new category is returned as a potential random question for the quiz.
$expected = ['essay', 'numerical', 'shortanswer', 'truefalse'];
diff --git a/mod/resource/classes/external.php b/mod/resource/classes/external.php
index b82c8e830c688..42c1d4a596b9a 100644
--- a/mod/resource/classes/external.php
+++ b/mod/resource/classes/external.php
@@ -14,21 +14,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Resource external API
- *
- * @package mod_resource
- * @category external
- * @copyright 2015 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 3.0
- */
-
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* Resource external functions
@@ -94,7 +88,7 @@ public static function view_resource($resourceid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_resource_returns() {
@@ -149,7 +143,7 @@ public static function get_resources_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the resources in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -158,7 +152,7 @@ public static function get_resources_by_courses($courseids = array()) {
$context = context_module::instance($resource->coursemodule);
helper_for_get_mods_by_courses::format_name_and_intro($resource, 'mod_resource');
- $resource->contentfiles = external_util::get_area_files($context->id, 'mod_resource', 'content');
+ $resource->contentfiles = util::get_area_files($context->id, 'mod_resource', 'content');
$returnedresources[] = $resource;
}
diff --git a/mod/resource/tests/externallib_test.php b/mod/resource/tests/externallib_test.php
index 946ffbeefb664..4b26c2fdbacc1 100644
--- a/mod/resource/tests/externallib_test.php
+++ b/mod/resource/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_resource;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_resource_external;
@@ -77,7 +78,7 @@ public function test_view_resource() {
$sink = $this->redirectEvents();
$result = mod_resource_external::view_resource($resource->id);
- $result = \external_api::clean_returnvalue(mod_resource_external::view_resource_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_resource_external::view_resource_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -184,7 +185,7 @@ public function test_mod_resource_get_resources_by_courses() {
// Call the external function passing course ids.
$result = mod_resource_external::get_resources_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
// Remove the contentfiles (to be checked bellow).
$result['resources'][0]['contentfiles'] = [];
@@ -196,7 +197,7 @@ public function test_mod_resource_get_resources_by_courses() {
// Call the external function without passing course id.
$result = mod_resource_external::get_resources_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
// Remove the contentfiles (to be checked bellow).
$result['resources'][0]['contentfiles'] = [];
@@ -221,7 +222,7 @@ public function test_mod_resource_get_resources_by_courses() {
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_resource_external::get_resources_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
// Check that we receive correctly the files.
$this->assertCount(1, $result['resources'][0]['introfiles']);
@@ -238,7 +239,7 @@ public function test_mod_resource_get_resources_by_courses() {
// Call the external function without passing course id.
$result = mod_resource_external::get_resources_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
// Remove the contentfiles (to be checked bellow).
$result['resources'][0]['contentfiles'] = [];
diff --git a/mod/scorm/classes/external.php b/mod/scorm/classes/external.php
index a470d7f49589c..ea3d7fd5cb375 100644
--- a/mod/scorm/classes/external.php
+++ b/mod/scorm/classes/external.php
@@ -25,10 +25,16 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/scorm/lib.php');
require_once($CFG->dirroot . '/mod/scorm/locallib.php');
@@ -94,7 +100,7 @@ public static function view_scorm($scormid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_scorm_returns() {
@@ -674,7 +680,7 @@ public static function get_scorms_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $courses);
// Get the scorms in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -879,7 +885,7 @@ public static function launch_sco($scormid, $scoid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.1
*/
public static function launch_sco_returns() {
diff --git a/mod/scorm/tests/externallib_test.php b/mod/scorm/tests/externallib_test.php
index f26ee06e80412..d0f618dad2592 100644
--- a/mod/scorm/tests/externallib_test.php
+++ b/mod/scorm/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_scorm;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_scorm_external;
@@ -96,7 +97,7 @@ public function test_view_scorm() {
$sink = $this->redirectEvents();
$result = mod_scorm_external::view_scorm($this->scorm->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::view_scorm_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::view_scorm_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -120,7 +121,7 @@ public function test_mod_scorm_get_scorm_attempt_count_own_empty() {
// Retrieve my attempts (should be 0).
$result = mod_scorm_external::get_scorm_attempt_count($this->scorm->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
$this->assertEquals(0, $result['attemptscount']);
}
@@ -135,7 +136,7 @@ public function test_mod_scorm_get_scorm_attempt_count_own_with_complete() {
scorm_insert_track($this->student->id, $this->scorm->id, $sco->id, 2, 'cmi.core.lesson_status', 'completed');
$result = mod_scorm_external::get_scorm_attempt_count($this->scorm->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
$this->assertEquals(2, $result['attemptscount']);
}
@@ -150,7 +151,7 @@ public function test_mod_scorm_get_scorm_attempt_count_own_incomplete() {
scorm_insert_track($this->student->id, $this->scorm->id, $sco->id, 2, 'cmi.core.credit', '0');
$result = mod_scorm_external::get_scorm_attempt_count($this->scorm->id, $this->student->id, true);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
$this->assertEquals(1, $result['attemptscount']);
}
@@ -165,7 +166,7 @@ public function test_mod_scorm_get_scorm_attempt_count_others_as_teacher() {
// I should be able to view the attempts for my students.
$result = mod_scorm_external::get_scorm_attempt_count($this->scorm->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_attempt_count_returns(), $result);
$this->assertEquals(1, $result['attemptscount']);
}
@@ -252,7 +253,7 @@ public function test_mod_scorm_get_scorm_scoes() {
// Retrieve my scoes, user with permission.
self::setUser($teacher);
$result = mod_scorm_external::get_scorm_scoes($scorm->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
$this->assertCount(2, $result['scoes']);
$this->assertCount(0, $result['warnings']);
@@ -284,7 +285,7 @@ public function test_mod_scorm_get_scorm_scoes() {
// Use organization.
$organization = 'golf_sample_default_org';
$result = mod_scorm_external::get_scorm_scoes($scorm->id, $organization);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
$this->assertCount(1, $result['scoes']);
$this->assertEquals($organization, $result['scoes'][0]['organization']);
$this->assertCount(0, $result['warnings']);
@@ -314,7 +315,7 @@ public function test_mod_scorm_get_scorm_scoes_complex_package() {
$scorm = self::getDataGenerator()->create_module('scorm', $record);
$result = mod_scorm_external::get_scorm_scoes($scorm->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_scoes_returns(), $result);
$this->assertCount(9, $result['scoes']);
$this->assertCount(0, $result['warnings']);
@@ -376,7 +377,7 @@ public function test_mod_scorm_get_scorm_user_data() {
scorm_insert_track($student1->id, $scorm->id, $sco->id, 2, 'cmi.core.lesson_status', 'completed');
$result = mod_scorm_external::get_scorm_user_data($scorm->id, 1);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_user_data_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_user_data_returns(), $result);
$this->assertCount(2, $result['data']);
// Find our tracking data.
$found = 0;
@@ -477,7 +478,7 @@ public function test_mod_scorm_insert_scorm_tracks() {
// Retrieve my tracks.
$result = mod_scorm_external::insert_scorm_tracks($sco->id, 1, $tracks);
- $result = \external_api::clean_returnvalue(mod_scorm_external::insert_scorm_tracks_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::insert_scorm_tracks_returns(), $result);
$this->assertCount(0, $result['warnings']);
$trackids = $DB->get_records('scorm_scoes_track', array('userid' => $student->id, 'scoid' => $sco->id,
@@ -525,7 +526,7 @@ public function test_mod_scorm_get_scorm_sco_tracks() {
scorm_insert_track($student->id, $scorm->id, $sco->id, 2, 'cmi.core.lesson_status', 'completed');
$result = mod_scorm_external::get_scorm_sco_tracks($sco->id, $student->id, 1);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_sco_tracks_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_sco_tracks_returns(), $result);
// 7 default elements + 2 custom ones.
$this->assertCount(9, $result['data']['tracks']);
$this->assertEquals(1, $result['data']['attempt']);
@@ -544,7 +545,7 @@ public function test_mod_scorm_get_scorm_sco_tracks() {
// Try invalid attempt.
$result = mod_scorm_external::get_scorm_sco_tracks($sco->id, $student->id, 10);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_sco_tracks_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_sco_tracks_returns(), $result);
$this->assertCount(0, $result['data']['tracks']);
$this->assertEquals(10, $result['data']['attempt']);
$this->assertCount(1, $result['warnings']);
@@ -561,7 +562,7 @@ public function test_mod_scorm_get_scorm_sco_tracks() {
self::setUser($teacher);
// Ommit the attempt parameter, the function should calculate the last attempt.
$result = mod_scorm_external::get_scorm_sco_tracks($sco->id, $student->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_sco_tracks_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_sco_tracks_returns(), $result);
// 7 default elements + 1 custom one.
$this->assertCount(8, $result['data']['tracks']);
$this->assertEquals(2, $result['data']['attempt']);
@@ -644,7 +645,7 @@ public function test_mod_scorm_get_scorms_by_courses() {
$DB->update_record('scorm', $scorm1);
$result = mod_scorm_external::get_scorms_by_courses(array($course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['warnings']);
// Only 'id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles'.
$this->assertCount(8, $result['scorms'][0]);
@@ -655,7 +656,7 @@ public function test_mod_scorm_get_scorms_by_courses() {
$DB->update_record('scorm', $scorm1);
$result = mod_scorm_external::get_scorms_by_courses(array($course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['warnings']);
// Only 'id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles'.
$this->assertCount(8, $result['scorms'][0]);
@@ -736,12 +737,12 @@ public function test_mod_scorm_get_scorms_by_courses() {
// Call the external function passing course ids.
$result = mod_scorm_external::get_scorms_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedscorms, $result['scorms']);
// Call the external function without passing course id.
$result = mod_scorm_external::get_scorms_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedscorms, $result['scorms']);
// Unenrol user from second course and alter expected scorms.
@@ -750,7 +751,7 @@ public function test_mod_scorm_get_scorms_by_courses() {
// Call the external function without passing course id.
$result = mod_scorm_external::get_scorms_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedscorms, $result['scorms']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -777,7 +778,7 @@ public function test_mod_scorm_get_scorms_by_courses() {
}
$result = mod_scorm_external::get_scorms_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedscorms, $result['scorms']);
// Even with the SCORM closed in time teacher should retrieve the info.
@@ -789,14 +790,14 @@ public function test_mod_scorm_get_scorms_by_courses() {
$expectedscorms[0]['timeclose'] = $scorm1->timeclose;
$result = mod_scorm_external::get_scorms_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedscorms, $result['scorms']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_scorm_external::get_scorms_by_courses(array($course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedscorms, $result['scorms']);
}
@@ -839,7 +840,7 @@ public function test_launch_sco() {
}
$result = mod_scorm_external::launch_sco($this->scorm->id, $sco->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::launch_sco_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::launch_sco_returns(), $result);
$events = $sink->get_events();
$this->assertCount(3, $events);
@@ -891,7 +892,7 @@ public function test_mod_scorm_get_scorm_access_information() {
self::setUser($student);
$result = mod_scorm_external::get_scorm_access_information($scorm->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_access_information_returns(), $result);
// Check default values for capabilities.
$enabledcaps = array('canskipview', 'cansavetrack', 'canviewscores');
@@ -910,7 +911,7 @@ public function test_mod_scorm_get_scorm_access_information() {
accesslib_clear_all_caches_for_unit_testing();
$result = mod_scorm_external::get_scorm_access_information($scorm->id);
- $result = \external_api::clean_returnvalue(mod_scorm_external::get_scorm_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_scorm_external::get_scorm_access_information_returns(), $result);
unset($result['warnings']);
foreach ($result as $capname => $capvalue) {
if (in_array($capname, $enabledcaps)) {
diff --git a/mod/survey/classes/external.php b/mod/survey/classes/external.php
index 8fc2e1592c88a..26ddc717a51a5 100644
--- a/mod/survey/classes/external.php
+++ b/mod/survey/classes/external.php
@@ -25,10 +25,16 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/survey/lib.php');
/**
@@ -82,8 +88,7 @@ public static function get_surveys_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
-
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the surveys in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -199,7 +204,7 @@ public static function view_survey($surveyid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_survey_returns() {
@@ -278,7 +283,7 @@ public static function get_questions($surveyid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function get_questions_returns() {
@@ -374,7 +379,7 @@ public static function submit_answers($surveyid, $answers) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function submit_answers_returns() {
diff --git a/mod/survey/tests/externallib_test.php b/mod/survey/tests/externallib_test.php
index 95fba65130386..4cb49e83ffcc1 100644
--- a/mod/survey/tests/externallib_test.php
+++ b/mod/survey/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_survey;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_survey_external;
@@ -132,14 +133,14 @@ public function test_mod_survey_get_surveys_by_courses() {
// Call the external function passing course ids.
$result = mod_survey_external::get_surveys_by_courses(array($course2->id, $this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedsurveys, $result['surveys']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_survey_external::get_surveys_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedsurveys, $result['surveys']);
$this->assertCount(0, $result['warnings']);
@@ -149,7 +150,7 @@ public function test_mod_survey_get_surveys_by_courses() {
// Call the external function without passing course id.
$result = mod_survey_external::get_surveys_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedsurveys, $result['surveys']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -168,14 +169,14 @@ public function test_mod_survey_get_surveys_by_courses() {
}
$result = mod_survey_external::get_surveys_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedsurveys, $result['surveys']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_survey_external::get_surveys_by_courses(array($this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedsurveys, $result['surveys']);
// Now, prohibit capabilities.
@@ -186,7 +187,7 @@ public function test_mod_survey_get_surveys_by_courses() {
accesslib_clear_all_caches_for_unit_testing();
$surveys = mod_survey_external::get_surveys_by_courses(array($this->course->id));
- $surveys = \external_api::clean_returnvalue(mod_survey_external::get_surveys_by_courses_returns(), $surveys);
+ $surveys = external_api::clean_returnvalue(mod_survey_external::get_surveys_by_courses_returns(), $surveys);
$this->assertFalse(isset($surveys['surveys'][0]['intro']));
}
@@ -221,7 +222,7 @@ public function test_view_survey() {
$sink = $this->redirectEvents();
$result = mod_survey_external::view_survey($this->survey->id);
- $result = \external_api::clean_returnvalue(mod_survey_external::view_survey_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_survey_external::view_survey_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -275,7 +276,7 @@ public function test_get_questions() {
}
$result = mod_survey_external::get_questions($this->survey->id);
- $result = \external_api::clean_returnvalue(mod_survey_external::get_questions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_survey_external::get_questions_returns(), $result);
// Check we receive the same questions.
$this->assertCount(0, $result['warnings']);
@@ -339,7 +340,7 @@ public function test_submit_answers() {
}
$result = mod_survey_external::submit_answers($this->survey->id, $realquestions);
- $result = \external_api::clean_returnvalue(mod_survey_external::submit_answers_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_survey_external::submit_answers_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
diff --git a/mod/url/classes/external.php b/mod/url/classes/external.php
index e0ff077bc31f5..9977d3b395daf 100644
--- a/mod/url/classes/external.php
+++ b/mod/url/classes/external.php
@@ -14,21 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * URL external API
- *
- * @package mod_url
- * @category external
- * @copyright 2015 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- * @since Moodle 3.0
- */
-
use core_course\external\helper_for_get_mods_by_courses;
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* URL external functions
@@ -94,7 +87,7 @@ public static function view_url($urlid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.0
*/
public static function view_url_returns() {
@@ -149,7 +142,7 @@ public static function get_urls_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the urls in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
diff --git a/mod/url/tests/externallib_test.php b/mod/url/tests/externallib_test.php
index d361c3d21ca1e..50bf5f40a080a 100644
--- a/mod/url/tests/externallib_test.php
+++ b/mod/url/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_url;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_url_external;
@@ -76,7 +77,7 @@ public function test_view_url() {
$sink = $this->redirectEvents();
$result = mod_url_external::view_url($url->id);
- $result = \external_api::clean_returnvalue(mod_url_external::view_url_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_url_external::view_url_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -179,14 +180,14 @@ public function test_mod_url_get_urls_by_courses() {
// Call the external function passing course ids.
$result = mod_url_external::get_urls_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedurls, $result['urls']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_url_external::get_urls_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedurls, $result['urls']);
$this->assertCount(0, $result['warnings']);
@@ -205,7 +206,7 @@ public function test_mod_url_get_urls_by_courses() {
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_url_external::get_urls_by_courses(array($course2->id, $course1->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['urls'][0]['introfiles']);
$this->assertEquals($filename, $result['urls'][0]['introfiles'][0]['filename']);
@@ -216,7 +217,7 @@ public function test_mod_url_get_urls_by_courses() {
// Call the external function without passing course id.
$result = mod_url_external::get_urls_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedurls, $result['urls']);
// Call for the second course we unenrolled the user from, expected warning.
diff --git a/mod/wiki/classes/external.php b/mod/wiki/classes/external.php
index 9c37f49586df3..e91a3f5b1971e 100644
--- a/mod/wiki/classes/external.php
+++ b/mod/wiki/classes/external.php
@@ -25,10 +25,18 @@
*/
use core_course\external\helper_for_get_mods_by_courses;
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
defined('MOODLE_INTERNAL') || die;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/mod/wiki/lib.php');
require_once($CFG->dirroot . '/mod/wiki/locallib.php');
@@ -83,7 +91,7 @@ public static function get_wikis_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the wikis in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
@@ -467,7 +475,7 @@ public static function get_subwiki_pages($wikiid, $groupid = -1, $userid = 0, $o
$retpage = array(
'id' => $page->id,
'subwikiid' => $page->subwikiid,
- 'title' => external_format_string($page->title, $context->id),
+ 'title' => \core_external\util::format_string($page->title, $context),
'timecreated' => $page->timecreated,
'timemodified' => $page->timemodified,
'timerendered' => $page->timerendered,
@@ -485,8 +493,14 @@ public static function get_subwiki_pages($wikiid, $groupid = -1, $userid = 0, $o
$page = $content['page'];
}
}
- list($cachedcontent, $contentformat) = external_format_text(
- $page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
+ list($cachedcontent, $contentformat) = \core_external\util::format_text(
+ $page->cachedcontent,
+ FORMAT_HTML,
+ $context,
+ 'mod_wiki',
+ 'attachments',
+ $subwiki->id
+ );
if ($options['includecontent']) {
// Return the page content.
@@ -623,8 +637,14 @@ public static function get_page_contents($pageid) {
}
}
- list($returnedpage['cachedcontent'], $returnedpage['contentformat']) = external_format_text(
- $page->cachedcontent, FORMAT_HTML, $context->id, 'mod_wiki', 'attachments', $subwiki->id);
+ list($returnedpage['cachedcontent'], $returnedpage['contentformat']) = \core_external\util::format_text(
+ $page->cachedcontent,
+ FORMAT_HTML,
+ $context,
+ 'mod_wiki',
+ 'attachments',
+ $subwiki->id
+ );
$returnedpage['caneditpage'] = wiki_user_can_edit($subwiki);
// Get page version.
@@ -730,7 +750,7 @@ public static function get_subwiki_files($wikiid, $groupid = -1, $userid = 0) {
throw new moodle_exception('cannotviewfiles', 'wiki');
} else if ($subwiki->id != -1) {
// The subwiki exists, let's get the files.
- $returnedfiles = external_util::get_area_files($context->id, 'mod_wiki', 'attachments', $subwiki->id);
+ $returnedfiles = util::get_area_files($context->id, 'mod_wiki', 'attachments', $subwiki->id);
}
$result = array();
diff --git a/mod/wiki/tests/externallib_test.php b/mod/wiki/tests/externallib_test.php
index 9f16ca4e02303..2d99bc02f4aaa 100644
--- a/mod/wiki/tests/externallib_test.php
+++ b/mod/wiki/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace mod_wiki;
+use core_external\external_api;
use externallib_advanced_testcase;
use mod_wiki_external;
@@ -204,14 +205,14 @@ public function test_mod_wiki_get_wikis_by_courses() {
// Call the external function passing course ids.
$result = mod_wiki_external::get_wikis_by_courses(array($course2->id, $this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedwikis, $result['wikis']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_wiki_external::get_wikis_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedwikis, $result['wikis']);
$this->assertCount(0, $result['warnings']);
@@ -221,7 +222,7 @@ public function test_mod_wiki_get_wikis_by_courses() {
// Call the external function without passing course id.
$result = mod_wiki_external::get_wikis_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedwikis, $result['wikis']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -240,14 +241,14 @@ public function test_mod_wiki_get_wikis_by_courses() {
}
$result = mod_wiki_external::get_wikis_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedwikis, $result['wikis']);
// Admin also should get all the information.
self::setAdminUser();
$result = mod_wiki_external::get_wikis_by_courses(array($this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedwikis, $result['wikis']);
// Now, prohibit capabilities.
@@ -256,7 +257,7 @@ public function test_mod_wiki_get_wikis_by_courses() {
// Default student role allows to view wiki and create pages.
$wikis = mod_wiki_external::get_wikis_by_courses(array($this->course->id));
- $wikis = \external_api::clean_returnvalue(mod_wiki_external::get_wikis_by_courses_returns(), $wikis);
+ $wikis = external_api::clean_returnvalue(mod_wiki_external::get_wikis_by_courses_returns(), $wikis);
$this->assertEquals('Test wiki 1', $wikis['wikis'][0]['intro']);
$this->assertEquals(1, $wikis['wikis'][0]['cancreatepages']);
@@ -266,7 +267,7 @@ public function test_mod_wiki_get_wikis_by_courses() {
\course_modinfo::clear_instance_cache(null);
$wikis = mod_wiki_external::get_wikis_by_courses(array($this->course->id));
- $wikis = \external_api::clean_returnvalue(mod_wiki_external::get_wikis_by_courses_returns(), $wikis);
+ $wikis = external_api::clean_returnvalue(mod_wiki_external::get_wikis_by_courses_returns(), $wikis);
$this->assertEquals(0, count($wikis['wikis']));
// Prohibit capability = mod:wiki:createpage on Course1 for students.
@@ -276,7 +277,7 @@ public function test_mod_wiki_get_wikis_by_courses() {
\course_modinfo::clear_instance_cache(null);
$wikis = mod_wiki_external::get_wikis_by_courses(array($this->course->id));
- $wikis = \external_api::clean_returnvalue(mod_wiki_external::get_wikis_by_courses_returns(), $wikis);
+ $wikis = external_api::clean_returnvalue(mod_wiki_external::get_wikis_by_courses_returns(), $wikis);
$this->assertFalse($wikis['wikis'][0]['cancreatepages']);
}
@@ -311,7 +312,7 @@ public function test_view_wiki() {
$sink = $this->redirectEvents();
$result = mod_wiki_external::view_wiki($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::view_wiki_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::view_wiki_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -369,7 +370,7 @@ public function test_view_page() {
$sink = $this->redirectEvents();
$result = mod_wiki_external::view_page($this->firstpage->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::view_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::view_page_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -436,7 +437,7 @@ public function test_get_subwikis() {
$expectedsubwikis[] = $expectedsubwiki;
$result = mod_wiki_external::get_subwikis($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwikis_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwikis_returns(), $result);
$this->assertEquals($expectedsubwikis, $result['subwikis']);
$this->assertCount(0, $result['warnings']);
@@ -610,17 +611,17 @@ public function test_get_subwiki_pages_collaborative() {
$expectedpages[] = $expectedfirstpage;
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that groupid param is ignored since the wiki isn't using groups.
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id, 1234);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that userid param is ignored since the wiki is collaborative.
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id, 1234, 1234);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Add a new page to the wiki and test again. We'll use a custom title so it's returned first if sorted by title.
@@ -635,13 +636,13 @@ public function test_get_subwiki_pages_collaborative() {
array_unshift($expectedpages, $expectednewpage); // Add page to the beginning since it orders by title by default.
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Now we'll order by ID. Since first page was created first it'll have a lower ID.
$expectedpages = array($expectedfirstpage, $expectednewpage);
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id, 0, 0, array('sortby' => 'id'));
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that WS doesn't return page content if includecontent is false, it returns the size instead.
@@ -659,7 +660,7 @@ public function test_get_subwiki_pages_collaborative() {
unset($expectedpages[$i]['contentformat']);
}
$result = mod_wiki_external::get_subwiki_pages($this->wiki->id, 0, 0, array('sortby' => 'id', 'includecontent' => 0));
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
}
@@ -674,7 +675,7 @@ public function test_get_subwiki_pages_individual() {
// Perform a request before creating any page to check that an empty array is returned if subwiki doesn't exist.
$result = mod_wiki_external::get_subwiki_pages($indwiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals(array(), $result['pages']);
// Create first pages as student and teacher.
@@ -692,7 +693,7 @@ public function test_get_subwiki_pages_individual() {
$expectedpages = array($expectedteacherpage);
$result = mod_wiki_external::get_subwiki_pages($indwiki->id, 0, $this->teacher->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that the teacher can see the student's pages.
@@ -704,19 +705,19 @@ public function test_get_subwiki_pages_individual() {
$expectedpages = array($expectedstudentpage);
$result = mod_wiki_external::get_subwiki_pages($indwiki->id, 0, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Now check that student can get his pages.
$this->setUser($this->student);
$result = mod_wiki_external::get_subwiki_pages($indwiki->id, 0, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that not using userid uses current user.
$result = mod_wiki_external::get_subwiki_pages($indwiki->id, 0);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
}
@@ -740,18 +741,18 @@ public function test_get_subwiki_pages_separate_groups_collaborative() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisep->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Let's check that not using groupid returns the same result (current group).
$result = mod_wiki_external::get_subwiki_pages($this->wikisep->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that teacher can view a group pages without belonging to it.
$this->setUser($this->teacher);
$result = mod_wiki_external::get_subwiki_pages($this->wikisep->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that teacher can get the pages from all participants.
@@ -763,7 +764,7 @@ public function test_get_subwiki_pages_separate_groups_collaborative() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisep->id, 0);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
}
@@ -787,7 +788,7 @@ public function test_get_subwiki_pages_visible_groups_collaborative() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivis->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that with visible groups a student can get the pages of groups he doesn't belong to.
@@ -799,7 +800,7 @@ public function test_get_subwiki_pages_visible_groups_collaborative() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivis->id, $this->group2->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that with visible groups a student can get the pages of all participants.
@@ -811,7 +812,7 @@ public function test_get_subwiki_pages_visible_groups_collaborative() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivis->id, 0);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
}
@@ -834,18 +835,18 @@ public function test_get_subwiki_pages_separate_groups_individual() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group1->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that not using userid uses current user.
$result = mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that the teacher can see the student pages.
$this->setUser($this->teacher);
$result = mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group1->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that a student can see pages from another user that belongs to his groups.
@@ -858,7 +859,7 @@ public function test_get_subwiki_pages_separate_groups_individual() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikisepind->id, $this->group1->id, $this->student2->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
}
@@ -881,7 +882,7 @@ public function test_get_subwiki_pages_visible_groups_individual() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivisind->id, $this->group1->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that student can see teacher pages in visible groups, even if the user doesn't belong to the group.
@@ -893,7 +894,7 @@ public function test_get_subwiki_pages_visible_groups_individual() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivisind->id, $this->group2->id, $this->teacher->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
// Check that with visible groups a student can get the pages of all participants.
@@ -905,7 +906,7 @@ public function test_get_subwiki_pages_visible_groups_individual() {
$expectedpages = array($expectedpage);
$result = mod_wiki_external::get_subwiki_pages($this->wikivisind->id, 0, $this->teacher->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_pages_returns(), $result);
$this->assertEquals($expectedpages, $result['pages']);
}
@@ -998,7 +999,7 @@ public function test_get_page_contents() {
$expectedpage['tags'][1]['isstandard'] = (bool) $expectedpage['tags'][1]['isstandard'];
$result = mod_wiki_external::get_page_contents($this->firstpage->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
$this->assertEquals($expectedpage, $result['page']);
// Add a new page to the wiki and test with it.
@@ -1010,7 +1011,7 @@ public function test_get_page_contents() {
$expectedpage['tags'] = array();
$result = mod_wiki_external::get_page_contents($newpage->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
$this->assertEquals($expectedpage, $result['page']);
}
@@ -1041,13 +1042,13 @@ public function test_get_page_contents_with_groups() {
);
$result = mod_wiki_external::get_page_contents($this->fpsepg1indstu->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
$this->assertEquals($expectedfpsepg1indstu, $result['page']);
// Check that teacher can view a group pages without belonging to it.
$this->setUser($this->teacher);
$result = mod_wiki_external::get_page_contents($this->fpsepg1indstu->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_contents_returns(), $result);
$this->assertEquals($expectedfpsepg1indstu, $result['page']);
}
@@ -1056,7 +1057,7 @@ public function test_get_page_contents_with_groups() {
*/
public function test_get_subwiki_files_no_files() {
$result = mod_wiki_external::get_subwiki_files($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
$this->assertCount(0, $result['files']);
$this->assertCount(0, $result['warnings']);
}
@@ -1101,7 +1102,7 @@ public function test_get_subwiki_files_collaborative_no_groups() {
// Call the WS and check that it returns this file.
$result = mod_wiki_external::get_subwiki_files($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
$this->assertCount(1, $result['files']);
$this->assertEquals($expectedfile, $result['files'][0]);
@@ -1119,7 +1120,7 @@ public function test_get_subwiki_files_collaborative_no_groups() {
// Call the WS and check that it returns both files file.
$result = mod_wiki_external::get_subwiki_files($this->wiki->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
$this->assertCount(2, $result['files']);
// The new file is returned first because they're returned in alphabetical order.
$this->assertEquals($expectedfile, $result['files'][0]);
@@ -1156,14 +1157,14 @@ public function test_get_subwiki_files_visible_groups_individual() {
// Call the WS and check that it returns this file.
$result = mod_wiki_external::get_subwiki_files($this->wikivisind->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
$this->assertCount(1, $result['files']);
$this->assertEquals($expectedfile, $result['files'][0]);
// Now check that a teacher can see it too.
$this->setUser($this->teacher);
$result = mod_wiki_external::get_subwiki_files($this->wikivisind->id, $this->group1->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_subwiki_files_returns(), $result);
$this->assertCount(1, $result['files']);
$this->assertEquals($expectedfile, $result['files'][0]);
}
@@ -1194,7 +1195,7 @@ public function test_get_page_for_editing() {
);
$result = mod_wiki_external::get_page_for_editing($newpage->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
$this->assertEquals($expected, $result['pagesection']);
// Set expected result: Section Page content.
@@ -1205,7 +1206,7 @@ public function test_get_page_for_editing() {
);
$result = mod_wiki_external::get_page_for_editing($newpage->id, 'Title1');
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
$this->assertEquals($expected, $result['pagesection']);
}
@@ -1229,7 +1230,7 @@ public function test_get_page_locking() {
);
$result = mod_wiki_external::get_page_for_editing($newpage->id, 'Title1', true);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
$this->assertEquals($expected, $result['pagesection']);
// Test the section is locked.
@@ -1251,7 +1252,7 @@ public function test_get_page_locking() {
// Test the other section is not locked.
$result = mod_wiki_external::get_page_for_editing($newpage->id, 'Title2', true);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
$this->assertEquals($expected, $result['pagesection']);
// Back to the original user to test version change when editing.
@@ -1263,7 +1264,7 @@ public function test_get_page_locking() {
'version' => '2'
);
$result = mod_wiki_external::get_page_for_editing($newpage->id, 'Title1', true);
- $result = \external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::get_page_for_editing_returns(), $result);
$this->assertEquals($expected, $result['pagesection']);
}
@@ -1284,7 +1285,7 @@ public function test_new_page() {
// Test on existing subwiki.
$result = mod_wiki_external::new_page($pagetitle, $pagecontent, 'html', $this->fpsepg1indstu->subwikiid);
- $result = \external_api::clean_returnvalue(mod_wiki_external::new_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::new_page_returns(), $result);
$this->assertIsInt($result['pageid']);
$version = wiki_get_current_version($result['pageid']);
@@ -1306,7 +1307,7 @@ public function test_new_page() {
$this->getDataGenerator()->create_group_member(array('userid' => $this->student->id, 'groupid' => $this->group2->id));
$result = mod_wiki_external::new_page($pagetitle, $pagecontent, 'html', null, $this->wikisepind->id, $this->student->id,
$this->group2->id);
- $result = \external_api::clean_returnvalue(mod_wiki_external::new_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::new_page_returns(), $result);
$this->assertIsInt($result['pageid']);
$version = wiki_get_current_version($result['pageid']);
@@ -1359,7 +1360,7 @@ public function test_edit_page() {
$newpagecontent = $sectioncontent.'Title2
Text inside section';
$result = mod_wiki_external::edit_page($newpage->id, $newpagecontent);
- $result = \external_api::clean_returnvalue(mod_wiki_external::edit_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::edit_page_returns(), $result);
$this->assertIsInt($result['pageid']);
$version = wiki_get_current_version($result['pageid']);
@@ -1370,7 +1371,7 @@ public function test_edit_page() {
$section = 'Title2';
$result = mod_wiki_external::edit_page($newpage->id, $newsectioncontent, $section);
- $result = \external_api::clean_returnvalue(mod_wiki_external::edit_page_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_wiki_external::edit_page_returns(), $result);
$this->assertIsInt($result['pageid']);
$expected = $sectioncontent . $newsectioncontent;
diff --git a/mod/workshop/classes/external.php b/mod/workshop/classes/external.php
index f185649bada1b..6605fc2ff041c 100644
--- a/mod/workshop/classes/external.php
+++ b/mod/workshop/classes/external.php
@@ -26,9 +26,16 @@
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . '/mod/workshop/locallib.php');
+use core_external\external_api;
+use core_external\external_files;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
use mod_workshop\external\workshop_summary_exporter;
use mod_workshop\external\submission_exporter;
use mod_workshop\external\assessment_exporter;
@@ -88,7 +95,7 @@ public static function get_workshops_by_courses($courseids = array()) {
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
- list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
+ list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
$output = $PAGE->get_renderer('core');
// Get the workshops in this course, this function checks users visibility permissions.
@@ -532,7 +539,7 @@ public static function add_submission($workshopid, $title, $content = '', $conte
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function add_submission_returns() {
@@ -640,7 +647,7 @@ public static function update_submission($submissionid, $title, $content = '', $
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function update_submission_returns() {
@@ -706,7 +713,7 @@ public static function delete_submission($submissionid) {
/**
* Returns the description of the external function return value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function delete_submission_returns() {
@@ -870,7 +877,7 @@ public static function get_submissions($workshopid, $userid = 0, $groupid = 0, $
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_submissions_returns() {
@@ -965,7 +972,7 @@ public static function get_submission($submissionid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_submission_returns() {
@@ -1118,7 +1125,7 @@ public static function get_submission_assessments($submissionid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_submission_assessments_returns() {
@@ -1186,7 +1193,7 @@ public static function get_assessment($assessmentid) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_assessment_returns() {
@@ -1255,7 +1262,7 @@ public static function get_assessment_form_definition($assessmentid, $mode = 'as
$result = array(
'dimenssionscount' => $formdata['nodims'],
- 'descriptionfiles' => external_util::get_area_files($context->id, $strategyname, 'description'),
+ 'descriptionfiles' => util::get_area_files($context->id, $strategyname, 'description'),
'warnings' => $warnings
);
// Include missing dimension fields.
@@ -1274,7 +1281,7 @@ public static function get_assessment_form_definition($assessmentid, $mode = 'as
if (strpos($key, 'description__idx_')) {
// Format dimension description.
$id = str_replace('description__idx_', '', $key);
- list($val, $format) = external_format_text($val, $alldata['dimensionid__idx_' . $id . 'format'],
+ list($val, $format) = \core_external\util::format_text($val, $alldata['dimensionid__idx_' . $id . 'format'],
$context->id, $strategyname, 'description', $alldata['dimensionid__idx_' . $id]);
}
$result[$typeofdata][] = array(
@@ -1295,7 +1302,7 @@ public static function get_assessment_form_definition($assessmentid, $mode = 'as
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_assessment_form_definition_returns() {
@@ -1421,7 +1428,7 @@ public static function get_reviewer_assessments($workshopid, $userid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_reviewer_assessments_returns() {
@@ -1549,7 +1556,7 @@ public static function update_assessment($assessmentid, $data) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function update_assessment_returns() {
@@ -1770,7 +1777,7 @@ public static function evaluate_assessment($assessmentid, $feedbacktext = '', $f
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function evaluate_assessment_returns() {
@@ -1900,7 +1907,7 @@ public static function get_grades_report($workshopid, $groupid = 0, $sortby = 'l
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function get_grades_report_returns() {
@@ -2120,7 +2127,7 @@ public static function evaluate_submission($submissionid, $feedbacktext = '', $f
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function evaluate_submission_returns() {
diff --git a/mod/workshop/classes/external/assessment_exporter.php b/mod/workshop/classes/external/assessment_exporter.php
index 9fdfbafa3250a..c18e1ca2fd6b0 100644
--- a/mod/workshop/classes/external/assessment_exporter.php
+++ b/mod/workshop/classes/external/assessment_exporter.php
@@ -26,8 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_util;
-use external_files;
+use core_external\util as external_util;
+use core_external\external_files;
/**
* Class for exporting assessment data.
diff --git a/mod/workshop/classes/external/submission_exporter.php b/mod/workshop/classes/external/submission_exporter.php
index 8bb4c451882e9..553e8ec74ef1e 100644
--- a/mod/workshop/classes/external/submission_exporter.php
+++ b/mod/workshop/classes/external/submission_exporter.php
@@ -26,8 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_util;
-use external_files;
+use core_external\util as external_util;
+use core_external\external_files;
/**
* Class for exporting submission data.
diff --git a/mod/workshop/classes/external/workshop_summary_exporter.php b/mod/workshop/classes/external/workshop_summary_exporter.php
index 02c12d2134ac4..d00f2e7c1ff0f 100644
--- a/mod/workshop/classes/external/workshop_summary_exporter.php
+++ b/mod/workshop/classes/external/workshop_summary_exporter.php
@@ -26,8 +26,8 @@
use core\external\exporter;
use renderer_base;
-use external_util;
-use external_files;
+use core_external\util as external_util;
+use core_external\external_files;
/**
* Class for exporting partial workshop data (some fields are only viewable by admins).
diff --git a/mod/workshop/tests/external/external_test.php b/mod/workshop/tests/external/external_test.php
index e8906a0ed721f..c86c17294a777 100644
--- a/mod/workshop/tests/external/external_test.php
+++ b/mod/workshop/tests/external/external_test.php
@@ -26,11 +26,10 @@
namespace mod_workshop\external;
+use core_external\external_api;
use externallib_advanced_testcase;
-use workshop;
use mod_workshop_external;
-use mod_workshop\external\workshop_summary_exporter;
-use mod_workshop\external\submission_exporter;
+use workshop;
defined('MOODLE_INTERNAL') || die();
@@ -197,14 +196,14 @@ public function test_mod_workshop_get_workshops_by_courses() {
// Call the external function passing course ids.
$result = mod_workshop_external::get_workshops_by_courses(array($course2->id, $this->course->id));
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedworkshops, $result['workshops']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_workshop_external::get_workshops_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedworkshops, $result['workshops']);
$this->assertCount(0, $result['warnings']);
@@ -214,7 +213,7 @@ public function test_mod_workshop_get_workshops_by_courses() {
// Call the external function without passing course id.
$result = mod_workshop_external::get_workshops_by_courses();
- $result = \external_api::clean_returnvalue($returndescription, $result);
+ $result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedworkshops, $result['workshops']);
// Call for the second course we unenrolled the user from, expected warning.
@@ -231,7 +230,7 @@ public function test_mod_workshop_get_workshop_access_information_student() {
self::setUser($this->student);
$result = mod_workshop_external::get_workshop_access_information($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
// Check default values for capabilities.
$enabledcaps = array('canpeerassess', 'cansubmit', 'canview', 'canviewauthornames', 'canviewauthorpublished',
'canviewpublishedsubmissions', 'canexportsubmissions');
@@ -254,7 +253,7 @@ public function test_mod_workshop_get_workshop_access_information_student() {
accesslib_clear_all_caches_for_unit_testing();
$result = mod_workshop_external::get_workshop_access_information($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
foreach ($result as $capname => $capvalue) {
if (strpos($capname, 'can') !== 0) {
continue;
@@ -278,7 +277,7 @@ public function test_mod_workshop_get_workshop_access_information_student() {
$workshop = new workshop($this->workshop, $this->cm, $this->course);
$workshop->switch_phase(workshop::PHASE_SUBMISSION);
$result = mod_workshop_external::get_workshop_access_information($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
$this->assertTrue($result['creatingsubmissionallowed']);
$this->assertTrue($result['modifyingsubmissionallowed']);
@@ -290,7 +289,7 @@ public function test_mod_workshop_get_workshop_access_information_student() {
// Switch to next (to assessment).
$workshop->switch_phase(workshop::PHASE_ASSESSMENT);
$result = mod_workshop_external::get_workshop_access_information($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
$this->assertFalse($result['creatingsubmissionallowed']);
$this->assertFalse($result['modifyingsubmissionallowed']);
@@ -307,7 +306,7 @@ public function test_mod_workshop_get_workshop_access_information_teacher() {
self::setUser($this->teacher);
$result = mod_workshop_external::get_workshop_access_information($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_workshop_access_information_returns(), $result);
// Check default values.
$disabledcaps = array('canpeerassess', 'cansubmit');
@@ -336,7 +335,7 @@ public function test_mod_workshop_get_user_plan_student() {
self::setUser($this->student);
$result = mod_workshop_external::get_user_plan($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
$this->assertCount(0, $result['userplan']['examples']); // No examples given.
$this->assertCount(5, $result['userplan']['phases']); // Always 5 phases.
@@ -348,7 +347,7 @@ public function test_mod_workshop_get_user_plan_student() {
$workshop->switch_phase(workshop::PHASE_SUBMISSION);
$result = mod_workshop_external::get_user_plan($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
$this->assertEquals(workshop::PHASE_SUBMISSION, $result['userplan']['phases'][1]['code']);
$this->assertTrue($result['userplan']['phases'][1]['active']); // We are now in submission phase.
@@ -361,7 +360,7 @@ public function test_mod_workshop_get_user_plan_teacher() {
self::setUser($this->teacher);
$result = mod_workshop_external::get_user_plan($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
$this->assertCount(0, $result['userplan']['examples']); // No examples given.
$this->assertCount(5, $result['userplan']['phases']); // Always 5 phases.
@@ -382,7 +381,7 @@ public function test_mod_workshop_get_user_plan_teacher() {
$workshop->switch_phase(workshop::PHASE_SUBMISSION);
$result = mod_workshop_external::get_user_plan($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
foreach ($result['userplan']['phases'][0]['tasks'] as $task) {
if ($task['code'] == 'intro' || $task['code'] == 'instructauthors' || $task['code'] == 'editform' ||
$task['code'] == 'switchtonextphase') {
@@ -393,7 +392,7 @@ public function test_mod_workshop_get_user_plan_teacher() {
}
$result = mod_workshop_external::get_user_plan($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_user_plan_returns(), $result);
$this->assertEquals(workshop::PHASE_SUBMISSION, $result['userplan']['phases'][1]['code']);
$this->assertTrue($result['userplan']['phases'][1]['active']); // We are now in submission phase.
@@ -429,7 +428,7 @@ public function test_view_workshop_user_student() {
$sink = $this->redirectEvents();
$result = mod_workshop_external::view_workshop($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::view_workshop_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::view_workshop_returns(), $result);
$this->assertTrue($result['status']);
$events = $sink->get_events();
@@ -501,7 +500,7 @@ public function test_add_submission() {
$result = mod_workshop_external::add_submission($this->workshop->id, $title, $content, FORMAT_MOODLE, $draftidinlineattach,
$draftidattach);
- $result = \external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
$this->assertEmpty($result['warnings']);
// Check submission created.
@@ -581,11 +580,11 @@ public function test_add_submission_already_added() {
// Create the submission.
$result = mod_workshop_external::add_submission($this->workshop->id, 'My submission', '', FORMAT_MOODLE, 0, $draftidattach);
- $result = \external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
// Try to create it again.
$result = mod_workshop_external::add_submission($this->workshop->id, 'My submission', '', FORMAT_MOODLE, 0, $draftidattach);
- $result = \external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::add_submission_returns(), $result);
$this->assertFalse($result['status']);
$this->assertArrayNotHasKey('submissionid', $result);
$this->assertCount(1, $result['warnings']);
@@ -677,7 +676,7 @@ public function test_update_submission() {
$result = mod_workshop_external::update_submission($submissionid, $title, $content, FORMAT_MOODLE, $draftidinlineattach,
$draftidattach);
- $result = \external_api::clean_returnvalue(mod_workshop_external::update_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::update_submission_returns(), $result);
$this->assertEmpty($result['warnings']);
// Check submission updated.
@@ -765,7 +764,7 @@ public function test_delete_submission() {
$sink = $this->redirectEvents();
$result = mod_workshop_external::delete_submission($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::delete_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::delete_submission_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertTrue($result['status']);
$workshop = new workshop($this->workshop, $this->cm, $this->course);
@@ -827,7 +826,7 @@ public function test_delete_submission_as_teacher() {
$this->setUser($this->teacher);
$result = mod_workshop_external::delete_submission($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::delete_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::delete_submission_returns(), $result);
$this->assertEmpty($result['warnings']);
$this->assertTrue($result['status']);
}
@@ -858,7 +857,7 @@ public function test_get_submissions_student() {
$this->setUser($this->student);
$result = mod_workshop_external::get_submissions($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
// We should get just our submission.
$this->assertCount(1, $result['submissions']);
$this->assertEquals(1, $result['totalcount']);
@@ -891,7 +890,7 @@ public function test_get_submissions_published_student() {
$this->setUser($this->student);
$result = mod_workshop_external::get_submissions($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
// We should get just our submission.
$this->assertCount(1, $result['submissions']);
$this->assertEquals(1, $result['totalcount']);
@@ -900,7 +899,7 @@ public function test_get_submissions_published_student() {
// Check with group restrictions.
$this->setUser($this->anotherstudentg2);
$result = mod_workshop_external::get_submissions($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
$this->assertCount(0, $result['submissions']); // I can't see other users in separated groups.
$this->assertEquals(0, $result['totalcount']);
}
@@ -932,7 +931,7 @@ public function test_get_submissions_from_student_with_feedback_from_teacher() {
$this->setUser($this->teacher);
$result = mod_workshop_external::get_submissions($this->workshop->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
// We should get just our submission.
$this->assertEquals(1, $result['totalcount']);
$this->assertEquals($submissionid, $result['submissions'][0]['id']);
@@ -951,23 +950,23 @@ public function test_get_submissions_from_students_as_teacher() {
$this->setUser($this->teacher);
$result = mod_workshop_external::get_submissions($this->workshop->id); // Get all.
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
$this->assertEquals(3, $result['totalcount']);
$this->assertCount(3, $result['submissions']);
$result = mod_workshop_external::get_submissions($this->workshop->id, 0, 0, 0, 2); // Check pagination.
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
$this->assertEquals(3, $result['totalcount']);
$this->assertCount(2, $result['submissions']);
$result = mod_workshop_external::get_submissions($this->workshop->id, 0, $this->group2->id); // Get group 2.
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
$this->assertEquals(1, $result['totalcount']);
$this->assertCount(1, $result['submissions']);
$this->assertEquals($submissionid3, $result['submissions'][0]['id']);
$result = mod_workshop_external::get_submissions($this->workshop->id, $this->anotherstudentg1->id); // Get one.
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submissions_returns(), $result);
$this->assertEquals(1, $result['totalcount']);
$this->assertEquals($submissionid2, $result['submissions'][0]['id']);
}
@@ -984,7 +983,7 @@ public function test_get_submission_student() {
$workshop->switch_phase(workshop::PHASE_CLOSED);
$this->setUser($this->student);
$result = mod_workshop_external::get_submission($firstsubmissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($firstsubmissionid, $result['submission']['id']);
$this->assertCount(1, $result['submission']['contentfiles']); // Check we retrieve submission text files.
$this->assertCount(1, $result['submission']['attachmentfiles']); // Check we retrieve attachment files.
@@ -997,7 +996,7 @@ public function test_get_submission_student() {
// Switch to a different phase (where feedback won't be available).
$workshop->switch_phase(workshop::PHASE_EVALUATION);
$result = mod_workshop_external::get_submission($firstsubmissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($firstsubmissionid, $result['submission']['id']);
$this->assertCount(1, $result['submission']['contentfiles']); // Check we retrieve submission text files.
$this->assertCount(1, $result['submission']['attachmentfiles']); // Check we retrieve attachment files.
@@ -1023,7 +1022,7 @@ public function test_get_submission_i_reviewed() {
// Now try to get the submission I just reviewed.
$this->setUser($this->anotherstudentg1);
$result = mod_workshop_external::get_submission($firstsubmissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($firstsubmissionid, $result['submission']['id']);
$this->assertCount(1, $result['submission']['contentfiles']); // Check we retrieve submission text files.
$this->assertCount(1, $result['submission']['attachmentfiles']); // Check we retrieve attachment files.
@@ -1061,7 +1060,7 @@ public function test_get_submission_published_student() {
$this->setUser($this->student);
$result = mod_workshop_external::get_submission($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($submissionid, $result['submission']['id']);
// Check that the student don't see the other student grade/feedback data even if is published.
// We should not see the grade or feedback information.
@@ -1102,7 +1101,7 @@ public function test_get_submission_from_student_with_feedback_from_teacher() {
$this->setUser($this->teacher);
$result = mod_workshop_external::get_submission($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($submissionid, $result['submission']['id']);
$this->assertEquals($record->feedbackauthor, $result['submission']['feedbackauthor']);
$this->assertEquals($record->gradeover, $result['submission']['gradeover']);
@@ -1112,7 +1111,7 @@ public function test_get_submission_from_student_with_feedback_from_teacher() {
// Go to phase where feedback and grades are not yet available.
$workshop->switch_phase(workshop::PHASE_SUBMISSION);
$result = mod_workshop_external::get_submission($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertArrayNotHasKey('feedbackauthor', $result['submission']);
$this->assertArrayNotHasKey('grade', $result['submission']);
$this->assertArrayNotHasKey('gradeover', $result['submission']);
@@ -1141,11 +1140,11 @@ public function test_get_submission_from_students_as_teacher() {
$this->setUser($this->teacher);
$result = mod_workshop_external::get_submission($submissionid1); // Get all.
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($submissionid1, $result['submission']['id']);
$result = mod_workshop_external::get_submission($submissionid3); // Get group 2.
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_returns(), $result);
$this->assertEquals($submissionid3, $result['submission']['id']);
}
@@ -1172,7 +1171,7 @@ public function test_get_submission_assessments_student() {
$workshop->switch_phase(workshop::PHASE_CLOSED);
$this->setUser($this->student);
$result = mod_workshop_external::get_submission_assessments($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_assessments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_assessments_returns(), $result);
$this->assertCount(2, $result['assessments']); // I received my two assessments.
foreach ($result['assessments'] as $assessment) {
if ($assessment['grade'] == 90) {
@@ -1219,7 +1218,7 @@ public function test_get_submission_assessments_teacher() {
$this->setUser($this->teacher);
$result = mod_workshop_external::get_submission_assessments($submissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_submission_assessments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_submission_assessments_returns(), $result);
$this->assertCount(1, $result['assessments']);
$this->assertEquals(50, $result['assessments'][0]['grade']);
$this->assertEquals($assessmentid, $result['assessments'][0]['id']);
@@ -1244,7 +1243,7 @@ public function test_get_assessment_author() {
$workshop->switch_phase(workshop::PHASE_CLOSED);
$this->setUser($this->anotherstudentg1);
$result = mod_workshop_external::get_assessment($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
$this->assertEquals($assessmentid, $result['assessment']['id']);
$this->assertEquals(90, $result['assessment']['grade']);
// I can't see the reviewer review.
@@ -1270,7 +1269,7 @@ public function test_get_assessment_reviewer() {
$workshop->switch_phase(workshop::PHASE_CLOSED);
$this->setUser($this->student);
$result = mod_workshop_external::get_assessment($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
$this->assertEquals($assessmentid, $result['assessment']['id']);
$this->assertEquals(90, $result['assessment']['grade']);
// I can see the reviewer review.
@@ -1296,7 +1295,7 @@ public function test_get_assessment_teacher() {
$workshop->switch_phase(workshop::PHASE_CLOSED);
$this->setUser($this->teacher);
$result = mod_workshop_external::get_assessment($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
$this->assertEquals($assessmentid, $result['assessment']['id']);
$this->assertEquals(90, $result['assessment']['grade']);
}
@@ -1361,7 +1360,7 @@ public function test_get_assessment_form_definition_reviewer_new_assessment() {
$workshop->switch_phase(workshop::PHASE_ASSESSMENT);
$this->setUser($this->student);
$result = mod_workshop_external::get_assessment_form_definition($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
$this->assertEquals(4, $result['dimenssionscount']); // We receive the expected 4 dimensions.
$this->assertEmpty($result['current']); // Assessment not yet done.
foreach ($result['fields'] as $field) {
@@ -1395,7 +1394,7 @@ public function test_get_assessment_form_definition_teacher_new_assessment() {
// Teachers need to be able to view assessments.
$this->setUser($this->teacher);
$result = mod_workshop_external::get_assessment_form_definition($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
$this->assertEquals(4, $result['dimenssionscount']);
}
@@ -1443,7 +1442,7 @@ public function test_get_reviewer_assessments() {
$this->setUser($this->student);
// Get my assessments.
$result = mod_workshop_external::get_reviewer_assessments($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_reviewer_assessments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_reviewer_assessments_returns(), $result);
$this->assertCount(2, $result['assessments']);
foreach ($result['assessments'] as $assessment) {
if ($assessment['id'] == $assessmentid1) {
@@ -1456,7 +1455,7 @@ public function test_get_reviewer_assessments() {
// Now, as teacher try to get the same student assessments.
$result = mod_workshop_external::get_reviewer_assessments($this->workshop->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_reviewer_assessments_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_reviewer_assessments_returns(), $result);
$this->assertCount(2, $result['assessments']);
$this->assertArrayNotHasKey('feedbackreviewer', $result['assessments'][0]);
}
@@ -1504,7 +1503,7 @@ public function test_update_assessment() {
$this->setUser($this->student);
// Get the form definition.
$result = mod_workshop_external::get_assessment_form_definition($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
// Prepare the data to be sent.
$data = $result['fields'];
@@ -1566,13 +1565,13 @@ public function test_update_assessment() {
// Update the assessment.
$result = mod_workshop_external::update_assessment($assessmentid, $data);
- $result = \external_api::clean_returnvalue(mod_workshop_external::update_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::update_assessment_returns(), $result);
$this->assertEquals(100, $result['rawgrade']);
$this->assertTrue($result['status']);
// Get the assessment and check it was updated properly.
$result = mod_workshop_external::get_assessment($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
$this->assertEquals(100, $result['assessment']['grade']);
$this->assertEquals($this->student->id, $result['assessment']['reviewerid']);
$this->assertEquals('Feedback for the author', $result['assessment']['feedbackauthor']);
@@ -1581,7 +1580,7 @@ public function test_update_assessment() {
// Now, get again the form and check we received the data we already sent.
$result = mod_workshop_external::get_assessment_form_definition($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_form_definition_returns(), $result);
foreach ($result['current'] as $currentdata) {
if (strpos($currentdata['name'], 'peercomment__idx_') === 0) {
$this->assertEquals('Some content', $currentdata['value']);
@@ -1619,7 +1618,7 @@ public function test_get_grades() {
// First retrieve my grades.
$this->setUser($this->student);
$result = mod_workshop_external::get_grades($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_grades_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($assessmentgrade['rawgrade'], $result['assessmentrawgrade']);
$this->assertEquals($submissiongrade['rawgrade'], $result['submissionrawgrade']);
@@ -1631,7 +1630,7 @@ public function test_get_grades() {
// Second, teacher retrieve user grades.
$this->setUser($this->teacher);
$result = mod_workshop_external::get_grades($this->workshop->id, $this->student->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_grades_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_grades_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertEquals($assessmentgrade['rawgrade'], $result['assessmentrawgrade']);
$this->assertEquals($submissiongrade['rawgrade'], $result['submissionrawgrade']);
@@ -1676,7 +1675,7 @@ public function test_evaluate_assessment() {
$gradinggradeover = 10;
$result = mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight,
$gradinggradeover);
- $result = \external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
$this->assertTrue($result['status']);
$assessment = $DB->get_record('workshop_assessments', array('id' => $assessmentid));
@@ -1688,7 +1687,7 @@ public function test_evaluate_assessment() {
$gradinggradeover = 100;
$result = mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight,
$gradinggradeover);
- $result = \external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
$this->assertFalse($result['status']);
$this->assertCount(2, $result['warnings']);
$found = 0;
@@ -1722,11 +1721,11 @@ public function test_evaluate_assessment_ignore_parameters() {
$gradinggradeover = 19;
$result = mod_workshop_external::evaluate_assessment($assessmentid, $feedbacktext, $feedbackformat, $weight,
$gradinggradeover);
- $result = \external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::evaluate_assessment_returns(), $result);
$this->assertTrue($result['status']);
$result = mod_workshop_external::get_assessment($assessmentid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_assessment_returns(), $result);
$this->assertNotEquals(10, $result['assessment']['weight']);
}
@@ -1772,7 +1771,7 @@ public function test_get_grades_report() {
$workshop->switch_phase(workshop::PHASE_CLOSED);
$this->setUser($this->teacher);
$result = mod_workshop_external::get_grades_report($this->workshop->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_grades_report_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_grades_report_returns(), $result);
$this->assertEquals(3, $result['report']['totalcount']); // Expect 3 potential submissions.
foreach ($result['report']['grades'] as $grade) {
@@ -1790,13 +1789,13 @@ public function test_get_grades_report() {
}
// Now check pagination.
$result = mod_workshop_external::get_grades_report($this->workshop->id, 0, 'lastname', 'ASC', 0, 1);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_grades_report_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_grades_report_returns(), $result);
$this->assertEquals(3, $result['report']['totalcount']); // Expect the total count.
$this->assertCount(1, $result['report']['grades']);
// Groups filtering.
$result = mod_workshop_external::get_grades_report($this->workshop->id, $this->group1->id);
- $result = \external_api::clean_returnvalue(mod_workshop_external::get_grades_report_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::get_grades_report_returns(), $result);
$this->assertEquals(2, $result['report']['totalcount']); // Expect the group count.
}
@@ -1832,7 +1831,7 @@ public function test_view_submission() {
$this->setUser($this->student);
$result = mod_workshop_external::view_submission($firstsubmissionid);
- $result = \external_api::clean_returnvalue(mod_workshop_external::view_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::view_submission_returns(), $result);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -1868,7 +1867,7 @@ public function test_evaluate_submission() {
$gradeover = 10;
$result = mod_workshop_external::evaluate_submission($submissionid, $feedbacktext, $feedbackformat, $published,
$gradeover);
- $result = \external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
$this->assertTrue($result['status']);
$submission = $DB->get_record('workshop_submissions', array('id' => $submissionid));
@@ -1893,7 +1892,7 @@ public function test_evaluate_submission_invalid_phase_for_override() {
$gradeover = 10;
$result = mod_workshop_external::evaluate_submission($submissionid, $feedbacktext, $feedbackformat, $published,
$gradeover);
- $result = \external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
$this->assertTrue($result['status']);
$submission = $DB->get_record('workshop_submissions', array('id' => $submissionid));
@@ -1937,7 +1936,7 @@ public function test_evaluate_submission_invalid_grade() {
$published = 1;
$gradeover = 150;
$result = mod_workshop_external::evaluate_submission($submissionid, $feedbacktext, $feedbackformat, $published, $gradeover);
- $result = \external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
+ $result = external_api::clean_returnvalue(mod_workshop_external::evaluate_submission_returns(), $result);
$this->assertCount(1, $result['warnings']);
$this->assertFalse($result['status']);
$this->assertEquals('gradeover', $result['warnings'][0]['item']);
diff --git a/notes/externallib.php b/notes/externallib.php
index 07459c747b510..d4b5a4fb7fe18 100644
--- a/notes/externallib.php
+++ b/notes/externallib.php
@@ -14,6 +14,14 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
+use core_external\external_api;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\util;
/**
* External notes API
@@ -26,7 +34,6 @@
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . "/notes/lib.php");
/**
@@ -140,7 +147,7 @@ public static function create_notes($notes = array()) {
case 'text':
$textformat = FORMAT_PLAIN;
default:
- $textformat = external_validate_format($note['format']);
+ $textformat = util::validate_format($note['format']);
break;
}
$dbnote->content = $note['text'];
@@ -185,7 +192,7 @@ public static function create_notes($notes = array()) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.2
*/
public static function create_notes_returns() {
@@ -252,7 +259,7 @@ public static function delete_notes($notes = array()) {
/**
* Returns description of delete_notes result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function delete_notes_returns() {
@@ -305,7 +312,7 @@ public static function get_notes($notes) {
$context = context_course::instance($note->courseid);
self::validate_context($context);
require_capability('moodle/notes:view', $context);
- list($gotnote['text'], $gotnote['format']) = external_format_text($note->content,
+ list($gotnote['text'], $gotnote['format']) = util::format_text($note->content,
$note->format,
$context->id,
'notes',
@@ -329,7 +336,7 @@ public static function get_notes($notes) {
/**
* Returns description of get_notes result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function get_notes_returns() {
@@ -408,7 +415,7 @@ public static function update_notes($notes = array()) {
$dbnote = new stdClass;
$dbnote->id = $note['id'];
$dbnote->content = $note['text'];
- $dbnote->format = external_validate_format($note['format']);
+ $dbnote->format = util::validate_format($note['format']);
// Get the state ('personal', 'course', 'site').
switch ($note['publishstate']) {
case 'personal':
@@ -447,7 +454,7 @@ public static function update_notes($notes = array()) {
/**
* Returns description of update_notes result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.5
*/
public static function update_notes_returns() {
@@ -485,16 +492,18 @@ public static function get_course_notes_parameters() {
* @since Moodle 2.9
*/
protected static function create_note_list($courseid, $context, $userid, $state, $author = 0) {
- $results = array();
+ $results = [];
$notes = note_list($courseid, $userid, $state, $author);
foreach ($notes as $key => $note) {
$note = (array)$note;
- list($note['content'], $note['format']) = external_format_text($note['content'],
- $note['format'],
- $context->id,
- '',
- '',
- 0);
+ [$note['content'], $note['format']] = util::format_text(
+ $note['content'],
+ $note['format'],
+ $context->id,
+ '',
+ '',
+ 0
+ );
$results[$key] = $note;
}
return $results;
@@ -588,7 +597,7 @@ public static function get_course_notes($courseid, $userid = 0) {
/**
* Returns array of note structure
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
protected static function get_note_structure() {
@@ -608,7 +617,7 @@ protected static function get_note_structure() {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function get_course_notes_returns() {
@@ -708,7 +717,7 @@ public static function view_notes($courseid, $userid = 0) {
/**
* Returns description of method result value
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 2.9
*/
public static function view_notes_returns() {
diff --git a/notes/tests/externallib_test.php b/notes/tests/externallib_test.php
index 61ca6245a73f2..e425ac191cd4d 100644
--- a/notes/tests/externallib_test.php
+++ b/notes/tests/externallib_test.php
@@ -25,6 +25,7 @@
namespace core_notes;
+use core_external\external_api;
use core_notes_external;
use externallib_advanced_testcase;
@@ -64,7 +65,7 @@ public function test_create_notes() {
$creatednotes = core_notes_external::create_notes($notes);
// We need to execute the return values cleaning process to simulate the web service server.
- $creatednotes = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
+ $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$thenote = $DB->get_record('post', array('id' => $creatednotes[0]['noteid']));
@@ -103,11 +104,11 @@ public function test_delete_notes() {
$cnote['clientnoteid'] = 4;
$cnotes = array($cnote);
$creatednotes = core_notes_external::create_notes($cnotes);
- $creatednotes = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
+ $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$dnotes1 = array($creatednotes[0]['noteid']);
$deletednotes1 = core_notes_external::delete_notes($dnotes1);
- $deletednotes1 = \external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes1);
+ $deletednotes1 = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes1);
// Confirm that base note data was deleted correctly.
$notdeletedcount = $DB->count_records_select('post', 'id = ' . $creatednotes[0]['noteid']);
@@ -115,7 +116,7 @@ public function test_delete_notes() {
$dnotes2 = array(33); // This note does not exist.
$deletednotes2 = core_notes_external::delete_notes($dnotes2);
- $deletednotes2 = \external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes2);
+ $deletednotes2 = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes2);
$this->assertEquals("note", $deletednotes2[0]["item"]);
$this->assertEquals(33, $deletednotes2[0]["itemid"]);
@@ -124,13 +125,13 @@ public function test_delete_notes() {
// Call without required capability.
$creatednotes = core_notes_external::create_notes($cnotes);
- $creatednotes = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
+ $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$dnotes3 = array($creatednotes[0]['noteid']);
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
$this->expectException('\required_capability_exception');
$deletednotes = core_notes_external::delete_notes($dnotes3);
- $deletednotes = \external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes);
+ $deletednotes = external_api::clean_returnvalue(core_notes_external::delete_notes_returns(), $deletednotes);
}
public function test_get_notes() {
@@ -159,14 +160,14 @@ public function test_get_notes() {
$creatednotes2 = core_notes_external::create_notes($cnotes);
$creatednotes3 = core_notes_external::create_notes($cnotes);
- $creatednotes1 = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes1);
- $creatednotes2 = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes2);
- $creatednotes3 = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes3);
+ $creatednotes1 = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes1);
+ $creatednotes2 = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes2);
+ $creatednotes3 = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes3);
// Note 33 does not exist.
$gnotes = array($creatednotes1[0]['noteid'], $creatednotes2[0]['noteid'], $creatednotes3[0]['noteid'], 33);
$getnotes = core_notes_external::get_notes($gnotes);
- $getnotes = \external_api::clean_returnvalue(core_notes_external::get_notes_returns(), $getnotes);
+ $getnotes = external_api::clean_returnvalue(core_notes_external::get_notes_returns(), $getnotes);
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
// Confirm that base note data was retrieved correctly.
@@ -217,7 +218,7 @@ public function test_update_notes() {
$notes1 = array($note1, $note2, $note3);
$creatednotes = core_notes_external::create_notes($notes1);
- $creatednotes = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
+ $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$note2 = array();
$note2["id"] = $creatednotes[0]['noteid'];
@@ -228,7 +229,7 @@ public function test_update_notes() {
$updatednotes = core_notes_external::update_notes($notes2);
- $updatednotes = \external_api::clean_returnvalue(core_notes_external::update_notes_returns(), $updatednotes);
+ $updatednotes = external_api::clean_returnvalue(core_notes_external::update_notes_returns(), $updatednotes);
$thenote = $DB->get_record('post', array('id' => $creatednotes[0]['noteid']));
// Confirm that base note data was updated correctly.
@@ -237,7 +238,7 @@ public function test_update_notes() {
// Call without required capability.
$creatednotes = core_notes_external::create_notes($notes1);
- $creatednotes = \external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
+ $creatednotes = external_api::clean_returnvalue(core_notes_external::create_notes_returns(), $creatednotes);
$this->unassignUserCapability('moodle/notes:manage', $contextid, $roleid);
$this->expectException('\required_capability_exception');
$note2 = array();
@@ -247,7 +248,7 @@ public function test_update_notes() {
$note2['format'] = FORMAT_HTML;
$notes2 = array($note2);
$updatednotes = core_notes_external::update_notes($notes2);
- $updatednotes = \external_api::clean_returnvalue(core_notes_external::update_notes_returns(), $updatednotes);
+ $updatednotes = external_api::clean_returnvalue(core_notes_external::update_notes_returns(), $updatednotes);
}
/**
@@ -310,7 +311,7 @@ public function test_get_course_notes() {
// Retrieve notes, normal case.
$result = core_notes_external::get_course_notes($course1->id, $student1->id);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEquals($notes1->id, $result['sitenotes'][0]['id']);
$this->assertCount(2, $result['coursenotes']);
// Teacher can manage only the course notes.
@@ -334,7 +335,7 @@ public function test_get_course_notes() {
}
$result = core_notes_external::get_course_notes(0, $student1->id);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEmpty($result['sitenotes']);
// Teacher can't manage system notes.
$this->assertFalse($result['canmanagesystemnotes']);
@@ -350,7 +351,7 @@ public function test_get_course_notes() {
$this->setAdminUser();
$result = core_notes_external::get_course_notes(0, $student1->id);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEquals($notes1->id, $result['sitenotes'][0]['id']);
$this->assertCount(1, $result['sitenotes']);
// Admin user can manage both system and course notes.
@@ -359,7 +360,7 @@ public function test_get_course_notes() {
$this->setUser($teacher1);
$result = core_notes_external::get_course_notes(0, 0);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEmpty($result['sitenotes']);
$this->assertEmpty($result['coursenotes']);
$this->assertEmpty($result['personalnotes']);
@@ -369,7 +370,7 @@ public function test_get_course_notes() {
$this->setUser($teacher2);
$result = core_notes_external::get_course_notes($course1->id, $student1->id);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEquals($notes1->id, $result['sitenotes'][0]['id']);
foreach ($result['coursenotes'] as $coursenote) {
@@ -385,7 +386,7 @@ public function test_get_course_notes() {
$this->assertTrue($result['canmanagecoursenotes']);
$result = core_notes_external::get_course_notes($course1->id, 0);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEquals($notes1->id, $result['sitenotes'][0]['id']);
foreach ($result['coursenotes'] as $coursenote) {
@@ -399,7 +400,7 @@ public function test_get_course_notes() {
$this->setUser($teacher1);
$result = core_notes_external::get_course_notes($course1->id, 0);
- $result = \external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::get_course_notes_returns(), $result);
$this->assertEquals($notep1->id, $result['personalnotes'][0]['id']);
$this->assertCount(1, $result['personalnotes']);
// Teacher can manage only the course notes.
@@ -443,10 +444,10 @@ public function test_view_notes() {
$sink = $this->redirectEvents();
$result = core_notes_external::view_notes($course->id, $student->id);
- $result = \external_api::clean_returnvalue(core_notes_external::view_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::view_notes_returns(), $result);
$result = core_notes_external::view_notes($course->id);
- $result = \external_api::clean_returnvalue(core_notes_external::view_notes_returns(), $result);
+ $result = external_api::clean_returnvalue(core_notes_external::view_notes_returns(), $result);
$events = $sink->get_events();
diff --git a/payment/classes/external/get_available_gateways.php b/payment/classes/external/get_available_gateways.php
index b926a3fe73f34..0997f3d592c27 100644
--- a/payment/classes/external/get_available_gateways.php
+++ b/payment/classes/external/get_available_gateways.php
@@ -25,15 +25,11 @@
namespace core_payment\external;
use core_payment\helper;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
class get_available_gateways extends external_api {
diff --git a/payment/gateway/paypal/classes/external/get_config_for_js.php b/payment/gateway/paypal/classes/external/get_config_for_js.php
index 342e483bee948..584b50512d075 100644
--- a/payment/gateway/paypal/classes/external/get_config_for_js.php
+++ b/payment/gateway/paypal/classes/external/get_config_for_js.php
@@ -27,14 +27,10 @@
namespace paygw_paypal\external;
use core_payment\helper;
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_value;
+use core_external\external_single_structure;
class get_config_for_js extends external_api {
diff --git a/payment/gateway/paypal/classes/external/transaction_complete.php b/payment/gateway/paypal/classes/external/transaction_complete.php
index 891028017f8d9..c7120d878eed4 100644
--- a/payment/gateway/paypal/classes/external/transaction_complete.php
+++ b/payment/gateway/paypal/classes/external/transaction_complete.php
@@ -26,17 +26,13 @@
namespace paygw_paypal\external;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_payment\helper;
-use external_api;
-use external_function_parameters;
-use external_value;
use core_payment\helper as payment_helper;
use paygw_paypal\paypal_helper;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
class transaction_complete extends external_api {
/**
diff --git a/question/bank/columnsortorder/classes/external/set_columnbank_order.php b/question/bank/columnsortorder/classes/external/set_columnbank_order.php
index cf2fcc2f73df8..a0f9613e2ff3f 100644
--- a/question/bank/columnsortorder/classes/external/set_columnbank_order.php
+++ b/question/bank/columnsortorder/classes/external/set_columnbank_order.php
@@ -17,10 +17,10 @@
namespace qbank_columnsortorder\external;
use context_system;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_value;
use qbank_columnsortorder\column_manager;
/**
diff --git a/question/bank/editquestion/classes/external/update_question_version_status.php b/question/bank/editquestion/classes/external/update_question_version_status.php
index 0fd9e7344f2f4..dc8fcfbd65e74 100644
--- a/question/bank/editquestion/classes/external/update_question_version_status.php
+++ b/question/bank/editquestion/classes/external/update_question_version_status.php
@@ -18,13 +18,12 @@
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/question/engine/bank.php');
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use qbank_editquestion\editquestion_helper;
use question_bank;
@@ -36,7 +35,7 @@
* @author Safat Shahin
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class update_question_version_status extends \external_api {
+class update_question_version_status extends external_api {
/**
* Returns description of method parameters.
diff --git a/question/bank/tagquestion/classes/external/submit_tags.php b/question/bank/tagquestion/classes/external/submit_tags.php
index db49f9350b603..c6087af5f7884 100644
--- a/question/bank/tagquestion/classes/external/submit_tags.php
+++ b/question/bank/tagquestion/classes/external/submit_tags.php
@@ -18,16 +18,15 @@
defined('MOODLE_INTERNAL') || die();
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/question/engine/lib.php');
require_once($CFG->dirroot . '/question/engine/datalib.php');
require_once($CFG->libdir . '/questionlib.php');
use core_tag_tag;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_single_structure;
+use core_external\external_value;
use qbank_tagquestion\form\tags_form;
/**
diff --git a/question/bank/viewquestionname/lib.php b/question/bank/viewquestionname/lib.php
index 281dab854b6ca..ff6f3d50b67c3 100644
--- a/question/bank/viewquestionname/lib.php
+++ b/question/bank/viewquestionname/lib.php
@@ -23,6 +23,20 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_files;
+use core_external\external_format_value;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_settings;
+use core_external\external_single_structure;
+use core_external\external_value;
+use core_external\external_warnings;
+use core_external\restricted_context_exception;
+use core_external\util;
+use core_external\util as external_util;
+
/**
* In place editing callback for question name.
*
@@ -43,7 +57,7 @@ function qbank_viewquestionname_inplace_editable ($itemtype, $itemid, $newvalue)
question_require_capability_on($question, 'edit');
// Context validation.
- \external_api::validate_context(context::instance_by_id($question->contextid));
+ external_api::validate_context(context::instance_by_id($question->contextid));
// Now update the question data.
$record->name = $newvalue;
diff --git a/question/classes/external.php b/question/classes/external.php
index 9d535c23c23c7..e324434288605 100644
--- a/question/classes/external.php
+++ b/question/classes/external.php
@@ -24,9 +24,16 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
+
defined('MOODLE_INTERNAL') || die();
-require_once("$CFG->libdir/externallib.php");
require_once($CFG->dirroot . '/question/engine/lib.php');
require_once($CFG->dirroot . '/question/engine/datalib.php');
require_once($CFG->libdir . '/questionlib.php');
diff --git a/rating/classes/external.php b/rating/classes/external.php
index 06e6580895c2e..3187cb0233f0d 100644
--- a/rating/classes/external.php
+++ b/rating/classes/external.php
@@ -26,9 +26,15 @@
defined('MOODLE_INTERNAL') || die;
-require_once("$CFG->libdir/externallib.php");
require_once("$CFG->dirroot/rating/lib.php");
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
+
/**
* Rating external functions
*
diff --git a/rating/classes/external/util.php b/rating/classes/external/util.php
index 39b165243c87e..463735e8184ce 100644
--- a/rating/classes/external/util.php
+++ b/rating/classes/external/util.php
@@ -27,11 +27,10 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/rating/lib.php');
-require_once($CFG->libdir . '/externallib.php');
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use rating_manager;
use stdClass;
diff --git a/rating/tests/externallib_test.php b/rating/tests/externallib_test.php
index ec4723354e41f..32d16c3b2bf68 100644
--- a/rating/tests/externallib_test.php
+++ b/rating/tests/externallib_test.php
@@ -25,6 +25,7 @@
namespace core_rating;
+use core_external\external_api;
use core_rating_external;
use externallib_advanced_testcase;
@@ -129,7 +130,7 @@ public function test_get_item_ratings() {
$ratings = core_rating_external::get_item_ratings('module', $this->forum->cmid, 'mod_forum', 'post', $this->post->id, 100, '');
// We need to execute the return values cleaning process to simulate the web service server.
- $ratings = \external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
+ $ratings = external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
$this->assertCount(2, $ratings['ratings']);
$indexedratings = array();
@@ -147,7 +148,7 @@ public function test_get_item_ratings() {
$ratings = core_rating_external::get_item_ratings('module', $this->forum->cmid, 'mod_forum', 'post', $this->post->id, 100, '');
// We need to execute the return values cleaning process to simulate the web service server.
- $ratings = \external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
+ $ratings = external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
$this->assertCount(2, $ratings['ratings']);
// Invalid item.
@@ -186,7 +187,7 @@ public function test_get_item_ratings() {
$this->setUser($this->teacher1);
$ratings = core_rating_external::get_item_ratings('module', $this->forum->cmid, 'mod_forum', 'post', $this->post->id, 100, '');
// We need to execute the return values cleaning process to simulate the web service server.
- $ratings = \external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
+ $ratings = external_api::clean_returnvalue(core_rating_external::get_item_ratings_returns(), $ratings);
$this->assertCount(2, $ratings['ratings']);
$this->setUser($this->teacher3);
@@ -209,7 +210,7 @@ public function test_add_rating() {
$rating = core_rating_external::add_rating('module', $this->forum->cmid, 'mod_forum', 'post', $this->post->id, 100,
50, $this->student1->id, RATING_AGGREGATE_AVERAGE);
// We need to execute the return values cleaning process to simulate the web service server.
- $rating = \external_api::clean_returnvalue(core_rating_external::add_rating_returns(), $rating);
+ $rating = external_api::clean_returnvalue(core_rating_external::add_rating_returns(), $rating);
$this->assertTrue($rating['success']);
$this->assertEquals(50, $rating['aggregate']);
$this->assertEquals(1, $rating['count']);
@@ -217,7 +218,7 @@ public function test_add_rating() {
// New different rate (it will replace the existing one).
$rating = core_rating_external::add_rating('module', $this->forum->cmid, 'mod_forum', 'post', $this->post->id, 100,
100, $this->student1->id, RATING_AGGREGATE_AVERAGE);
- $rating = \external_api::clean_returnvalue(core_rating_external::add_rating_returns(), $rating);
+ $rating = external_api::clean_returnvalue(core_rating_external::add_rating_returns(), $rating);
$this->assertTrue($rating['success']);
$this->assertEquals(100, $rating['aggregate']);
$this->assertEquals(1, $rating['count']);
@@ -226,7 +227,7 @@ public function test_add_rating() {
$this->setUser($this->teacher2);
$rating = core_rating_external::add_rating('module', $this->forum->cmid, 'mod_forum', 'post', $this->post->id, 100,
50, $this->student1->id, RATING_AGGREGATE_AVERAGE);
- $rating = \external_api::clean_returnvalue(core_rating_external::add_rating_returns(), $rating);
+ $rating = external_api::clean_returnvalue(core_rating_external::add_rating_returns(), $rating);
$this->assertEquals(75, $rating['aggregate']);
$this->assertEquals(2, $rating['count']);
diff --git a/report/competency/classes/external.php b/report/competency/classes/external.php
index d432e3c1e5247..3f194684c4c49 100644
--- a/report/competency/classes/external.php
+++ b/report/competency/classes/external.php
@@ -14,33 +14,23 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external API for this report.
- *
- * @package report_competency
- * @copyright 2015 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace report_competency;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
use context_course;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
use core_competency\external\user_competency_course_exporter;
+use core_course\external\course_summary_exporter;
+use core_external\external_api;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use core_user\external\user_summary_exporter;
use tool_lp\external\competency_summary_exporter;
-use core_course\external\course_summary_exporter;
/**
* This is the external API for this report.
*
+ * @package report_competency
* @copyright 2015 Damyon Wiese
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -49,7 +39,7 @@ class external extends external_api {
/**
* Returns description of data_for_competency_frameworks_manage_page() parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
public static function data_for_report_parameters() {
$courseid = new external_value(
@@ -111,7 +101,7 @@ public static function data_for_report($courseid, $userid, $moduleid) {
/**
* Returns description of data_for_report() result value.
*
- * @return \external_description
+ * @return external_description
*/
public static function data_for_report_returns() {
return new external_single_structure(array (
diff --git a/report/insights/classes/external.php b/report/insights/classes/external.php
index 737ff32ef9807..f8dd4b58416d9 100644
--- a/report/insights/classes/external.php
+++ b/report/insights/classes/external.php
@@ -14,30 +14,19 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This is the external API for this component.
- *
- * @package report_insights
- * @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace report_insights;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-
-use external_api;
-use external_function_parameters;
-use external_value;
-use external_single_structure;
-use external_multiple_structure;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
/**
* This is the external API for this component.
*
+ * @package report_insights
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -79,7 +68,7 @@ public static function set_notuseful_prediction($predictionid) {
/**
* set_notuseful_prediction return
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function set_notuseful_prediction_returns() {
@@ -134,7 +123,7 @@ public static function set_fixed_prediction($predictionid) {
/**
* set_fixed_prediction return
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.4
*/
public static function set_fixed_prediction_returns() {
@@ -197,7 +186,7 @@ public static function action_executed(string $actionname, array $predictionids)
/**
* action_executed return
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.8
*/
public static function action_executed_returns() {
diff --git a/reportbuilder/classes/external/audiences/delete.php b/reportbuilder/classes/external/audiences/delete.php
index a84610d7881a7..469d958764be0 100644
--- a/reportbuilder/classes/external/audiences/delete.php
+++ b/reportbuilder/classes/external/audiences/delete.php
@@ -19,17 +19,12 @@
namespace core_reportbuilder\external\audiences;
use core_reportbuilder\local\audiences\base;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for deleting a report audience
*
diff --git a/reportbuilder/classes/external/columns/add.php b/reportbuilder/classes/external/columns/add.php
index f79b163c24cbd..3ed497571eb67 100644
--- a/reportbuilder/classes/external/columns/add.php
+++ b/reportbuilder/classes/external/columns/add.php
@@ -19,19 +19,14 @@
namespace core_reportbuilder\external\columns;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for adding report columns
*
diff --git a/reportbuilder/classes/external/columns/delete.php b/reportbuilder/classes/external/columns/delete.php
index 270f177866b8b..afc8783974b50 100644
--- a/reportbuilder/classes/external/columns/delete.php
+++ b/reportbuilder/classes/external/columns/delete.php
@@ -19,19 +19,14 @@
namespace core_reportbuilder\external\columns;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for deleting report columns
*
diff --git a/reportbuilder/classes/external/columns/reorder.php b/reportbuilder/classes/external/columns/reorder.php
index d2624fc27447f..62ba6094edfd9 100644
--- a/reportbuilder/classes/external/columns/reorder.php
+++ b/reportbuilder/classes/external/columns/reorder.php
@@ -18,18 +18,13 @@
namespace core_reportbuilder\external\columns;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for re-ordering report columns
*
diff --git a/reportbuilder/classes/external/columns/sort/get.php b/reportbuilder/classes/external/columns/sort/get.php
index e2354b7c7ec81..4f163633e3402 100644
--- a/reportbuilder/classes/external/columns/sort/get.php
+++ b/reportbuilder/classes/external/columns/sort/get.php
@@ -18,19 +18,14 @@
namespace core_reportbuilder\external\columns\sort;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for retrieving report column sorting
*
diff --git a/reportbuilder/classes/external/columns/sort/reorder.php b/reportbuilder/classes/external/columns/sort/reorder.php
index 72482cb3a64de..04263cca03914 100644
--- a/reportbuilder/classes/external/columns/sort/reorder.php
+++ b/reportbuilder/classes/external/columns/sort/reorder.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\columns\sort;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for re-ordering report column sorting
*
diff --git a/reportbuilder/classes/external/columns/sort/toggle.php b/reportbuilder/classes/external/columns/sort/toggle.php
index 640d6f37663f7..11b18e54c295a 100644
--- a/reportbuilder/classes/external/columns/sort/toggle.php
+++ b/reportbuilder/classes/external/columns/sort/toggle.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\columns\sort;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
use core_reportbuilder\external\custom_report_columns_sorting_exporter;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for toggling report column sorting
*
diff --git a/reportbuilder/classes/external/conditions/add.php b/reportbuilder/classes/external/conditions/add.php
index 1210363b309f8..b9301dc093fa6 100644
--- a/reportbuilder/classes/external/conditions/add.php
+++ b/reportbuilder/classes/external/conditions/add.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\conditions;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for adding report conditions
*
diff --git a/reportbuilder/classes/external/conditions/delete.php b/reportbuilder/classes/external/conditions/delete.php
index 48a57cdf11cf8..d960c54d5ab80 100644
--- a/reportbuilder/classes/external/conditions/delete.php
+++ b/reportbuilder/classes/external/conditions/delete.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\conditions;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for deleting report conditions
*
diff --git a/reportbuilder/classes/external/conditions/reorder.php b/reportbuilder/classes/external/conditions/reorder.php
index fe97c327acf2e..ba7ac70693dc8 100644
--- a/reportbuilder/classes/external/conditions/reorder.php
+++ b/reportbuilder/classes/external/conditions/reorder.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\conditions;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for re-ordering report conditions
*
diff --git a/reportbuilder/classes/external/conditions/reset.php b/reportbuilder/classes/external/conditions/reset.php
index 6bea18b05eaff..55b06ec09b320 100644
--- a/reportbuilder/classes/external/conditions/reset.php
+++ b/reportbuilder/classes/external/conditions/reset.php
@@ -18,19 +18,14 @@
namespace core_reportbuilder\external\conditions;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_conditions_exporter;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for resetting report conditions
*
diff --git a/reportbuilder/classes/external/filters/add.php b/reportbuilder/classes/external/filters/add.php
index 2977ec93d6574..d2c69a58023a6 100644
--- a/reportbuilder/classes/external/filters/add.php
+++ b/reportbuilder/classes/external/filters/add.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\filters;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_filters_exporter;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for adding report filters
*
diff --git a/reportbuilder/classes/external/filters/delete.php b/reportbuilder/classes/external/filters/delete.php
index ee57495c0a458..77902bb6931d8 100644
--- a/reportbuilder/classes/external/filters/delete.php
+++ b/reportbuilder/classes/external/filters/delete.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\filters;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_filters_exporter;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for deleting report filters
*
diff --git a/reportbuilder/classes/external/filters/reorder.php b/reportbuilder/classes/external/filters/reorder.php
index 55cee5e581740..bc6ccb94fd59e 100644
--- a/reportbuilder/classes/external/filters/reorder.php
+++ b/reportbuilder/classes/external/filters/reorder.php
@@ -18,20 +18,15 @@
namespace core_reportbuilder\external\filters;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_filters_exporter;
use core_reportbuilder\local\helpers\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for re-ordering report filters
*
diff --git a/reportbuilder/classes/external/filters/reset.php b/reportbuilder/classes/external/filters/reset.php
index e6021900603c8..b999e4d087949 100644
--- a/reportbuilder/classes/external/filters/reset.php
+++ b/reportbuilder/classes/external/filters/reset.php
@@ -18,18 +18,13 @@
namespace core_reportbuilder\external\filters;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\user_filter_manager;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for resetting report filters
*
diff --git a/reportbuilder/classes/external/filters/set.php b/reportbuilder/classes/external/filters/set.php
index eb8eb33212bd0..68a8205a88f1f 100644
--- a/reportbuilder/classes/external/filters/set.php
+++ b/reportbuilder/classes/external/filters/set.php
@@ -18,17 +18,12 @@
namespace core_reportbuilder\external\filters;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for setting report filter values
*
diff --git a/reportbuilder/classes/external/reports/delete.php b/reportbuilder/classes/external/reports/delete.php
index c00e06dc2a0eb..9c05633a52e59 100644
--- a/reportbuilder/classes/external/reports/delete.php
+++ b/reportbuilder/classes/external/reports/delete.php
@@ -18,18 +18,13 @@
namespace core_reportbuilder\external\reports;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\report;
use core_reportbuilder\local\models\report as report_model;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for deleting reports
*
diff --git a/reportbuilder/classes/external/reports/get.php b/reportbuilder/classes/external/reports/get.php
index 01f0d8756e474..1835dd152d9be 100644
--- a/reportbuilder/classes/external/reports/get.php
+++ b/reportbuilder/classes/external/reports/get.php
@@ -18,21 +18,16 @@
namespace core_reportbuilder\external\reports;
-use external_api;
-use external_value;
-use external_single_structure;
-use external_function_parameters;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\output\custom_report;
use core_reportbuilder\external\custom_report_exporter;
use moodle_url;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for getting a custom report
*
diff --git a/reportbuilder/classes/external/reports/listing.php b/reportbuilder/classes/external/reports/listing.php
index e3509a6fec07d..5e19eea4ed3c3 100644
--- a/reportbuilder/classes/external/reports/listing.php
+++ b/reportbuilder/classes/external/reports/listing.php
@@ -19,23 +19,18 @@
namespace core_reportbuilder\external\reports;
use context_system;
-use external_api;
-use external_function_parameters;
-use external_multiple_structure;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
use stdClass;
use core_reportbuilder\permission;
use core_reportbuilder\external\custom_report_details_exporter;
use core_reportbuilder\local\helpers\audience;
use core_reportbuilder\local\models\report;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for listing users' custom reports
*
diff --git a/reportbuilder/classes/external/reports/retrieve.php b/reportbuilder/classes/external/reports/retrieve.php
index a0209343811a6..17256e3e6826a 100644
--- a/reportbuilder/classes/external/reports/retrieve.php
+++ b/reportbuilder/classes/external/reports/retrieve.php
@@ -19,19 +19,14 @@
namespace core_reportbuilder\external\reports;
use core_reportbuilder\manager;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
use core_reportbuilder\permission;
use core_reportbuilder\external\{custom_report_data_exporter, custom_report_details_exporter};
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for retrieving custom report content
*
diff --git a/reportbuilder/classes/external/reports/view.php b/reportbuilder/classes/external/reports/view.php
index fa6b4fed40fdc..c0ef63a296172 100644
--- a/reportbuilder/classes/external/reports/view.php
+++ b/reportbuilder/classes/external/reports/view.php
@@ -18,19 +18,15 @@
namespace core_reportbuilder\external\reports;
-use external_api;
-use external_function_parameters;
-use external_single_structure;
-use external_value;
-use external_warnings;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_single_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\event\report_viewed;
-defined('MOODLE_INTERNAL') || die();
-
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method to record the viewing of a report
*
diff --git a/reportbuilder/classes/external/schedules/delete.php b/reportbuilder/classes/external/schedules/delete.php
index ca4b24dcda943..caeab1788dbe2 100644
--- a/reportbuilder/classes/external/schedules/delete.php
+++ b/reportbuilder/classes/external/schedules/delete.php
@@ -18,18 +18,13 @@
namespace core_reportbuilder\external\schedules;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\schedule;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for deleting report schedules
*
diff --git a/reportbuilder/classes/external/schedules/send.php b/reportbuilder/classes/external/schedules/send.php
index 129f3bba06459..010482b5e7be9 100644
--- a/reportbuilder/classes/external/schedules/send.php
+++ b/reportbuilder/classes/external/schedules/send.php
@@ -18,18 +18,13 @@
namespace core_reportbuilder\external\schedules;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\task\send_schedule;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for sending report schedules
*
diff --git a/reportbuilder/classes/external/schedules/toggle.php b/reportbuilder/classes/external/schedules/toggle.php
index 8c380ca7aab32..85e64d6e90d17 100644
--- a/reportbuilder/classes/external/schedules/toggle.php
+++ b/reportbuilder/classes/external/schedules/toggle.php
@@ -18,18 +18,13 @@
namespace core_reportbuilder\external\schedules;
-use external_api;
-use external_function_parameters;
-use external_value;
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_function_parameters;
use core_reportbuilder\manager;
use core_reportbuilder\permission;
use core_reportbuilder\local\helpers\schedule;
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once("{$CFG->libdir}/externallib.php");
-
/**
* External method for toggling report schedules
*
diff --git a/reportbuilder/classes/output/report_name_editable.php b/reportbuilder/classes/output/report_name_editable.php
index ab29172e01221..03eca76d40755 100644
--- a/reportbuilder/classes/output/report_name_editable.php
+++ b/reportbuilder/classes/output/report_name_editable.php
@@ -18,18 +18,12 @@
namespace core_reportbuilder\output;
-use core_external;
use html_writer;
use moodle_url;
use core\output\inplace_editable;
use core_reportbuilder\permission;
use core_reportbuilder\local\models\report;
-defined('MOODLE_INTERNAL') || die;
-
-global $CFG;
-require_once("{$CFG->libdir}/external/externallib.php");
-
/**
* Report name editable component
*
@@ -73,7 +67,7 @@ public function __construct(int $reportid, ?report $report = null) {
public static function update(int $reportid, string $value): self {
$report = new report($reportid);
- core_external::validate_context($report->get_context());
+ \core_external\external_api::validate_context($report->get_context());
permission::require_can_edit_report($report);
$value = trim(clean_param($value, PARAM_TEXT));
diff --git a/reportbuilder/tests/external/audiences/delete_test.php b/reportbuilder/tests/external/audiences/delete_test.php
index c75ef74a830e0..8d87c30309225 100644
--- a/reportbuilder/tests/external/audiences/delete_test.php
+++ b/reportbuilder/tests/external/audiences/delete_test.php
@@ -21,7 +21,7 @@
use context_system;
use core_reportbuilder\local\models\audience;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/columns/add_test.php b/reportbuilder/tests/external/columns/add_test.php
index 2073aca9a3299..f8ca3651dd183 100644
--- a/reportbuilder/tests/external/columns/add_test.php
+++ b/reportbuilder/tests/external/columns/add_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\columns;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\column;
diff --git a/reportbuilder/tests/external/columns/delete_test.php b/reportbuilder/tests/external/columns/delete_test.php
index f54d175f5d680..5ba8d9ab45435 100644
--- a/reportbuilder/tests/external/columns/delete_test.php
+++ b/reportbuilder/tests/external/columns/delete_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\columns;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\column;
diff --git a/reportbuilder/tests/external/columns/reorder_test.php b/reportbuilder/tests/external/columns/reorder_test.php
index c39a7c937c2ee..ad727883b05f8 100644
--- a/reportbuilder/tests/external/columns/reorder_test.php
+++ b/reportbuilder/tests/external/columns/reorder_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\columns;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\column;
diff --git a/reportbuilder/tests/external/columns/sort/get_test.php b/reportbuilder/tests/external/columns/sort/get_test.php
index 805c10d7ac3f3..55dc19734710f 100644
--- a/reportbuilder/tests/external/columns/sort/get_test.php
+++ b/reportbuilder/tests/external/columns/sort/get_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\columns\sort;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/columns/sort/reorder_test.php b/reportbuilder/tests/external/columns/sort/reorder_test.php
index 96e9ce5b4bf0a..226cb2f21e10c 100644
--- a/reportbuilder/tests/external/columns/sort/reorder_test.php
+++ b/reportbuilder/tests/external/columns/sort/reorder_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\columns\sort;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\column;
diff --git a/reportbuilder/tests/external/columns/sort/toggle_test.php b/reportbuilder/tests/external/columns/sort/toggle_test.php
index 07f68c2b9a410..dd5bb53d4a4a2 100644
--- a/reportbuilder/tests/external/columns/sort/toggle_test.php
+++ b/reportbuilder/tests/external/columns/sort/toggle_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\columns\sort;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\column;
diff --git a/reportbuilder/tests/external/conditions/add_test.php b/reportbuilder/tests/external/conditions/add_test.php
index 73051f8baf38a..fc89ad9f47255 100644
--- a/reportbuilder/tests/external/conditions/add_test.php
+++ b/reportbuilder/tests/external/conditions/add_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\conditions;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\filter;
diff --git a/reportbuilder/tests/external/conditions/delete_test.php b/reportbuilder/tests/external/conditions/delete_test.php
index 81f63871887d6..9ef9bbc6e782d 100644
--- a/reportbuilder/tests/external/conditions/delete_test.php
+++ b/reportbuilder/tests/external/conditions/delete_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\conditions;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\filter;
diff --git a/reportbuilder/tests/external/conditions/reorder_test.php b/reportbuilder/tests/external/conditions/reorder_test.php
index dcad8a0d91339..bb0a5e648a9c9 100644
--- a/reportbuilder/tests/external/conditions/reorder_test.php
+++ b/reportbuilder/tests/external/conditions/reorder_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\conditions;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\filter;
diff --git a/reportbuilder/tests/external/conditions/reset_test.php b/reportbuilder/tests/external/conditions/reset_test.php
index 5145ef185a6f4..1538583c1baaa 100644
--- a/reportbuilder/tests/external/conditions/reset_test.php
+++ b/reportbuilder/tests/external/conditions/reset_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\conditions;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\manager;
use core_reportbuilder\report_access_exception;
diff --git a/reportbuilder/tests/external/filters/add_test.php b/reportbuilder/tests/external/filters/add_test.php
index bdfb55db37441..4e60a4aeca084 100644
--- a/reportbuilder/tests/external/filters/add_test.php
+++ b/reportbuilder/tests/external/filters/add_test.php
@@ -20,7 +20,7 @@
use core_reportbuilder\manager;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\filter;
diff --git a/reportbuilder/tests/external/filters/delete_test.php b/reportbuilder/tests/external/filters/delete_test.php
index 249333811abfe..249270592b6de 100644
--- a/reportbuilder/tests/external/filters/delete_test.php
+++ b/reportbuilder/tests/external/filters/delete_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\filters;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\filter;
diff --git a/reportbuilder/tests/external/filters/reorder_test.php b/reportbuilder/tests/external/filters/reorder_test.php
index 94c74ca670395..faa60a308debf 100644
--- a/reportbuilder/tests/external/filters/reorder_test.php
+++ b/reportbuilder/tests/external/filters/reorder_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\filters;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\filter;
diff --git a/reportbuilder/tests/external/filters/reset_test.php b/reportbuilder/tests/external/filters/reset_test.php
index ef0a67776a0b6..94a24d1fdfe50 100644
--- a/reportbuilder/tests/external/filters/reset_test.php
+++ b/reportbuilder/tests/external/filters/reset_test.php
@@ -21,7 +21,7 @@
use core_reportbuilder_generator;
use core_reportbuilder\manager;
use core_reportbuilder\report_access_exception;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/filters/set_test.php b/reportbuilder/tests/external/filters/set_test.php
index 8e0a1316d49ba..758a92f372c5a 100644
--- a/reportbuilder/tests/external/filters/set_test.php
+++ b/reportbuilder/tests/external/filters/set_test.php
@@ -21,7 +21,7 @@
use core_reportbuilder_generator;
use core_reportbuilder\manager;
use core_reportbuilder\report_access_exception;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/reports/delete_test.php b/reportbuilder/tests/external/reports/delete_test.php
index 7176a7b2fa7c3..592c9f263324b 100644
--- a/reportbuilder/tests/external/reports/delete_test.php
+++ b/reportbuilder/tests/external/reports/delete_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\reports;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\report;
diff --git a/reportbuilder/tests/external/reports/get_test.php b/reportbuilder/tests/external/reports/get_test.php
index e737cb3eba327..db56fd7098e91 100644
--- a/reportbuilder/tests/external/reports/get_test.php
+++ b/reportbuilder/tests/external/reports/get_test.php
@@ -20,7 +20,7 @@
use context_system;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/reports/listing_test.php b/reportbuilder/tests/external/reports/listing_test.php
index cb81798c5d8f7..8325f6d448768 100644
--- a/reportbuilder/tests/external/reports/listing_test.php
+++ b/reportbuilder/tests/external/reports/listing_test.php
@@ -20,7 +20,7 @@
use context_system;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\local\models\report;
diff --git a/reportbuilder/tests/external/reports/retrieve_test.php b/reportbuilder/tests/external/reports/retrieve_test.php
index 15b1ecd3d45f8..ac50ab448ac5d 100644
--- a/reportbuilder/tests/external/reports/retrieve_test.php
+++ b/reportbuilder/tests/external/reports/retrieve_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\reports;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/reports/view_test.php b/reportbuilder/tests/external/reports/view_test.php
index 2708e377e3ef8..a2b165de4fd1d 100644
--- a/reportbuilder/tests/external/reports/view_test.php
+++ b/reportbuilder/tests/external/reports/view_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\reports;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\event\report_viewed;
use core_reportbuilder\report_access_exception;
diff --git a/reportbuilder/tests/external/schedules/delete_test.php b/reportbuilder/tests/external/schedules/delete_test.php
index af0816718340b..3bfdea2f0f7aa 100644
--- a/reportbuilder/tests/external/schedules/delete_test.php
+++ b/reportbuilder/tests/external/schedules/delete_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\schedules;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_user\reportbuilder\datasource\users;
diff --git a/reportbuilder/tests/external/schedules/send_test.php b/reportbuilder/tests/external/schedules/send_test.php
index f66ec95158ecc..6ec59e27bce4d 100644
--- a/reportbuilder/tests/external/schedules/send_test.php
+++ b/reportbuilder/tests/external/schedules/send_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\schedules;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_reportbuilder\task\send_schedule;
diff --git a/reportbuilder/tests/external/schedules/toggle_test.php b/reportbuilder/tests/external/schedules/toggle_test.php
index cbb4d64a09ed3..b5bdc4f9493e0 100644
--- a/reportbuilder/tests/external/schedules/toggle_test.php
+++ b/reportbuilder/tests/external/schedules/toggle_test.php
@@ -19,7 +19,7 @@
namespace core_reportbuilder\external\schedules;
use core_reportbuilder_generator;
-use external_api;
+use core_external\external_api;
use externallib_advanced_testcase;
use core_reportbuilder\report_access_exception;
use core_user\reportbuilder\datasource\users;
diff --git a/search/classes/external.php b/search/classes/external.php
index 947d336a6fca1..6629f6069ca95 100644
--- a/search/classes/external.php
+++ b/search/classes/external.php
@@ -24,15 +24,11 @@
namespace core_search;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use core_user\external\user_summary_exporter;
-use \external_value;
-use \external_single_structure;
-use \external_multiple_structure;
-
-defined('MOODLE_INTERNAL') || die();
-
-global $CFG;
-require_once($CFG->libdir . '/externallib.php');
/**
* Handles external (web service) function calls related to search.
@@ -41,32 +37,35 @@
* @copyright 2017 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class external extends \external_api {
+class external extends \core_external\external_api {
/**
* Returns parameter types for get_relevant_users function.
*
- * @return \external_function_parameters Parameters
+ * @return external_function_parameters Parameters
*/
public static function get_relevant_users_parameters() {
- return new \external_function_parameters([
- 'query' => new external_value(PARAM_RAW,
- 'Query string (full or partial user full name or other details)'),
- 'courseid' => new external_value(PARAM_INT, 'Course id (0 if none)'),
- ]);
+ return new external_function_parameters([
+ 'query' => new external_value(
+ PARAM_RAW,
+ 'Query string (full or partial user full name or other details)'
+ ),
+ 'courseid' => new external_value(PARAM_INT, 'Course id (0 if none)'),
+ ]);
}
/**
* Returns result type for get_relevant_users function.
*
- * @return \external_description Result type
+ * @return external_description Result type
*/
public static function get_relevant_users_returns() {
return new external_multiple_structure(
- new external_single_structure([
- 'id' => new external_value(PARAM_INT, 'User id'),
- 'fullname' => new external_value(PARAM_RAW, 'Full name as text'),
- 'profileimageurlsmall' => new external_value(PARAM_URL, 'URL to small profile image')
- ]));
+ new external_single_structure([
+ 'id' => new external_value(PARAM_INT, 'User id'),
+ 'fullname' => new external_value(PARAM_RAW, 'Full name as text'),
+ 'profileimageurlsmall' => new external_value(PARAM_URL, 'URL to small profile image')
+ ])
+ );
}
/**
diff --git a/search/classes/output/form/search.php b/search/classes/output/form/search.php
index 1684cff3f9f83..2f6c4d2e2addb 100644
--- a/search/classes/output/form/search.php
+++ b/search/classes/output/form/search.php
@@ -29,7 +29,6 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->libdir . '/formslib.php');
-require_once($CFG->libdir . '/externallib.php');
class search extends \moodleform {
diff --git a/tag/classes/external.php b/tag/classes/external.php
index 6214f86ac02ad..8bea3c2e7ec2d 100644
--- a/tag/classes/external.php
+++ b/tag/classes/external.php
@@ -14,18 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Contains class core_tag_external
- *
- * @package core_tag
- * @copyright 2015 Marina Glancy
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
-require_once("$CFG->dirroot/webservice/externallib.php");
+use core_external\external_api;
+use core_external\external_value;
+use core_external\external_format_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
/**
* Tags-related web services
@@ -153,7 +148,7 @@ public static function update_tags($tags) {
/**
* Return structure for update_tag()
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function update_tags_returns() {
return new external_single_structure(
@@ -235,7 +230,7 @@ public static function get_tags($tags) {
/**
* Return structure for get_tag()
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_tags_returns() {
return new external_single_structure(
@@ -315,7 +310,7 @@ public static function get_tagindex($params) {
/**
* Return structure for get_tag()
*
- * @return external_description
+ * @return \core_external\external_description
*/
public static function get_tagindex_returns() {
return new external_single_structure(
@@ -445,7 +440,7 @@ public static function get_tagindex_per_area($params) {
/**
* Return structure for get_tagindex_per_area
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_tagindex_per_area_returns() {
@@ -507,7 +502,7 @@ public static function get_tag_areas() {
/**
* Returns description of get_tag_areas() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_tag_areas_returns() {
@@ -566,7 +561,7 @@ public static function get_tag_collections() {
/**
* Returns description of get_tag_collections() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_tag_collections_returns() {
@@ -657,7 +652,7 @@ public static function get_tag_cloud($tagcollid = 0, $isstandard = false, $limit
/**
* Returns description of get_tag_cloud() result value.
*
- * @return external_description
+ * @return \core_external\external_description
* @since Moodle 3.7
*/
public static function get_tag_cloud_returns() {
diff --git a/tag/classes/external/util.php b/tag/classes/external/util.php
index a4a1fed850659..248a7058ef905 100644
--- a/tag/classes/external/util.php
+++ b/tag/classes/external/util.php
@@ -14,21 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Tag external functions utility class.
- *
- * @package core_tag
- * @copyright 2019 Juan Leyva
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_tag\external;
-defined('MOODLE_INTERNAL') || die();
-
-require_once($CFG->libdir . '/externallib.php');
-
-use core_tag\external\tag_item_exporter;
use core_tag_tag;
/**
@@ -40,8 +27,6 @@
* @since Moodle 3.7
*/
class util {
-
-
/**
* Get the array of core_tag_tag objects for external functions associated with an item (instances).
*
@@ -53,8 +38,13 @@ class util {
* @param int $tiuserid tag instance user id, only needed for tag areas with user tagging
* @return array tags for external functions
*/
- public static function get_item_tags($component, $itemtype, $itemid, $standardonly = core_tag_tag::BOTH_STANDARD_AND_NOT,
- $tiuserid = 0) {
+ public static function get_item_tags(
+ $component,
+ $itemtype,
+ $itemid,
+ $standardonly = core_tag_tag::BOTH_STANDARD_AND_NOT,
+ $tiuserid = 0
+ ) {
global $PAGE;
$output = $PAGE->get_renderer('core');
diff --git a/tag/classes/output/tag.php b/tag/classes/output/tag.php
index f965399a04e82..ea51b06058a36 100644
--- a/tag/classes/output/tag.php
+++ b/tag/classes/output/tag.php
@@ -74,17 +74,14 @@ public function __construct($tag) {
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
- global $CFG;
- require_once($CFG->libdir . '/externallib.php');
-
$r = new stdClass();
$r->id = (int)$this->record->id;
$r->tagcollid = clean_param($this->record->tagcollid, PARAM_INT);
$r->rawname = clean_param($this->record->rawname, PARAM_TAG);
$r->name = clean_param($this->record->name, PARAM_TAG);
$format = clean_param($this->record->descriptionformat, PARAM_INT);
- list($r->description, $r->descriptionformat) = external_format_text($this->record->description,
- $format, \context_system::instance()->id, 'core', 'tag', $r->id);
+ list($r->description, $r->descriptionformat) = \core_external\util::format_text($this->record->description,
+ $format, \context_system::instance(), 'core', 'tag', $r->id);
$r->flag = clean_param($this->record->flag, PARAM_INT);
if (isset($this->record->isstandard)) {
$r->isstandard = clean_param($this->record->isstandard, PARAM_INT) ? 1 : 0;
diff --git a/tag/lib.php b/tag/lib.php
index 2d5e2dddbf90b..a0c4027b6e34e 100644
--- a/tag/lib.php
+++ b/tag/lib.php
@@ -24,6 +24,8 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
+use core_external\external_api;
+
/**
* Return a list of page types
*
@@ -50,7 +52,7 @@ function tag_page_type_list($pagetype, $parentcontext, $currentcontext) {
* @return \core\output\inplace_editable
*/
function core_tag_inplace_editable($itemtype, $itemid, $newvalue) {
- \external_api::validate_context(context_system::instance());
+ external_api::validate_context(context_system::instance());
if ($itemtype === 'tagname') {
return \core_tag\output\tagname::update($itemid, $newvalue);
} else if ($itemtype === 'tagareaenable') {
diff --git a/tag/tests/external/external_test.php b/tag/tests/external/external_test.php
index 6e3e34e6c9faa..071f5da7c66dc 100644
--- a/tag/tests/external/external_test.php
+++ b/tag/tests/external/external_test.php
@@ -26,12 +26,12 @@
namespace core_tag\external;
use externallib_advanced_testcase;
+use core_external\external_api;
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
class external_test extends externallib_advanced_testcase {
@@ -65,7 +65,7 @@ public function test_update_tags() {
// User without any caps can not change anything about a tag but can request [partial] tag data.
$this->setUser($this->getDataGenerator()->create_user());
$result = \core_tag_external::update_tags(array($updatetag));
- $result = \external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
$this->assertEquals($tag->id, $result['warnings'][0]['item']);
$this->assertEquals('nothingtoupdate', $result['warnings'][0]['warningcode']);
$this->assertEquals($originaltag['rawname'], $DB->get_field('tag', 'rawname',
@@ -74,7 +74,7 @@ public function test_update_tags() {
array('id' => $tag->id)));
$result = \core_tag_external::get_tags(array($gettag));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
$this->assertEquals($originaltag['rawname'], $result['tags'][0]['rawname']);
$this->assertEquals($originaltag['description'], $result['tags'][0]['description']);
$this->assertNotEmpty($result['tags'][0]['viewurl']);
@@ -87,11 +87,11 @@ public function test_update_tags() {
// User with editing only capability can change description but not the tag name.
$roleid = $this->assignUserCapability('moodle/tag:edit', $context->id);
$result = \core_tag_external::update_tags(array($updatetag));
- $result = \external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
$this->assertEmpty($result['warnings']);
$result = \core_tag_external::get_tags(array($gettag));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
$this->assertEquals($updatetag['id'], $result['tags'][0]['id']);
$this->assertEquals($updatetag['description'], $result['tags'][0]['description']);
$this->assertEquals($originaltag['rawname'], $result['tags'][0]['rawname']);
@@ -108,11 +108,11 @@ public function test_update_tags() {
assign_capability('moodle/tag:manage', CAP_ALLOW, $roleid, $context->id);
$this->assertTrue(has_capability('moodle/tag:manage', $context));
$result = \core_tag_external::update_tags(array($updatetag));
- $result = \external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
$this->assertEmpty($result['warnings']);
$result = \core_tag_external::get_tags(array($gettag));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
$this->assertEquals($updatetag['id'], $result['tags'][0]['id']);
$this->assertEquals($updatetag['rawname'], $result['tags'][0]['rawname']);
$this->assertEquals(\core_text::strtolower($updatetag['rawname']), $result['tags'][0]['name']);
@@ -132,12 +132,12 @@ public function test_update_tags() {
'id' => 123,
);
$result = \core_tag_external::update_tags(array($nonexistingtag));
- $result = \external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
$this->assertEquals(123, $result['warnings'][0]['item']);
$this->assertEquals('tagnotfound', $result['warnings'][0]['warningcode']);
$result = \core_tag_external::get_tags(array($getnonexistingtag));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tags_returns(), $result);
$this->assertEmpty($result['tags']);
$this->assertEquals(123, $result['warnings'][0]['item']);
$this->assertEquals('tagnotfound', $result['warnings'][0]['warningcode']);
@@ -146,7 +146,7 @@ public function test_update_tags() {
$anothertag = $this->getDataGenerator()->create_tag(array('rawname' => 'Mytag'));
$updatetag2 = array('id' => $tag->id, 'rawname' => 'MYTAG');
$result = \core_tag_external::update_tags(array($updatetag2));
- $result = \external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::update_tags_returns(), $result);
$this->assertEquals($tag->id, $result['warnings'][0]['item']);
$this->assertEquals('namesalreadybeeingused', $result['warnings'][0]['warningcode']);
}
@@ -174,7 +174,7 @@ public function test_update_inplace_editable() {
// Change to admin user and make sure that tag name can be updated using web service update_inplace_editable().
$this->setAdminUser();
$res = \core_external::update_inplace_editable('core_tag', 'tagname', $tag->id, 'New tag name');
- $res = \external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
+ $res = external_api::clean_returnvalue(\core_external::update_inplace_editable_returns(), $res);
$this->assertEquals('New tag name', $res['value']);
$this->assertEquals('New tag name', $DB->get_field('tag', 'rawname', array('id' => $tag->id)));
@@ -210,7 +210,7 @@ public function test_get_tagindex_per_area() {
// First, search by id.
$result = \core_tag_external::get_tagindex_per_area(array('id' => $tag->id));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
$this->assertCount(2, $result); // Two different areas: course and user.
$this->assertEquals($tag->id, $result[0]['tagid']);
$this->assertEquals('course', $result[0]['itemtype']);
@@ -219,7 +219,7 @@ public function test_get_tagindex_per_area() {
// Now, search by name.
$result = \core_tag_external::get_tagindex_per_area(array('tag' => 'test'));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
$this->assertCount(2, $result); // Two different areas: course and user.
$this->assertEquals($tag->id, $result[0]['tagid']);
$this->assertEquals('course', $result[0]['itemtype']);
@@ -228,14 +228,14 @@ public function test_get_tagindex_per_area() {
// Filter by tag area.
$result = \core_tag_external::get_tagindex_per_area(array('tag' => 'test', 'ta' => $result[0]['ta']));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
$this->assertCount(1, $result); // Just the given area.
$this->assertEquals($tag->id, $result[0]['tagid']);
$this->assertEquals('course', $result[0]['itemtype']);
// Now, search by tag collection (use default).
$result = \core_tag_external::get_tagindex_per_area(array('id' => $tag->id, 'tc' => 1));
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tagindex_per_area_returns(), $result);
$this->assertCount(2, $result); // Two different areas: course and user.
}
@@ -248,7 +248,7 @@ public function test_get_tag_areas() {
$this->setAdminUser();
$result = \core_tag_external::get_tag_areas();
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_areas_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_areas_returns(), $result);
$areas = $DB->get_records('tag_area');
$this->assertCount(count($areas), $result['areas']);
foreach ($result['areas'] as $area) {
@@ -270,7 +270,7 @@ public function test_get_tag_collections() {
$this->setAdminUser();
$result = \core_tag_external::get_tag_collections();
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_collections_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_collections_returns(), $result);
$collections = $DB->get_records('tag_coll');
$this->assertCount(count($collections), $result['collections']);
@@ -309,7 +309,7 @@ public function test_get_tag_cloud() {
// First, retrieve complete cloud.
$result = \core_tag_external::get_tag_cloud();
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(4, $result['tags']); // Four different tags: Cats, Dogs, Mice, Horses.
$this->assertEquals(4, $result['tagscount']);
$this->assertEquals(4, $result['totalcount']);
@@ -325,7 +325,7 @@ public function test_get_tag_cloud() {
// Test filter by collection, pagination and sorting.
$defaultcoll = \core_tag_collection::get_default();
$result = \core_tag_external::get_tag_cloud($defaultcoll, false, 2, 'count');
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(2, $result['tags']); // Only two tags.
$this->assertEquals(2, $result['tagscount']);
$this->assertEquals(4, $result['totalcount']);
@@ -333,14 +333,14 @@ public function test_get_tag_cloud() {
// Test search.
$result = \core_tag_external::get_tag_cloud(0, false, 150, 'name', 'Mice');
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(1, $result['tags']); // Only the searched tags.
$this->assertEquals(1, $result['tagscount']);
$this->assertEquals(1, $result['totalcount']); // When searching, the total is always for the search.
$this->assertEquals('Mice', $result['tags'][0]['name']);
$result = \core_tag_external::get_tag_cloud(0, false, 150, 'name', 'Conejo');
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(0, $result['tags']); // Nothing found.
$this->assertEquals(0, $result['tagscount']);
$this->assertEquals(0, $result['totalcount']); // When searching, the total is always for the search.
@@ -350,7 +350,7 @@ public function test_get_tag_cloud() {
$micetag->update(array('isstandard' => 1));
$result = \core_tag_external::get_tag_cloud(0, true);
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(1, $result['tags']);
$this->assertEquals(1, $result['tagscount']);
$this->assertEquals(1, $result['totalcount']); // When searching, the total is always for the search.
@@ -358,7 +358,7 @@ public function test_get_tag_cloud() {
// Test course context filtering.
$result = \core_tag_external::get_tag_cloud(0, false, 150, 'name', '', 0, $coursecontext->id);
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(1, $result['tags']);
$this->assertEquals(1, $result['tagscount']);
$this->assertEquals(1, $result['totalcount']); // When searching, the total is always for the search.
@@ -366,13 +366,13 @@ public function test_get_tag_cloud() {
// Complete system context.
$result = \core_tag_external::get_tag_cloud(0, false, 150, 'name', '', 0, \context_system::instance()->id);
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(4, $result['tags']);
$this->assertEquals(4, $result['tagscount']);
// Just system context - avoid children.
$result = \core_tag_external::get_tag_cloud(0, false, 150, 'name', '', 0, \context_system::instance()->id, 0);
- $result = \external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_tag_external::get_tag_cloud_returns(), $result);
$this->assertCount(2, $result['tags']);
$this->assertEquals(2, $result['tagscount']); // Horses and Cats.
$this->assertEquals('Cats', $result['tags'][0]['name']);
diff --git a/user/classes/external/search_identity.php b/user/classes/external/search_identity.php
index ac66824e1ba7f..e4419ee0a8f55 100644
--- a/user/classes/external/search_identity.php
+++ b/user/classes/external/search_identity.php
@@ -16,6 +16,13 @@
namespace core_user\external;
+use core_external\external_api;
+use core_external\external_description;
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
/**
* Provides the core_user_search_identity external function.
*
@@ -24,16 +31,16 @@
* @copyright 2021 David Mudrák
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-class search_identity extends \external_api {
+class search_identity extends external_api {
/**
* Describes the external function parameters.
*
- * @return \external_function_parameters
+ * @return external_function_parameters
*/
- public static function execute_parameters(): \external_function_parameters {
- return new \external_function_parameters([
- 'query' => new \external_value(PARAM_RAW, 'The search query', VALUE_REQUIRED),
+ public static function execute_parameters(): external_function_parameters {
+ return new external_function_parameters([
+ 'query' => new external_value(PARAM_RAW, 'The search query', VALUE_REQUIRED),
]);
}
@@ -46,7 +53,7 @@ public static function execute_parameters(): \external_function_parameters {
public static function execute(string $query): array {
global $DB, $CFG;
- $params = \external_api::validate_parameters(self::execute_parameters(), [
+ $params = external_api::validate_parameters(self::execute_parameters(), [
'query' => $query,
]);
$query = clean_param($params['query'], PARAM_TEXT);
@@ -105,26 +112,26 @@ public static function execute(string $query): array {
/**
* Describes the external function result value.
*
- * @return \external_description
+ * @return external_description
*/
- public static function execute_returns(): \external_description {
+ public static function execute_returns(): external_description {
- return new \external_single_structure([
- 'list' => new \external_multiple_structure(
- new \external_single_structure([
- 'id' => new \external_value(\core_user::get_property_type('id'), 'ID of the user'),
+ return new external_single_structure([
+ 'list' => new external_multiple_structure(
+ new external_single_structure([
+ 'id' => new external_value(\core_user::get_property_type('id'), 'ID of the user'),
// The output of the {@see fullname()} can contain formatting HTML such as tags.
// So we need PARAM_RAW here and the caller is supposed to render it appropriately.
- 'fullname' => new \external_value(PARAM_RAW, 'The fullname of the user'),
- 'extrafields' => new \external_multiple_structure(
- new \external_single_structure([
- 'name' => new \external_value(PARAM_TEXT, 'Name of the extrafield.'),
- 'value' => new \external_value(PARAM_TEXT, 'Value of the extrafield.'),
+ 'fullname' => new external_value(PARAM_RAW, 'The fullname of the user'),
+ 'extrafields' => new external_multiple_structure(
+ new external_single_structure([
+ 'name' => new external_value(PARAM_TEXT, 'Name of the extrafield.'),
+ 'value' => new external_value(PARAM_TEXT, 'Value of the extrafield.'),
]), 'List of extra fields', VALUE_OPTIONAL)
])
),
- 'maxusersperpage' => new \external_value(PARAM_INT, 'Configured maximum users per page.'),
- 'overflow' => new \external_value(PARAM_BOOL, 'Were there more records than maxusersperpage found?'),
+ 'maxusersperpage' => new external_value(PARAM_INT, 'Configured maximum users per page.'),
+ 'overflow' => new external_value(PARAM_BOOL, 'Were there more records than maxusersperpage found?'),
]);
}
}
diff --git a/user/classes/output/user_roles_editable.php b/user/classes/output/user_roles_editable.php
index cc75328a899b4..76e319a3595c0 100644
--- a/user/classes/output/user_roles_editable.php
+++ b/user/classes/output/user_roles_editable.php
@@ -14,14 +14,6 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Contains class core_user\output\user_roles_editable
- *
- * @package core_user
- * @copyright 2017 Damyon Wiese
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
namespace core_user\output;
use context_course;
@@ -29,8 +21,6 @@
use core_external;
use coding_exception;
-defined('MOODLE_INTERNAL') || die();
-
/**
* Class to display list of user roles.
*
@@ -145,9 +135,8 @@ public function export_for_template(\renderer_base $output) {
* @return \self
*/
public static function update($itemid, $newvalue) {
- global $DB, $CFG;
+ global $DB;
- require_once($CFG->libdir . '/external/externallib.php');
// Check caps.
// Do the thing.
// Return one of me.
diff --git a/user/externallib.php b/user/externallib.php
index b121c76c0f897..9a58d1103daff 100644
--- a/user/externallib.php
+++ b/user/externallib.php
@@ -14,18 +14,13 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * External user API
- *
- * @package core_user
- * @category external
- * @copyright 2009 Petr Skodak
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
-
-require_once("$CFG->libdir/externallib.php");
+use core_external\external_description;
+use core_external\external_value;
+use core_external\external_format_value;
+use core_external\external_single_structure;
+use core_external\external_multiple_structure;
+use core_external\external_function_parameters;
+use core_external\external_warnings;
/**
* User external functions
@@ -36,7 +31,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.2
*/
-class core_user_external extends external_api {
+class core_user_external extends \core_external\external_api {
/**
* Returns description of method parameters
diff --git a/user/lib.php b/user/lib.php
index 020ccc11fa4f0..a2022b462c179 100644
--- a/user/lib.php
+++ b/user/lib.php
@@ -423,8 +423,8 @@ function user_get_user_details($user, $course = null, array $userfields = array(
if (in_array('description', $userfields)) {
// Always return the descriptionformat if description is requested.
list($userdetails['description'], $userdetails['descriptionformat']) =
- external_format_text($user->description, $user->descriptionformat,
- $usercontext->id, 'user', 'profile', null);
+ \core_external\util::format_text($user->description, $user->descriptionformat,
+ $usercontext, 'user', 'profile', null);
}
}
@@ -525,8 +525,8 @@ function user_get_user_details($user, $course = null, array $userfields = array(
$userdetails['groups'] = array();
foreach ($usergroups as $group) {
list($group->description, $group->descriptionformat) =
- external_format_text($group->description, $group->descriptionformat,
- $context->id, 'group', 'description', $group->id);
+ \core_external\util::format_text($group->description, $group->descriptionformat,
+ $context, 'group', 'description', $group->id);
$userdetails['groups'][] = array('id' => $group->id, 'name' => $group->name,
'description' => $group->description, 'descriptionformat' => $group->descriptionformat);
}
@@ -1369,4 +1369,3 @@ function user_edit_map_field_purpose($userid, $fieldname) {
return $purpose;
}
-
diff --git a/user/tests/externallib_test.php b/user/tests/externallib_test.php
index cbabc9d824bba..2feb7115da7b8 100644
--- a/user/tests/externallib_test.php
+++ b/user/tests/externallib_test.php
@@ -26,6 +26,7 @@
namespace core_user;
+use core_external\external_api;
use core_files_external;
use core_user_external;
use externallib_advanced_testcase;
@@ -100,7 +101,7 @@ public function test_get_users() {
$result = core_user_external::get_users($searchparams);
// We need to execute the return values cleaning process to simulate the web service server
- $result = \external_api::clean_returnvalue(core_user_external::get_users_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_users_returns(), $result);
// Check we retrieve the good total number of enrolled users + no error on capability.
$expectedreturnedusers = 1;
@@ -231,7 +232,7 @@ public function test_get_users_by_field() {
// Call the external function.
$returnedusers = core_user_external::get_users_by_field($fieldtosearch,
array($USER->{$fieldtosearch}, $user1->{$fieldtosearch}, $user2->{$fieldtosearch}));
- $returnedusers = \external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers);
+ $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers);
// Expected result differ following the searched field
// Admin user in the PHPunit framework doesn't have an idnumber.
@@ -298,7 +299,7 @@ public function test_get_users_by_field() {
// Call the external function.
$returnedusers = core_user_external::get_users_by_field('username',
array($USER->username, $user1->username, $user2->username));
- $returnedusers = \external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers);
+ $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers);
// Only the own $USER username should be returned
$this->assertEquals(1, count($returnedusers));
@@ -309,7 +310,7 @@ public function test_get_users_by_field() {
// Call the external function.
$returnedusers = core_user_external::get_users_by_field('username',
array($USER->username, $user1->username, $user2->username));
- $returnedusers = \external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers);
+ $returnedusers = external_api::clean_returnvalue(core_user_external::get_users_by_field_returns(), $returnedusers);
// Only the own $USER username should be returned still.
$this->assertEquals(1, count($returnedusers));
@@ -374,7 +375,7 @@ public function test_get_course_user_profiles() {
array('userid' => $USER->id, 'courseid' => $data->course->id)));
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledusers = \external_api::clean_returnvalue(core_user_external::get_course_user_profiles_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_user_external::get_course_user_profiles_returns(), $enrolledusers);
// Check we retrieve the good total number of enrolled users + no error on capability.
$this->assertEquals(1, count($enrolledusers));
@@ -398,7 +399,7 @@ public function test_get_user_course_profile_as_admin() {
array('userid' => $data->user1->id, 'courseid' => $data->course->id)));
// We need to execute the return values cleaning process to simulate the web service server.
- $enrolledusers = \external_api::clean_returnvalue(core_user_external::get_course_user_profiles_returns(), $enrolledusers);
+ $enrolledusers = external_api::clean_returnvalue(core_user_external::get_course_user_profiles_returns(), $enrolledusers);
foreach($enrolledusers as $enrolleduser) {
if ($enrolleduser['username'] == $data->user1->username) {
@@ -476,7 +477,7 @@ public function test_create_users() {
$createdusers = core_user_external::create_users(array($user1, $user2));
// We need to execute the return values cleaning process to simulate the web service server.
- $createdusers = \external_api::clean_returnvalue(core_user_external::create_users_returns(), $createdusers);
+ $createdusers = external_api::clean_returnvalue(core_user_external::create_users_returns(), $createdusers);
// Check we retrieve the good total number of created users + no error on capability.
$this->assertCount(2, $createdusers);
@@ -735,7 +736,7 @@ public function test_update_users() {
// Call the files api to create a file.
$draftfile = core_files_external::upload($contextid, 'user', 'draft', 0, '/',
$filename, $filecontent, null, null);
- $draftfile = \external_api::clean_returnvalue(core_files_external::upload_returns(), $draftfile);
+ $draftfile = external_api::clean_returnvalue(core_files_external::upload_returns(), $draftfile);
$draftid = $draftfile['itemid'];
@@ -792,7 +793,7 @@ public function test_update_users() {
// Call the external function.
$returnvalue = core_user_external::update_users(array($user1, $user2, $user3, $user4));
- $returnvalue = \external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
// Check warnings.
$this->assertEquals($user2['id'], $returnvalue['warnings'][0]['itemid']); // Guest user.
@@ -846,7 +847,7 @@ public function test_update_users() {
// Updating user with an invalid email.
$user5['email'] = 'bogus';
$returnvalue = core_user_external::update_users(array($user5));
- $returnvalue = \external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
$this->assertEquals('useremailinvalid', $returnvalue['warnings'][0]['warningcode']);
$this->assertStringContainsString('Invalid email address',
$returnvalue['warnings'][0]['message']);
@@ -854,7 +855,7 @@ public function test_update_users() {
// Updating user with a duplicate email.
$user5['email'] = $user1['email'];
$returnvalue = core_user_external::update_users(array($user1, $user5));
- $returnvalue = \external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
$this->assertEquals('useremailduplicate', $returnvalue['warnings'][0]['warningcode']);
$this->assertStringContainsString('Duplicate email address',
$returnvalue['warnings'][0]['message']);
@@ -862,7 +863,7 @@ public function test_update_users() {
// Updating a user that does not exist.
$user5['id'] = -1;
$returnvalue = core_user_external::update_users(array($user5));
- $returnvalue = \external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
$this->assertEquals('invaliduserid', $returnvalue['warnings'][0]['warningcode']);
$this->assertStringContainsString('Invalid user ID',
$returnvalue['warnings'][0]['message']);
@@ -872,7 +873,7 @@ public function test_update_users() {
user_update_user($user1); // Update user not using webservice.
unset($user1['mnethostid']); // The mnet host ID field is not in the allowed field list for the webservice.
$returnvalue = core_user_external::update_users(array($user1));
- $returnvalue = \external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
+ $returnvalue = external_api::clean_returnvalue(core_user_external::update_users_returns(), $returnvalue);
$this->assertEquals('usernotupdatedremote', $returnvalue['warnings'][0]['warningcode']);
$this->assertStringContainsString('User is a remote user',
$returnvalue['warnings'][0]['message']);
@@ -994,7 +995,7 @@ public function test_add_user_private_files() {
// Call the files api to create a file.
$draftfile = core_files_external::upload($contextid, $component, $filearea, $itemid, $filepath,
$filename, $filecontent, $contextlevel, $instanceid);
- $draftfile = \external_api::clean_returnvalue(core_files_external::upload_returns(), $draftfile);
+ $draftfile = external_api::clean_returnvalue(core_files_external::upload_returns(), $draftfile);
$draftid = $draftfile['itemid'];
// Make sure the file was created.
@@ -1044,14 +1045,14 @@ public function test_add_user_device() {
$warnings = core_user_external::add_user_device($device['appid'], $device['name'], $device['model'], $device['platform'],
$device['version'], $device['pushid'], $device['uuid']);
// We need to execute the return values cleaning process to simulate the web service server.
- $warnings = \external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
+ $warnings = external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
$this->assertCount(1, $warnings);
// Test update an existing device.
$device['pushid'] = 'different than before';
$warnings = core_user_external::add_user_device($device['appid'], $device['name'], $device['model'], $device['platform'],
$device['version'], $device['pushid'], $device['uuid']);
- $warnings = \external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
+ $warnings = external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
$this->assertEquals(1, $DB->count_records('user_devices'));
$updated = $DB->get_record('user_devices', array('pushid' => $device['pushid']));
@@ -1062,7 +1063,7 @@ public function test_add_user_device() {
$device['pushid'] = 'new different than before';
$warnings = core_user_external::add_user_device($device['appid'], $device['name'], $device['model'], $device['platform'],
$device['version'], $device['pushid'], $device['uuid']);
- $warnings = \external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
+ $warnings = external_api::clean_returnvalue(core_user_external::add_user_device_returns(), $warnings);
$this->assertEquals(2, $DB->count_records('user_devices'));
}
@@ -1100,24 +1101,24 @@ public function test_remove_user_device() {
// Try to remove a device that does not exist.
$result = core_user_external::remove_user_device('1234567890');
- $result = \external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
$this->assertFalse($result['removed']);
$this->assertCount(1, $result['warnings']);
// Try to remove a device that does not exist for an existing app.
$result = core_user_external::remove_user_device('1234567890', $device['appid']);
- $result = \external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
$this->assertFalse($result['removed']);
$this->assertCount(1, $result['warnings']);
// Remove an existing device for an existing app. This will remove one of the two devices.
$result = core_user_external::remove_user_device($device['uuid'], $device['appid']);
- $result = \external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
$this->assertTrue($result['removed']);
// Remove all the devices. This must remove the remaining device.
$result = core_user_external::remove_user_device($device['uuid']);
- $result = \external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::remove_user_device_returns(), $result);
$this->assertTrue($result['removed']);
}
@@ -1134,7 +1135,7 @@ public function test_get_user_preferences() {
$this->setUser($user);
$result = core_user_external::get_user_preferences();
- $result = \external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
// Expect 3, _lastloaded is always returned.
$this->assertCount(3, $result['preferences']);
@@ -1149,14 +1150,14 @@ public function test_get_user_preferences() {
// Retrieve just one preference.
$result = core_user_external::get_user_preferences('some_random_text');
- $result = \external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['preferences']);
$this->assertEquals('text', $result['preferences'][0]['value']);
// Retrieve non-existent preference.
$result = core_user_external::get_user_preferences('non_existent');
- $result = \external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['preferences']);
$this->assertEquals(null, $result['preferences'][0]['value']);
@@ -1164,7 +1165,7 @@ public function test_get_user_preferences() {
// Check that as admin we can retrieve all the preferences for any user.
$this->setAdminUser();
$result = core_user_external::get_user_preferences('', $user->id);
- $result = \external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(3, $result['preferences']);
@@ -1207,7 +1208,7 @@ public function test_update_picture() {
// Change user profile image.
$result = core_user_external::update_picture($draftid);
- $result = \external_api::clean_returnvalue(core_user_external::update_picture_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::update_picture_returns(), $result);
$picture = $DB->get_field('user', 'picture', array('id' => $user->id));
// The new revision is in the url for the user.
$this->assertStringContainsString($picture, $result['profileimageurl']);
@@ -1216,7 +1217,7 @@ public function test_update_picture() {
// Delete image.
$result = core_user_external::update_picture(0, true);
- $result = \external_api::clean_returnvalue(core_user_external::update_picture_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::update_picture_returns(), $result);
$picture = $DB->get_field('user', 'picture', array('id' => $user->id));
// No picture.
$this->assertEquals(0, $picture);
@@ -1230,7 +1231,7 @@ public function test_update_picture() {
$draftid = $draftfile['itemid'];
$result = core_user_external::update_picture($draftid, false, $user->id);
- $result = \external_api::clean_returnvalue(core_user_external::update_picture_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::update_picture_returns(), $result);
// The new revision is in the url for the user.
$picture = $DB->get_field('user', 'picture', array('id' => $user->id));
$this->assertStringContainsString($picture, $result['profileimageurl']);
@@ -1276,7 +1277,7 @@ public function test_set_user_preferences_save() {
);
$result = core_user_external::set_user_preferences($preferences);
- $result = \external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(2, $result['saved']);
@@ -1307,7 +1308,7 @@ public function test_set_user_preferences_save_invalid_pref() {
);
$result = core_user_external::set_user_preferences($preferences);
- $result = \external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
$this->assertCount(1, $result['warnings']);
$this->assertCount(0, $result['saved']);
$this->assertEquals('nopermission', $result['warnings'][0]['warningcode']);
@@ -1332,7 +1333,7 @@ public function test_set_user_preferences_invalid_user() {
);
$result = core_user_external::set_user_preferences($preferences);
- $result = \external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
$this->assertCount(1, $result['warnings']);
$this->assertCount(0, $result['saved']);
$this->assertEquals('invaliduser', $result['warnings'][0]['warningcode']);
@@ -1357,7 +1358,7 @@ public function test_set_user_preferences_invalid_preference() {
);
$result = core_user_external::set_user_preferences($preferences);
- $result = \external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['saved']);
// Cleaned valud of the preference was saved.
@@ -1411,7 +1412,7 @@ public function test_update_user_preferences_unset() {
);
$result = core_user_external::set_user_preferences($preferences);
- $result = \external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::set_user_preferences_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertCount(1, $result['saved']);
@@ -1437,7 +1438,7 @@ public function test_agree_site_policy() {
// Site policy not set.
$result = core_user_external::agree_site_policy();
- $result = \external_api::clean_returnvalue(core_user_external::agree_site_policy_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::agree_site_policy_returns(), $result);
$this->assertFalse($result['status']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('nositepolicy', $result['warnings'][0]['warningcode']);
@@ -1447,7 +1448,7 @@ public function test_agree_site_policy() {
$this->assertEquals(0, $USER->policyagreed);
$result = core_user_external::agree_site_policy();
- $result = \external_api::clean_returnvalue(core_user_external::agree_site_policy_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::agree_site_policy_returns(), $result);
$this->assertTrue($result['status']);
$this->assertCount(0, $result['warnings']);
$this->assertEquals(1, $USER->policyagreed);
@@ -1455,7 +1456,7 @@ public function test_agree_site_policy() {
// Try again, we should get a warning.
$result = core_user_external::agree_site_policy();
- $result = \external_api::clean_returnvalue(core_user_external::agree_site_policy_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::agree_site_policy_returns(), $result);
$this->assertFalse($result['status']);
$this->assertCount(1, $result['warnings']);
$this->assertEquals('alreadyagreed', $result['warnings'][0]['warningcode']);
@@ -1500,7 +1501,7 @@ public function test_get_private_files_info() {
// Get my private files information.
$result = core_user_external::get_private_files_info();
- $result = \external_api::clean_returnvalue(core_user_external::get_private_files_info_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_private_files_info_returns(), $result);
$this->assertEquals(1, $result['filecount']);
$this->assertEquals($file->get_filesize(), $result['filesize']);
$this->assertEquals(0, $result['foldercount']);
@@ -1509,7 +1510,7 @@ public function test_get_private_files_info() {
// As admin, get user information.
$this->setAdminUser();
$result = core_user_external::get_private_files_info($user->id);
- $result = \external_api::clean_returnvalue(core_user_external::get_private_files_info_returns(), $result);
+ $result = external_api::clean_returnvalue(core_user_external::get_private_files_info_returns(), $result);
$this->assertEquals(1, $result['filecount']);
$this->assertEquals($file->get_filesize(), $result['filesize']);
$this->assertEquals(0, $result['foldercount']);
@@ -1586,7 +1587,7 @@ public function test_external_search_identity() {
$CFG->maxusersperpage = 3;
$result = \core_user\external\search_identity::execute('Lastt');
- $result = \external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
$this->assertEquals(2, count($result['list']));
$this->assertEquals(3, $result['maxusersperpage']);
@@ -1603,7 +1604,7 @@ public function test_external_search_identity() {
$CFG->maxusersperpage = 2;
$result = \core_user\external\search_identity::execute('Firstt');
- $result = \external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
$this->assertEquals(2, count($result['list']));
$this->assertEquals(2, $result['maxusersperpage']);
@@ -1618,7 +1619,7 @@ public function test_external_search_identity() {
$CFG->maxusersperpage = 2;
$result = \core_user\external\search_identity::execute('City One');
- $result = \external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
$this->assertEquals(0, count($result['list']));
$this->assertEquals(2, $result['maxusersperpage']);
@@ -1633,7 +1634,7 @@ public function test_external_search_identity() {
}
$result = \core_user\external\search_identity::execute('City One');
- $result = \external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
$this->assertEquals(2, count($result['list']));
$this->assertEquals(2, $result['maxusersperpage']);
@@ -1664,7 +1665,7 @@ public function test_external_search_identity_with_alternativefullnameformat() {
'lastname firstname ';
$result = \core_user\external\search_identity::execute('Ak');
- $result = \external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_user\external\search_identity::execute_returns(), $result);
$this->assertEquals(1, count($result['list']));
$this->assertEquals(3, $result['maxusersperpage']);
diff --git a/webservice/externallib.php b/webservice/externallib.php
index 478064fdf676c..591debdf9b769 100644
--- a/webservice/externallib.php
+++ b/webservice/externallib.php
@@ -14,20 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-
-/**
- * external API for mobile web services
- *
- * @package core_webservice
- * @category external
- * @copyright 2011 Jerome Mouneyrac
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die;
-
-require_once("$CFG->libdir/externallib.php");
-
+use core_external\external_function_parameters;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* Web service related functions
*
@@ -37,7 +27,7 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 2.2
*/
-class core_webservice_external extends external_api {
+class core_webservice_external extends \core_external\external_api {
/**
* Returns description of method parameters
@@ -85,7 +75,7 @@ public static function get_site_info($serviceshortnames = array()) {
// Site information.
$siteinfo = array(
- 'sitename' => external_format_string($SITE->fullname, $systemcontext),
+ 'sitename' => \core_external\util::format_string($SITE->fullname, $systemcontext),
'siteurl' => $CFG->wwwroot,
'username' => $USER->username,
'firstname' => $USER->firstname,
diff --git a/webservice/lib.php b/webservice/lib.php
index 0107f8d1c13a6..993d1960c176d 100644
--- a/webservice/lib.php
+++ b/webservice/lib.php
@@ -23,7 +23,11 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-require_once($CFG->libdir.'/externallib.php');
+use core_external\external_api;
+use core_external\external_multiple_structure;
+use core_external\external_settings;
+use core_external\external_single_structure;
+use core_external\external_value;
/**
* WEBSERVICE_AUTHMETHOD_USERNAME - username/password authentication (also called simple authentication)
@@ -1821,7 +1825,7 @@ protected function service_class_method_body($function, $params) {
$function->classname::$function->methodname($paramsstr);
return null;
}
- return external_api::clean_returnvalue($callforreturnvaluedesc, $function->classname::$function->methodname($paramsstr));
+ return \\core_external\\external_api::clean_returnvalue($callforreturnvaluedesc, $function->classname::$function->methodname($paramsstr));
EOD;
return $methodbody;
}
diff --git a/webservice/rest/tests/server_test.php b/webservice/rest/tests/server_test.php
index 04724a8cea818..3d7c47d56021f 100644
--- a/webservice/rest/tests/server_test.php
+++ b/webservice/rest/tests/server_test.php
@@ -16,10 +16,13 @@
namespace webservice_rest;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
+
defined('MOODLE_INTERNAL') || die();
global $CFG;
-require_once($CFG->libdir . '/externallib.php');
require_once($CFG->dirroot . '/webservice/rest/locallib.php');
/**
@@ -38,13 +41,13 @@ class server_test extends \advanced_testcase {
public function xmlize_provider() {
$data = [];
$data[] = [null, null, ''];
- $data[] = [new \external_value(PARAM_BOOL), false, "0\n"];
- $data[] = [new \external_value(PARAM_BOOL), true, "1\n"];
- $data[] = [new \external_value(PARAM_ALPHA), null, "\n"];
- $data[] = [new \external_value(PARAM_ALPHA), 'a', "a\n"];
- $data[] = [new \external_value(PARAM_INT), 123, "123\n"];
+ $data[] = [new external_value(PARAM_BOOL), false, "0\n"];
+ $data[] = [new external_value(PARAM_BOOL), true, "1\n"];
+ $data[] = [new external_value(PARAM_ALPHA), null, "\n"];
+ $data[] = [new external_value(PARAM_ALPHA), 'a', "a\n"];
+ $data[] = [new external_value(PARAM_INT), 123, "123\n"];
$data[] = [
- new \external_multiple_structure(new \external_value(PARAM_INT)),
+ new external_multiple_structure(new external_value(PARAM_INT)),
[1, 2, 3],
"\n" .
"1\n" .
@@ -53,7 +56,7 @@ public function xmlize_provider() {
"\n"
];
$data[] = [ // Multiple structure with null value.
- new \external_multiple_structure(new \external_value(PARAM_ALPHA)),
+ new external_multiple_structure(new external_value(PARAM_ALPHA)),
['A', null, 'C'],
"\n" .
"A\n" .
@@ -62,16 +65,16 @@ public function xmlize_provider() {
"\n"
];
$data[] = [ // Multiple structure without values.
- new \external_multiple_structure(new \external_value(PARAM_ALPHA)),
+ new external_multiple_structure(new external_value(PARAM_ALPHA)),
[],
"\n" .
"\n"
];
$data[] = [
- new \external_single_structure([
- 'one' => new \external_value(PARAM_INT),
- 'two' => new \external_value(PARAM_INT),
- 'three' => new \external_value(PARAM_INT),
+ new external_single_structure([
+ 'one' => new external_value(PARAM_INT),
+ 'two' => new external_value(PARAM_INT),
+ 'three' => new external_value(PARAM_INT),
]),
['one' => 1, 'two' => 2, 'three' => 3],
"\n" .
@@ -81,10 +84,10 @@ public function xmlize_provider() {
"\n"
];
$data[] = [ // Single structure with null value.
- new \external_single_structure([
- 'one' => new \external_value(PARAM_INT),
- 'two' => new \external_value(PARAM_INT),
- 'three' => new \external_value(PARAM_INT),
+ new external_single_structure([
+ 'one' => new external_value(PARAM_INT),
+ 'two' => new external_value(PARAM_INT),
+ 'three' => new external_value(PARAM_INT),
]),
['one' => 1, 'two' => null, 'three' => 3],
"\n" .
@@ -94,10 +97,10 @@ public function xmlize_provider() {
"\n"
];
$data[] = [ // Single structure missing keys.
- new \external_single_structure([
- 'one' => new \external_value(PARAM_INT),
- 'two' => new \external_value(PARAM_INT),
- 'three' => new \external_value(PARAM_INT),
+ new external_single_structure([
+ 'one' => new external_value(PARAM_INT),
+ 'two' => new external_value(PARAM_INT),
+ 'three' => new external_value(PARAM_INT),
]),
['two' => null, 'three' => 3],
"\n" .
@@ -107,19 +110,19 @@ public function xmlize_provider() {
"\n"
];
$data[] = [ // Nested structure.
- new \external_single_structure([
- 'one' => new \external_multiple_structure(
- new \external_value(PARAM_INT)
+ new external_single_structure([
+ 'one' => new external_multiple_structure(
+ new external_value(PARAM_INT)
),
- 'two' => new \external_multiple_structure(
- new \external_single_structure([
- 'firstname' => new \external_value(PARAM_RAW),
- 'lastname' => new \external_value(PARAM_RAW),
+ 'two' => new external_multiple_structure(
+ new external_single_structure([
+ 'firstname' => new external_value(PARAM_RAW),
+ 'lastname' => new external_value(PARAM_RAW),
])
),
- 'three' => new \external_single_structure([
- 'firstname' => new \external_value(PARAM_RAW),
- 'lastname' => new \external_value(PARAM_RAW),
+ 'three' => new external_single_structure([
+ 'firstname' => new external_value(PARAM_RAW),
+ 'lastname' => new external_value(PARAM_RAW),
]),
]),
[
@@ -153,19 +156,19 @@ public function xmlize_provider() {
"\n"
];
$data[] = [ // Nested structure with missing keys.
- new \external_single_structure([
- 'one' => new \external_multiple_structure(
- new \external_value(PARAM_INT)
+ new external_single_structure([
+ 'one' => new external_multiple_structure(
+ new external_value(PARAM_INT)
),
- 'two' => new \external_multiple_structure(
- new \external_single_structure([
- 'firstname' => new \external_value(PARAM_RAW),
- 'lastname' => new \external_value(PARAM_RAW),
+ 'two' => new external_multiple_structure(
+ new external_single_structure([
+ 'firstname' => new external_value(PARAM_RAW),
+ 'lastname' => new external_value(PARAM_RAW),
])
),
- 'three' => new \external_single_structure([
- 'firstname' => new \external_value(PARAM_RAW),
- 'lastname' => new \external_value(PARAM_RAW),
+ 'three' => new external_single_structure([
+ 'firstname' => new external_value(PARAM_RAW),
+ 'lastname' => new external_value(PARAM_RAW),
]),
]),
[
diff --git a/webservice/tests/externallib_test.php b/webservice/tests/externallib_test.php
index 64b69b3fa41a0..a46a32ec78abd 100644
--- a/webservice/tests/externallib_test.php
+++ b/webservice/tests/externallib_test.php
@@ -16,6 +16,7 @@
namespace core_webservice;
+use core_external\external_api;
use externallib_advanced_testcase;
defined('MOODLE_INTERNAL') || die();
@@ -90,7 +91,7 @@ public function test_get_site_info() {
$siteinfo = \core_webservice_external::get_site_info();
// We need to execute the return values cleaning process to simulate the web service server.
- $siteinfo = \external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $siteinfo);
+ $siteinfo = external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $siteinfo);
$this->assertEquals('johnd', $siteinfo['username']);
$this->assertEquals('John', $siteinfo['firstname']);
@@ -162,7 +163,7 @@ public function test_get_site_info() {
$siteinfo = \core_webservice_external::get_site_info();
// We need to execute the return values cleaning process to simulate the web service server.
- $siteinfo = \external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $siteinfo);
+ $siteinfo = external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $siteinfo);
$this->assertEquals(0, $siteinfo['userquota']);
$this->assertEquals(USER_CAN_IGNORE_FILE_SIZE_LIMITS, $siteinfo['usermaxuploadfilesize']);
@@ -185,7 +186,7 @@ public function test_get_site_info() {
$DB->insert_record('sessions', $record);
$siteinfo = \core_webservice_external::get_site_info();
- $siteinfo = \external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $siteinfo);
+ $siteinfo = external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $siteinfo);
$this->assertEquals($CFG->limitconcurrentlogins, $siteinfo['limitconcurrentlogins']);
$this->assertEquals(1, $siteinfo['usersessionscount']);
}
@@ -203,7 +204,7 @@ public function test_get_site_info_max_int() {
set_config('userquota', $userquota);
$result = \core_webservice_external::get_site_info();
- $result = \external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $result);
+ $result = external_api::clean_returnvalue(\core_webservice_external::get_site_info_returns(), $result);
$this->assertEquals(PHP_INT_MAX, $result['userquota']);
}
diff --git a/webservice/tests/generator/lib.php b/webservice/tests/generator/lib.php
index 330e2f06c4f3a..dacd3647738ff 100644
--- a/webservice/tests/generator/lib.php
+++ b/webservice/tests/generator/lib.php
@@ -128,9 +128,9 @@ public function create_token(array $data): void {
$service = $webservicemanager->get_external_service_by_shortname($data['service']);
- external_generate_token(
+ \core_external\util::generate_token(
EXTERNAL_TOKEN_PERMANENT,
- $service->id,
+ $service,
$data['userid'],
$data['context'],
$data['validuntil'],
diff --git a/webservice/tests/helpers.php b/webservice/tests/helpers.php
index e30a955ac4925..8d0f2c2c1315a 100644
--- a/webservice/tests/helpers.php
+++ b/webservice/tests/helpers.php
@@ -14,15 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * This file contains helper classes for testing the web service and external files.
- *
- * @package core_webservice
- * @copyright 2012 Jerome Mouneyrac
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
-
-defined('MOODLE_INTERNAL') || die();
+use core_external\external_settings;
/**
* Helper base class for external tests. Helpfull to test capabilities.
@@ -135,4 +127,3 @@ public static function unassignUserCapability($capability, $contextid = null, $r
accesslib_clear_all_caches_for_unit_testing();
}
}
-
diff --git a/webservice/tests/lib_test.php b/webservice/tests/lib_test.php
index 4fe60afa1bc5f..287485ffacf31 100644
--- a/webservice/tests/lib_test.php
+++ b/webservice/tests/lib_test.php
@@ -24,6 +24,10 @@
*/
namespace core_webservice;
+use core_external\external_api;
+use core_external\external_multiple_structure;
+use core_external\external_single_structure;
+use core_external\external_value;
use webservice;
defined('MOODLE_INTERNAL') || die();
@@ -125,7 +129,7 @@ public function test_init_service_class() {
// Check the contents of service methods.
foreach ($servicemethods as $method) {
// Get the external function info.
- $function = \external_api::external_function_info($method->name);
+ $function = external_api::external_function_info($method->name);
// Check input params.
foreach ($function->parameters_desc->keys as $name => $keydesc) {