-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CONTRIB-8227 autocomplete boxes loaded via web service
- Loading branch information
Showing
10 changed files
with
318 additions
and
12 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Potential user selector module. | ||
* | ||
* @module mod_scheduler/studentid | ||
* @copyright 2022 University of Glasgow | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
define(['jquery', 'core/ajax', 'core/templates'], function($, Ajax, Templates) { | ||
|
||
return /** @alias module:mod_scheduler/studentid */ { | ||
|
||
processResults: function(selector, results) { | ||
var users = []; | ||
$.each(results, function(index, user) { | ||
users.push({ | ||
value: user.id, | ||
label: user._label | ||
}); | ||
}); | ||
return users; | ||
}, | ||
|
||
transport: function(selector, query, success, failure) { | ||
var promise; | ||
|
||
let scheduler = $(selector).attr('scheduler') || null; | ||
let groupids = $(selector).attr('groupids') || null; | ||
promise = Ajax.call([{ | ||
methodname: 'mod_scheduler_studentid', | ||
args: { | ||
query: query, | ||
scheduler: scheduler, | ||
groupids: groupids | ||
} | ||
}]); | ||
|
||
promise[0].then(function(results) { | ||
var promises = [], | ||
i = 0; | ||
|
||
// Render the label. | ||
$.each(results, function(index, user) { | ||
promises.push(Templates.render('mod_scheduler/studentid', user)); | ||
}); | ||
|
||
// Apply the label to the results. | ||
return $.when.apply($.when, promises).then(function() { | ||
var args = arguments; | ||
$.each(results, function(index, user) { | ||
user._label = args[i]; | ||
i++; | ||
}); | ||
success(results); | ||
return; | ||
}); | ||
|
||
}).fail(failure); | ||
} | ||
|
||
}; | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* This is the external API for this component. | ||
* | ||
* @package mod_scheduler | ||
* @copyright 2022 University of Glasgow | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace mod_scheduler; | ||
|
||
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 \mod_scheduler\model\scheduler; | ||
|
||
/** | ||
* This is the external API for this component. | ||
* | ||
* @copyright 2022 University of Glasgow | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class external extends external_api { | ||
|
||
/** | ||
* studentid parameters | ||
* | ||
* @return external_function_parameters | ||
*/ | ||
public static function studentid_parameters() { | ||
return new external_function_parameters([ | ||
'query' => new external_value(PARAM_TEXT, 'The search query', VALUE_REQUIRED), | ||
'scheduler' => new external_value(PARAM_INT, 'The scheduler id', VALUE_REQUIRED), | ||
'groupids' => new external_value(PARAM_INT, 'The group ids', VALUE_DEFAULT) | ||
]); | ||
} | ||
|
||
/** | ||
* Fetch the details of a user's data request. | ||
* | ||
* @since Moodle 3.5 | ||
* @param string $query The search query. | ||
* @param string $scheduler The scheduler id. | ||
* @param string $groupids The group ids. | ||
* @return array | ||
* @throws required_capability_exception | ||
* @throws dml_exception | ||
* @throws invalid_parameter_exception | ||
* @throws restricted_context_exception | ||
*/ | ||
|
||
public static function studentid($query, $scheduler, $groupids) { | ||
$params = external_api::validate_parameters(self::studentid_parameters(), [ | ||
'query' => $query, | ||
'scheduler' => $scheduler, | ||
'groupids' => $groupids | ||
]); | ||
$query = $params['query']; | ||
$scheduler = $params['scheduler']; | ||
$groupids = $params['groupids']; | ||
|
||
$scheduler = scheduler::load_by_id($scheduler); | ||
$availablestudents = $scheduler->get_available_students(); | ||
|
||
$students = []; | ||
$i = 0; | ||
foreach ($availablestudents as $id => $student) { | ||
$fullname = fullname($student); | ||
|
||
if (mb_stripos($fullname, $query) !== false) { | ||
$students[] = ['id' => $id, 'fullname' => fullname($student)]; | ||
$i++; | ||
} | ||
} | ||
|
||
return $students; | ||
|
||
} | ||
|
||
/** | ||
* Parameter description for get_users(). | ||
* | ||
* @since Moodle 3.5 | ||
* @return external_description | ||
* @throws coding_exception | ||
*/ | ||
public static function studentid_returns() { | ||
return new external_multiple_structure( | ||
new external_single_structure([ | ||
'id' => new external_value(PARAM_INT, 'User ID'), | ||
'fullname' => new external_value(PARAM_NOTAGS, 'User fullname') | ||
]) | ||
); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Mod Scheduler webservice definitions | ||
* | ||
* @package mod_scheduler | ||
* @copyright 2022 University of Glasgow | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$functions = array( | ||
|
||
'mod_scheduler_studentid' => array( | ||
'classname' => 'mod_scheduler\external', | ||
'methodname' => 'studentid', | ||
'description' => 'Retrieve the list of potential studentids.', | ||
'type' => 'read', | ||
'ajax' => true, | ||
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE) | ||
), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{{! | ||
This file is part of Moodle - http://moodle.org/ | ||
Moodle is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
Moodle is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
}} | ||
{{! | ||
@template mod_scheduler/studentid | ||
Moodle template for the list of valid options in an autocomplate form element. | ||
Classes required for JS: | ||
* none | ||
Data attributes required for JS: | ||
* none | ||
Context variables required for this template: | ||
* fullname string Users full name | ||
* email string user email field | ||
Example context (json): | ||
{ | ||
"fullname": "Admin User", | ||
"extrafields": [ | ||
{ | ||
"name": "email", | ||
"value": "admin@example.com" | ||
}, | ||
{ | ||
"name": "phone1", | ||
"value": "0123456789" | ||
} | ||
] | ||
} | ||
}} | ||
<span> | ||
<span>{{fullname}}</span> | ||
{{#extrafields}} | ||
<span><small>{{{value}}}</small></span> | ||
{{/extrafields}} | ||
</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters