Skip to content

Commit

Permalink
Merge pull request #3 from andreasschenkel/develop
Browse files Browse the repository at this point in the history
v1.0.3
  • Loading branch information
andreasschenkel authored Dec 3, 2021
2 parents a056d5c + f195bec commit 407d539
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 88 deletions.
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ Plugin that helps to generate an xml-file to import into activity feedback to su
![image](https://user-images.githubusercontent.com/31856043/144513664-fed4377f-1517-44a4-a020-16094002a874.png)


TODO Provide more detailed description here.

## Changelog ##
[[v1.0.3]]

03.12.2021

- check that length of options is less than maxoptions
- some layoutchanges
- optimize implementation of reseting input
- added missing languagestrings


[[v1.0.2]]

Expand Down
25 changes: 4 additions & 21 deletions classes/Security/Security.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,20 @@ public function __construct(moodle_database $dbM)
$this->dbM = $dbM;
}

/**
* @param int $courseId
* @param stdClass $user
* @return bool
*/
public function allowedToViewDeleteAllFiles($courseId, $user): bool
{
$coursecontext = context_course::instance($courseId);
// here you can change the roles or capabilities of who can view and delete the orphaned files
return is_enrolled($coursecontext, $user, 'moodle/course:manageactivities') || is_siteadmin();
}

/**
* @throws coding_exception
* @throws moodle_exception
* @throws require_login_exception
* @todo userIsAllowedToViewTheCourse is not the correct name of this function
* because alsocapabilitiy to view report is checked. to do: refactoring
*/
public function userIsAllowedToViewTheCourse($courseId)
public function userIsAllowedToViewTheCourseAndHasCapabilityToUseGenerator($courseId)
{
$params = ['id' => $courseId];
/**
* @todo check this code if it works correct????
*/
$course = $this->dbM->get_record('course', $params, '*', MUST_EXIST);
// validate if the user is allowed to view this course
require_login($course);

/**
* @todo userIsAllowedToViewTheCourse is not the correct name of this function.
*/
$coursecontext = context_course::instance($courseId);
require_capability('report/feedbackchoicegenerator:view', $coursecontext);
}
Expand Down
28 changes: 9 additions & 19 deletions classes/View/FeedbackChoiceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,39 +67,30 @@ public function getPage(): Page
public function init()
{
global $CFG;
$maxlength = $CFG->report_feedbackchoicegenerator_maxlength;
$maxoptionslength = $CFG->report_feedbackchoicegenerator_maxoptionslength;
$maxlength = (int)$CFG->report_feedbackchoicegenerator_maxlength;
$maxoptionslength = (int)$CFG->report_feedbackchoicegenerator_maxoptionslength;

// validate if the user is logged in and allowed to view the course
// this method throws an exception if the user is not allowed
$this->apiM->security()->userIsAllowedToViewTheCourse($this->courseId);
$this->apiM->security()->userIsAllowedToViewTheCourseAndHasCapabilityToUseGenerator($this->courseId);

echo $this->getPage()->getOutput()->header();

/**
* todo type int casten
*/
$size = trim($_POST["size"]);
if ($size != '') {

$size = (is_numeric($_POST['size']) ? (int)$_POST['size'] : 2);
if ($size > $maxlength) {
$size = $maxlength;
}
}

if ($size === '') {
$size = 2;
}


/**
* todo 'optionvalue' => $option_i auf maxoptionslength reduzieren
*/
$filename = '';
for ($i = 1; $i <= (int)$size; $i++) {
$option_i = trim($_POST["option$i"]); //bisherige werte auslesen trim($_POST["size"])
$option_i = trim($_POST["option$i"]);
// cut option_i if it is to long
$option_i = substr($option_i , 0, $maxoptionslength);
$options[] = array(
'optionnumber' => $i,
'optionlable' => "Option $i",
'optionlabel' => "Option $i",
'optionname' => "option$i",
'optionvalue' => $option_i
);
Expand Down Expand Up @@ -144,7 +135,6 @@ public function init()
*/
public function textareagenerator($optionsArray): string
{

// define the itemnumber to start with (maybe later I will set it to 1 instead of 367)
$itemnumber = 367;

Expand Down
3 changes: 1 addition & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

/*
* @todo Assign global variables to local (parameter) variables.
* At the moment, this approach is used for documentation
* purposes.
* At the moment, this approach is used for documentation purposes.
*/

$courseId = required_param('id', PARAM_INT);
Expand Down
17 changes: 10 additions & 7 deletions lang/de/report_feedbackchoicegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,27 @@

$string['feedbackchoicegenerator:view'] = '1./2. Wahl Feedback-Generator anzeigen';

$string['isactive'] = 'Bericht aktivieren';
$string['configisactive'] = 'Wenn aktiviert kann der Bericht bei vorhandenen Berechtigungen im der Kursnavigation aufgerufen werden.';
$string['isactive'] = 'Generator aktivieren';
$string['configisactive'] = 'Wenn aktiviert kann der Generator bei vorhandenen Berechtigungen im der Kursnavigation aufgerufen werden.';

$string['maxlength'] = 'Max. Länge der Optionen';
$string['configmaxlength'] = 'Bis zu dieser Länge kann der Text einer Option eingegeben werden.';
$string['maxoptionslength'] = 'Max. Länge der Optionen';
$string['configmaxoptionslength'] = 'Bis zu dieser Länge kann der Text einer Option eingegeben werden.';

$string['maxlength'] = 'Max. Anzahl der Optionen';
$string['configmaxlength'] = 'Maximale Anzahl an Optionen, die man anbieten kann.';

$string['firstchoicelabel'] = '1. Wahl';
$string['secondchoicelabel'] = '2. Wahl';

$string['header3'] = '1. Wahl und 2. Wahl';
$string['summary'] = 'Ein Generator für die Aktivität Feedback';
$string['summary'] = 'Ein Generator für die Aktivität Feedback, um eine 1. und 2. Wahl umzusetzen.';

$string['courseidlabel'] = 'Kursid';
$string['sizelabel'] = 'Anzahl der Optionen';

$string['optionsheader'] = 'Eingabebereich der Optionen:';

$string['description'] = 'Den hier erzeugten xml-Code in einer Textdatei kopieren und mit der Endung .xml speichern.
Erste Zeile muss identisch zu dieser Zeile aussehen: <\?xml version=\"1.0\" encoding=\"UTF-8\" ?>';
$string['description'] = 'Den hier erzeugten xml-Code mit Hilfe des Download-Buttons herunterladen (rechte Maustaste nutzen und Speichern unter wählen).
Alternativ den xml-Code in einer Textdatei kopieren und mit der Endung .xml speichern.';

$string['buttonlabel'] = 'XML erzeugen oder aktualisieren';
11 changes: 7 additions & 4 deletions lang/en/report_feedbackchoicegenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@

$string['feedbackchoicegenerator:view'] = 'see 1.2-choice feedback-generator';

$string['isactive'] = 'Activate report';
$string['configisactive'] = 'When activate the report can be started in the coursenavigation.';
$string['isactive'] = 'Activate generator';
$string['configisactive'] = 'When activate the generator can be started in the coursenavigation.';

$string['maxlength'] = 'maximum text length of an option';
$string['configmaxlength'] = 'Up to this length a user can enter text as an option.';
$string['maxoptionslength'] = 'maximum text length of an option';
$string['configmaxoptionslength'] = 'Up to this length a user can enter text as an option.';

$string['maxlength'] = 'max. count of options';
$string['configmaxlength'] = 'Up to how many options can be used.';

$string['firstchoicelabel'] = '1. choice';
$string['secondchoicelabel'] = '2. choice';
Expand Down
8 changes: 0 additions & 8 deletions reset.php

This file was deleted.

44 changes: 21 additions & 23 deletions templates/reportgenerator.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,37 @@
<?php session_start(); ?>

<h3>{{header3}}</h3>
<div>{{summary}}</div><br>
<div class="form-row mb-2">
{{summary}}
</div>

<form action="index.php?id={{courseid}}" method="post">
<input name='courseid' type='hidden' value='{{courseid}}' disabled>

<form action="index.php?id={{courseid}}" method="post">
<div class="form-row mb-2">
{{courseidlabel}}: <input name='courseid' type='number' value='{{courseid}}' disabled>
<b>{{optionsheader}} (maxoptionslength {{maxoptionslength}})</b><br>
</div>

<div class="form-row mb-2">
{{sizelabel}}: <input name='size' type='number' value='{{size}}' max='{{maxlength}}'> (max. {{maxlength}})
{{sizelabel}}:&nbsp;<input name='size' type='number' value='{{size}}' max='{{maxlength}}' size='5'> (max. {{maxlength}})
</div>

<b>{{optionsheader}} (maxoptionslength {{maxoptionslength}})</b><br>

{{#options}}
{{{optionlabel}}}:&nbsp;<input name='{{{optionname}}}' value='{{{optionvalue}}}' maxlength='{{maxoptionslength}}'><br>
{{/options}}

{{#options}}
{{{optionlable}}}: <input name='{{{optionname}}}' value='{{{optionvalue}}}' maxlength='{{maxoptionslength}}'><br>
{{/options}}
<br>
<div class="form-row mb-2">
<button id='input_feedbackchoicegenerator' class='btn btn-primary' type='submit'>{{buttonlabel}}</button>
<a class='btn btn-warning' href='{{dataurl}}' type='application/xml'>Download (rechte Maustaste speichern unter)</a>
<a class='btn btn-danger' href='index.php?id={{courseid}}'>Session zurücksetzen</a>
</div>

<br>
<div class="form-row mb-2">
<button id='input_feedbackchoicegenerator' class='btn btn-primary' type='submit'>{{buttonlabel}}</button>
</div>
</form>

<div class="form-row mb-2">
<a class='btn btn-warning' href='{{dataurl}}' type='application/xml'>Download (rechte Maustaste speichern unter)</a>
</div>


<div class="form-row mb-2">
<a class='btn btn-danger' href='reset.php'>Session zurücksetzen</a>
</div>


{{description}}<br>
{{description}}
</div>

<textarea id="textarea_feedbackchoicegenerator" name="textarea_feedbackchoicegenerator" rows="20" cols="100" readonly >
{{textareacontent}}
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
defined('MOODLE_INTERNAL') || die();

$plugin->component = 'report_feedbackchoicegenerator';
$plugin->release = '1.0.1';
$plugin->version = 2021112401;
$plugin->release = '1.0.3';
$plugin->version = 2021120301;
$plugin->requires = 2020061500;
$plugin->maturity = MATURITY_RC;

0 comments on commit 407d539

Please sign in to comment.