91334a46b5
Co-authored-by: Cursor <cursoragent@cursor.com>
87 lines
3.3 KiB
PHP
87 lines
3.3 KiB
PHP
<?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/>.
|
|
|
|
/**
|
|
* Ajax: poll meeting join status.
|
|
*
|
|
* @package mod_meetletacbfree
|
|
* @copyright 2026 MeetLet
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
|
|
namespace mod_meetletacbfree\external;
|
|
|
|
use core_external\external_api;
|
|
use core_external\external_function_parameters;
|
|
use core_external\external_single_structure;
|
|
use core_external\external_value;
|
|
use mod_meetletacbfree\local\featureaccess;
|
|
use mod_meetletacbfree\local\instance;
|
|
use mod_meetletacbfree\local\meetingstatus;
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
/**
|
|
* Lightweight status poll for the activity hero badge / join gate.
|
|
*/
|
|
class get_meeting_status extends external_api {
|
|
public static function execute_parameters(): external_function_parameters {
|
|
return new external_function_parameters([
|
|
'cmid' => new external_value(PARAM_INT, 'Course module id'),
|
|
'groupid' => new external_value(PARAM_INT, 'Group id', VALUE_DEFAULT, 0),
|
|
]);
|
|
}
|
|
|
|
public static function execute(int $cmid, int $groupid = 0): array {
|
|
global $USER;
|
|
|
|
$params = self::validate_parameters(self::execute_parameters(), [
|
|
'cmid' => $cmid,
|
|
'groupid' => $groupid,
|
|
]);
|
|
|
|
\mod_meetletacbfree\registration\manager::require_registered();
|
|
|
|
$inst = instance::get_from_cmid($params['cmid'], $params['groupid']);
|
|
self::validate_context($inst->context);
|
|
require_capability('mod/meetletacbfree:view', $inst->context);
|
|
|
|
$info = meetingstatus::resolve($inst, (int)$USER->id, true);
|
|
$featurejoin = featureaccess::allowed(featureaccess::JOIN, $inst->context, $inst->record);
|
|
$joinable = $featurejoin && !empty($info['joinable']);
|
|
|
|
return [
|
|
'status' => (string)$info['status'],
|
|
'statuslabel' => (string)$info['statuslabel'],
|
|
'joinable' => (bool)$joinable,
|
|
'message' => (string)$info['message'],
|
|
'errorcode' => (string)$info['errorcode'],
|
|
'servertime' => time(),
|
|
];
|
|
}
|
|
|
|
public static function execute_returns(): external_single_structure {
|
|
return new external_single_structure([
|
|
'status' => new external_value(PARAM_ALPHANUMEXT, 'Status code'),
|
|
'statuslabel' => new external_value(PARAM_TEXT, 'Localized status label'),
|
|
'joinable' => new external_value(PARAM_BOOL, 'Whether join may be requested'),
|
|
'message' => new external_value(PARAM_TEXT, 'User-facing gate message'),
|
|
'errorcode' => new external_value(PARAM_ALPHANUMEXT, 'Exception string id when not joinable'),
|
|
'servertime' => new external_value(PARAM_INT, 'Server unix time'),
|
|
]);
|
|
}
|
|
}
|