Skip to content

Commit

Permalink
Sem opção de campos extras. Será feito no kopere BY
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokraus committed Dec 16, 2022
1 parent 749d6ad commit 8abd2ed
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 99 deletions.
82 changes: 21 additions & 61 deletions classes/install/report_install.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ public static function create_categores() {
public static function create_reports() {
global $DB, $CFG;

$alternatenames = self::get_all_user_name_fields(true, 'u');

$table = new report_install();

$report = kopere_dashboard_reports::create_by_default();
Expand Down Expand Up @@ -140,7 +138,7 @@ public static function create_reports() {
$report->title = '[[reports_report_badge-2]]';
if ($CFG->dbtype == 'pgsql') {
$report->reportsql = "
SELECT d.id, u.id AS userid, {$alternatenames},
SELECT d.id, u.id AS userid,
u.lastname, b.\"name\" AS badgename, t.criteriatype, t.method, d.dateissued,
(SELECT c.shortname FROM {course} c WHERE c.id = b.courseid) as course
FROM {badge_issued} d
Expand All @@ -151,7 +149,7 @@ public static function create_reports() {
ORDER BY u.username";
} else {
$report->reportsql = "
SELECT d.id, u.id AS userid, {$alternatenames},
SELECT d.id, u.id AS userid,
u.lastname, b.name AS badgename, t.criteriatype, t.method, d.dateissued,
(SELECT c.shortname FROM {course} c WHERE c.id = b.courseid) as course
FROM {badge_issued} d
Expand Down Expand Up @@ -180,8 +178,8 @@ public static function create_reports() {
$report->reportkey = 'courses-1';
$report->title = '[[reports_report_courses-1]]';
$report->prerequisit = 'listCourses';
$report->reportsql = "
SELECT ue.id, u.id AS userid, {$alternatenames},
$report->reportsql = "
SELECT ue.id, u.id AS userid,
u.email,
ue.timecreated,
IFNULL( MAX(cc.timecompleted), 0) AS timecompleted,
Expand All @@ -192,8 +190,8 @@ public static function create_reports() {
JOIN {user} u ON u.id = ue.userid
JOIN {enrol} e ON e.id = ue.enrolid
JOIN {course} c ON c.id = e.courseid
LEFT JOIN {course_completions} cc ON cc.timecompleted > 0
AND cc.course = e.courseid
LEFT JOIN {course_completions} cc ON cc.timecompleted > 0
AND cc.course = e.courseid
AND cc.userid = ue.userid
LEFT JOIN (
SELECT course, count(id) AS modules
Expand All @@ -212,7 +210,7 @@ public static function create_reports() {
AND cmc_i.completionstate IN (1,2)
AND cm_i.deletioninprogress = 0
GROUP BY cm_i.course, cmc_i.userid
) AS cmc ON cmc.course = c.id
) AS cmc ON cmc.course = c.id
AND cmc.userid = ue.userid
WHERE ue.id > 0
AND u.id > 1
Expand Down Expand Up @@ -255,7 +253,7 @@ public static function create_reports() {
JOIN {groups} g ON c.id = g.courseid
WHERE c.groupmode > 0";
} else {
$report->reportsql = "
$report->reportsql = "
SELECT concat(c.id,g.id), c.id, c.fullname, c.shortname, g.name, c.visible, c.groupmode
FROM {course} c
JOIN {groups} g ON c.id = g.courseid
Expand Down Expand Up @@ -308,8 +306,8 @@ public static function create_reports() {
$report->reportcatid = $DB->get_field('kopere_dashboard_reportcat', 'id', array('type' => 'enrol_cohort'));
$report->reportkey = 'enrol_cohort-1';
$report->title = '[[reports_report_enrol_cohort-1]]';
$report->reportsql = "
SELECT u.id, {$alternatenames}, h.idnumber, h.name
$report->reportsql = "
SELECT u.id, h.idnumber, h.name
FROM {cohort} h
JOIN {cohort_members} hm ON h.id = hm.cohortid
JOIN {user} u ON hm.userid = u.id
Expand All @@ -328,8 +326,8 @@ public static function create_reports() {
$report->reportcatid = $DB->get_field('kopere_dashboard_reportcat', 'id', array('type' => 'enrol_guest'));
$report->reportkey = 'enrol_guest-1';
$report->title = '[[reports_report_enrol_guest-1]]';
$report->reportsql = "
SELECT u.id, {$alternatenames}, u.id AS userid, lsl.timecreated, lsl.ip
$report->reportsql = "
SELECT u.id, u.id AS userid, lsl.timecreated, lsl.ip
FROM {logstore_standard_log} lsl
JOIN {user} u ON u.id = lsl.userid
WHERE lsl.action LIKE 'loggedin'
Expand Down Expand Up @@ -388,7 +386,7 @@ public static function create_reports() {
$report->reportcatid = $DB->get_field('kopere_dashboard_reportcat', 'id', array('type' => 'user'));
$report->reportkey = 'user-1';
$report->title = '[[reports_report_user-1]]';
$report->reportsql = "
$report->reportsql = "
SELECT DISTINCT c.id, c.fullname, c.shortname, ctx.id AS contextid,
(SELECT COUNT(userid) FROM {role_assignments}
WHERE contextid = asg.contextid GROUP BY contextid) AS alunos
Expand All @@ -411,8 +409,8 @@ public static function create_reports() {
$report->reportcatid = $DB->get_field('kopere_dashboard_reportcat', 'id', array('type' => 'user'));
$report->reportkey = 'user-2';
$report->title = '[[reports_report_user-2]]';
$report->reportsql = "
SELECT concat(u.id, p.id) AS id, u.id AS userid, {$alternatenames},
$report->reportsql = "
SELECT concat(u.id, p.id) AS id, u.id AS userid,
c.fullname, c.shortname, t.timecompleted, p.module, p.moduleinstance
FROM {course_completion_crit_compl} t
JOIN {user} u ON t.userid = u.id
Expand All @@ -433,8 +431,8 @@ public static function create_reports() {
$report->reportcatid = $DB->get_field('kopere_dashboard_reportcat', 'id', array('type' => 'user'));
$report->reportkey = 'user-4';
$report->title = '[[reports_report_user-4]]';
$report->reportsql = "
SELECT lsl.id, u.id AS userid, {$alternatenames},
$report->reportsql = "
SELECT lsl.id, u.id AS userid,
u.email, u.city, lsl.timecreated
FROM {logstore_standard_log} lsl
JOIN {user} u ON u.id = lsl.userid
Expand All @@ -458,7 +456,7 @@ public static function create_reports() {
$report->reportkey = 'user-5';
$report->title = '[[reports_report_user-5]]';
$report->reportsql = "
SELECT u.id, {$alternatenames}, u.email, u.city, u.timecreated
SELECT u.id, u.email, u.city, u.timecreated
FROM {user} u
WHERE u.deleted = 0
AND u.lastlogin = 0
Expand All @@ -482,7 +480,7 @@ public static function create_reports() {
$report->reportkey = 'user-6';
$report->title = '[[reports_report_user-6]]';
$report->prerequisit = 'listCourses';
$report->reportsql = "SELECT concat(u.id, p.id), u.id, {$alternatenames},
$report->reportsql = "SELECT concat(u.id, p.id), u.id,
c.fullname, c.shortname, p.timecompleted
FROM {course_completions} p
JOIN {course} c ON p.course = c.id
Expand All @@ -509,7 +507,7 @@ public static function create_reports() {
$report->title = '[[reports_report_user-7]]';
if ($CFG->dbtype == 'pgsql') {
$report->reportsql = "
SELECT ue.id, u.id AS userid, ul.timeaccess, {$alternatenames}, u.email, u.city, u.lastaccess,
SELECT ue.id, u.id AS userid, ul.timeaccess, u.email, u.city, u.lastaccess,
c.fullname, c.shortname,
(SELECT r.\"name\"
FROM {user_enrolments} ue2
Expand All @@ -525,7 +523,7 @@ public static function create_reports() {
WHERE ul.timeaccess IS NULL";
} else {
$report->reportsql = "
SELECT ue.id, u.id AS userid, ul.timeaccess, {$alternatenames}, u.email, u.city, u.lastaccess,
SELECT ue.id, u.id AS userid, ul.timeaccess, u.email, u.city, u.lastaccess,
c.fullname, c.shortname,
(SELECT r.name
FROM {user_enrolments} ue2
Expand Down Expand Up @@ -635,42 +633,4 @@ private static function report_insert($report) {
$DB->insert_record('kopere_dashboard_reports', $report);
}
}

private static function get_all_user_name_fields($returnsql = false, $tableprefix = null) {
$alternatenames = [
// Para a função fullname()
'firstnamephonetic' => 'firstnamephonetic',
'lastnamephonetic' => 'lastnamephonetic',
'middlename' => 'middlename',
'alternatename' => 'alternatename',
'firstname' => 'firstname',
'lastname' => 'lastname',

// Para as configurações do setting
'institution' => 'institution',
'department' => 'department',
'phone1' => 'phone1',
'phone2' => 'phone2',
'address' => 'address',
'description' => 'description',
'city' => 'city',
'country' => 'country',
'timezone' => 'timezone',
'firstaccess' => 'firstaccess',
'lastaccess' => 'lastaccess',
'lastlogin' => 'lastlogin',
'lastip' => 'lastip',
];

// Create an sql field snippet if requested.
if ($returnsql) {
if ($tableprefix) {
foreach ($alternatenames as $key => $altname) {
$alternatenames[$key] = $tableprefix . '.' . $altname;
}
}
$alternatenames = implode(',', $alternatenames);
}
return $alternatenames;
}
}
18 changes: 1 addition & 17 deletions classes/reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function dashboard() {
* @throws \dml_exception
*/
public function load_report() {
global $DB, $CFG;
global $DB;

$report = optional_param('report', 0, PARAM_INT);
$courseid = optional_param('courseid', 0, PARAM_INT);
Expand Down Expand Up @@ -176,22 +176,6 @@ public function load_report() {
$columns->header = array();
}

if (isset($CFG->add_report_user_fields [2])) {
$report_user_fields = explode(",", $CFG->add_report_user_fields);
foreach ($report_user_fields as $report_user_field) {
if (isset($report_user_field[1])) {
$columns->columns[] = (object)[
'chave' => $report_user_field,
'type' => 'text',
'title' => get_string($report_user_field),
'funcao' => "",
'style_header' => "",
'style_col' => "",
];
}
}
}

$table = new data_table($columns->columns, $columns->header);
$table->set_ajax_url("?classname=reports&method=getdata&report={$report}&courseid={$courseid}");
$table->print_header();
Expand Down
21 changes: 0 additions & 21 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,5 @@
$open_itens
)
);

$fild_itens = [
'institution' => get_string('institution'),
'department' => get_string('department'),
'phone1' => get_string('phone1'),
'phone2' => get_string('phone2'),
'address' => get_string('address'),
'description' => get_string('description'),
'city' => get_string('city'),
'country' => get_string('country'),
'timezone' => get_string('timezone'),
'firstaccess' => get_string('firstsiteaccess'),
'lastaccess' => get_string('lastaccess'),
'lastlogin' => get_string('lastsiteaccess'),
'lastip' => get_string('lastip'),
];
$settings->add(new admin_setting_configmultiselect('add_report_user_fields',
get_string('add_report_user_fields', 'local_kopere_dashboard'),
get_string('add_report_user_fields_alt', 'local_kopere_dashboard'),
[], $fild_itens));

}
}

0 comments on commit 8abd2ed

Please sign in to comment.