Browse Source

Use table_sql for manage table generation.

SABERES_37_STABLE
Johannes Burk 9 years ago
committed by test
parent
commit
a01b669a5f
  1. 30
      lib.php
  2. 87
      manage.php
  3. 86
      manage_table.php
  4. 3
      style.css

30
lib.php

@ -238,36 +238,6 @@ class enrol_apply_plugin extends enrol_plugin {
}
}
function getAllEnrolment($id = null) {
global $DB;
if ($id) {
$sql = 'SELECT ue.userid,ue.id,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status
FROM {course} c
JOIN {enrol} e
ON e.courseid = c.id
JOIN {user_enrolments} ue
ON ue.enrolid = e.id
JOIN {user} u
ON ue.userid = u.id
WHERE ue.status != 0
AND e.id = ?';
$userenrolments = $DB->get_records_sql($sql, array($id));
} else {
$sql = 'SELECT ue.id,ue.userid,u.firstname,u.lastname,u.email,u.picture,c.fullname as course,ue.timecreated,ue.status
FROM {user_enrolments} ue
LEFT JOIN {user} u
ON ue.userid = u.id
LEFT JOIN {enrol} e
ON ue.enrolid = e.id
LEFT JOIN {course} c
ON e.courseid = c.id
WHERE ue.status != 0
AND e.enrol = ?';
$userenrolments = $DB->get_records_sql($sql, array('apply'));
}
return $userenrolments;
}
function confirmEnrolment($enrols){
global $DB;
global $CFG;

87
manage.php

@ -12,6 +12,7 @@
require_once ('../../config.php');
require_once($CFG->dirroot.'/enrol/apply/lib.php');
require_once($CFG->dirroot.'/enrol/apply/manage_table.php');
$id = optional_param('id', null, PARAM_INT);
$userenrolments = optional_param_array('userenrolments', null, PARAM_INT);
@ -41,6 +42,7 @@ $PAGE->set_pagelayout('admin');
$PAGE->set_heading($pageheading);
$PAGE->navbar->add(get_string('confirmusers', 'enrol_apply'));
$PAGE->set_title(get_string('confirmusers', 'enrol_apply'));
$PAGE->requires->css('/enrol/apply/style.css');
if ($userenrolments != null) {
$action = required_param('type', PARAM_TEXT);
@ -61,59 +63,37 @@ if ($userenrolments != null) {
redirect($manageurl);
}
$enrols = getAllEnrolment($id);
if ($id == null) {
$applicationinfo = $DB->get_records_sql('
SELECT userenrolmentid, comment
FROM {enrol_apply_applicationinfo}
WHERE userenrolmentid IN (
SELECT id
FROM {user_enrolments}
WHERE enrolid IN (
SELECT id
FROM {enrol}
WHERE enrol = ?))', array('apply'));
} else {
$applicationinfo = $DB->get_records_sql('
SELECT userenrolmentid, comment
FROM {enrol_apply_applicationinfo}
WHERE userenrolmentid IN (
SELECT id
FROM {user_enrolments}
WHERE enrolid = ?)', array($instance->id));
}
echo $OUTPUT->header ();
echo $OUTPUT->heading ( get_string ( 'confirmusers', 'enrol_apply' ) );
echo get_string('confirmusers_desc', 'enrol_apply');
$table = new enrol_apply_manage_table($id);
$table->define_baseurl($manageurl);
$columns = array(
'checkboxcolumn',
'course',
'fullname', // Magic happens here: The column heading will automatically be set.
'email',
'applydate',
'applycomment');
$headers = array(
'',
get_string('course'),
'fullname', // Magic happens here: The column heading will automatically be set due to column name 'fullname'.
get_string('email'),
get_string('applydate', 'enrol_apply'),
get_string('comment', 'enrol_apply'));
$table->define_columns($columns);
$table->define_headers($headers);
$table->sortable(true, 'id');
echo '<form id="frmenrol" method="post" action="manage.php?id=' . $id . '">';
echo '<input type="hidden" id="type" name="type" value="confirm">';
echo '<table class="generalbox editcourse boxaligncenter"><tr class="header">';
echo '<th class="header" scope="col">&nbsp;</th>';
echo '<th class="header" scope="col">' . get_string ( 'coursename', 'enrol_apply' ) . '</th>';
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 ( 'applyusermail', '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>';
foreach ( $enrols as $enrol ) {
$picture = get_user_picture($enrol->userid);
if ($enrol->status == 2) {
echo '<tr style="vertical-align: top; background-color: #ccc;">';
} else {
echo '<tr style="vertical-align: top;">';
}
echo '<td><input type="checkbox" name="userenrolments[]" value="' . $enrol->id . '"></td>';
echo '<td>' . format_string($enrol->course) . '</td>';
echo '<td>' . $OUTPUT->render($picture) . '</td>';
echo '<td>'.$enrol->firstname . ' ' . $enrol->lastname.'</td>';
echo '<td>' . $enrol->email . '</td>';
echo '<td>' . date ( "Y-m-d", $enrol->timecreated ) . '</td>';
echo '<td>' . htmlspecialchars($applicationinfo[$enrol->id]->comment) . '</td>';
echo '</tr>';
}
echo '</table>';
$table->out(50, true);
echo '<p align="center">';
echo '<input type="button" value="' . get_string ( 'btnconfirm', 'enrol_apply' ) . '" onclick="doSubmit(\'confirm\');">';
echo '<input type="button" value="' . get_string ( 'btnwait', 'enrol_apply' ) . '" onclick="doSubmit(\'wait\');">';
@ -125,14 +105,3 @@ echo '<script>function doSubmit(type){
document.getElementById("frmenrol").submit();
}</script>';
echo $OUTPUT->footer ();
function get_user_picture($userid){
global $DB;
$extrafields[] = 'lastaccess';
$ufields = user_picture::fields('u', $extrafields);
$sql = "SELECT DISTINCT $ufields FROM {user} u where u.id=$userid";
$user = $DB->get_record_sql($sql);
return new user_picture($user);
}

86
manage_table.php

@ -0,0 +1,86 @@
<?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 2016 Johannes Burk
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/tablelib.php');
class enrol_apply_manage_table extends table_sql {
public $is_collapsible = false;
public function __construct($enrolid = null) {
parent::__construct('enrol_apply_manage_table');
global $DB;
$sqlwhere = 'ue.status != 0';
$sqlparams = array();
if ($enrolid != null) {
$sqlwhere .= " AND e.id = :enrolid";
$sqlparams['enrolid'] = $enrolid;
} else {
$sqlwhere = "e.enrol = :enrol";
$sqlparams['enrol'] = 'apply';
}
$this->set_sql(
'ue.id AS userenrolmentid, ue.userid, ue.status AS enrolstatus, ue.timecreated AS applydate, ai.comment AS applycomment, u.*, c.fullname as course',
"{user_enrolments} AS ue
LEFT JOIN {enrol_apply_applicationinfo} AS ai ON ai.userenrolmentid = ue.id
JOIN {user} AS u ON u.id = ue.userid
JOIN {enrol} AS e ON e.id = ue.enrolid
JOIN {course} AS c ON c.id = e.courseid",
$sqlwhere,
$sqlparams);
}
/**
* Get any extra classes names to add to this row in the HTML.
* @param $row array the data for this row. Note (Johannes): this is actually an object with all sql columns.
* @return string added to the class="" attribute of the tr.
*/
function get_row_class($row) {
if ($row->enrolstatus == 2) {
return 'enrol_apply_waitinglist_highlight';
}
return '';
}
public function col_checkboxcolumn($row) {
return html_writer::checkbox('userenrolments[]', $row->userenrolmentid, false);
}
public function col_fullname($row) {
// $row contains all user fields, see sql query.
global $OUTPUT;
$col = $OUTPUT->user_picture($row, array('popup'=>true));
$col .= fullname($row);
return $col;
}
public function col_applydate($row) {
return date("Y-m-d", $row->applydate);
}
}

3
style.css

@ -0,0 +1,3 @@
.enrol_apply_waitinglist_highlight {
border-left: 6px solid grey;
}
Loading…
Cancel
Save