Skip to content

Commit 9ed4c34

Browse files
committed
OWORK-654 add tool_certify
1 parent 148f02b commit 9ed4c34

File tree

155 files changed

+25610
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+25610
-0
lines changed

catalogue/certification.php

+99
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Certification browsing for learners.
19+
*
20+
* @package tool_certify
21+
* @copyright 2023 Open LMS (https://www.openlms.net/)
22+
* @author Petr Skoda
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
/** @var moodle_database $DB */
27+
/** @var moodle_page $PAGE */
28+
/** @var core_renderer $OUTPUT */
29+
/** @var stdClass $CFG */
30+
/** @var stdClass $COURSE */
31+
/** @var stdClass $USER */
32+
33+
require('../../../../config.php');
34+
35+
$id = required_param('id', PARAM_INT);
36+
37+
$syscontext = context_system::instance();
38+
39+
$PAGE->set_url(new moodle_url('/admin/tool/certify/catalogue/certification.php', ['id' => $id]));
40+
$PAGE->set_context(context_system::instance());
41+
42+
require_login();
43+
require_capability('tool/certify:viewcatalogue', context_system::instance());
44+
45+
if (!enrol_is_enabled('programs')) {
46+
redirect(new moodle_url('/'));
47+
}
48+
49+
$certification = $DB->get_record('tool_certify_certifications', ['id' => $id]);
50+
if (!$certification || $certification->archived) {
51+
if ($certification) {
52+
$context = context::instance_by_id($certification->contextid);
53+
} else {
54+
$context = context_system::instance();
55+
}
56+
if (has_capability('tool/certify:view', $context)) {
57+
if ($certification) {
58+
redirect(new moodle_url('/admin/tool/certify/management/certification.php', ['id' => $certification->id]));
59+
} else {
60+
redirect(new moodle_url('/admin/tool/certify/management/index.php'));
61+
}
62+
} else {
63+
redirect(new moodle_url('/admin/tool/certify/catalogue/index.php'));
64+
}
65+
}
66+
$certificationcontext = context::instance_by_id($certification->contextid);
67+
68+
$assignment = $DB->get_record('tool_certify_assignments', ['certificationid' => $certification->id, 'userid' => $USER->id]);
69+
if ($assignment && !$assignment->archived) {
70+
redirect(new moodle_url('/admin/tool/certify/my/certification.php', ['id' => $id]));
71+
}
72+
73+
if (!\tool_certify\local\catalogue::is_certification_visible($certification)) {
74+
if (has_capability('tool/certify:view', $certificationcontext)) {
75+
redirect(new moodle_url('/admin/tool/certify/management/certification.php', ['id' => $certification->id]));
76+
} else {
77+
redirect(new moodle_url('/admin/tool/certify/catalogue/index.php'));
78+
}
79+
}
80+
81+
if (has_capability('tool/certify:view', $certificationcontext)) {
82+
$manageurl = new moodle_url('/admin/tool/certify/management/certification.php', ['id' => $certification->id]);
83+
$button = html_writer::link($manageurl, get_string('management', 'tool_certify'), ['class' => 'btn btn-secondary']);
84+
$PAGE->set_button($button . $PAGE->button);
85+
}
86+
87+
/** @var \tool_certify\output\catalogue\renderer $catalogueoutput */
88+
$catalogueoutput = $PAGE->get_renderer('tool_certify', 'catalogue');
89+
90+
$PAGE->set_heading(get_string('catalogue', 'tool_certify'));
91+
$PAGE->navigation->override_active_url(new moodle_url('/admin/tool/certify/catalogue/index.php'));
92+
$PAGE->set_title(get_string('catalogue', 'tool_certify'));
93+
$PAGE->navbar->add(format_string($certification->fullname));
94+
95+
echo $OUTPUT->header();
96+
97+
echo $catalogueoutput->render_certification($certification);
98+
99+
echo $OUTPUT->footer();

catalogue/index.php

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Certification browsing for learners.
19+
*
20+
* @package tool_certify
21+
* @copyright 2023 Open LMS (https://www.openlms.net/)
22+
* @author Petr Skoda
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
/** @var moodle_database $DB */
27+
/** @var moodle_page $PAGE */
28+
/** @var core_renderer $OUTPUT */
29+
/** @var stdClass $CFG */
30+
/** @var stdClass $COURSE */
31+
32+
require('../../../../config.php');
33+
require_once($CFG->dirroot . '/lib/formslib.php');
34+
35+
$catalogue = new \tool_certify\local\catalogue($_REQUEST);
36+
$syscontext = context_system::instance();
37+
38+
$PAGE->set_url($catalogue->get_current_url());
39+
$PAGE->set_context($syscontext);
40+
41+
require_login();
42+
require_capability('tool/certify:viewcatalogue', $syscontext);
43+
44+
if (!enrol_is_enabled('programs')) {
45+
redirect(new moodle_url('/'));
46+
}
47+
48+
$buttons = [];
49+
$manageurl = \tool_certify\local\management::get_management_url();
50+
if ($manageurl) {
51+
$buttons[] = html_writer::link($manageurl, get_string('management', 'tool_certify'), ['class' => 'btn btn-secondary']);
52+
}
53+
if (!isguestuser()) {
54+
$mycertificationsurl = new moodle_url('/admin/tool/certify/my/index.php');
55+
$buttons[] = html_writer::link($mycertificationsurl, get_string('mycertifications', 'tool_certify'), ['class' => 'btn btn-secondary']);
56+
}
57+
$buttons = implode('&nbsp;', $buttons);
58+
$PAGE->set_button($buttons . $PAGE->button);
59+
60+
$PAGE->set_heading(get_string('catalogue', 'tool_certify'));
61+
$PAGE->set_title(get_string('catalogue', 'tool_certify'));
62+
$PAGE->set_pagelayout('report');
63+
64+
echo $OUTPUT->header();
65+
66+
echo $catalogue->render_certifications();
67+
68+
echo $OUTPUT->footer();

catalogue/source_approval_request.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Request assignment to certification.
19+
*
20+
* @package tool_certify
21+
* @copyright 2023 Open LMS (https://www.openlms.net/)
22+
* @author Petr Skoda
23+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
/** @var moodle_database $DB */
27+
/** @var moodle_page $PAGE */
28+
/** @var core_renderer $OUTPUT */
29+
/** @var stdClass $CFG */
30+
/** @var stdClass $COURSE */
31+
/** @var stdClass $USER */
32+
33+
if (!empty($_SERVER['HTTP_X_LEGACY_DIALOG_FORM_REQUEST'])) {
34+
define('AJAX_SCRIPT', true);
35+
}
36+
37+
require('../../../../config.php');
38+
39+
$sourceid = required_param('sourceid', PARAM_INT);
40+
41+
$PAGE->set_context(context_system::instance());
42+
$PAGE->set_url(new moodle_url('/admin/tool/certify/catalogue/source_approval_requests.php', ['sourceid' => $sourceid]));
43+
44+
require_login();
45+
require_capability('tool/certify:viewcatalogue', context_system::instance());
46+
47+
if (!enrol_is_enabled('programs')) {
48+
redirect(new moodle_url('/'));
49+
}
50+
51+
$source = $DB->get_record('tool_certify_sources', ['id' => $sourceid, 'type' => 'approval'], '*', MUST_EXIST);
52+
$certification = $DB->get_record('tool_certify_certifications', ['id' => $source->certificationid], '*', MUST_EXIST);
53+
$certificationcontext = context::instance_by_id($certification->contextid);
54+
55+
$PAGE->set_heading(get_string('catalogue', 'tool_certify'));
56+
$PAGE->navigation->override_active_url(new moodle_url('/admin/tool/certify/catalogue/index.php'));
57+
$PAGE->set_title(get_string('catalogue', 'tool_certify'));
58+
$PAGE->navbar->add(format_string($certification->fullname));
59+
60+
if (!\tool_certify\local\source\approval::can_user_request($certification, $source, $USER->id)) {
61+
redirect(new moodle_url('/admin/tool/certify/catalogue/index.php'));
62+
}
63+
64+
$returnurl = new moodle_url('/admin/tool/certify/catalogue/certification.php', ['id' => $certification->id]);
65+
66+
$form = new tool_certify\local\form\source_approval_request(null, ['source' => $source, 'certification' => $certification]);
67+
68+
if ($form->is_cancelled()) {
69+
redirect($returnurl);
70+
}
71+
72+
if ($data = $form->get_data()) {
73+
tool_certify\local\source\approval::request($certification->id, $source->id);
74+
$form->redirect_submitted($returnurl);
75+
}
76+
77+
/** @var \tool_certify\output\catalogue\renderer $catalogueoutput */
78+
$catalogueoutput = $PAGE->get_renderer('tool_certify', 'catalogue');
79+
80+
echo $OUTPUT->header();
81+
82+
echo $catalogueoutput->render_certification($certification);
83+
84+
echo $form->render();
85+
86+
echo $OUTPUT->footer();

catalogue/source_selfassignment.php

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
/**
18+
* Confirm self-assignment to certification.
19+
*
20+
* @package tool_certify
21+
* @copyright 2023 Open LMS (https://www.openlms.net/)
22+
* @author Petr Skoda
23+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24+
*/
25+
26+
/** @var moodle_database $DB */
27+
/** @var moodle_page $PAGE */
28+
/** @var core_renderer $OUTPUT */
29+
/** @var stdClass $CFG */
30+
/** @var stdClass $COURSE */
31+
/** @var stdClass $USER */
32+
33+
if (!empty($_SERVER['HTTP_X_LEGACY_DIALOG_FORM_REQUEST'])) {
34+
define('AJAX_SCRIPT', true);
35+
}
36+
37+
require('../../../../config.php');
38+
39+
$sourceid = required_param('sourceid', PARAM_INT);
40+
41+
$PAGE->set_context(context_system::instance());
42+
$PAGE->set_url(new moodle_url('/admin/tool/certify/catalogue/source_selfassignment.php', ['sourceid' => $sourceid]));
43+
44+
require_login();
45+
require_capability('tool/certify:viewcatalogue', context_system::instance());
46+
47+
if (!enrol_is_enabled('programs')) {
48+
redirect(new moodle_url('/'));
49+
}
50+
51+
$source = $DB->get_record('tool_certify_sources', ['id' => $sourceid, 'type' => 'selfassignment'], '*', MUST_EXIST);
52+
$certification = $DB->get_record('tool_certify_certifications', ['id' => $source->certificationid], '*', MUST_EXIST);
53+
$certificationcontext = context::instance_by_id($certification->contextid);
54+
55+
$PAGE->set_heading(get_string('catalogue', 'tool_certify'));
56+
$PAGE->navigation->override_active_url(new moodle_url('/admin/tool/certify/catalogue/index.php'));
57+
$PAGE->set_title(get_string('catalogue', 'tool_certify'));
58+
$PAGE->navbar->add(format_string($certification->fullname));
59+
60+
if (!\tool_certify\local\source\selfassignment::can_user_request($certification, $source, $USER->id)) {
61+
redirect(new moodle_url('/admin/tool/certify/catalogue/index.php'));
62+
}
63+
64+
$returnurl = new moodle_url('/admin/tool/certify/catalogue/certification.php', ['id' => $certification->id]);
65+
66+
$form = new tool_certify\local\form\source_selfassignment(null, ['source' => $source, 'certification' => $certification]);
67+
68+
if ($form->is_cancelled()) {
69+
redirect($returnurl);
70+
}
71+
72+
if ($data = $form->get_data()) {
73+
tool_certify\local\source\selfassignment::signup($certification->id, $source->id);
74+
$form->redirect_submitted($returnurl);
75+
}
76+
77+
/** @var \tool_certify\output\catalogue\renderer $catalogueoutput */
78+
$catalogueoutput = $PAGE->get_renderer('tool_certify', 'catalogue');
79+
80+
echo $OUTPUT->header();
81+
82+
echo $catalogueoutput->render_certification($certification);
83+
84+
echo $form->render();
85+
86+
echo $OUTPUT->footer();

classes/callback/local_navmenu.php

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
// This file is part of Moodle - https://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <https://www.gnu.org/licenses/>.
16+
17+
namespace tool_certify\callback;
18+
19+
/**
20+
* Callbacks from local_navmenu related code.
21+
*
22+
* @package tool_certify
23+
* @copyright 2023 Open LMS
24+
* @author Petr Skoda
25+
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26+
*/
27+
class local_navmenu {
28+
/**
29+
* Callback method for discovering of primary navigation item classes.
30+
*/
31+
public static function item_classes(\local_navmenu\hook\item_classes $hook): void {
32+
$hook->add_class(\tool_certify\local\navmenu\tool_certify_catalogue::class);
33+
$hook->add_class(\tool_certify\local\navmenu\tool_certify_mycertifications::class);
34+
}
35+
}

0 commit comments

Comments
 (0)