1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
declare(strict_types = 1);
|
|
|
18 |
|
|
|
19 |
namespace mod_edusharing;
|
|
|
20 |
|
|
|
21 |
use Exception;
|
|
|
22 |
|
|
|
23 |
/**
|
|
|
24 |
* Class PluginRegistrationFrontend
|
|
|
25 |
*
|
|
|
26 |
* @author Marian Ziegler <ziegler@edu-sharing.net>
|
|
|
27 |
* @package mod_edusharing
|
|
|
28 |
*/
|
|
|
29 |
class PluginRegistrationFrontend {
|
|
|
30 |
/**
|
|
|
31 |
* Function register_plugin
|
|
|
32 |
*
|
|
|
33 |
* @param string $repourl
|
|
|
34 |
* @param string $login
|
|
|
35 |
* @param string $pwd
|
|
|
36 |
* @return string
|
|
|
37 |
*/
|
|
|
38 |
public static function register_plugin(string $repourl, string $login, string $pwd): string {
|
|
|
39 |
$return = '';
|
|
|
40 |
$errormessage = '<h3 class="edu_error">ERROR: Could not register the edusharing-moodle-plugin at: '.$repourl.'</h3>';
|
|
|
41 |
$service = new EduSharingService();
|
|
|
42 |
$registrationlogic = new PluginRegistration($service);
|
|
|
43 |
$metadatalogic = new MetadataLogic($service);
|
|
|
44 |
$data = $metadatalogic->create_xml_metadata();
|
|
|
45 |
try {
|
|
|
46 |
$result = $registrationlogic->register_plugin($repourl, $login, $pwd, $data);
|
|
|
47 |
} catch (Exception $exception) {
|
|
|
48 |
$exceptionmessage = $exception instanceof EduSharingUserException
|
|
|
49 |
? $exception->getMessage() : 'Unexpected error';
|
|
|
50 |
$return .= $errormessage . '<p class="edu_error">' . $exceptionmessage . '</p>';
|
|
|
51 |
return $return;
|
|
|
52 |
}
|
|
|
53 |
if (isset($result['appid'])) {
|
|
|
54 |
return '<h3 class="edu_success">Successfully registered the edusharing-moodle-plugin at: '. $repourl .'</h3>';
|
|
|
55 |
}
|
|
|
56 |
$return .= $errormessage . isset($result['message']) ? '<p class="edu_error">'.$result['message'].'</p>' : '';
|
|
|
57 |
$return .= '<h3>Register the Moodle-Plugin in the Repository manually:</h3>';
|
|
|
58 |
// phpcs:disable -- just messy html.
|
|
|
59 |
$return .= '<p class="edu_metadata"> To register the Moodle-PlugIn manually got to the
|
|
|
60 |
<a href="'.$repourl.'" target="_blank"> Repository</a> and open the "APPLICATIONS"-tab of the "Admin-Tools" interface.<br>
|
|
|
61 |
Only the system administrator may use this tool.<br>
|
|
|
62 |
Enter the URL of the Moodle you want to connect. The URL should look like this:
|
|
|
63 |
„[Moodle-install-directory]/mod/edusharing/metadata.php".<br>
|
|
|
64 |
Click on "CONNECT" to register the LMS. You will be notified with a feedback message and your LMS instance
|
|
|
65 |
will appear as an entry in the list of registered applications.<br>
|
|
|
66 |
If the automatic registration failed due to a connection issue caused by a proxy-server, you also need to
|
|
|
67 |
add the proxy-server IP-address as a "host_aliases"-attribute.
|
|
|
68 |
</p>';
|
|
|
69 |
// phpcs:enable
|
|
|
70 |
|
|
|
71 |
return $return;
|
|
|
72 |
}
|
|
|
73 |
}
|