Commit c27a3e58 authored by Francois Gannaz's avatar Francois Gannaz
Browse files

starting point

parents
This diff is collapsed.
# LabNbook #
TODO Describe the plugin shortly here.
TODO Provide more detailed description here.
## License ##
2019 Université Grenoble Alpes
This program 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.
This program 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
this program. If not, see <http://www.gnu.org/licenses/>.
<?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/>.
/**
* Defines {@link \mod_labnbook\privacy\provider} class.
*
* @package mod_labnbook
* @category privacy
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_labnbook\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy API implementation for the LabNbook plugin.
*
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Returns stringid of a text explaining that this plugin stores no personal data.
*
* @return string
*/
public static function get_reason() : string {
return 'privacy:metadata';
}
}
<?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/>.
/**
* Plugin capabilities are defined here.
*
* @package mod_labnbook
* @category access
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = [
'mod/labnbook:view' => [
'captype' => 'view',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => [
'student' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/course:view',
],
'mod/labnbook:update' => [
'captype' => 'write',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => [
'student' => CAP_PREVENT,
'editingteacher' => CAP_ALLOW,
],
'clonepermissionsfrom' => 'moodle/course:update',
],
];
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/labnbook/db" VERSION="20190201" COMMENT="XMLDB file for Moodle mod/labnbook"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="labnbook_user" COMMENT="matching users bewteen M and L">
<FIELDS>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="labnbook_userid" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="userid,labnbook_userid"/>
</KEYS>
</TABLE>
</TABLES>
</XMLDB>
<?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/>.
/**
* Plugin upgrade steps are defined here.
*
* @package mod_labnbook
* @category upgrade
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once(__DIR__.'/upgradelib.php');
/**
* Execute mod_labnbook upgrade from the given old version.
*
* @param int $oldversion
* @return bool
*/
function xmldb_labnbook_upgrade($oldversion) {
global $DB;
$dbman = $DB->get_manager();
// For further information please read the Upgrade API documentation:
// https://docs.moodle.org/dev/Upgrade_API
//
// You will also have to create the db/install.xml file by using the XMLDB Editor.
// Documentation for the XMLDB Editor can be found at:
// https://docs.moodle.org/dev/XMLDB_editor
return true;
}
<?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/>.
/**
* Plugin upgrade helper functions are defined here.
*
* @package mod_labnbook
* @category upgrade
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Helper function used by the upgrade.php file.
*/
function mod_labnbook_helper_function() {
global $DB;
// Please note that you should always be performing any task using raw (low
// level) database access exclusively, avoiding any use of the Moodle APIs.
//
// For more information please read the available Moodle documentation:
// https://docs.moodle.org/dev/Upgrade_API
}
<?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/>.
/**
* Redirect the user to the appropiate submission related page.
*
* @package mod_labnbook
* @category grade
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../config.php');
// Course module ID.
$id = required_param('id', PARAM_INT);
// Item number may be != 0 for activities that allow more than one grade per user.
$itemnumber = optional_param('itemnumber', 0, PARAM_INT);
// Graded user ID (optional).
$userid = optional_param('userid', 0, PARAM_INT);
// In the simplest case just redirect to the view page.
redirect('view.php?id='.$id);
<?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/>.
/**
* Display information about all the mod_labnbook modules in the requested course.
*
* @package mod_labnbook
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../config.php');
require_once(__DIR__.'/lib.php');
$id = required_param('id', PARAM_INT);
$course = $DB->get_record('course', array('id' => $id), '*', MUST_EXIST);
require_course_login($course);
$coursecontext = context_course::instance($course->id);
$event = \mod_labnbook\event\course_module_instance_list_viewed::create(array(
'context' => $modulecontext
));
$event->add_record_snapshot('course', $course);
$event->trigger();
$PAGE->set_url('/mod/labnbook/index.php', array('id' => $id));
$PAGE->set_title(format_string($course->fullname));
$PAGE->set_heading(format_string($course->fullname));
$PAGE->set_context($coursecontext);
echo $OUTPUT->header();
$modulenameplural = get_string('modulenameplural', 'mod_labnbook');
echo $OUTPUT->heading($modulenameplural);
$labnbooks = get_all_instances_in_course('labnbook', $course);
if (empty($labnbooks)) {
notice(get_string('nonewmodules', 'mod_labnbook'), new moodle_url('/course/view.php', array('id' => $course->id)));
}
$table = new html_table();
$table->attributes['class'] = 'generaltable mod_index';
if ($course->format == 'weeks') {
$table->head = array(get_string('week'), get_string('name'));
$table->align = array('center', 'left');
} else if ($course->format == 'topics') {
$table->head = array(get_string('topic'), get_string('name'));
$table->align = array('center', 'left', 'left', 'left');
} else {
$table->head = array(get_string('name'));
$table->align = array('left', 'left', 'left');
}
foreach ($labnbooks as $labnbook) {
if (!$labnbook->visible) {
$link = html_writer::link(
new moodle_url('/mod/labnbook/view.php', array('id' => $labnbook->coursemodule)),
format_string($labnbook->name, true),
array('class' => 'dimmed'));
} else {
$link = html_writer::link(
new moodle_url('/mod/labnbook/view.php', array('id' => $labnbook->coursemodule)),
format_string($labnbook->name, true));
}
if ($course->format == 'weeks' or $course->format == 'topics') {
$table->data[] = array($labnbook->section, $link);
} else {
$table->data[] = array($link);
}
}
echo html_writer::table($table);
echo $OUTPUT->footer();
<?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/>.
/**
* Plugin strings are defined here.
*
* @package mod_labnbook
* @category string
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$string['labnbook:edit'] = 'Edit labnbook';
$string['labnbook:view'] = 'View labnbook';
$string['missingidandcmid'] = 'Missing id and cmid';
$string['modulename'] = 'LabNbook';
$string['modulename_help'] = 'LabNbook Help';
$string['modulenameplural'] = 'LabNbook activities';
$string['newmodulefieldset'] = 'LabNbook';
$string['newmodulename'] = 'New LabNbook activity';
$string['newmodulename_help'] = 'Create a new activity matched with a LabNbook mission.';
$string['newmodulesettings'] = 'Settings';
$string['nonewmodules'] = 'No newmodules';
$string['pluginadministration'] = 'LabNbook administration';
$string['pluginname'] = 'LabNbook';
$string['privacy:metadata'] = 'LabNbook does not store any personal data';
$string['view'] = 'View';
<?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/>.
/**
* Library of interface functions and constants.
*
* @package mod_labnbook
* @copyright 2019 Université Grenoble Alpes
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Return if the plugin supports $feature.
*
* @param string $feature Constant representing the feature.
* @return true | null True if the feature is supported, null otherwise.
*/
function mod_labnbook_supports($feature) {
switch ($feature) {
case FEATURE_GRADE_HAS_GRADE:
return true;
case FEATURE_MOD_INTRO:
return true;
case FEATURE_BACKUP_MOODLE2:
return true;
default:
return null;
}
}
/**
* Saves a new instance of the mod_labnbook into the database.
*
* Given an object containing all the necessary data, (defined by the form
* in mod_form.php) this function will create a new instance and return the id
* number of the instance.
*
* @param object $moduleinstance An object from the form.
* @param mod_labnbook_mod_form $mform The form.
* @return int The id of the newly inserted record.
*/
function mod_labnbook_add_instance($moduleinstance, $mform = null) {
global $DB;
$moduleinstance->timecreated = time();
$id = $DB->insert_record('mod_labnbook', $moduleinstance);
return $id;
}
/**
* Updates an instance of the mod_labnbook in the database.
*
* Given an object containing all the necessary data (defined in mod_form.php),
* this function will update an existing instance with new data.
*
* @param object $moduleinstance An object from the form in mod_form.php.
* @param mod_labnbook_mod_form $mform The form.
* @return bool True if successful, false otherwise.
*/
function mod_labnbook_update_instance($moduleinstance, $mform = null) {
global $DB;
$moduleinstance->timemodified = time();
$moduleinstance->id = $moduleinstance->instance;
return $DB->update_record('mod_labnbook', $moduleinstance);
}
/**
* Removes an instance of the mod_labnbook from the database.
*
* @param int $id Id of the module instance.
* @return bool True if successful, false on failure.
*/
function mod_labnbook_delete_instance($id) {
global $DB;
$exists = $DB->get_record('mod_labnbook', array('id' => $id));
if (!$exists) {
return false;
}
$DB->delete_records('mod_labnbook', array('id' => $id));
return true;
}
/**
* Is a given scale used by the instance of mod_labnbook?
*
* This function returns if a scale is being used by one mod_labnbook
* if it has support for grading and scales.
*
* @param int $moduleinstanceid ID of an instance of this module.
* @param int $scaleid ID of the scale.
* @return bool True if the scale is used by the given mod_labnbook instance.
*/
function mod_labnbook_scale_used($moduleinstanceid, $scaleid) {
global $DB;
if ($scaleid && $DB->record_exists('mod_labnbook', array('id' => $moduleinstanceid, 'grade' => -$scaleid))) {
return true;
} else {
return false;
}
}
/**
* Checks if scale is being used by any instance of mod_labnbook.
*
* This is used to find out if scale used anywhere.
*
* @param int $scaleid ID of the scale.
* @return bool True if the scale is used by any mod_labnbook instance.
*/
function mod_labnbook_scale_used_anywhere($scaleid) {
global $DB;
if ($scaleid and $DB->record_exists('mod_labnbook', array('grade' => -$scaleid))) {
return true;
} else {
return false;
}
}
/**
* Creates or updates grade item for the given mod_labnbook instance.
*
* Needed by {@link grade_update_mod_grades()}.
*
* @param stdClass $moduleinstance Instance object with extra cmidnumber and modname property.
* @param bool $reset Reset grades in the gradebook.
* @return void.
*/
function mod_labnbook_grade_item_update($moduleinstance, $reset=false) {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
$item = array();
$item['itemname'] = clean_param($moduleinstance->name, PARAM_NOTAGS);
$item['gradetype'] = GRADE_TYPE_VALUE;
if ($moduleinstance->grade > 0) {
$item['gradetype'] = GRADE_TYPE_VALUE;
$item['grademax'] = $moduleinstance->grade;
$item['grademin'] = 0;
} else if ($moduleinstance->grade < 0) {
$item['gradetype'] = GRADE_TYPE_SCALE;
$item['scaleid'] = -$moduleinstance->grade;
} else {
$item['gradetype'] = GRADE_TYPE_NONE;
}
if ($reset) {
$item['reset'] = true;
}
grade_update('/mod/labnbook', $moduleinstance->course, 'mod', 'mod_labnbook', $moduleinstance->id, 0, null, $item);
}
/**
* Delete grade item for given mod_labnbook instance.
*
* @param stdClass $moduleinstance Instance object.
* @return grade_item.
*/
function mod_labnbook_grade_item_delete($moduleinstance) {
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
return grade_update('/mod/labnbook', $moduleinstance->course, 'mod', 'labnbook',
$moduleinstance->id, 0, null, array('deleted' => 1));
}
/**
* Update mod_labnbook grades in the gradebook.
*
* Needed by {@link grade_update_mod_grades()}.
*
* @param stdClass $moduleinstance Instance object with extra cmidnumber and modname property.
* @param int $userid Update grade of specific user only, 0 means all participants.
*/
function mod_labnbook_update_grades($moduleinstance, $userid = 0) {
global $CFG, $DB;
require_once($CFG->libdir.'/gradelib.php');
// Populate array of grade objects indexed by userid.
$grades = array();
grade_update('/mod/labnbook', $moduleinstance->course, 'mod', 'mod_labnbook', $moduleinstance->id, 0, $grades);
}
/**
* Extends the global navigation tree by adding mod_labnbook nodes if there is a relevant content.
*
* This can be called by an AJAX request so do not rely on $PAGE as it might not be set up properly.
*
* @param navigation_node $labnbooknode An object representing the navigation tree node.
* @param stdClass $course.
* @param stdClass $module.
* @param cm_info $cm.
*/
function mod_labnbook_extend_navigation($labnbooknode, $course, $module, $cm) {
}
/**
* Extends the settings navigation with the mod_labnbook settings.