Browse Source

Store user comment for enrolment application in database to display it in the apply table.

Create enrol_apply_applicationinfo table
SABERES_37_STABLE
Johannes Burk 9 years ago
parent
commit
871cff063d
  1. 12
      apply.php
  2. 19
      db/install.xml
  3. 54
      db/upgrade.php
  4. 7
      lib.php
  5. 2
      version.php

12
apply.php

@ -48,6 +48,13 @@ if ($userenrolments != null) {
} }
$enrols = getAllEnrolment ($enrolid); $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->header ();
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) ); echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) );
@ -61,6 +68,7 @@ echo '<th class="header" scope="col">&nbsp;</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyuser', 'enrol_apply' ) . '</th>'; echo '<th class="header" scope="col">' . get_string ( 'applyuser', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applyusermail', 'enrol_apply' ) . '</th>'; echo '<th class="header" scope="col">' . get_string ( 'applyusermail', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply' ) . '</th>'; echo '<th class="header" scope="col">' . get_string ( 'applydate', 'enrol_apply' ) . '</th>';
echo '<th class="header" scope="col">' . get_string ( 'comment', 'enrol_apply' ) . '</th>';
echo '</tr>'; echo '</tr>';
foreach ( $enrols as $enrol ) { foreach ( $enrols as $enrol ) {
$picture = get_user_picture($enrol->userid); $picture = get_user_picture($enrol->userid);
@ -74,7 +82,9 @@ foreach ( $enrols as $enrol ) {
echo '<td>' . $OUTPUT->render($picture) . '</td>'; echo '<td>' . $OUTPUT->render($picture) . '</td>';
echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>'; echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>';
echo '<td>' . $enrol->email . '</td>'; echo '<td>' . $enrol->email . '</td>';
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td></tr>'; echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td>';
echo '<td>' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '</td>';
echo '</tr>';
} }
echo '</table>'; echo '</table>';
echo '<p align="center">'; echo '<p align="center">';

19
db/install.xml

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="enrol/apply/db" VERSION="20160409" COMMENT="XMLDB file for Moodle enrol/apply"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="enrol_apply_applicationinfo" COMMENT="Table containing additional information for each enrolment application.">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="userenrolmentid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="user enrolment id this entry belongs to"/>
<FIELD NAME="comment" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="comment given by the user during application"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id"/>
<KEY NAME="userenrolment" TYPE="foreign-unique" FIELDS="userenrolmentid" REFTABLE="user_enrolments" REFFIELDS="id"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>

54
db/upgrade.php

@ -0,0 +1,54 @@
<?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/>.
/**
* @package enrol_apply
* @copyright emeneo.com
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Johannes Burk <johannes.burk@sudile.com>
*/
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');
}
}

7
lib.php

@ -122,6 +122,11 @@ class enrol_apply_plugin extends enrol_plugin {
} }
$this->enrol_user($instance, $USER->id, $roleid, $timestart, $timeend,1); $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); sendConfirmMailToTeachers($instance, $data, $applydescription);
sendConfirmMailToManagers($instance, $data, $applydescription); sendConfirmMailToManagers($instance, $data, $applydescription);
@ -285,6 +290,7 @@ function confirmEnrolment($enrols){
@$roleAssignments->modifierid = 2; @$roleAssignments->modifierid = 2;
$DB->insert_record('role_assignments',$roleAssignments); $DB->insert_record('role_assignments',$roleAssignments);
$info = getRelatedInfo($enrol); $info = getRelatedInfo($enrol);
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
sendConfirmMail($info); sendConfirmMail($info);
} }
} }
@ -309,6 +315,7 @@ function cancelEnrolment($enrols){
foreach ($enrols as $enrol){ foreach ($enrols as $enrol){
$info = getRelatedInfo($enrol); $info = getRelatedInfo($enrol);
if($DB->delete_records('user_enrolments',array('id'=>$enrol))){ if($DB->delete_records('user_enrolments',array('id'=>$enrol))){
$DB->delete_records('enrol_apply_applicationinfo', array('userenrolmentid' => $enrol));
sendCancelMail($info); sendCancelMail($info);
} }
} }

2
version.php

@ -18,7 +18,7 @@
*/ */
defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();
$plugin->version = 2016012800; $plugin->version = 2016012801;
$plugin->requires = 2011080100; $plugin->requires = 2011080100;
$plugin->maturity = MATURITY_STABLE; $plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Enrolment upon approval plugin Version 3.0-a'; $plugin->release = 'Enrolment upon approval plugin Version 3.0-a';

Loading…
Cancel
Save