diff --git a/apply.php b/apply.php index df7fd4a..9910698 100644 --- a/apply.php +++ b/apply.php @@ -48,6 +48,13 @@ if ($userenrolments != null) { } $enrols = getAllEnrolment ($enrolid); +$applicationinfo = $DB->get_records_sql(' + SELECT userenrolmentid, comment + FROM {enrol_apply_applicationinfo} + WHERE userenrolmentid IN ( + SELECT id + FROM {user_enrolments} + WHERE enrolid = ?)', array($enrolid)); echo $OUTPUT->header (); echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); @@ -61,6 +68,7 @@ echo ' '; echo '' . get_string ( 'applyuser', 'enrol_apply' ) . ''; echo '' . get_string ( 'applyusermail', 'enrol_apply' ) . ''; echo '' . get_string ( 'applydate', 'enrol_apply' ) . ''; +echo '' . get_string ( 'comment', 'enrol_apply' ) . ''; echo ''; foreach ( $enrols as $enrol ) { $picture = get_user_picture($enrol->userid); @@ -74,7 +82,9 @@ foreach ( $enrols as $enrol ) { echo '' . $OUTPUT->render($picture) . ''; echo ''.$enrol->firstname . ' ' . $enrol->lastname.''; echo '' . $enrol->email . ''; - echo '' . date ( "Y-m-d", $enrol->timecreated ) . ''; + echo '' . date ( "Y-m-d", $enrol->timecreated ) . ''; + echo '' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . ''; + echo ''; } echo ''; echo '

'; diff --git a/db/install.xml b/db/install.xml new file mode 100644 index 0000000..4b69458 --- /dev/null +++ b/db/install.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + +
+
+
\ No newline at end of file diff --git a/db/upgrade.php b/db/upgrade.php new file mode 100644 index 0000000..07d3053 --- /dev/null +++ b/db/upgrade.php @@ -0,0 +1,54 @@ +. + +/** + * @package enrol_apply + * @copyright emeneo.com + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @author Johannes Burk + */ + +defined('MOODLE_INTERNAL') || die; + +function xmldb_enrol_apply_upgrade($oldversion) { + global $CFG, $DB; + + $dbman = $DB->get_manager(); + + if ($oldversion < 2016012801) { + + // Define table enrol_apply_applicationinfo to be created. + $table = new xmldb_table('enrol_apply_applicationinfo'); + + // Adding fields to table enrol_apply_applicationinfo. + $table->add_field('id', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, XMLDB_SEQUENCE, null); + $table->add_field('userenrolmentid', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, null); + $table->add_field('comment', XMLDB_TYPE_TEXT, null, null, null, null, null); + + // Adding keys to table enrol_apply_applicationinfo. + $table->add_key('primary', XMLDB_KEY_PRIMARY, array('id')); + $table->add_key('userenrolment', XMLDB_KEY_FOREIGN_UNIQUE, array('userenrolmentid'), 'user_enrolments', array('id')); + + // Conditionally launch create table for enrol_apply_applicationinfo. + if (!$dbman->table_exists($table)) { + $dbman->create_table($table); + } + + // Apply savepoint reached. + upgrade_plugin_savepoint(true, 2016012801, 'enrol', 'apply'); + } + +} \ No newline at end of file diff --git a/lib.php b/lib.php index 781fe41..bbd633a 100644 --- a/lib.php +++ b/lib.php @@ -122,6 +122,11 @@ class enrol_apply_plugin extends enrol_plugin { } $this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); + $userenrolment = $DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id), 'id', MUST_EXIST); + $applicationinfo = new stdClass(); + $applicationinfo->userenrolmentid = $userenrolment->id; + $applicationinfo->comment = $applydescription; + $DB->insert_record('enrol_apply_applicationinfo', $applicationinfo, false); sendConfirmMailToTeachers($instance, $data, $applydescription); sendConfirmMailToManagers($instance, $data, $applydescription); @@ -285,6 +290,7 @@ function confirmEnrolment($enrols){ @$roleAssignments->modifierid = 2; $DB->insert_record('role_assignments',$roleAssignments); $info = getRelatedInfo($enrol); + $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); sendConfirmMail($info); } } @@ -309,6 +315,7 @@ function cancelEnrolment($enrols){ foreach ($enrols as $enrol){ $info = getRelatedInfo($enrol); if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ + $DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol)); sendCancelMail($info); } } diff --git a/version.php b/version.php index 4bd8012..25f326c 100644 --- a/version.php +++ b/version.php @@ -18,7 +18,7 @@ */ defined('MOODLE_INTERNAL') || die(); -$plugin->version = 2016012800; +$plugin->version = 2016012801; $plugin->requires = 2011080100; $plugin->maturity = MATURITY_STABLE; $plugin->release = 'Enrolment upon approval plugin Version 3.0-a';