Files
meetletacbfree/classes/external/get_content_launch_url.php
T

98 lines
3.8 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: SSO URL to view uploaded meeting content in Adobe Connect.
*
* @package mod_meetletacbfree
* @copyright 2026 MeetLet <info@meetlet.net>
* @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\api\service;
use mod_meetletacbfree\local\config;
use mod_meetletacbfree\local\content;
use mod_meetletacbfree\local\featureaccess;
use mod_meetletacbfree\local\instance;
use mod_meetletacbfree\local\roles;
use mod_meetletacbfree\local\sso;
use mod_meetletacbfree\local\usererror;
use moodle_exception;
defined('MOODLE_INTERNAL') || die();
/**
* Prepare Adobe Connect content view URL with session for current user.
*/
class get_content_launch_url 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'),
'contentscoid' => new external_value(PARAM_INT, 'Content sco id'),
'groupid' => new external_value(PARAM_INT, 'Group id', VALUE_DEFAULT, 0),
]);
}
public static function execute(int $cmid, int $contentscoid, int $groupid = 0): array {
global $USER;
$params = self::validate_parameters(self::execute_parameters(), [
'cmid' => $cmid,
'contentscoid' => $contentscoid,
'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);
featureaccess::require_feature(featureaccess::CONTENT, $inst->context, $inst->record);
$service = new service();
$service->login_admin();
$item = content::find_in_meeting($service, $inst->require_meeting(), (int)$params['contentscoid']);
$service->logout();
if (!$item || empty($item->urlpath)) {
throw new moodle_exception('nocontent', 'meetletacbfree');
}
try {
$adoberole = roles::resolve_adobe_role($inst->record, $inst->context, $USER->id);
$permission = $adoberole ?: service::ROLE_PARTICIPANT;
$auth = sso::provision_and_login($USER, (int)$params['contentscoid'], $permission);
$url = config::content_view_url((string)$item->urlpath, $auth['cookie']);
return usererror::ws_ok($url);
} catch (\Throwable $e) {
if ($e instanceof moodle_exception && in_array($e->errorcode, ['nopermissions', 'requirelogin', 'invalidparameter'], true)) {
throw $e;
}
return usererror::ws_fail($e, $inst->context);
}
}
public static function execute_returns(): external_single_structure {
return new external_single_structure(usererror::ws_url_returns());
}
}