Hi,
In $navigation->add the second parameters should be the url of you page, something like that new moodle_url('/local/coursecompletion/view.php')
For your renderer you shoulduse Moodle api but im not good with it (to not said bad)
So I'll give a you an example without it that you can consider has a proove of concept and I didn't test it so it can have syntax error or else !
<?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 local_coursecompletion
* @copyright 2023 xyz
* @author Tagnavi M Y
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/locallib.php');
global $DB, $USER;
if (!has_capability('local/coursecompletion:canview', \context_system::instance())) {
die;
}
$PAGE->set_url('/local/coursecompletion/view.php');
$PAGE->set_title(format_string(get_string('main_title','local_coursecompletion'));
$PAGE->set_heading(format_string('...'));
$PAGE->set_context(\context_system::instance());
echo $OUTPUT->header();
// $completions = get_completions($USER->id); // from locallib
// The function that has to be put in the locallib.php is
// function get_completions($userid) {
// $rs = $DB->get_records_sql('SELECT t2.shortname, t2.fullname, t1.timecompleted from mdl_course_completions t1, mdl_course t2 WHERE t1.userid = ? AND t1.course = t2.id', array($userid));
// return $rs;
// }
// but for test
$rs = $DB->get_records_sql('SELECT t2.shortname, t2.fullname, t1.timecompleted from mdl_course_completions t1, mdl_course t2 WHERE t1.timecompleted is not null AND t1.userid = ? AND t1.course = t2.id', array($USER->id));
echo('<table>
<thead>
<tr>
<th>'.get_string('header1', 'local_coursecompletion').'</th>
<th>'.get_string('header2', 'local_coursecompletion').'</th>
<th>'.get_string('header3', 'local_coursecompletion').'</th>
</tr>
</thead>
<tbody>
');
foreach ($rs as $completion) {
echo('<tr>
<td>'.$completion->shortname.'</td>
<td>'.$completion->fullname.'</td>
<td>'.date("Y-m-d",$completion->timecompleted).'</td>
</tr>
');
}
echo('
</tbody>
</table>
');
echo $OUTPUT->footer();