Enter in your MoodleNet profile details here to be redirected to your profile while visiting MoodleNet.
'; +$string['moodlenetsettings'] = 'MoodleNet settings'; +$string['moodlenetnotenabled'] = 'The MoodleNet integration must be enabled before resource imports can be processed. +To enable this feature, see the \'enablemoodlenet\' setting.'; +$string['notification'] = 'You are about to import the content "{$a->name} ({$a->type})" into your site. Select the course in which it should be added, or cancel.'; +$string['searchcourses'] = "Search courses"; +$string['selectpagetitle'] = 'Select page'; +$string['pluginname'] = 'MoodleNet'; +$string['privacy:metadata'] = "The MoodleNet tool only facilitates communication with MoodleNet. It stores no data."; +$string['profilevalidationerror'] = 'There was a problem trying to validate your profile'; +$string['profilevalidationfail'] = 'Please enter a valid MoodleNet profile'; +$string['profilevalidationpass'] = 'Looks good!'; +$string['saveandgo'] = "Save and go"; +$string['uploadlimitexceeded'] = 'The file size {$a->filesize} exceeds the user upload limit of {$a->uploadlimit} bytes.'; diff --git a/admin/tool/moodlenet/lib.php b/admin/tool/moodlenet/lib.php new file mode 100644 index 00000000000..5affcd9de19 --- /dev/null +++ b/admin/tool/moodlenet/lib.php @@ -0,0 +1,104 @@ +. + +/** + * This page lists public api for tool_moodlenet plugin. + * + * @package tool_moodlenet + * @copyright 2020 Peter Dias + * @license http://www.gnu.org/copyleft/gpl.html GNU + */ + +defined('MOODLE_INTERNAL') || die; + +use \core_course\local\entity\activity_chooser_footer; + +/** + * The default endpoint to MoodleNet. + */ +define('MOODLENET_DEFAULT_ENDPOINT', "lms/moodle/search"); + +/** + * Generate the endpoint url to the user's moodlenet site. + * + * @param string $profileurl The user's moodlenet profile page + * @param int $course The moodle course the mnet resource will be added to + * @param int $section The section of the course will be added to. Defaults to the 0th element. + * @return string the resulting endpoint + * @throws moodle_exception + */ +function generate_mnet_endpoint(string $profileurl, int $course, int $section = 0) { + global $CFG; + $urlportions = explode('@', $profileurl); + $domain = end($urlportions); + $parsedurl = parse_url($domain); + $params = [ + 'site' => $CFG->wwwroot, + 'course' => $course, + 'section' => $section + ]; + $endpoint = new moodle_url(MOODLENET_DEFAULT_ENDPOINT, $params); + return (isset($parsedurl['scheme']) ? $domain : "https://$domain")."/{$endpoint->out(false)}"; +} + +/** + * Hooking function to build up the initial Activity Chooser footer information for MoodleNet + * + * @param int $courseid The course the user is currently in and wants to add resources to + * @param int $sectionid The section the user is currently in and wants to add resources to + * @return activity_chooser_footer + * @throws dml_exception + * @throws moodle_exception + */ +function tool_moodlenet_custom_chooser_footer(int $courseid, int $sectionid): activity_chooser_footer { + global $CFG, $USER, $OUTPUT; + $defaultlink = get_config('tool_moodlenet', 'defaultmoodlenet'); + $enabled = get_config('tool_moodlenet', 'enablemoodlenet'); + + $advanced = false; + // We are in the MoodleNet lib. It is safe assume we have our own functions here. + $mnetprofile = \tool_moodlenet\profile_manager::get_moodlenet_user_profile($USER->id); + if ($mnetprofile !== null) { + $advanced = $mnetprofile->get_domain() ?? false; + } + + $defaultlink = generate_mnet_endpoint($defaultlink, $courseid, $sectionid); + if ($advanced !== false) { + $advanced = generate_mnet_endpoint($advanced, $courseid, $sectionid); + } + + $renderedfooter = $OUTPUT->render_from_template('tool_moodlenet/chooser_footer', (object)[ + 'enabled' => (bool)$enabled, + 'generic' => $defaultlink, + 'advanced' => $advanced, + 'courseID' => $courseid, + 'sectionID' => $sectionid, + 'img' => $OUTPUT->image_url('MoodleNet', 'tool_moodlenet')->out(false), + ]); + + $renderedcarousel = $OUTPUT->render_from_template('tool_moodlenet/chooser_moodlenet', (object)[ + 'buttonName' => get_config('tool_moodlenet', 'defaultmoodlenetname'), + 'generic' => $defaultlink, + 'courseID' => $courseid, + 'sectionID' => $sectionid, + 'img' => $OUTPUT->image_url('MoodleNet', 'tool_moodlenet')->out(false), + ]); + return new activity_chooser_footer( + 'tool_moodlenet/instance_form', + $renderedfooter, + $renderedcarousel + ); +} diff --git a/admin/tool/moodlenet/options.php b/admin/tool/moodlenet/options.php new file mode 100644 index 00000000000..a510f53e206 --- /dev/null +++ b/admin/tool/moodlenet/options.php @@ -0,0 +1,128 @@ +. + +/** + * Page to select WHAT to do with a given resource stored on MoodleNet. + * + * This collates and presents the same options as a user would see for a drag and drop upload. + * That is, it leverages the dndupload_register() hooks and delegates the resource handling to the dndupload_handle hooks. + * + * This page requires a course, section an resourceurl to be provided via import_info. + * + * @package tool_moodlenet + * @copyright 2020 Jake Dallimore