MDL-59369 enrol: Edit user enrolment fragment
authorJun Pataleta <jun@moodle.com>
Thu, 13 Jul 2017 02:29:17 +0000 (10:29 +0800)
committerJun Pataleta <jun@moodle.com>
Wed, 26 Jul 2017 01:44:02 +0000 (09:44 +0800)
lib/enrollib.php

index 7157bc5..7995e77 100644 (file)
@@ -1414,6 +1414,44 @@ function enrol_send_welcome_email_options() {
     ];
 }
 
+/**
+ * Serve the user enrolment form as a fragment.
+ *
+ * @param array $args List of named arguments for the fragment loader.
+ * @return string
+ */
+function enrol_output_fragment_user_enrolment_form($args) {
+    global $CFG, $DB;
+
+    $args = (object) $args;
+    $context = $args->context;
+    require_capability('moodle/course:enrolreview', $context);
+
+    $ueid = $args->ueid;
+    $userenrolment = $DB->get_record('user_enrolments', ['id' => $ueid], '*', MUST_EXIST);
+    $customdata = [
+        'ue' => $userenrolment,
+        'modal' => true,
+    ];
+
+    // Set the data if applicable.
+    $data = [];
+    if (isset($args->formdata)) {
+        $serialiseddata = json_decode($args->formdata);
+        parse_str($serialiseddata, $data);
+    }
+
+    require_once("$CFG->dirroot/enrol/editenrolment_form.php");
+    $mform = new \enrol_user_enrolment_form(null, $customdata, 'post', '', null, true, $data);
+
+    if (!empty($data)) {
+        $mform->set_data($data);
+        $mform->is_validated();
+    }
+
+    return $mform->render();
+}
+
 /**
  * Returns the course where a user enrolment belong to.
  *