Skip to content

Commit

Permalink
BugFix: Privacy null provider and parameter, context validation impro…
Browse files Browse the repository at this point in the history
…ved.

- CD-355, CD-358, CD-357
  • Loading branch information
abinesh-lmsace committed Jan 10, 2025
1 parent 22f9d91 commit bc91e21
Show file tree
Hide file tree
Showing 14 changed files with 193 additions and 14 deletions.
2 changes: 1 addition & 1 deletion classes/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function display() {
/**
* Render the module elements for student view.
* @param int $chapterafter Load the chapters after the given chapter.
* @return void
* @return string
*/
public function render_elements($chapterafter=false) {
global $OUTPUT, $DB;
Expand Down
5 changes: 3 additions & 2 deletions classes/elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,13 @@ public function render_element($instance) {
* @return string
*/
public function title_editable($instance) {
global $OUTPUT, $PAGE;
global $OUTPUT;
$title = $instance->title ?: $this->info()->name;
$name = 'instance_title['.$this->shortname.']['.$instance->id.']';
// Todo: Need to implement capability in place of true 4th param.
$tmpl = new \core\output\inplace_editable('mod_contentdesigner', $name, $this->elementid.$instance->id,
true, format_string($title), $title, "Edit the title of instance" , 'New value for ' . format_string($title));
true, format_string($title), $title, get_string('titleeditable', 'mod_contentdesigner'),
get_string('newvalue', 'mod_contentdesigner') . format_string($title));

return $OUTPUT->render($tmpl);
}
Expand Down
7 changes: 7 additions & 0 deletions element/chapter/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ public static function update_completion_parameters() {
public static function update_completion($cmid, $chapter) {
global $DB, $USER;

$vaildparams = self::validate_parameters(self::update_completion_parameters(),
['cmid' => $cmid, 'chapter' => $chapter]);

self::validate_context(\context_module::instance($cmid));

$chapter = $vaildparams['chapter'];

$record = $DB->get_record('element_chapter_completion', ['instance' => $chapter, 'userid' => $USER->id]);
$data = new \stdclass();
$data->instance = $chapter;
Expand Down
8 changes: 8 additions & 0 deletions element/h5p/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public static function store_result_data_parameters() {
public static function store_result_data($cmid, $instanceid, $result) {
global $DB, $USER;

$vaildparams = self::validate_parameters(self::store_result_data_parameters(),
['cmid' => $cmid, 'instanceid' => $instanceid, 'result' => $result]);

self::validate_context(\context_module::instance($cmid));

$instanceid = $vaildparams['instanceid'];
$result = $vaildparams['result'];

if ($record = $DB->get_record('element_h5p_completion', ['instance' => $instanceid, 'userid' => $USER->id])) {
// Store only highest scored results only.
if ($record->score > $result['score']['raw']) {
Expand Down
40 changes: 40 additions & 0 deletions element/heading/classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Privacy class for requesting user data.
*
* @package element_heading
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace element_heading\privacy;

class provider implements
// This plugin does not store any personal user data.
\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';
}
}
1 change: 1 addition & 0 deletions element/heading/lang/en/element_heading.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@

$string['elementdescription'] = 'Add a heading';
$string['pluginname'] = "Heading";
$string['privacy:metadata'] = 'The heading only displays the heading element content and does not store any user data.';
40 changes: 40 additions & 0 deletions element/outro/classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Privacy class for requesting user data.
*
* @package element_outro
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace element_outro\privacy;

class provider implements
// This plugin does not store any personal user data.
\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';
}
}
1 change: 1 addition & 0 deletions element/outro/lang/en/element_outro.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@
defined("MOODLE_INTERNAL") || die();

$string['pluginname'] = "Outro";
$string['privacy:metadata'] = 'The outro only displays the outro content and does not store any user data.';
40 changes: 40 additions & 0 deletions element/paragraph/classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Privacy class for requesting user data.
*
* @package element_paragraph
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace element_paragraph\privacy;

class provider implements
// This plugin does not store any personal user data.
\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';
}
}
1 change: 1 addition & 0 deletions element/paragraph/lang/en/element_paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@
$string['content'] = "Content";
$string['elementdescription'] = 'Add text';
$string['pluginname'] = "Paragraph";
$string['privacy:metadata'] = 'The pragraph only displays the pragraph content and does not store any user data.';
40 changes: 40 additions & 0 deletions element/richtext/classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -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/>.

/**
* Privacy class for requesting user data.
*
* @package element_richtext
* @copyright 2024 bdecent gmbh <https://bdecent.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace element_richtext\privacy;

class provider implements
// This plugin does not store any personal user data.
\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';
}
}
1 change: 1 addition & 0 deletions element/richtext/lang/en/element_richtext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@

$string['elementdescription'] = 'Add content using the Moodle editor (atto/tinymce)';
$string['pluginname'] = "Rich text";
$string['privacy:metadata'] = 'The richtext only displays the richtext content and does not store any user data.';
3 changes: 3 additions & 0 deletions lang/en/contentdesigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
$string['margin_help'] = 'Margin controls the space outside the element, creating distance between it and other elements. Set a single value to apply the same margin on all sides of the element.<br> <b>Example:</b> 10px (This will apply a 10px margin on all four sides: top, right, bottom, and left).';
$string['modulename'] = 'Content Designer';
$string['modulenameplural'] = "Content Designers";
$string['newvalue'] = 'New value for';
$string['outro:btnbacktocourse'] = 'Back to course';
$string['outro:btnbacktosection'] = 'Back to section';
$string['outro:btncustom'] = 'Custom';
Expand Down Expand Up @@ -168,6 +169,7 @@
<b>Same Window:</b> Opens the link in the current browser tab, replacing the current page.<br>
<b>New Window:</b> Opens the link in a new browser tab, keeping the current page open.
Choose ‘New Window’ if you want users to keep this page open while viewing the link.';
$string['titleeditable'] = 'Edit instance title';
$string['titlestatus'] = 'Display title';
$string['titlestatus_help'] = 'Enable this option to display the chapter\'s title to learners. When unchecked, the title will only be used for administrative purposes and will not be visible to learners. Checking this option makes the chapter title visible on the learner\'s view.';
$string['toleft'] = "To left";
Expand All @@ -182,3 +184,4 @@
$string['viewport_help'] = 'Define when the scrolling effect should start relative to the user\'s viewport. This helps control how soon the effect is triggered based on how much of the element is visible on the screen.';
$string['visibility'] = "Visibility";
$string['visibility_help'] = "Show / Hide the element";

18 changes: 7 additions & 11 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @return int instance id
*/
function contentdesigner_add_instance($data, $mform = null) {
global $CFG, $DB, $OUTPUT;
global$DB;
contentdesigner_process_pre_save($data);
$moduleid = $DB->insert_record('contentdesigner', $data);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
Expand Down Expand Up @@ -69,7 +69,7 @@ function contentdesigner_process_pre_save(&$data) {
* @return bool true
*/
function contentdesigner_update_instance($data, $mform) {
global $CFG, $DB;
global $DB;
$data->id = $data->instance;
contentdesigner_process_pre_save($data);
$completiontimeexpected = !empty($data->completionexpected) ? $data->completionexpected : null;
Expand All @@ -85,7 +85,7 @@ function contentdesigner_update_instance($data, $mform) {
* @return bool true
*/
function contentdesigner_delete_instance($id) {
global $CFG, $DB;
global $DB;

if (!$record = $DB->get_record('contentdesigner', ['id' => $id])) {
return false;
Expand Down Expand Up @@ -265,7 +265,6 @@ function contentdesigner_output_fragment_get_elements_list($args) {
* @return string
*/
function contentdesigner_output_fragment_insert_element($args) {
global $OUTPUT;
list ($course, $cm) = get_course_and_cm_from_cmid($args['cmid'], 'contentdesigner');
$editor = new mod_contentdesigner\editor($cm, $course);
$chapter = $args['chapter'] ?? 0;
Expand All @@ -288,7 +287,7 @@ function contentdesigner_output_fragment_load_elements($args) {
* Prepare the next available chapters to users view after the chapter completed.
*
* @param array $args
* @return void
* @return bool|string
*/
function contentdesigner_output_fragment_load_next_chapters($args) {
list ($course, $cm) = get_course_and_cm_from_cmid($args['cmid'], 'contentdesigner');
Expand All @@ -304,10 +303,9 @@ function contentdesigner_output_fragment_load_next_chapters($args) {
* Fragment output to load the list of elements to insert.
*
* @param array $args Context and cmid.
* @return string
* @return string|bool
*/
function contentdesigner_output_fragment_edit_element($args) {
global $DB;
$elementid = $args['elementid'];
$instanceid = $args['instanceid'];
$cmid = $args['cmid'];
Expand All @@ -325,8 +323,6 @@ function contentdesigner_output_fragment_edit_element($args) {
* @return string
*/
function contentdesigner_output_fragment_move_element($args) {
global $OUTPUT;

if (isset($args['context']) && !empty($args['chapterid'])) {
$editor = editor::get_editor($args['cmid']);
if ($editor->chapter->update_postion($args['chapterid'], $args['contents'])) {
Expand Down Expand Up @@ -400,8 +396,8 @@ function mod_contentdesigner_inplace_editable($itemtype, $itemid, $itemvalue) {

return new \core\output\inplace_editable(
'mod_contentdesigner', $itemtype, $element->elementid.$record->id, true,
format_string($record->title), $record->title, 'Edit instance title',
'New value for ' . format_string($record->title)
format_string($record->title), $record->title, get_string('titleeditable', 'mod_contentdesigner'),
get_string('newvalue', 'mod_contentdesigner') . format_string($record->title)
);
}
}
Expand Down

0 comments on commit bc91e21

Please sign in to comment.