first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
+103
View File
@@ -0,0 +1,103 @@
<?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/>.
/**
* Provides support for the conversion of moodle1 backup to the moodle2 format
* Based off of a template @ http://docs.moodle.org/dev/Backup_1.9_conversion_for_developers
*
* @package mod_label
* @copyright 2011 Aparup Banerjee <aparup@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Label conversion handler
*/
class moodle1_mod_label_handler extends moodle1_mod_handler {
/**
* Declare the paths in moodle.xml we are able to convert
*
* The method returns list of {@link convert_path} instances.
* For each path returned, the corresponding conversion method must be
* defined.
*
* Note that the path /MOODLE_BACKUP/COURSE/MODULES/MOD/LABEL does not
* actually exist in the file. The last element with the module name was
* appended by the moodle1_converter class.
*
* @return array of {@link convert_path} instances
*/
public function get_paths() {
return array(
new convert_path(
'label', '/MOODLE_BACKUP/COURSE/MODULES/MOD/LABEL',
array(
'renamefields' => array(
'content' => 'intro'
),
'newfields' => array(
'introformat' => FORMAT_HTML
)
)
)
);
}
/**
* This is executed every time we have one /MOODLE_BACKUP/COURSE/MODULES/MOD/LABEL
* data available
*/
public function process_label($data) {
// get the course module id and context id
$instanceid = $data['id'];
$cminfo = $this->get_cminfo($instanceid);
$moduleid = $cminfo['id'];
$contextid = $this->converter->get_contextid(CONTEXT_MODULE, $moduleid);
// get a fresh new file manager for this instance
$fileman = $this->converter->get_file_manager($contextid, 'mod_label');
// convert course files embedded into the intro
$fileman->filearea = 'intro';
$fileman->itemid = 0;
$data['intro'] = moodle1_converter::migrate_referenced_files($data['intro'], $fileman);
// write inforef.xml
$this->open_xml_writer("activities/label_{$moduleid}/inforef.xml");
$this->xmlwriter->begin_tag('inforef');
$this->xmlwriter->begin_tag('fileref');
foreach ($fileman->get_fileids() as $fileid) {
$this->write_xml('file', array('id' => $fileid));
}
$this->xmlwriter->end_tag('fileref');
$this->xmlwriter->end_tag('inforef');
$this->close_xml_writer();
// write label.xml
$this->open_xml_writer("activities/label_{$moduleid}/label.xml");
$this->xmlwriter->begin_tag('activity', array('id' => $instanceid, 'moduleid' => $moduleid,
'modulename' => 'label', 'contextid' => $contextid));
$this->write_xml('label', $data, array('/label/id'));
$this->xmlwriter->end_tag('activity');
$this->close_xml_writer();
return $data;
}
}
@@ -0,0 +1,58 @@
<?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 backup_label_activity_task class
*
* @package mod_label
* @category backup
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/mod/label/backup/moodle2/backup_label_stepslib.php');
/**
* Provides the steps to perform one complete backup of the Label instance
*/
class backup_label_activity_task extends backup_activity_task {
/**
* No specific settings for this activity
*/
protected function define_my_settings() {
}
/**
* Defines a backup step to store the instance data in the label.xml file
*/
protected function define_my_steps() {
$this->add_step(new backup_label_activity_structure_step('label_structure', 'label.xml'));
}
/**
* No content encoding needed for this activity
*
* @param string $content some HTML text that eventually contains URLs to the activity instance scripts
* @return string the same content with no changes
*/
public static function encode_content_links($content) {
return $content;
}
}
@@ -0,0 +1,57 @@
<?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 mod_label
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the backup steps that will be used by the backup_label_activity_task
*/
/**
* Define the complete label structure for backup, with file and id annotations
*/
class backup_label_activity_structure_step extends backup_activity_structure_step {
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define each element separated
$label = new backup_nested_element('label', array('id'), array(
'name', 'intro', 'introformat', 'timemodified'));
// Build the tree
// (love this)
// Define sources
$label->set_source_table('label', array('id' => backup::VAR_ACTIVITYID));
// Define id annotations
// (none)
// Define file annotations
$label->annotate_files('mod_label', 'intro', null); // This file area hasn't itemid
// Return the root element (label), wrapped into standard activity structure
return $this->prepare_activity_structure($label);
}
}
@@ -0,0 +1,103 @@
<?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 mod_label
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/mod/label/backup/moodle2/restore_label_stepslib.php'); // Because it exists (must)
/**
* label restore task that provides all the settings and steps to perform one
* complete restore of the activity
*/
class restore_label_activity_task extends restore_activity_task {
/**
* Define (add) particular settings this activity can have
*/
protected function define_my_settings() {
// No particular settings for this activity
}
/**
* Define (add) particular steps this activity can have
*/
protected function define_my_steps() {
// label only has one structure step
$this->add_step(new restore_label_activity_structure_step('label_structure', 'label.xml'));
}
/**
* Define the contents in the activity that must be
* processed by the link decoder
*/
public static function define_decode_contents() {
$contents = array();
$contents[] = new restore_decode_content('label', array('intro'), 'label');
return $contents;
}
/**
* Define the decoding rules for links belonging
* to the activity to be executed by the link decoder
*/
public static function define_decode_rules() {
return array();
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* label logs. It must return one array
* of {@link restore_log_rule} objects
*/
public static function define_restore_log_rules() {
$rules = array();
$rules[] = new restore_log_rule('label', 'add', 'view.php?id={course_module}', '{label}');
$rules[] = new restore_log_rule('label', 'update', 'view.php?id={course_module}', '{label}');
$rules[] = new restore_log_rule('label', 'view', 'view.php?id={course_module}', '{label}');
return $rules;
}
/**
* Define the restore log rules that will be applied
* by the {@link restore_logs_processor} when restoring
* course logs. It must return one array
* of {@link restore_log_rule} objects
*
* Note this rules are applied when restoring course logs
* by the restore final task, but are defined here at
* activity level. All them are rules not linked to any module instance (cmid = 0)
*/
public static function define_restore_log_rules_for_course() {
$rules = array();
$rules[] = new restore_log_rule('label', 'view all', 'index.php?id={course}', null);
return $rules;
}
}
@@ -0,0 +1,64 @@
<?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 mod_label
* @subpackage backup-moodle2
* @copyright 2010 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Define all the restore steps that will be used by the restore_url_activity_task
*/
/**
* Structure step to restore one label activity
*/
class restore_label_activity_structure_step extends restore_activity_structure_step {
protected function define_structure() {
$paths = array();
$paths[] = new restore_path_element('label', '/activity/label');
// Return the paths wrapped into standard activity structure
return $this->prepare_activity_structure($paths);
}
protected function process_label($data) {
global $DB;
$data = (object)$data;
$oldid = $data->id;
$data->course = $this->get_courseid();
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
// insert the label record
$newitemid = $DB->insert_record('label', $data);
// immediately after inserting "activity" record, call this
$this->apply_activity_instance($newitemid);
}
protected function after_execute() {
// Add label related files, no need to match by itemname (just internally handled context)
$this->add_related_files('mod_label', 'intro', null);
}
}
@@ -0,0 +1,46 @@
<?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/>.
/**
* Activity base class.
*
* @package mod_label
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_label\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Activity base class.
*
* @package mod_label
* @copyright 2017 onwards Ankit Agarwal <ankit.agrr@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class activity_base extends \core_analytics\local\indicator\community_of_inquiry_activity {
/**
* No need to fetch grades for resources.
*
* @param \core_analytics\course $course
* @return void
*/
public function fetch_student_grades(\core_analytics\course $course) {
}
}
@@ -0,0 +1,57 @@
<?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/>.
/**
* Cognitive depth indicator - label.
*
* @package mod_label
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_label\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Cognitive depth indicator - label.
*
* @package mod_label
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cognitive_depth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:cognitivedepth', 'mod_label');
}
public function get_indicator_type() {
return self::INDICATOR_COGNITIVE;
}
public function get_cognitive_depth_level(\cm_info $cm) {
return self::COGNITIVE_LEVEL_1;
}
}
@@ -0,0 +1,56 @@
<?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/>.
/**
* Social breadth indicator - label.
*
* @package mod_label
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_label\analytics\indicator;
defined('MOODLE_INTERNAL') || die();
/**
* Social breadth indicator - label.
*
* @package mod_label
* @copyright 2017 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class social_breadth extends activity_base {
/**
* Returns the name.
*
* If there is a corresponding '_help' string this will be shown as well.
*
* @return \lang_string
*/
public static function get_name(): \lang_string {
return new \lang_string('indicator:socialbreadth', 'mod_label');
}
public function get_indicator_type() {
return self::INDICATOR_SOCIAL;
}
public function get_social_breadth_level(\cm_info $cm) {
return self::SOCIAL_LEVEL_1;
}
}
@@ -0,0 +1,83 @@
<?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/>.
declare(strict_types=1);
namespace mod_label\completion;
use core_completion\activity_custom_completion;
/**
* Activity custom completion subclass for the label.
*
* Class for defining mod_label's custom completion rules and fetching the completion statuses
* of the custom completion rules for a given label instance and a user.
*
* @package mod_label
* @copyright 2021 Huong Nguyen <huongn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class custom_completion extends activity_custom_completion {
/**
* Fetches the completion state for a given completion rule.
*
* @param string $rule The completion rule.
* @return int The completion state.
*/
public function get_state(string $rule): int {
return COMPLETION_UNKNOWN;
}
/**
* Fetch the list of custom completion rules that this module defines.
*
* @return array
*/
public static function get_defined_custom_rules(): array {
// This activity/resource do not have any custom rules.
return [];
}
/**
* Returns an associative array of the descriptions of custom completion rules.
*
* @return array
*/
public function get_custom_rule_descriptions(): array {
// This activity/resource do not have any custom rule descriptions.
return [];
}
/**
* Show the manual completion or not regardless of the course's showcompletionconditions setting.
*
* @return bool
*/
public function manual_completion_always_shown(): bool {
return true;
}
/**
* Returns an array of all completion rules, in the order they should be displayed to users.
*
* @return array
*/
public function get_sort_order(): array {
// This module only supports manual completion.
return [];
}
}
+129
View File
@@ -0,0 +1,129 @@
<?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/>.
/**
* Label external API
*
* @package mod_label
* @category external
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.3
*/
use core_course\external\helper_for_get_mods_by_courses;
use core_external\external_api;
use core_external\external_function_parameters;
use core_external\external_multiple_structure;
use core_external\external_single_structure;
use core_external\external_value;
use core_external\external_warnings;
use core_external\util;
/**
* Label external functions
*
* @package mod_label
* @category external
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.3
*/
class mod_label_external extends external_api {
/**
* Describes the parameters for get_labels_by_courses.
*
* @return external_function_parameters
* @since Moodle 3.3
*/
public static function get_labels_by_courses_parameters() {
return new external_function_parameters (
array(
'courseids' => new external_multiple_structure(
new external_value(PARAM_INT, 'Course id'), 'Array of course ids', VALUE_DEFAULT, array()
),
)
);
}
/**
* Returns a list of labels in a provided list of courses.
* If no list is provided all labels that the user can view will be returned.
*
* @param array $courseids course ids
* @return array of warnings and labels
* @since Moodle 3.3
*/
public static function get_labels_by_courses($courseids = array()) {
$warnings = array();
$returnedlabels = array();
$params = array(
'courseids' => $courseids,
);
$params = self::validate_parameters(self::get_labels_by_courses_parameters(), $params);
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = util::validate_courses($params['courseids'], $mycourses);
// Get the labels in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$labels = get_all_instances_in_courses("label", $courses);
foreach ($labels as $label) {
helper_for_get_mods_by_courses::format_name_and_intro($label, 'mod_label');
$returnedlabels[] = $label;
}
}
$result = array(
'labels' => $returnedlabels,
'warnings' => $warnings
);
return $result;
}
/**
* Describes the get_labels_by_courses return value.
*
* @return external_single_structure
* @since Moodle 3.3
*/
public static function get_labels_by_courses_returns() {
return new external_single_structure(
array(
'labels' => new external_multiple_structure(
new external_single_structure(array_merge(
helper_for_get_mods_by_courses::standard_coursemodule_elements_returns(),
[
'timemodified' => new external_value(PARAM_INT, 'Last time the label was modified'),
]
))
),
'warnings' => new external_warnings(),
)
);
}
}
@@ -0,0 +1,52 @@
<?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/>.
namespace mod_label\navigation\views;
use core\navigation\views\secondary as core_secondary;
use settings_navigation;
use navigation_node;
/**
* Class secondary_navigation_view.
*
* Custom implementation for a plugin.
*
* @package mod_label
* @category navigation
* @copyright 2021 onwards Peter Dias
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class secondary extends core_secondary {
/**
* Custom module construct for label
*
* @param settings_navigation $settingsnav The settings navigation object related to the module page
* @param navigation_node|null $rootnode The node where the module navigation nodes should be added into as children.
* If not explicitly defined, the nodes will be added to the secondary root
* node by default.
*/
protected function load_module_navigation(settings_navigation $settingsnav, ?navigation_node $rootnode = null): void {
parent::load_module_navigation($settingsnav, $rootnode);
$rootnode = $rootnode ?? $this;
$node = $rootnode->find('modulepage', null);
if ($node) {
// Label does not have a view and redirects to the course page. Change text to indicate this.
$node->text = get_string('course');
}
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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/>.
/**
* Privacy Subsystem implementation for mod_label.
*
* @package mod_label
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_label\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* The mod_label module does not store any data.
*
* @copyright 2018 Zig Tan <zig@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {
/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
*
* @return string
*/
public static function get_reason(): string {
return 'privacy:metadata';
}
}
+78
View File
@@ -0,0 +1,78 @@
<?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/>.
/**
* Search area for mod_label activities.
*
* @package mod_label
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace mod_label\search;
defined('MOODLE_INTERNAL') || die();
/**
* Search area for mod_label activities.
*
* Although there is no name field the intro value is stored internally, so no need
* to overwrite self::get_document.
*
* @package mod_label
* @copyright 2015 David Monllao {@link http://www.davidmonllao.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class activity extends \core_search\base_activity {
/**
* Returns true if this area uses file indexing.
*
* @return bool
*/
public function uses_file_indexing() {
return true;
}
/**
* Overwritten as labels are displayed in-course.
*
* @param \core_search\document $doc
* @return \moodle_url
*/
public function get_doc_url(\core_search\document $doc) {
// Get correct URL to section that contains label, from course format.
$cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid'));
$format = course_get_format($cminfo->get_course());
$url = $format->get_view_url($cminfo->sectionnum);
// Add the ID of the label to the section URL.
$url->set_anchor('module-' . $cminfo->id);
return $url;
}
/**
* Overwritten as labels are displayed in-course. Link to the course.
*
* @param \core_search\document $doc
* @return \moodle_url
*/
public function get_context_url(\core_search\document $doc) {
return new \moodle_url('/course/view.php', array('id' => $doc->get('courseid')));
}
}
+49
View File
@@ -0,0 +1,49 @@
<?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/>.
/**
* Capability definitions for the label module.
*
* @package mod_label
* @copyright 2012 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'mod/label:addinstance' => array(
'riskbitmask' => RISK_XSS,
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'editingteacher' => CAP_ALLOW,
'manager' => CAP_ALLOW
),
'clonepermissionsfrom' => 'moodle/course:manageactivities'
),
'mod/label:view' => array(
'captype' => 'read',
'contextlevel' => CONTEXT_MODULE,
'archetypes' => array(
'user' => CAP_ALLOW,
'guest' => CAP_ALLOW
)
),
);
+24
View File
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/label/db" VERSION="20120122" COMMENT="XMLDB file for Moodle mod/label"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
<TABLES>
<TABLE NAME="label" COMMENT="Defines labels">
<FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="course" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="intro" TYPE="text" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="false" 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="id"/>
</KEYS>
<INDEXES>
<INDEX NAME="course" UNIQUE="false" FIELDS="course"/>
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
+32
View File
@@ -0,0 +1,32 @@
<?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/>.
/**
* Definition of log events
*
* @package mod_label
* @category log
* @copyright 2010 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$logs = array(
array('module'=>'label', 'action'=>'add', 'mtable'=>'label', 'field'=>'name'),
array('module'=>'label', 'action'=>'update', 'mtable'=>'label', 'field'=>'name'),
);
+40
View File
@@ -0,0 +1,40 @@
<?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/>.
/**
* Label external functions and service definitions.
*
* @package mod_label
* @category external
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.3
*/
defined('MOODLE_INTERNAL') || die;
$functions = array(
'mod_label_get_labels_by_courses' => array(
'classname' => 'mod_label_external',
'methodname' => 'get_labels_by_courses',
'description' => 'Returns a list of labels in a provided list of courses, if no list is provided all labels that the user
can view will be returned.',
'type' => 'read',
'capabilities' => 'mod/label:view',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
);
+104
View File
@@ -0,0 +1,104 @@
<?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/>.
/**
* Label module upgrade
*
* @package mod_label
* @copyright 2006 onwards Eloy Lafuente (stronk7) {@link http://stronk7.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
// This file keeps track of upgrades to
// the label module
//
// Sometimes, changes between versions involve
// alterations to database structures and other
// major things that may break installations.
//
// The upgrade function in this file will attempt
// to perform all the necessary actions to upgrade
// your older installation to the current version.
//
// If there's something it cannot do itself, it
// will tell you what you need to do.
//
// The commands in here will all be database-neutral,
// using the methods of database_manager class
//
// Please do not forget to use upgrade_set_timeout()
// before any action that may take longer time to finish.
function xmldb_label_upgrade($oldversion) {
global $CFG, $DB;
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2022112801) {
$prevlang = force_current_language($CFG->lang);
$select = $DB->sql_like('name', ':tofind');
$params = ['tofind' => '%@@PLUGINFILE@@%'];
$total = $DB->count_records_select('label', $select, $params);
if ($total > 0) {
$labels = $DB->get_recordset_select('label', $select, $params, '', 'id, name, intro');
// Show a progress bar.
$pbar = new progress_bar('upgrademodlabelpluginfile', 500, true);
$current = 0;
$defaultname = get_string('modulename', 'label');
foreach ($labels as $label) {
$originalname = $label->name;
// Make sure that all labels have now the same name according to the new convention.
// Note this is the same (and duplicated) code as in get_label_name as we cannot call any API function
// during upgrade.
$name = html_to_text(format_string($label->intro, true));
$name = preg_replace('/@@PLUGINFILE@@\/[[:^space:]]+/i', '', $name);
// Remove double space and also nbsp; characters.
$name = preg_replace('/\s+/u', ' ', $name);
$name = trim($name);
if (core_text::strlen($name) > LABEL_MAX_NAME_LENGTH) {
$name = core_text::substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
}
if (empty($name)) {
$name = $defaultname;
}
$label->name = $name;
if ($originalname !== $name) {
$DB->update_record('label', $label);
}
$current++;
$pbar->update($current, $total, "Upgrading label activity names - $current/$total.");
}
$labels->close();
}
force_current_language($prevlang);
upgrade_mod_savepoint(true, 2022112801, 'label');
}
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
+35
View File
@@ -0,0 +1,35 @@
<?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 functions and constants for module label
*
* @package mod_label
* @copyright 2003 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
require_once("lib.php");
$id = required_param('id',PARAM_INT); // course
$PAGE->set_url('/mod/label/index.php', array('id'=>$id));
redirect("$CFG->wwwroot/course/view.php?id=$id");
+62
View File
@@ -0,0 +1,62 @@
<?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/>.
/**
* Strings for component 'label', language 'en', branch 'MOODLE_20_STABLE'
*
* @package mod_label
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['configdndmedia'] = 'Offer to create a Text and media area when media files are dragged and dropped onto a course.';
$string['configdndresizeheight'] = 'When a Text and media area is created from a dragged and dropped media file, resize it if it is higher than this many pixels. If set to zero, the media file will not be resized.';
$string['configdndresizewidth'] = 'When a Text and media area is created from a dragged and dropped media file, resize it if it is wider than this many pixels. If set to zero, the media file will not be resized.';
$string['dndmedia'] = 'Media drag and drop';
$string['dndresizeheight'] = 'Resize drag and drop height';
$string['dndresizewidth'] = 'Resize drag and drop width';
$string['dnduploadlabel'] = 'Add media to course page';
$string['dnduploadlabeltext'] = 'Add a Text and media area to the course page';
$string['indicator:cognitivedepth'] = 'Text and media area cognitive';
$string['indicator:cognitivedepth_help'] = 'This indicator is based on the cognitive depth reached by the student in a Text and media area resource.';
$string['indicator:cognitivedepthdef'] = 'Text and media area cognitive';
$string['indicator:cognitivedepthdef_help'] = 'The participant has reached this percentage of the cognitive engagement offered by the Text and media area resources during this analysis interval (Levels = No view, View)';
$string['indicator:cognitivedepthdef_link'] = 'Learning_analytics_indicators#Cognitive_depth';
$string['indicator:socialbreadth'] = 'Text and media area social';
$string['indicator:socialbreadth_help'] = 'This indicator is based on the social breadth reached by the student in a Text and media area resource.';
$string['indicator:socialbreadthdef'] = 'Text and media area social';
$string['indicator:socialbreadthdef_help'] = 'The participant has reached this percentage of the social engagement offered by the Text and media area resources during this analysis interval (Levels = No participation, Participant alone)';
$string['indicator:socialbreadthdef_link'] = 'Learning_analytics_indicators#Social_breadth';
$string['label:addinstance'] = 'Add a new Text and media area';
$string['label:view'] = 'View Text and media area';
$string['labelname'] = 'Title in course index';
$string['labelname_help'] = 'The title is only used to identify the Text and media area in the course index and for activity completion. If you leave it empty, a title will be automatically generated using the first characters of the text.';
$string['labeltext'] = 'Text';
$string['modulename'] = 'Text and media area';
$string['modulename_help'] = 'The Text and media area enables you to display text and multimedia on the course page.
You can use a Text and media area to:
* Split up a long list of course activities with a subheading or an image
* Display an embedded video directly on the course page
* Add a short description to a course section';
$string['modulename_link'] = 'mod/label/view';
$string['modulenameplural'] = 'Text and media areas';
$string['privacy:metadata'] = 'The Text and media area plugin does not store any personal data.';
$string['pluginadministration'] = 'Text and media area administration';
$string['pluginname'] = 'Text and media area';
$string['search:activity'] = 'Text and media area';
+405
View File
@@ -0,0 +1,405 @@
<?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 functions and constants for module label
*
* @package mod_label
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
/** LABEL_MAX_NAME_LENGTH = 50 */
define("LABEL_MAX_NAME_LENGTH", 50);
/**
* @uses LABEL_MAX_NAME_LENGTH
* @param object $label
* @return string
*/
function get_label_name($label) {
// Return label name if not empty.
if ($label->name) {
return $label->name;
}
$context = context_module::instance($label->coursemodule);
$intro = format_text($label->intro, $label->introformat, ['filter' => false, 'context' => $context]);
$name = html_to_text(format_string($intro, true, ['context' => $context]));
$name = preg_replace('/@@PLUGINFILE@@\/[[:^space:]]+/i', '', $name);
// Remove double space and also nbsp; characters.
$name = preg_replace('/\s+/u', ' ', $name);
$name = trim($name);
if (core_text::strlen($name) > LABEL_MAX_NAME_LENGTH) {
$name = core_text::substr($name, 0, LABEL_MAX_NAME_LENGTH) . "...";
}
if (empty($name)) {
// arbitrary name
$name = get_string('modulename','label');
}
return $name;
}
/**
* 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 new instance.
*
* @global object
* @param object $label
* @return bool|int
*/
function label_add_instance($label) {
global $DB;
$label->name = get_label_name($label);
$label->timemodified = time();
$id = $DB->insert_record("label", $label);
$completiontimeexpected = !empty($label->completionexpected) ? $label->completionexpected : null;
\core_completion\api::update_completion_date_event($label->coursemodule, 'label', $id, $completiontimeexpected);
return $id;
}
/**
* Sets the special label display on course page.
*
* @param cm_info $cm Course-module object
*/
function label_cm_info_view(cm_info $cm) {
$cm->set_custom_cmlist_item(true);
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
* @global object
* @param object $label
* @return bool
*/
function label_update_instance($label) {
global $DB;
$label->name = get_label_name($label);
$label->timemodified = time();
$label->id = $label->instance;
$completiontimeexpected = !empty($label->completionexpected) ? $label->completionexpected : null;
\core_completion\api::update_completion_date_event($label->coursemodule, 'label', $label->id, $completiontimeexpected);
return $DB->update_record("label", $label);
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @global object
* @param int $id
* @return bool
*/
function label_delete_instance($id) {
global $DB;
if (! $label = $DB->get_record("label", array("id"=>$id))) {
return false;
}
$result = true;
$cm = get_coursemodule_from_instance('label', $id);
\core_completion\api::update_completion_date_event($cm->id, 'label', $label->id, null);
if (! $DB->delete_records("label", array("id"=>$label->id))) {
$result = false;
}
return $result;
}
/**
* Given a course_module object, this function returns any
* "extra" information that may be needed when printing
* this activity in a course listing.
* See get_array_of_activities() in course/lib.php
*
* @global object
* @param object $coursemodule
* @return cached_cm_info|null
*/
function label_get_coursemodule_info($coursemodule) {
global $DB;
if ($label = $DB->get_record('label', array('id'=>$coursemodule->instance), 'id, name, intro, introformat')) {
if (empty($label->name)) {
// label name missing, fix it
$label->name = "label{$label->id}";
$DB->set_field('label', 'name', $label->name, array('id'=>$label->id));
}
$info = new cached_cm_info();
// no filtering hre because this info is cached and filtered later
$info->content = format_module_intro('label', $label, $coursemodule->id, false);
$info->name = $label->name;
return $info;
} else {
return null;
}
}
/**
* This function is used by the reset_course_userdata function in moodlelib.
*
* @param object $data the data submitted from the reset course.
* @return array status array
*/
function label_reset_userdata($data) {
// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.
// See MDL-9367.
return array();
}
/**
* @uses FEATURE_IDNUMBER
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
* @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, false if not, null if doesn't know or string for the module purpose.
*/
function label_supports($feature) {
switch($feature) {
case FEATURE_IDNUMBER: return true;
case FEATURE_GROUPS: return false;
case FEATURE_GROUPINGS: return false;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_MOD_ARCHETYPE: return MOD_ARCHETYPE_RESOURCE;
case FEATURE_BACKUP_MOODLE2: return true;
case FEATURE_NO_VIEW_LINK: return true;
case FEATURE_MOD_PURPOSE: return MOD_PURPOSE_CONTENT;
default: return null;
}
}
/**
* Register the ability to handle drag and drop file uploads
* @return array containing details of the files / types the mod can handle
*/
function label_dndupload_register() {
$strdnd = get_string('dnduploadlabel', 'mod_label');
if (get_config('label', 'dndmedia')) {
$mediaextensions = file_get_typegroup('extension', ['web_image', 'web_video', 'web_audio']);
$files = array();
foreach ($mediaextensions as $extn) {
$extn = trim($extn, '.');
$files[] = array('extension' => $extn, 'message' => $strdnd);
}
$ret = array('files' => $files);
} else {
$ret = array();
}
$strdndtext = get_string('dnduploadlabeltext', 'mod_label');
return array_merge($ret, array('types' => array(
array('identifier' => 'text/html', 'message' => $strdndtext, 'noname' => true),
array('identifier' => 'text', 'message' => $strdndtext, 'noname' => true)
)));
}
/**
* Handle a file that has been uploaded
* @param object $uploadinfo details of the file / content that has been uploaded
* @return int instance id of the newly created mod
*/
function label_dndupload_handle($uploadinfo) {
global $USER;
// Gather the required info.
$data = new stdClass();
$data->course = $uploadinfo->course->id;
$data->name = $uploadinfo->displayname;
$data->intro = '';
$data->introformat = FORMAT_HTML;
$data->coursemodule = $uploadinfo->coursemodule;
// Extract the first (and only) file from the file area and add it to the label as an img tag.
if (!empty($uploadinfo->draftitemid)) {
$fs = get_file_storage();
$draftcontext = context_user::instance($USER->id);
$context = context_module::instance($uploadinfo->coursemodule);
$files = $fs->get_area_files($draftcontext->id, 'user', 'draft', $uploadinfo->draftitemid, '', false);
if ($file = reset($files)) {
if (file_mimetype_in_typegroup($file->get_mimetype(), 'web_image')) {
// It is an image - resize it, if too big, then insert the img tag.
$config = get_config('label');
$data->intro = label_generate_resized_image($file, $config->dndresizewidth, $config->dndresizeheight);
} else {
// We aren't supposed to be supporting non-image types here, but fallback to adding a link, just in case.
$url = moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename());
$data->intro = html_writer::link($url, $file->get_filename());
}
$data->intro = file_save_draft_area_files($uploadinfo->draftitemid, $context->id, 'mod_label', 'intro', 0,
null, $data->intro);
}
} else if (!empty($uploadinfo->content)) {
$data->intro = $uploadinfo->content;
if ($uploadinfo->type != 'text/html') {
$data->introformat = FORMAT_PLAIN;
}
}
return label_add_instance($data, null);
}
/**
* Resize the image, if required, then generate an img tag and, if required, a link to the full-size image
* @param stored_file $file the image file to process
* @param int $maxwidth the maximum width allowed for the image
* @param int $maxheight the maximum height allowed for the image
* @return string HTML fragment to add to the label
*/
function label_generate_resized_image(stored_file $file, $maxwidth, $maxheight) {
global $CFG;
$fullurl = moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename());
$link = null;
$attrib = array('alt' => $file->get_filename(), 'src' => $fullurl);
if ($imginfo = $file->get_imageinfo()) {
// Work out the new width / height, bounded by maxwidth / maxheight
$width = $imginfo['width'];
$height = $imginfo['height'];
if (!empty($maxwidth) && $width > $maxwidth) {
$height *= (float)$maxwidth / $width;
$width = $maxwidth;
}
if (!empty($maxheight) && $height > $maxheight) {
$width *= (float)$maxheight / $height;
$height = $maxheight;
}
$attrib['width'] = $width;
$attrib['height'] = $height;
// If the size has changed and the image is of a suitable mime type, generate a smaller version
if ($width != $imginfo['width']) {
$mimetype = $file->get_mimetype();
if ($mimetype === 'image/gif' or $mimetype === 'image/jpeg' or $mimetype === 'image/png') {
require_once($CFG->libdir.'/gdlib.php');
$data = $file->generate_image_thumbnail($width, $height);
if (!empty($data)) {
$fs = get_file_storage();
$record = array(
'contextid' => $file->get_contextid(),
'component' => $file->get_component(),
'filearea' => $file->get_filearea(),
'itemid' => $file->get_itemid(),
'filepath' => '/',
'filename' => 's_'.$file->get_filename(),
);
$smallfile = $fs->create_file_from_string($record, $data);
// Replace the image 'src' with the resized file and link to the original
$attrib['src'] = moodle_url::make_draftfile_url($smallfile->get_itemid(), $smallfile->get_filepath(),
$smallfile->get_filename());
$link = $fullurl;
}
}
}
} else {
// Assume this is an image type that get_imageinfo cannot handle (e.g. SVG)
$attrib['width'] = $maxwidth;
}
$attrib['class'] = "img-fluid";
$img = html_writer::empty_tag('img', $attrib);
if ($link) {
return html_writer::link($link, $img);
} else {
return $img;
}
}
/**
* Check if the module has any update that affects the current user since a given time.
*
* @param cm_info $cm course module data
* @param int $from the time to check updates from
* @param array $filter if we need to check only specific updates
* @return stdClass an object with the different type of areas indicating if they were updated or not
* @since Moodle 3.2
*/
function label_check_updates_since(cm_info $cm, $from, $filter = array()) {
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
return $updates;
}
/**
* This function receives a calendar event and returns the action associated with it, or null if there is none.
*
* This is used by block_myoverview in order to display the event appropriately. If null is returned then the event
* is not displayed on the block.
*
* @param calendar_event $event
* @param \core_calendar\action_factory $factory
* @param int $userid User id to use for all capability checks, etc. Set to 0 for current user (default).
* @return \core_calendar\local\event\entities\action_interface|null
*/
function mod_label_core_calendar_provide_event_action(calendar_event $event,
\core_calendar\action_factory $factory,
int $userid = 0) {
$cm = get_fast_modinfo($event->courseid, $userid)->instances['label'][$event->instance];
if (!$cm->uservisible) {
// The module is not visible to the user for any reason.
return null;
}
$completion = new \completion_info($cm->get_course());
$completiondata = $completion->get_data($cm, false, $userid);
if ($completiondata->completionstate != COMPLETION_INCOMPLETE) {
return null;
}
return $factory->create_instance(
get_string('view'),
new \moodle_url('/mod/label/view.php', ['id' => $cm->id]),
1,
true
);
}
+83
View File
@@ -0,0 +1,83 @@
<?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/>.
/**
* Add label form
*
* @package mod_label
* @copyright 2006 Jamie Pratt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_label_mod_form extends moodleform_mod {
function definition() {
global $PAGE;
$PAGE->force_settings_menu();
$mform = $this->_form;
$mform->addElement('header', 'generalhdr', get_string('general'));
// Add element for name.
$mform->addElement('text', 'name', get_string('labelname', 'label'), ['size' => '64', 'maxlength' => 255]);
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEANHTML);
}
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addHelpButton('name', 'labelname', 'label');
$this->standard_intro_elements(get_string('labeltext', 'label'));
// Label does not add "Show description" checkbox meaning that 'intro' is always shown on the course page.
$mform->addElement('hidden', 'showdescription', 1);
$mform->setType('showdescription', PARAM_INT);
$this->standard_coursemodule_elements();
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons(true, false, null);
}
/**
* Override validation in order to make name field non-required.
*
* @param array $data
* @param array $files
* @return array
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// Name field should not be required.
if (array_key_exists('name', $errors)) {
if ($errors['name'] === get_string('required')) {
unset($errors['name']);
}
}
return $errors;
}
}
+4
View File
@@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMinYMid meet">
<path d="M8.00391 8.49805C8.00391 8.2219 8.22776 7.99805 8.50391 7.99805L15.5085 7.99805C15.7847 7.99805 16.0085 8.22191 16.0085 8.49805C16.0085 8.52777 16.006 8.55689 16.001 8.5852V10.3735C16.001 10.6496 15.7771 10.8735 15.501 10.8735C15.2248 10.8735 15.001 10.6496 15.001 10.3735V8.99805H12.5V14.9988H13.5C13.7761 14.9988 14 15.2226 14 15.4988C14 15.7749 13.7761 15.9988 13.5 15.9988H10.5C10.2239 15.9988 10 15.7749 10 15.4988C10 15.2226 10.2239 14.9988 10.5 14.9988H11.5V8.99805H9.00391V10.3735C9.00391 10.6496 8.78005 10.8735 8.50391 10.8735C8.22776 10.8735 8.00391 10.6496 8.00391 10.3735V8.49805Z" fill="#212529"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M3 2.50012C2.72386 2.50012 2.5 2.72398 2.5 3.00012V6.00012C2.5 6.27626 2.72386 6.50012 3 6.50012H4V17.4999H3C2.72386 17.4999 2.5 17.7237 2.5 17.9999V20.9999C2.5 21.276 2.72386 21.4999 3 21.4999H6C6.27614 21.4999 6.5 21.276 6.5 20.9999V19.9999H17.5V20.9999C17.5 21.276 17.7239 21.4999 18 21.4999H21C21.2761 21.4999 21.5 21.276 21.5 20.9999V17.9999C21.5 17.7237 21.2761 17.4999 21 17.4999H19.9998V6.50012H21C21.2761 6.50012 21.5 6.27626 21.5 6.00012V3.00012C21.5 2.72398 21.2761 2.50012 21 2.50012H18C17.7239 2.50012 17.5 2.72398 17.5 3.00012V4.00012H6.5V3.00012C6.5 2.72398 6.27614 2.50012 6 2.50012H3ZM6.5 5.00012V6.00012C6.5 6.27626 6.27614 6.50012 6 6.50012H5V17.4999H6C6.27614 17.4999 6.5 17.7237 6.5 17.9999V18.9999H17.5V17.9999C17.5 17.7237 17.7239 17.4999 18 17.4999H18.9998V6.50012H18C17.7239 6.50012 17.5 6.27626 17.5 6.00012V5.00012H6.5ZM3.5 5.50012V3.50012H5.5V5.50012H3.5ZM3.5 20.4999V18.4999H5.5V20.4999H3.5ZM18.5 3.50012V5.50012H20.5V3.50012H18.5ZM18.5 20.4999V18.4999H20.5V20.4999H18.5Z" fill="#212529"/>
</svg>

After

Width:  |  Height:  |  Size: 1.8 KiB

+37
View File
@@ -0,0 +1,37 @@
<?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/>.
/**
* Resource module admin settings and defaults
*
* @package mod_label
* @copyright 2013 Davo Smith, Synergy Learning
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
if ($ADMIN->fulltree) {
$settings->add(new admin_setting_configcheckbox('label/dndmedia',
get_string('dndmedia', 'mod_label'), get_string('configdndmedia', 'mod_label'), 1));
$settings->add(new admin_setting_configtext('label/dndresizewidth',
get_string('dndresizewidth', 'mod_label'), get_string('configdndresizewidth', 'mod_label'), 400, PARAM_INT, 6));
$settings->add(new admin_setting_configtext('label/dndresizeheight',
get_string('dndresizeheight', 'mod_label'), get_string('configdndresizeheight', 'mod_label'), 400, PARAM_INT, 6));
}
@@ -0,0 +1,56 @@
@mod @mod_label @core_completion
Feature: View activity completion information for the label
In order to have visibility of Label completion requirements
As a student
I need to be able to view my Label completion progress
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Vinnie | Student1 | student1@example.com |
| teacher1 | Darrell | Teacher1 | teacher1@example.com |
And the following "courses" exist:
| fullname | shortname | category | enablecompletion |
| Course 1 | C1 | 0 | 1 |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
| teacher1 | C1 | editingteacher |
And the following "activity" exists:
| activity | label |
| course | C1 |
| idnumber | mh1 |
| section | 1 |
| completion | 1 |
@javascript
Scenario: The manual completion button will be shown on the course page if the Show activity completion conditions is set to No
Given I am on the "Course 1" course page logged in as teacher1
# Teacher view.
And "Test label 1" should have the "Mark as done" completion condition
And I log out
# Student view.
When I log in as "student1"
And I am on "Course 1" course homepage
Then the manual completion button for "Test label 1" should exist
And the manual completion button of "Test label 1" is displayed as "Mark as done"
And I toggle the manual completion state of "Test label 1"
And the manual completion button of "Test label 1" is displayed as "Done"
@javascript
Scenario: The manual completion button will be shown on the course page if the Show activity completion conditions is set to Yes
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Settings" in current page administration
And I expand all fieldsets
And I set the field "Show activity completion conditions" to "Yes"
And I press "Save and display"
# Teacher view.
And "Test label 1" should have the "Mark as done" completion condition
And I log out
# Student view.
When I log in as "student1"
And I am on "Course 1" course homepage
Then the manual completion button for "Test label 1" should exist
And the manual completion button of "Test label 1" is displayed as "Mark as done"
And I toggle the manual completion state of "Test label 1"
And the manual completion button of "Test label 1" is displayed as "Done"
@@ -0,0 +1,36 @@
@mod @mod_label
Feature: set label idnumber
In order to set label idnumber
As a teacher
I should create label activity and set an ID number
Scenario: label ID number input box should be shown.
Given the following "courses" exist:
| fullname | shortname | category |
| Test | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher | Teacher | First | teacher1@example.com |
| student | Student | First | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
| student | C1 | student |
And the following "activities" exist:
| activity | course | section | intro | idnumber |
| label | C1 | 1 | Label with ID number set | C1LABEL1 |
When I log in as "teacher"
And I am on "Test" course homepage with editing mode on
Then "Label with ID number set" activity should be visible
And I turn editing mode off
And "Label with ID number set" activity should be visible
And I log out
And I log in as "student"
And I am on "Test" course homepage
And I should see "Label with ID number set"
And I log out
And I am on the "Label with ID number set" "label activity editing" page logged in as teacher
And I expand all fieldsets
And I should see "ID number" in the "Common module settings" "fieldset"
And the field "ID number" matches value "C1LABEL1"
+30
View File
@@ -0,0 +1,30 @@
@mod @mod_label
Feature: Set label name
As a teacher
I should be able to create a label activity and set a name
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Test | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher | Teacher | First | teacher1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
And the following "activities" exist:
| activity | course | section | intro | idnumber |
| label | C1 | 1 | Intro Text | C1LABEL1 |
Scenario: label name input box should be shown and can be set
When I log in as "teacher"
And I am on "Test" course homepage
And "Intro Text" activity should be visible
And I am on the "Intro Text" "label activity editing" page logged in as teacher
And I should see "Title in course index" in the "General" "fieldset"
And I set the field "Title in course index" to "Test Label 1"
And I press "Save and return to course"
And I am on "Test" course homepage
Then "Test Label 1" activity should be visible
@@ -0,0 +1,64 @@
@mod @mod_label
Feature: Check label visibility works
In order to check label visibility works
As a teacher
I should create label activity
Background:
Given the following "courses" exist:
| fullname | shortname | category |
| Test | C1 | 0 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher | Teacher | First | teacher1@example.com |
| student | Student | First | student1@example.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher | C1 | editingteacher |
| student | C1 | student |
And the following "activities" exist:
| activity | course | section | intro | idnumber | visible |
| label | C1 | 1 | Swanky label | 1 | 1 |
| label | C1 | 1 | Swanky label 2 | 2 | 0 |
Scenario: Hidden label activity should be show as hidden.
Given I log in as "teacher"
When I am on "Test" course homepage with editing mode on
Then "Swanky label 2" label should be hidden
And I turn editing mode off
And "Swanky label 2" label should be hidden
And I log out
And I log in as "student"
And I am on "Test" course homepage
And I should not see "Swanky label 2"
And I log out
Scenario: Visible label activity should be shown as visible.
Given I log in as "teacher"
When I am on "Test" course homepage with editing mode on
Then "Swanky label" activity should be visible
And I log out
And I log in as "student"
And I am on "Test" course homepage
And "Swanky label" activity should be visible
And I log out
@javascript
Scenario: Teacher can not show label inside the hidden section
Given I log in as "teacher"
And I am on "Test" course homepage with editing mode on
When I hide section "1"
Then "Swanky label" label should be hidden
And I open "Swanky label" actions menu
And "Swanky label" actions menu should not have "Availability" item
And I click on "Edit settings" "link" in the "Swanky label" activity
And I expand all fieldsets
And the "Availability" select box should contain "Hide on course page"
And the "Availability" select box should not contain "Make available but don't show on course page"
And the "Availability" select box should not contain "Show on course page"
And I log out
And I log in as "student"
And I am on "Test" course homepage
And I should not see "Swanky label"
And I log out
+158
View File
@@ -0,0 +1,158 @@
<?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/>.
namespace mod_label;
use core_external\external_api;
use externallib_advanced_testcase;
use mod_label_external;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
/**
* External mod_label functions unit tests
*
* @package mod_label
* @category external
* @copyright 2017 Juan Leyva <juan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @since Moodle 3.3
*/
class externallib_test extends externallib_advanced_testcase {
/**
* Test test_mod_label_get_labels_by_courses
*/
public function test_mod_label_get_labels_by_courses(): void {
global $DB;
$this->resetAfterTest(true);
$course1 = self::getDataGenerator()->create_course();
$course2 = self::getDataGenerator()->create_course();
$student = self::getDataGenerator()->create_user();
$studentrole = $DB->get_record('role', array('shortname' => 'student'));
$this->getDataGenerator()->enrol_user($student->id, $course1->id, $studentrole->id);
// First label.
$record = new \stdClass();
$record->course = $course1->id;
$label1 = self::getDataGenerator()->create_module('label', $record);
// Second label.
$record = new \stdClass();
$record->course = $course2->id;
$label2 = self::getDataGenerator()->create_module('label', $record);
// Execute real Moodle enrolment as we'll call unenrol() method on the instance later.
$enrol = enrol_get_plugin('manual');
$enrolinstances = enrol_get_instances($course2->id, true);
foreach ($enrolinstances as $courseenrolinstance) {
if ($courseenrolinstance->enrol == "manual") {
$instance2 = $courseenrolinstance;
break;
}
}
$enrol->enrol_user($instance2, $student->id, $studentrole->id);
self::setUser($student);
$returndescription = mod_label_external::get_labels_by_courses_returns();
// Create what we expect to be returned when querying the two courses.
$expectedfields = array('id', 'coursemodule', 'course', 'name', 'intro', 'introformat', 'introfiles', 'timemodified',
'section', 'visible', 'groupmode', 'groupingid', 'lang');
// Add expected coursemodule and data.
$label1->coursemodule = $label1->cmid;
$label1->introformat = 1;
$label1->section = 0;
$label1->visible = true;
$label1->groupmode = 0;
$label1->groupingid = 0;
$label1->introfiles = [];
$label1->lang = '';
$label2->coursemodule = $label2->cmid;
$label2->introformat = 1;
$label2->section = 0;
$label2->visible = true;
$label2->groupmode = 0;
$label2->groupingid = 0;
$label2->introfiles = [];
$label2->lang = '';
foreach ($expectedfields as $field) {
$expected1[$field] = $label1->{$field};
$expected2[$field] = $label2->{$field};
}
$expectedlabels = array($expected2, $expected1);
// Call the external function passing course ids.
$result = mod_label_external::get_labels_by_courses(array($course2->id, $course1->id));
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlabels, $result['labels']);
$this->assertCount(0, $result['warnings']);
// Call the external function without passing course id.
$result = mod_label_external::get_labels_by_courses();
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlabels, $result['labels']);
$this->assertCount(0, $result['warnings']);
// Add a file to the intro.
$filename = "file.txt";
$filerecordinline = array(
'contextid' => \context_module::instance($label2->cmid)->id,
'component' => 'mod_label',
'filearea' => 'intro',
'itemid' => 0,
'filepath' => '/',
'filename' => $filename,
);
$fs = get_file_storage();
$timepost = time();
$fs->create_file_from_string($filerecordinline, 'image contents (not really)');
$result = mod_label_external::get_labels_by_courses(array($course2->id, $course1->id));
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertCount(1, $result['labels'][0]['introfiles']);
$this->assertEquals($filename, $result['labels'][0]['introfiles'][0]['filename']);
// Unenrol user from second course.
$enrol->unenrol_user($instance2, $student->id);
array_shift($expectedlabels);
// Call the external function without passing course id.
$result = mod_label_external::get_labels_by_courses();
$result = external_api::clean_returnvalue($returndescription, $result);
$this->assertEquals($expectedlabels, $result['labels']);
// Call for the second course we unenrolled the user from, expected warning.
$result = mod_label_external::get_labels_by_courses(array($course2->id));
$this->assertCount(1, $result['warnings']);
$this->assertEquals('1', $result['warnings'][0]['warningcode']);
$this->assertEquals($course2->id, $result['warnings'][0]['itemid']);
}
}
+44
View File
@@ -0,0 +1,44 @@
<?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/>.
/**
* mod_label data generator
*
* @package mod_label
* @category test
* @copyright 2013 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Label module data generator class
*
* @package mod_label
* @category test
* @copyright 2013 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_label_generator extends testing_module_generator {
public function create_instance($record = null, array $options = null) {
$record = (array)$record;
$record['showdescription'] = 1;
return parent::create_instance($record, $options);
}
}
+55
View File
@@ -0,0 +1,55 @@
<?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/>.
namespace mod_label;
/**
* PHPUnit label generator testcase
*
* @package mod_label
* @category phpunit
* @copyright 2013 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class generator_test extends \advanced_testcase {
public function test_generator(): void {
global $DB;
$this->resetAfterTest(true);
$this->assertEquals(0, $DB->count_records('label'));
$course = $this->getDataGenerator()->create_course();
/** @var mod_label_generator $generator */
$generator = $this->getDataGenerator()->get_plugin_generator('mod_label');
$this->assertInstanceOf('mod_label_generator', $generator);
$this->assertEquals('label', $generator->get_modulename());
$generator->create_instance(array('course'=>$course->id));
$generator->create_instance(array('course'=>$course->id));
$label = $generator->create_instance(array('course'=>$course->id));
$this->assertEquals(3, $DB->count_records('label'));
$cm = get_coursemodule_from_instance('label', $label->id);
$this->assertEquals($label->id, $cm->instance);
$this->assertEquals('label', $cm->modname);
$this->assertEquals($course->id, $cm->course);
$context = \context_module::instance($cm->id);
$this->assertEquals($label->cmid, $context->instanceid);
}
}
+364
View File
@@ -0,0 +1,364 @@
<?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/>.
namespace mod_label;
/**
* Unit tests for the activity label's lib.
*
* @package mod_label
* @category test
* @copyright 2017 Mark Nelson <markn@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class lib_test extends \advanced_testcase {
/**
* Set up.
*/
public function setUp(): void {
$this->resetAfterTest();
$this->setAdminUser();
}
public function test_label_core_calendar_provide_event_action(): void {
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $label->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_label_core_calendar_provide_event_action($event, $factory);
// Confirm the event was decorated.
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
$this->assertEquals(get_string('view'), $actionevent->get_name());
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
$this->assertEquals(1, $actionevent->get_item_count());
$this->assertTrue($actionevent->is_actionable());
}
public function test_label_core_calendar_provide_event_action_as_non_user(): void {
global $CFG;
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id));
// Create a calendar event.
$event = $this->create_action_event($course->id, $label->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Now log out.
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
$this->setUser();
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_label_core_calendar_provide_event_action($event, $factory);
// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}
public function test_label_core_calendar_provide_event_action_in_hidden_section(): void {
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id));
// Create a student.
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Create a calendar event.
$event = $this->create_action_event($course->id, $label->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Set sections 0 as hidden.
set_section_visible($course->id, 0, 0);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event for the student.
$actionevent = mod_label_core_calendar_provide_event_action($event, $factory, $student->id);
// Confirm the event is not shown at all.
$this->assertNull($actionevent);
}
public function test_label_core_calendar_provide_event_action_for_user(): void {
global $CFG;
// Create the activity.
$course = $this->getDataGenerator()->create_course();
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id));
// Enrol a student in the course.
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Create a calendar event.
$event = $this->create_action_event($course->id, $label->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Now, log out.
$CFG->forcelogin = true; // We don't want to be logged in as guest, as guest users might still have some capabilities.
$this->setUser();
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event for the student.
$actionevent = mod_label_core_calendar_provide_event_action($event, $factory, $student->id);
// Confirm the event was decorated.
$this->assertInstanceOf('\core_calendar\local\event\value_objects\action', $actionevent);
$this->assertEquals(get_string('view'), $actionevent->get_name());
$this->assertInstanceOf('moodle_url', $actionevent->get_url());
$this->assertEquals(1, $actionevent->get_item_count());
$this->assertTrue($actionevent->is_actionable());
}
public function test_label_core_calendar_provide_event_action_already_completed(): void {
global $CFG;
$CFG->enablecompletion = 1;
// Create the activity.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
// Get some additional data.
$cm = get_coursemodule_from_instance('label', $label->id);
// Create a calendar event.
$event = $this->create_action_event($course->id, $label->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Mark the activity as completed.
$completion = new \completion_info($course);
$completion->set_module_viewed($cm);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event.
$actionevent = mod_label_core_calendar_provide_event_action($event, $factory);
// Ensure result was null.
$this->assertNull($actionevent);
}
public function test_label_core_calendar_provide_event_action_already_completed_for_user(): void {
global $CFG;
$CFG->enablecompletion = 1;
// Create the activity.
$course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
$label = $this->getDataGenerator()->create_module('label', array('course' => $course->id),
array('completion' => 2, 'completionview' => 1, 'completionexpected' => time() + DAYSECS));
// Enrol a student in the course.
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
// Get some additional data.
$cm = get_coursemodule_from_instance('label', $label->id);
// Create a calendar event.
$event = $this->create_action_event($course->id, $label->id,
\core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED);
// Mark the activity as completed for the student.
$completion = new \completion_info($course);
$completion->set_module_viewed($cm, $student->id);
// Create an action factory.
$factory = new \core_calendar\action_factory();
// Decorate action event for the student.
$actionevent = mod_label_core_calendar_provide_event_action($event, $factory, $student->id);
// Ensure result was null.
$this->assertNull($actionevent);
}
/**
* Check label name with different content inserted in the label intro.
*
* @param string $name
* @param string $content
* @param string $format
* @param string $expectedname
* @return void
* @covers \get_label_name
* @dataProvider label_get_name_data_provider
*/
public function test_label_get_label_name(string $name, string $content, string $format, string $expectedname): void {
$course = $this->getDataGenerator()->create_course();
// When creating the module, get_label_name is called and fills label->name.
$label = $this->getDataGenerator()->create_module('label', [
'name' => $name,
'course' => $course->id,
'intro' => $content,
'introformat' => $format
]
);
$this->assertEquals($expectedname, $label->name);
}
/**
* Dataprovider for test_label_get_label_name
*
* @return array
*/
public function label_get_name_data_provider(): array {
return [
'withlabelname' => [
'name' => 'Test label 1',
'content' => '<p>Simple textual content<p>',
'format' => FORMAT_HTML,
'expected' => 'Test label 1'
],
'simple' => [
'name' => '',
'content' => '<p>Simple textual content<p>',
'format' => FORMAT_HTML,
'expected' => 'Simple textual content'
],
'empty' => [
'name' => '',
'content' => '',
'format' => FORMAT_HTML,
'expected' => 'Test label 1'
],
'withaudiocontent' => [
'name' => '',
'content' => '<p>Test with audio</p>
<p>&nbsp; &nbsp;<audio controls="controls">
<source src="@@PLUGINFILE@@/moodle-hit-song.mp3">
@@PLUGINFILE@@/moodle-hit-song.mp3
</audio>&nbsp;</p>',
'format' => FORMAT_HTML,
'expected' => 'Test with audio'
],
'withvideo' => [
'name' => '',
'content' => '<p>Test video</p>
<p>&nbsp;<video controls="controls">
<source src="https://www.youtube.com/watch?v=xxxyy">
https://www.youtube.com/watch?v=xxxyy
</video>&nbsp;</p>',
'format' => FORMAT_HTML,
'expected' => 'Test video https://www.youtube.com/watch?v=xxxyy'
],
'with video trimming' => [
'name' => '',
'content' => '<p>Test with video to be trimmed</p>
<p>&nbsp;<video controls="controls">
<source src="https://www.youtube.com/watch?v=xxxyy">
https://www.youtube.com/watch?v=xxxyy
</video>&nbsp;</p>',
'format' => FORMAT_HTML,
'expected' => 'Test with video to be trimmed https://www.youtube....'
],
'with plain text' => [
'name' => '',
'content' => 'Content with @@PLUGINFILE@@/moodle-hit-song.mp3 nothing',
'format' => FORMAT_HTML,
'expected' => 'Content with nothing'
],
'with several spaces' => [
'name' => '',
'content' => "Content with @@PLUGINFILE@@/moodle-hit-song.mp3 \r &nbsp; several spaces",
'format' => FORMAT_HTML,
'expected' => 'Content with several spaces'
],
'empty spaces' => [
'name' => '',
'content' => ' &nbsp; ',
'format' => FORMAT_HTML,
'expected' => 'Text and media area'
],
'only html' => [
'name' => '',
'content' => '<audio controls="controls"><source src=""></audio>',
'format' => FORMAT_HTML,
'expected' => 'Text and media area'
],
'markdown' => [
'name' => '',
'content' => "##Simple Title\n simple markdown format",
'format' => FORMAT_MARKDOWN,
'expected' => 'Simple Title simple markdown format'
],
'markdown with pluginfile' => [
'name' => '',
'content' => "##Simple Title\n simple markdown format @@PLUGINFILE@@/moodle-hit-song.mp3",
'format' => FORMAT_MARKDOWN,
'expected' => 'Simple Title simple markdown format'
],
'plain text' => [
'name' => '',
'content' => "Simple plain text @@PLUGINFILE@@/moodle-hit-song.mp3",
'format' => FORMAT_PLAIN,
'expected' => 'Simple plain text'
],
'moodle format text' => [
'name' => '',
'content' => "Simple plain text @@PLUGINFILE@@/moodle-hit-song.mp3",
'format' => FORMAT_MOODLE,
'expected' => 'Simple plain text'
],
'html format text' => [
'name' => '',
'content' => "<h1>Simple plain title</h1><p> with plain text</p> @@PLUGINFILE@@/moodle-hit-song.mp3",
'format' => FORMAT_HTML,
'expected' => 'Simple plain title with plain text'
],
];
}
/**
* Creates an action event.
*
* @param int $courseid The course id.
* @param int $instanceid The instance id.
* @param string $eventtype The event type.
* @return bool|calendar_event
*/
private function create_action_event($courseid, $instanceid, $eventtype) {
$event = new \stdClass();
$event->name = 'Calendar event';
$event->modulename = 'label';
$event->courseid = $courseid;
$event->instance = $instanceid;
$event->type = CALENDAR_EVENT_TYPE_ACTION;
$event->eventtype = $eventtype;
$event->timestart = time();
return \calendar_event::create($event);
}
}
+30
View File
@@ -0,0 +1,30 @@
<?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/>.
/**
* Label module version info
*
* @package mod_label
* @copyright 2003 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'mod_label'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;
+64
View File
@@ -0,0 +1,64 @@
<?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/>.
/**
* Label module
*
* @package mod_label
* @copyright 2003 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once("../../config.php");
$id = optional_param('id',0,PARAM_INT); // Course Module ID, or
$l = optional_param('l',0,PARAM_INT); // Label ID
if ($id) {
$PAGE->set_url('/mod/label/view.php', array('id' => $id));
if (! $cm = get_coursemodule_from_id('label', $id, 0, true)) {
throw new \moodle_exception('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
throw new \moodle_exception('coursemisconf');
}
if (! $label = $DB->get_record("label", array("id"=>$cm->instance))) {
throw new \moodle_exception('invalidcoursemodule');
}
} else {
$PAGE->set_url('/mod/label/view.php', array('l' => $l));
if (! $label = $DB->get_record("label", array("id"=>$l))) {
throw new \moodle_exception('invalidcoursemodule');
}
if (! $course = $DB->get_record("course", array("id"=>$label->course)) ){
throw new \moodle_exception('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance("label", $label->id, $course->id, true)) {
throw new \moodle_exception('invalidcoursemodule');
}
}
require_login($course, true, $cm);
$url = course_get_url($course, $cm->sectionnum, []);
$url->set_anchor('module-' . $id);
redirect($url);