2012-12-07 09:34:46 +00:00
|
|
|
<?php
|
2022-09-07 14:54:32 +00:00
|
|
|
// This file is part of the mycerts module for Moodle - http://moodle.org/
|
2012-12-07 09:34:46 +00:00
|
|
|
//
|
|
|
|
// 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
|
2013-07-22 05:06:18 +00:00
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
2012-12-07 09:34:46 +00:00
|
|
|
|
|
|
|
/**
|
2015-03-11 07:24:51 +00:00
|
|
|
* Customcert module core interaction API
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
2022-09-07 14:54:32 +00:00
|
|
|
* @package mod_mycerts
|
2013-07-22 05:06:18 +00:00
|
|
|
* @copyright 2013 Mark Nelson <markn@moodle.com>
|
2012-12-07 09:34:46 +00:00
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2013-04-10 09:17:19 +00:00
|
|
|
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
|
|
|
|
2012-12-07 09:34:46 +00:00
|
|
|
/**
|
2022-09-07 14:54:32 +00:00
|
|
|
* Add mycerts instance.
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
2013-05-28 08:33:46 +00:00
|
|
|
* @param stdClass $data
|
2022-09-07 14:54:32 +00:00
|
|
|
* @param mod_mycerts_mod_form $mform
|
|
|
|
* @return int new mycerts instance id
|
2012-12-07 09:34:46 +00:00
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_add_instance($data, $mform) {
|
2012-12-07 09:34:46 +00:00
|
|
|
global $DB;
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
// Create a template for this mycerts to use.
|
2016-02-16 09:03:34 +00:00
|
|
|
$context = context_module::instance($data->coursemodule);
|
2022-09-07 14:54:32 +00:00
|
|
|
$template = \mod_mycerts\template::create($data->name, $context->id);
|
2016-02-16 09:03:34 +00:00
|
|
|
|
|
|
|
// Add the data to the DB.
|
|
|
|
$data->templateid = $template->get_id();
|
2022-09-07 14:54:32 +00:00
|
|
|
$data->protection = \mod_mycerts\certificate::set_protection($data);
|
2013-02-20 12:21:57 +00:00
|
|
|
$data->timecreated = time();
|
2012-12-07 09:34:46 +00:00
|
|
|
$data->timemodified = $data->timecreated;
|
2022-09-07 14:54:32 +00:00
|
|
|
$data->id = $DB->insert_record('mycerts', $data);
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
// Add a page to this mycerts.
|
2016-02-16 09:03:34 +00:00
|
|
|
$template->add_page();
|
2013-05-16 09:12:51 +00:00
|
|
|
|
|
|
|
return $data->id;
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-07 14:54:32 +00:00
|
|
|
* Update mycerts instance.
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
|
|
|
* @param stdClass $data
|
2022-09-07 14:54:32 +00:00
|
|
|
* @param mod_mycerts_mod_form $mform
|
2012-12-07 09:34:46 +00:00
|
|
|
* @return bool true
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_update_instance($data, $mform) {
|
2012-12-07 09:34:46 +00:00
|
|
|
global $DB;
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
$data->protection = \mod_mycerts\certificate::set_protection($data);
|
2012-12-07 09:34:46 +00:00
|
|
|
$data->timemodified = time();
|
|
|
|
$data->id = $data->instance;
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
return $DB->update_record('mycerts', $data);
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given an ID of an instance of this module,
|
|
|
|
* this function will permanently delete the instance
|
|
|
|
* and any data that depends on it.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return bool true if successful
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_delete_instance($id) {
|
2015-03-14 04:09:56 +00:00
|
|
|
global $CFG, $DB;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
// Ensure the mycerts exists.
|
|
|
|
if (!$mycerts = $DB->get_record('mycerts', array('id' => $id))) {
|
2012-12-07 09:34:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-02-20 12:21:57 +00:00
|
|
|
// Get the course module as it is used when deleting files.
|
2022-09-07 14:54:32 +00:00
|
|
|
if (!$cm = get_coursemodule_from_instance('mycerts', $id)) {
|
2012-12-07 09:34:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
// Delete the mycerts instance.
|
|
|
|
if (!$DB->delete_records('mycerts', array('id' => $id))) {
|
2012-12-07 09:34:46 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-16 09:03:34 +00:00
|
|
|
// Now, delete the template associated with this certificate.
|
2022-09-07 14:54:32 +00:00
|
|
|
if ($template = $DB->get_record('mycerts_templates', array('id' => $mycerts->templateid))) {
|
|
|
|
$template = new \mod_mycerts\template($template);
|
2016-02-16 09:03:34 +00:00
|
|
|
$template->delete();
|
2013-02-20 12:21:57 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
// Delete the mycerts issues.
|
|
|
|
if (!$DB->delete_records('mycerts_issues', array('mycertsid' => $id))) {
|
2013-02-20 12:21:57 +00:00
|
|
|
return false;
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
// Delete any files associated with the mycerts.
|
2013-05-28 09:00:07 +00:00
|
|
|
$context = context_module::instance($cm->id);
|
2012-12-07 09:34:46 +00:00
|
|
|
$fs = get_file_storage();
|
|
|
|
$fs->delete_area_files($context->id);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This function is used by the reset_course_userdata function in moodlelib.
|
2022-09-07 14:54:32 +00:00
|
|
|
* This function will remove all posts from the specified mycerts
|
2012-12-07 09:34:46 +00:00
|
|
|
* and clean up any related data.
|
|
|
|
*
|
2016-02-16 09:03:34 +00:00
|
|
|
* @param stdClass $data the data submitted from the reset course.
|
2012-12-07 09:34:46 +00:00
|
|
|
* @return array status array
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_reset_userdata($data) {
|
2013-05-30 09:53:19 +00:00
|
|
|
global $DB;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
$componentstr = get_string('modulenameplural', 'mycerts');
|
2012-12-07 09:34:46 +00:00
|
|
|
$status = array();
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
if (!empty($data->reset_mycerts)) {
|
2012-12-07 09:34:46 +00:00
|
|
|
$sql = "SELECT cert.id
|
2022-09-07 14:54:32 +00:00
|
|
|
FROM {mycerts} cert
|
2015-03-11 08:22:44 +00:00
|
|
|
WHERE cert.course = :courseid";
|
2022-09-07 14:54:32 +00:00
|
|
|
$DB->delete_records_select('mycerts_issues', "mycertsid IN ($sql)", array('courseid' => $data->courseid));
|
|
|
|
$status[] = array('component' => $componentstr, 'item' => get_string('deleteissuedcertificates', 'mycerts'),
|
2017-09-09 05:21:50 +00:00
|
|
|
'error' => false);
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of the function for printing the form elements that control
|
2022-09-07 14:54:32 +00:00
|
|
|
* whether the course reset functionality affects the mycerts.
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
2022-09-07 14:54:32 +00:00
|
|
|
* @param mod_mycerts_mod_form $mform form passed by reference
|
2012-12-07 09:34:46 +00:00
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_reset_course_form_definition(&$mform) {
|
|
|
|
$mform->addElement('header', 'mycertsheader', get_string('modulenameplural', 'mycerts'));
|
|
|
|
$mform->addElement('advcheckbox', 'reset_mycerts', get_string('deleteissuedcertificates', 'mycerts'));
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Course reset form defaults.
|
|
|
|
*
|
|
|
|
* @param stdClass $course
|
|
|
|
* @return array
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_reset_course_form_defaults($course) {
|
|
|
|
return array('reset_mycerts' => 1);
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-07 14:54:32 +00:00
|
|
|
* Returns information about received mycerts.
|
2012-12-07 09:34:46 +00:00
|
|
|
* Used for user activity reports.
|
|
|
|
*
|
|
|
|
* @param stdClass $course
|
|
|
|
* @param stdClass $user
|
|
|
|
* @param stdClass $mod
|
2022-09-07 14:54:32 +00:00
|
|
|
* @param stdClass $mycerts
|
2012-12-07 09:34:46 +00:00
|
|
|
* @return stdClass the user outline object
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_user_outline($course, $user, $mod, $mycerts) {
|
2012-12-07 09:34:46 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
$result = new stdClass();
|
2022-09-07 14:54:32 +00:00
|
|
|
if ($issue = $DB->get_record('mycerts_issues', array('mycertsid' => $mycerts->id, 'userid' => $user->id))) {
|
|
|
|
$result->info = get_string('receiveddate', 'mycerts');
|
2012-12-07 09:34:46 +00:00
|
|
|
$result->time = $issue->timecreated;
|
|
|
|
} else {
|
2022-09-07 14:54:32 +00:00
|
|
|
$result->info = get_string('notissued', 'mycerts');
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-07 14:54:32 +00:00
|
|
|
* Returns information about received mycerts.
|
2012-12-07 09:34:46 +00:00
|
|
|
* Used for user activity reports.
|
|
|
|
*
|
|
|
|
* @param stdClass $course
|
|
|
|
* @param stdClass $user
|
|
|
|
* @param stdClass $mod
|
2022-09-07 14:54:32 +00:00
|
|
|
* @param stdClass $mycerts
|
2012-12-07 09:34:46 +00:00
|
|
|
* @return string the user complete information
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_user_complete($course, $user, $mod, $mycerts) {
|
2013-07-25 04:32:39 +00:00
|
|
|
global $DB, $OUTPUT;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
if ($issue = $DB->get_record('mycerts_issues', array('mycertsid' => $mycerts->id, 'userid' => $user->id))) {
|
2012-12-07 09:34:46 +00:00
|
|
|
echo $OUTPUT->box_start();
|
2022-09-07 14:54:32 +00:00
|
|
|
echo get_string('receiveddate', 'mycerts') . ": ";
|
2012-12-07 09:34:46 +00:00
|
|
|
echo userdate($issue->timecreated);
|
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
} else {
|
2022-09-07 14:54:32 +00:00
|
|
|
print_string('notissued', 'mycerts');
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-05 05:38:35 +00:00
|
|
|
/**
|
|
|
|
* Serves certificate issues and other files.
|
|
|
|
*
|
|
|
|
* @param stdClass $course
|
|
|
|
* @param stdClass $cm
|
|
|
|
* @param context $context
|
|
|
|
* @param string $filearea
|
|
|
|
* @param array $args
|
|
|
|
* @param bool $forcedownload
|
2016-02-16 09:03:34 +00:00
|
|
|
* @return bool|null false if file not found, does not return anything if found - just send the file
|
2015-08-05 05:38:35 +00:00
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
|
2015-08-05 05:38:35 +00:00
|
|
|
global $CFG;
|
|
|
|
|
|
|
|
require_once($CFG->libdir . '/filelib.php');
|
|
|
|
|
|
|
|
// We are positioning the elements.
|
|
|
|
if ($filearea === 'image') {
|
|
|
|
if ($context->contextlevel == CONTEXT_MODULE) {
|
|
|
|
require_login($course, false, $cm);
|
2022-09-07 14:54:32 +00:00
|
|
|
} else if ($context->contextlevel == CONTEXT_SYSTEM && !has_capability('local/mycerts:manage', $context)) {
|
2015-08-05 05:38:35 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$relativepath = implode('/', $args);
|
2022-09-07 14:54:32 +00:00
|
|
|
$fullpath = '/' . $context->id . '/mod_mycerts/image/' . $relativepath;
|
2015-08-05 05:38:35 +00:00
|
|
|
|
|
|
|
$fs = get_file_storage();
|
|
|
|
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
send_stored_file($file, 0, 0, $forcedownload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-07 09:34:46 +00:00
|
|
|
/**
|
2017-02-16 12:12:19 +00:00
|
|
|
* The features this activity supports.
|
|
|
|
*
|
2012-12-07 09:34:46 +00:00
|
|
|
* @uses FEATURE_GROUPS
|
|
|
|
* @uses FEATURE_GROUPINGS
|
|
|
|
* @uses FEATURE_GROUPMEMBERSONLY
|
|
|
|
* @uses FEATURE_MOD_INTRO
|
|
|
|
* @uses FEATURE_COMPLETION_TRACKS_VIEWS
|
|
|
|
* @uses FEATURE_GRADE_HAS_GRADE
|
|
|
|
* @uses FEATURE_GRADE_OUTCOMES
|
|
|
|
* @param string $feature FEATURE_xx constant for requested feature
|
|
|
|
* @return mixed True if module supports feature, null if doesn't know
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_supports($feature) {
|
2012-12-07 09:34:46 +00:00
|
|
|
switch ($feature) {
|
2013-07-25 04:32:39 +00:00
|
|
|
case FEATURE_GROUPS:
|
|
|
|
return true;
|
|
|
|
case FEATURE_GROUPINGS:
|
|
|
|
return true;
|
|
|
|
case FEATURE_MOD_INTRO:
|
|
|
|
return true;
|
2021-04-03 02:37:15 +00:00
|
|
|
case FEATURE_SHOW_DESCRIPTION:
|
|
|
|
return true;
|
2013-07-25 04:32:39 +00:00
|
|
|
case FEATURE_COMPLETION_TRACKS_VIEWS:
|
|
|
|
return true;
|
|
|
|
case FEATURE_BACKUP_MOODLE2:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return null;
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-07 14:54:32 +00:00
|
|
|
* Used for course participation report (in case mycerts is added).
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_get_view_actions() {
|
2012-12-07 09:34:46 +00:00
|
|
|
return array('view', 'view all', 'view report');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-09-07 14:54:32 +00:00
|
|
|
* Used for course participation report (in case mycerts is added).
|
2012-12-07 09:34:46 +00:00
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_get_post_actions() {
|
2012-12-07 09:34:46 +00:00
|
|
|
return array('received');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Function to be run periodically according to the moodle cron.
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_cron() {
|
2012-12-07 09:34:46 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-06-13 11:39:57 +00:00
|
|
|
/**
|
|
|
|
* Serve the edit element as a fragment.
|
|
|
|
*
|
|
|
|
* @param array $args List of named arguments for the fragment loader.
|
|
|
|
* @return string
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mod_mycerts_output_fragment_editelement($args) {
|
2016-06-13 11:39:57 +00:00
|
|
|
global $DB;
|
|
|
|
|
|
|
|
// Get the element.
|
2022-09-07 14:54:32 +00:00
|
|
|
$element = $DB->get_record('mycerts_elements', array('id' => $args['elementid']), '*', MUST_EXIST);
|
2016-06-13 11:39:57 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
$pageurl = new moodle_url('/local/mycerts/rearrange.php', array('pid' => $element->pageid));
|
|
|
|
$form = new \mod_mycerts\edit_element_form($pageurl, array('element' => $element));
|
2016-06-13 11:39:57 +00:00
|
|
|
|
|
|
|
return $form->render();
|
|
|
|
}
|
|
|
|
|
2012-12-07 09:34:46 +00:00
|
|
|
/**
|
|
|
|
* This function extends the settings navigation block for the site.
|
|
|
|
*
|
|
|
|
* It is safe to rely on PAGE here as we will only ever be within the module
|
|
|
|
* context when this is called.
|
|
|
|
*
|
|
|
|
* @param settings_navigation $settings
|
2022-09-07 14:54:32 +00:00
|
|
|
* @param navigation_node $mycertsnode
|
2012-12-07 09:34:46 +00:00
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mycerts_extend_settings_navigation(settings_navigation $settings, navigation_node $mycertsnode) {
|
2016-02-16 09:03:34 +00:00
|
|
|
global $DB, $PAGE;
|
2012-12-07 09:34:46 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
$keys = $mycertsnode->get_children_key_list();
|
2012-12-07 09:34:46 +00:00
|
|
|
$beforekey = null;
|
|
|
|
$i = array_search('modedit', $keys);
|
|
|
|
if ($i === false and array_key_exists(0, $keys)) {
|
|
|
|
$beforekey = $keys[0];
|
|
|
|
} else if (array_key_exists($i + 1, $keys)) {
|
|
|
|
$beforekey = $keys[$i + 1];
|
|
|
|
}
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
if (has_capability('local/mycerts:manage', $PAGE->cm->context)) {
|
2016-02-16 09:03:34 +00:00
|
|
|
// Get the template id.
|
2022-09-07 14:54:32 +00:00
|
|
|
$templateid = $DB->get_field('mycerts', 'templateid', array('id' => $PAGE->cm->instance));
|
|
|
|
$node = navigation_node::create(get_string('editmycerts', 'mycerts'),
|
|
|
|
new moodle_url('/local/mycerts/edit.php', array('tid' => $templateid)),
|
|
|
|
navigation_node::TYPE_SETTING, null, 'mod_mycerts_edit',
|
2012-12-07 09:34:46 +00:00
|
|
|
new pix_icon('t/edit', ''));
|
2022-09-07 14:54:32 +00:00
|
|
|
$mycertsnode->add_node($node, $beforekey);
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
if (has_capability('local/mycerts:verifycertificate', $PAGE->cm->context)) {
|
|
|
|
$node = navigation_node::create(get_string('verifycertificate', 'mycerts'),
|
|
|
|
new moodle_url('/local/mycerts/verify_certificate.php', array('contextid' => $PAGE->cm->context->id)),
|
|
|
|
navigation_node::TYPE_SETTING, null, 'mod_mycerts_verify_certificate',
|
2017-02-01 10:23:15 +00:00
|
|
|
new pix_icon('t/check', ''));
|
2022-09-07 14:54:32 +00:00
|
|
|
$mycertsnode->add_node($node, $beforekey);
|
2017-02-01 10:23:15 +00:00
|
|
|
}
|
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
return $mycertsnode->trim_if_empty();
|
2012-12-07 09:34:46 +00:00
|
|
|
}
|
2016-08-25 04:38:41 +00:00
|
|
|
|
2016-10-21 21:16:13 +00:00
|
|
|
/**
|
|
|
|
* Add nodes to myprofile page.
|
|
|
|
*
|
|
|
|
* @param \core_user\output\myprofile\tree $tree Tree object
|
|
|
|
* @param stdClass $user user object
|
|
|
|
* @param bool $iscurrentuser
|
|
|
|
* @param stdClass $course Course object
|
|
|
|
* @return bool
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mod_mycerts_myprofile_navigation(core_user\output\myprofile\tree $tree, $user, $iscurrentuser, $course) {
|
2021-11-04 13:26:18 +00:00
|
|
|
$params = [
|
|
|
|
'userid' => $user->id
|
|
|
|
];
|
|
|
|
if ($course) {
|
|
|
|
$params['course'] = $course->id;
|
|
|
|
}
|
2022-09-07 14:54:32 +00:00
|
|
|
$url = new moodle_url('/local/mycerts/my_certificates.php', $params);
|
|
|
|
$node = new core_user\output\myprofile\node('miscellaneous', 'mymycertss',
|
|
|
|
get_string('mycertificates', 'mycerts'), null, $url);
|
2016-10-21 21:16:13 +00:00
|
|
|
$tree->add_node($node);
|
|
|
|
}
|
|
|
|
|
2016-08-25 04:38:41 +00:00
|
|
|
/**
|
|
|
|
* Handles editing the 'name' of the element in a list.
|
|
|
|
*
|
2017-02-16 12:12:19 +00:00
|
|
|
* @param string $itemtype
|
|
|
|
* @param int $itemid
|
|
|
|
* @param string $newvalue
|
2016-08-25 04:38:41 +00:00
|
|
|
* @return \core\output\inplace_editable
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mod_mycerts_inplace_editable($itemtype, $itemid, $newvalue) {
|
2016-08-25 09:58:51 +00:00
|
|
|
global $DB, $PAGE;
|
2016-08-25 04:38:41 +00:00
|
|
|
|
|
|
|
if ($itemtype === 'elementname') {
|
2022-09-07 14:54:32 +00:00
|
|
|
$element = $DB->get_record('mycerts_elements', array('id' => $itemid), '*', MUST_EXIST);
|
|
|
|
$page = $DB->get_record('mycerts_pages', array('id' => $element->pageid), '*', MUST_EXIST);
|
|
|
|
$template = $DB->get_record('mycerts_templates', array('id' => $page->templateid), '*', MUST_EXIST);
|
2016-08-25 04:38:41 +00:00
|
|
|
|
|
|
|
// Set the template object.
|
2022-09-07 14:54:32 +00:00
|
|
|
$template = new \mod_mycerts\template($template);
|
2016-08-25 04:38:41 +00:00
|
|
|
// Perform checks.
|
|
|
|
if ($cm = $template->get_cm()) {
|
|
|
|
require_login($cm->course, false, $cm);
|
|
|
|
} else {
|
2016-08-25 09:58:51 +00:00
|
|
|
$PAGE->set_context(context_system::instance());
|
2016-08-25 04:38:41 +00:00
|
|
|
require_login();
|
|
|
|
}
|
|
|
|
// Make sure the user has the required capabilities.
|
|
|
|
$template->require_manage();
|
|
|
|
|
|
|
|
// Clean input and update the record.
|
|
|
|
$updateelement = new stdClass();
|
|
|
|
$updateelement->id = $element->id;
|
|
|
|
$updateelement->name = clean_param($newvalue, PARAM_TEXT);
|
2022-09-07 14:54:32 +00:00
|
|
|
$DB->update_record('mycerts_elements', $updateelement);
|
2016-08-25 04:38:41 +00:00
|
|
|
|
2022-09-07 14:54:32 +00:00
|
|
|
return new \core\output\inplace_editable('mod_mycerts', 'elementname', $element->id, true,
|
2016-08-25 04:38:41 +00:00
|
|
|
$updateelement->name, $updateelement->name);
|
|
|
|
}
|
|
|
|
}
|
2018-05-21 13:34:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get icon mapping for font-awesome.
|
|
|
|
*/
|
2022-09-07 14:54:32 +00:00
|
|
|
function mod_mycerts_get_fontawesome_icon_map() {
|
2018-05-21 13:34:53 +00:00
|
|
|
return [
|
2022-09-07 14:54:32 +00:00
|
|
|
'mod_mycerts:download' => 'fa-download'
|
2018-05-21 13:34:53 +00:00
|
|
|
];
|
|
|
|
}
|