diff --git a/README.md b/README.md
index 9cc4ffe..7cdc277 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Report #
+# Local #
Plugin that helps to generate an xml-file to import into activity feedback to support first and second choise feedback.
@@ -7,32 +7,37 @@ 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)
## Changelog ##
-[[v1.0.4]]
-03.12.2021
+[[v2.0.0]]
-- codebeautyfing
+- 12.12.2021 to support moodle styleguide use code checker to find codebeautyfing issues
+- 20.12.2021 add privacy provider implementation to inform that no private date is stored
+- 29.12.2021 transfer code from plugintype report to local
+- 30.12.2021 settings-problem solved
-[[v1.0.3]]
+[[v1.0.5]]
+unknown
-03.12.2021
+[[v1.0.4]]
-- check that length of options is less than maxoptions
-- some layoutchanges
-- optimize implementation of reseting input
-- added missing languagestrings
+- 03.12.2021 codebeautyfing
+[[v1.0.3]]
+
+- 03.12.2021 check that length of options is less than maxoptions
+- 03.12.2021 some layoutchanges
+- 03.12.2021 optimize implementation of reseting input
+- 03.12.2021 added missing languagestrings
-[[v1.0.2]]
-02.12.2021
+[[v1.0.2]]
-- use dataurl to be able to download xml-file
-- max length of option configurable
-- set capability für role editingteacher instead of teacher
-- check, if user has capability to view report also by checking the capapility
-- do not prevent capability for student
-- added missing languagestring feedbackchoicegenerator:view
+- 02.12.2021 use dataurl to be able to download xml-file
+- 02.12.2021 max length of option configurable
+- 02.12.2021 set capability für role editingteacher instead of teacher
+- 02.12.2021 check, if user has capability to view report also by checking the capapility
+- 02.12.2021 do not prevent capability for student
+- 02.12.2021 added missing languagestring feedbackchoicegenerator:view
[[v1.0.1]] beta
@@ -56,7 +61,7 @@ Plugin that helps to generate an xml-file to import into activity feedback to su
The plugin can be also installed by putting the contents of this directory to
- {your/moodle/dirroot}/report/feedbackchoicegenerator
+ {your/moodle/dirroot}/local/feedbackchoicegenerator
Afterwards, log in to your Moodle site as an admin and go to _Site administration >
Notifications_ to complete the installation.
diff --git a/classes/Database/DataFiles.php b/classes/Database/DataFiles.php
index eff6c4f..8079d61 100644
--- a/classes/Database/DataFiles.php
+++ b/classes/Database/DataFiles.php
@@ -1,6 +1,21 @@
.
+namespace local_feedbackchoicegenerator\Database;
+defined('MOODLE_INTERNAL') || die();
use moodle_database;
/**
@@ -15,50 +30,41 @@ class DataFiles
* @var moodle_database The database connection an instance of this class
* operates on.
*/
- private $dbM;
+ private $dbm;
/**
* Creates a new instance which is bound to a database using the given
* database connection.
- *
- * @param moodle_database $dbM The database connection to be used by this
+ * @param moodle_database $dbm The database connection to be used by this
* instance.
*/
- public function __construct(moodle_database $dbM)
- {
- $this->dbM = $dbM;
+ public function __construct(moodle_database $dbm) {
+ $this->dbm = $dbm;
}
/**
* Returns the database connection used by the instance.
- *
* @return moodle_database The database instance.
*/
- public function getDatabase(): moodle_database
- {
- return $this->dbM;
+ public function get_database(): moodle_database {
+ return $this->dbm;
}
/**
* Queries created by this class are based on SELECT statements. The Moodle
* database subsystem provides functionality for statement construction, i.e.
* a mechanism that substitutes variables in strings with concrete values.
- *
* This method creates strings that follow this pattern. For each variable
* name in the parameter array, a corresponding entry in the result array is
* created, consisting of the variable's name (SQL world) and its substitution
* position (Moodle world), i.e. the name prefixed with „:“.
- *
* Example: „userid“ ---> „userid = :userid“
- *
* @param array $elements The array of strings which should be interpreted as
* variable names.
- *
* @return array An array of strings conforming to the described structural
- * pattern.
+ * pattern.
*/
- protected function createWhereString(array $elements): array
- {
+ protected function create_where_string(array $elements): array {
return array_map(function ($element) {
return $element . " = :" . $element;
}, $elements);
@@ -68,41 +74,33 @@ protected function createWhereString(array $elements): array
* Prepares the statement to be emitted to the database layer of the Moodle
* system. Given parameters are combined using AND, forming the final
* WHERE clause.
- *
* @param array $params An array whose keys should be used as components of the
* WHERE clause for a SELECT statement.
- *
* @return string A valid SQL statement ready to be used with the Moodle database
* subsystem.
*/
- protected function prepareStatement(array $params): string
- {
- $where = implode(" AND ", $this->createWhereString(array_keys($params)));
+ protected function prepare_statement(array $params): string {
+ $where = implode(" AND ", $this->create_where_string(array_keys($params)));
return "SELECT * FROM {files} WHERE {$where}";
}
- /**
+ /**
* Performs a query using the keys and values of the parameter array as part
* of the command's WHERE clause.
- *
* @param array $params An array whose keys should be used as components of the
* WHERE clause for the SELECT statement.
- *
* @return array An array containing the results of the performed query.
*/
- protected function performQuery(array $params): array
- {
- return $this->getDatabase()->get_records_sql($this->prepareStatement($params), $params);
+ protected function perform_query(array $params): array {
+ return $this->get_database()->get_records_sql($this->prepare_statement($params), $params);
}
- public function getCourse($courseId)
- {
- return $this->getDatabase()->get_record('course', ['id' => $courseId], '*', MUST_EXIST);
+ public function get_course($courseid) {
+ return $this->get_database()->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
}
- public function getPage($instance)
- {
- return $this->getDatabase()->get_record('page', ['id' => $instance->instance], '*');
+ public function get_page($instance) {
+ return $this->get_database()->get_record('page', ['id' => $instance->instance], '*');
}
}
diff --git a/classes/Database/Factory.php b/classes/Database/Factory.php
index c85ae45..a760aaf 100644
--- a/classes/Database/Factory.php
+++ b/classes/Database/Factory.php
@@ -1,7 +1,21 @@
.
-namespace report_feedbackchoicegenerator\Database;
-
+namespace local_feedbackchoicegenerator\Database;
+defined('MOODLE_INTERNAL') || die;
use moodle_database;
/**
@@ -13,43 +27,36 @@ class Factory
{
/**
* The database connection used by the factory.
- *
* @var moodle_database
*/
- private $dbM;
+ private $dbm;
/**
* Creates a new factory using the given database connection to
* access the necessary information.
- *
- * @param moodle_database $dbM The database connection to be used.
+ * @param moodle_database $dbm The database connection to be used.
*/
- public function __construct(moodle_database $dbM)
- {
- $this->dbM = $dbM;
+ public function __construct(moodle_database $dbm) {
+ $this->dbm = $dbm;
}
/**
* Returns an instance of DataFiles, i.e. an abstraction for accessing
* relevant database information based on the factory's connection
* object.
- *
* @return DataFiles An abstraction providing a high-level view for the
* file storage information managed by Moodle.
*/
- public function dataFiles(): DataFiles
- {
- return new DataFiles($this->getDbM());
+ public function data_files(): DataFiles {
+ return new DataFiles($this->get_dbm());
}
/**
- * Returns the database connection this factory uses when constructing
+ * Returns the database connection this factory uses when constructing
* DataFiles instances.
- *
* @return moodle_database The factory's database connection object.
*/
- public function getDbM(): moodle_database
- {
- return $this->dbM;
+ public function get_dbm(): moodle_database {
+ return $this->dbm;
}
}
diff --git a/classes/Helper.php b/classes/Helper.php
index d2662f4..33802f5 100644
--- a/classes/Helper.php
+++ b/classes/Helper.php
@@ -1,144 +1,155 @@
.
+namespace local_feedbackchoicegenerator;
+defined('MOODLE_INTERNAL') || die;
use html_writer;
-class Helper
+class Helper
{
+ /**
+ * generates the options seperated by |
+ * @return string with all options without the $selectedoption
+ */
+ public static function generate_options_list($options, $selectedoption) {
+ $htmloutput = '';
+ $counter = 0;
+ foreach ($options as $option) {
+ if ($option != $selectedoption) {
+ if ($counter != 0) {
+ $htmloutput = $htmloutput . "|";
+ }
+ $counter++;
+ $htmloutput = $htmloutput . $option . "\n";
+ }
+ }
+ return $htmloutput;
+ }
- /**
- * generates the options seperated by |
- * @return string with all options without the $selectedoption
- */
- static function generateOptionsList($options, $selectedoption)
- {
- $htmloutput = '';
- $counter = 0;
- foreach ($options as $option) {
- if ($option != $selectedoption) {
- if ($counter != 0) {
- $htmloutput = $htmloutput . "|";
- }
- $counter++;
- $htmloutput = $htmloutput . $option . "\n";
- }
- }
- return $htmloutput;
- }
+ /**
+ * generates nessesary lines at the beginning of the file
+ * @return string
+ */
+ public static function generate_document_header_openinglines() {
+ $output = "\n";
+ $output = $output . html_writer::start_tag('FEEDBACK',
+ array('VERSION' => '200701', 'COMMENT' => 'XML-Importfile for mod/feedback')) . "\n";
+ $output = $output . html_writer::start_tag('ITEMS') . "\n";
+ return $output;
+ }
- /**
- * generates nessesary lines at the beginning of the file
- * @return string
- */
- static function generateDocumentHeaderOpeninglines()
- {
- $output = "\n";
- $output = $output . html_writer::start_tag('FEEDBACK', array('VERSION' => '200701', 'COMMENT' => 'XML-Importfile for mod/feedback')) . "\n";
- $output = $output . html_writer::start_tag('ITEMS') . "\n";
- return $output;
- }
+ /**
+ * generates nessesary lines at the end of the file to close the opened tags
+ * @return string
+ */
+ public static function generate_document_last_lines() {
+ $output = "";
+ $output = $output . html_writer::end_tag('ITEMS') . "\n";
+ $output = $output . html_writer::end_tag('FEEDBACK') . "\n";
+ return $output;
+ }
- /**
- * generates nessesary lines at the end of the file to close the opened tags
- * @return string
- */
- static function generateDocumentLastlines()
- {
- $output = "";
- $output = $output . html_writer::end_tag('ITEMS') . "\n";
- $output = $output . html_writer::end_tag('FEEDBACK') . "\n";
- return $output;
- }
+ /**
+ * generates the header that can be found in all xml-files for feedback
+ * @param int $itemnumber The number of the actual xml-component to be generated
+ * @return string
+ */
+ public static function generate_document_header($itemnumber) {
+ $output = "";
+ $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'info', 'REQUIRED' => '0')) . "\n";
+ $output = $output . html_writer::tag('ITEMID', "") . "\n";
+ $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
+ $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
+ $output = $output . html_writer::tag('PRESENTATION', "") . "\n";
+ $output = $output . html_writer::tag('OPTIONS', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
+ $output = $output . html_writer::end_tag('ITEM') . "\n";
+ return $output;
+ }
- /**
- * generates the header that can be found in all xml-files for feedback
- * @param int $itemnumber The number of the actual xml-component to be generated
- * @return string
- */
- static function generateDocumentHeader($itemnumber)
- {
- $output = "";
- $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'info', 'REQUIRED' => '0')) . "\n";
- $output = $output . html_writer::tag('ITEMID', "") . "\n";
- $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
- $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
- $output = $output . html_writer::tag('PRESENTATION', "") . "\n";
- $output = $output . html_writer::tag('OPTIONS', "") . "\n";
- $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
- $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
- $output = $output . html_writer::end_tag('ITEM') . "\n";
- return $output;
- }
+ /**
+ * generates the pagebrakes to seperate the different options
+ * @param int $itemnumber The number of the actual xml-component to be generated
+ */
+ public static function generate_pagebreak($itemnumber) {
+ $output = "";
+ $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'pagebreak', 'REQUIRED' => '0')) . "\n";
+ $output = $output . html_writer::tag('ITEMID', "") . "\n";
+ $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
+ $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
+ $output = $output . html_writer::tag('PRESENTATION', "") . "\n";
+ $output = $output . html_writer::tag('OPTIONS', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
+ $output = $output . html_writer::end_tag('ITEM') . "\n";
+ return $output;
+ }
- /**
- * generates the pagebrakes to seperate the different options
- * @param int $itemnumber The number of the actual xml-component to be generated
- */
- static function generatePagebreak($itemnumber)
- {
- $output = "";
- $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'pagebreak', 'REQUIRED' => '0')) . "\n";
- $output = $output . html_writer::tag('ITEMID', "") . "\n";
- $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
- $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
- $output = $output . html_writer::tag('PRESENTATION', "") . "\n";
- $output = $output . html_writer::tag('OPTIONS', "") . "\n";
- $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
- $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
- $output = $output . html_writer::end_tag('ITEM') . "\n";
- return $output;
- }
-
- /**
- * generates the list of options for first or second choice
- * @param integer $level indicates if first choice oder second choise
- * @param int $itemnumber The number of the actual xml-component to be generated
- * @param int $firstchoicereferencenumber Number for to reference to in the second second choice
- * @param string $allOptionsToAdd
- * @param string $option DEPENDVALUE
- */
- static function generateSelectionOverview($level, $itemnumber, $firstchoicereferencenumber, $allOptionsToAdd, $option)
- {
- $selectlabel = get_string('selectlabel', 'report_feedbackchoicegenerator');
- if ($level === 1) {
- $choicelabel = get_string('firstchoicelabel', 'report_feedbackchoicegenerator');
- $firstchoicereferencenumber = 0;
- } else {
- $choicelabel = get_string('secondchoicelabel', 'report_feedbackchoicegenerator');;
- }
- $output = "";
- $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'multichoice', 'REQUIRED' => '0')) . "\n";
- $output = $output . html_writer::tag('ITEMID', "") . "\n";
- $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
- $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
- $output = $output . html_writer::tag('PRESENTATION', ">>>>$allOptionsToAdd]]>") . "\n";
- $output = $output . html_writer::tag('OPTIONS', "") . "\n";
- $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
- $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
- $output = $output . html_writer::end_tag('ITEM') . "\n";
- return $output;
- }
-
- /**
- * generates the xml-code for the label
- * @param $xmlWriterPlus
- * @param int $itemnumber The number of the actual xml-component to be generated
- * @param int $firstchoicereferencenumber Number for to reference to in the second second choice
- * @param string $option DEPENDVALUE
- */
- static function generateLabel($itemnumber, $firstchoicereferencenumber, $option)
- {
- $output = "";
- $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'label', 'REQUIRED' => '0')) . "\n";
- $output = $output . html_writer::tag('ITEMID', "") . "\n";
- $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
- $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
- $output = $output . html_writer::tag('PRESENTATION', "") . "\n";
- $output = $output . html_writer::tag('OPTIONS', "") . "\n";
- $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
- $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
- $output = $output . html_writer::end_tag('ITEM') . "\n";
- return $output;
- }
+ /**
+ * generates the list of options for first or second choice
+ * @param integer $level indicates if first choice oder second choise
+ * @param int $itemnumber The number of the actual xml-component to be generated
+ * @param int $firstchoicereferencenumber Number for to reference to in the second second choice
+ * @param string $alloptionstoadd
+ * @param string $option DEPENDVALUE
+ */
+ public static function generate_selection_overview($level,
+ $itemnumber,
+ $firstchoicereferencenumber,
+ $alloptionstoadd, $option) {
+ $selectlabel = get_string('selectlabel', 'local_feedbackchoicegenerator');
+ if ($level === 1) {
+ $choicelabel = get_string('firstchoicelabel', 'local_feedbackchoicegenerator');
+ $firstchoicereferencenumber = 0;
+ } else {
+ $choicelabel = get_string('secondchoicelabel', 'local_feedbackchoicegenerator');;
+ }
+ $output = "";
+ $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'multichoice', 'REQUIRED' => '0')) . "\n";
+ $output = $output . html_writer::tag('ITEMID', "") . "\n";
+ $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
+ $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
+ $output = $output . html_writer::tag('PRESENTATION', ">>>>$alloptionstoadd]]>") . "\n";
+ $output = $output . html_writer::tag('OPTIONS', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
+ $output = $output . html_writer::end_tag('ITEM') . "\n";
+ return $output;
+ }
+ /**
+ * generates the xml-code for the label
+ * @param $xmlWriterPlus
+ * @param int $itemnumber The number of the actual xml-component to be generated
+ * @param int $firstchoicereferencenumber Number for to reference to in the second second choice
+ * @param string $option DEPENDVALUE
+ */
+ public static function generate_label($itemnumber, $firstchoicereferencenumber, $option) {
+ $output = "";
+ $output = $output . html_writer::start_tag('ITEM', array('TYPE' => 'label', 'REQUIRED' => '0')) . "\n";
+ $output = $output . html_writer::tag('ITEMID', "") . "\n";
+ $output = $output . html_writer::tag('ITEMTEXT', "") . "\n";
+ $output = $output . html_writer::tag('ITEMLABEL', "") . "\n";
+ $output = $output . html_writer::tag('PRESENTATION',
+ "") . "\n";
+ $output = $output . html_writer::tag('OPTIONS', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDITEM', "") . "\n";
+ $output = $output . html_writer::tag('DEPENDVALUE', "") . "\n";
+ $output = $output . html_writer::end_tag('ITEM') . "\n";
+ return $output;
+ }
}
diff --git a/classes/Manager.php b/classes/Manager.php
index 73ec15e..b198203 100644
--- a/classes/Manager.php
+++ b/classes/Manager.php
@@ -1,10 +1,24 @@
.
+
+namespace local_feedbackchoicegenerator;
+defined('MOODLE_INTERNAL') || die;
use moodle_database;
-
-use report_feedbackchoicegenerator\Database\Factory as DatabaseFactory;
-use report_feedbackchoicegenerator\Security\Security;
+use local_feedbackchoicegenerator\Database\Factory as DatabaseFactory;
+use local_feedbackchoicegenerator\Security\Security;
defined('MOODLE_INTERNAL') || die();
@@ -16,31 +30,27 @@ class Manager
/**
* @var moodle_database
*/
- private $dbM;
+ private $dbm;
/**
* Manager constructor.
- * @param moodle_database $dbM
+ * @param moodle_database $dbm
*/
- public function __construct(moodle_database $dbM)
- {
- $this->dbM = $dbM;
+ public function __construct(moodle_database $dbm) {
+ $this->dbm = $dbm;
}
/**
* @return DatabaseFactory
*/
- public function database(): DatabaseFactory
- {
- return new DatabaseFactory($this->dbM);
+ public function database(): DatabaseFactory {
+ return new DatabaseFactory($this->dbm);
}
/**
* @return Security
*/
- public function security(): Security
- {
- return new Security($this->dbM);
+ public function security(): Security {
+ return new Security($this->dbm);
}
-
}
diff --git a/classes/Security/Security.php b/classes/Security/Security.php
index 7928916..04c75d7 100644
--- a/classes/Security/Security.php
+++ b/classes/Security/Security.php
@@ -1,7 +1,21 @@
.
-namespace report_feedbackchoicegenerator\Security;
-
+namespace local_feedbackchoicegenerator\Security;
+defined('MOODLE_INTERNAL') || die;
use coding_exception;
use context_course;
use moodle_database;
@@ -17,15 +31,14 @@ class Security
/**
* @var moodle_database
*/
- private $dbM;
+ private $dbm;
/**
* Security constructor.
- * @param moodle_database $dbM
+ * @param moodle_database $dbm
*/
- public function __construct(moodle_database $dbM)
- {
- $this->dbM = $dbM;
+ public function __construct(moodle_database $dbm) {
+ $this->dbm = $dbm;
}
/**
@@ -33,16 +46,14 @@ public function __construct(moodle_database $dbM)
* @throws moodle_exception
* @throws require_login_exception
*/
- public function userIsAllowedToViewTheCourseAndHasCapabilityToUseGenerator($courseId)
- {
- $params = ['id' => $courseId];
- /**
- * @todo check this code if it works correct????
- */
- $course = $this->dbM->get_record('course', $params, '*', MUST_EXIST);
+ public function user_is_allowed_to_view_the_course_and_has_capability_to_use_generator($courseid) {
+ $params = ['id' => $courseid];
+
+ // Check this code if it works correct????
+ $course = $this->dbm->get_record('course', $params, '*', MUST_EXIST);
require_login($course);
- $coursecontext = context_course::instance($courseId);
- require_capability('report/feedbackchoicegenerator:view', $coursecontext);
+ $coursecontext = context_course::instance($courseid);
+ require_capability('local/feedbackchoicegenerator:view', $coursecontext);
}
}
diff --git a/classes/View/FeedbackChoiceGenerator.php b/classes/View/FeedbackChoiceGenerator.php
index db72d6b..4541f30 100644
--- a/classes/View/FeedbackChoiceGenerator.php
+++ b/classes/View/FeedbackChoiceGenerator.php
@@ -1,12 +1,26 @@
.
+
+namespace local_feedbackchoicegenerator\View;
use stdClass;
use moodle_database;
-use report_feedbackchoicegenerator\Helper;
-use report_feedbackchoicegenerator\Manager;
+use local_feedbackchoicegenerator\Helper;
+use local_feedbackchoicegenerator\Manager;
/**
* Class FeedbackChoiceGenerator
@@ -22,44 +36,35 @@ class FeedbackChoiceGenerator
/**
* @var int
*/
- private $courseId;
+ private $courseid;
- /**
- * @var stdClass
- */
- private $user;
/**
* @var Manager
*/
- private $apiM;
-
+ private $apim;
/**
* FeedbackChoiceGenerator constructor.
* @param moodle_database $db
- * @param int $courseId
+ * @param int $courseid
* @param moodle_page $page
* @param bootstrap_renderer $output
- * @param stdClass $user
*/
- public function __construct($db, int $courseId, $page, $output, $user)
- {
- $this->courseId = $courseId;
- $this->user = $user;
- $this->apiM = new Manager($db);
+ public function __construct($db, int $courseid, $page, $output) {
+ $this->courseid = $courseid;
+ $this->apim = new Manager($db);
- $course = $this->apiM->database()->dataFiles()->getCourse($courseId);
+ $course = $this->apim->database()->data_files()->get_course($courseid);
- $this->page = new Page($page, $course, $courseId, $output);
+ $this->page = new Page($page, $course, $courseid, $output);
}
/**
* getter for Page
* @return Page
*/
- public function getPage(): Page
- {
+ public function get_page(): Page {
return $this->page;
}
@@ -69,20 +74,26 @@ public function getPage(): Page
* @throws moodle_exception
* @throws require_login_exception
*/
- public function init()
- {
+ public function init() {
global $CFG;
- $maxlength = (int)$CFG->report_feedbackchoicegenerator_maxlength;
- $maxoptionslength = (int)$CFG->report_feedbackchoicegenerator_maxoptionslength;
+ $maxlength = (int)$CFG->local_feedbackchoicegenerator_maxlength;
+ $maxoptionslength = (int)$CFG->local_feedbackchoicegenerator_maxoptionslength;
- $this->apiM->security()->userIsAllowedToViewTheCourseAndHasCapabilityToUseGenerator($this->courseId);
+ $this->apim->security()->user_is_allowed_to_view_the_course_and_has_capability_to_use_generator($this->courseid);
- echo $this->getPage()->getOutput()->header();
-
- $size = (is_numeric($_POST['size']) ? (int)$_POST['size'] : 2);
- if ($size > $maxlength) {
- $size = $maxlength;
- }
+ echo $this->get_page()->get_output()->header();
+
+ if (isset($_POST['size'])) {
+ $size = (is_numeric($_POST['size']) ? (int)$_POST['size'] : 2);
+ } else {
+ $size = 3;
+ }
+
+
+
+ if ($size > $maxlength) {
+ $size = $maxlength;
+ }
if ($size === '') {
$size = 2;
@@ -90,101 +101,109 @@ public function init()
$filename = '';
for ($i = 1; $i <= (int)$size; $i++) {
- $option_i = trim($_POST["option$i"]);
- // cut option_i if it is to long
- $option_i = substr($option_i , 0, $maxoptionslength);
+ if (isset($_POST["option$i"])) {
+ $optioncounter = trim($_POST["option$i"]);
+ } else {
+ $optioncounter = '';
+ }
+
+ // Cut optioncounter if it is to long.
+ $optioncounter = substr($optioncounter , 0, $maxoptionslength);
$options[] = array(
'optionnumber' => $i,
'optionlabel' => "Option $i",
'optionname' => "option$i",
- 'optionvalue' => $option_i
+ 'optionvalue' => $optioncounter
);
- $optionsArray[$i] = "$option_i";
+ $optionsarray[$i] = "$optioncounter";
}
- $textareacontent = $this->textareagenerator($optionsArray);
+ $textareacontent = $this->textareagenerator($optionsarray);
$dataurl = 'data:application/xml;charset=UTF-8;utf8,' . $textareacontent;
- echo $this->getPage()->getOutput()->render_from_template(
- 'report_feedbackchoicegenerator/reportgenerator',
+ echo $this->get_page()->get_output()->render_from_template(
+ 'local_feedbackchoicegenerator/mainpage',
[
- 'courseid' => $this->courseId,
- 'title' => $this->getPage()->getTitle(),
- 'header3' => get_string('header3', 'report_feedbackchoicegenerator'),
- 'summary' => get_string('summary', 'report_feedbackchoicegenerator'),
+ 'courseid' => $this->courseid,
+ 'title' => $this->get_page()->get_title(),
+ 'header3' => get_string('header3', 'local_feedbackchoicegenerator'),
+ 'summary' => get_string('summary', 'local_feedbackchoicegenerator'),
- 'courseidlabel' => get_string('courseidlabel', 'report_feedbackchoicegenerator'),
- 'sizelabel' => get_string('sizelabel', 'report_feedbackchoicegenerator'),
+ 'courseidlabel' => get_string('courseidlabel', 'local_feedbackchoicegenerator'),
+ 'sizelabel' => get_string('sizelabel', 'local_feedbackchoicegenerator'),
'maxlength' => $maxlength,
- 'optionsheader' => get_string('optionsheader', 'report_feedbackchoicegenerator'),
- 'description' => get_string('description', 'report_feedbackchoicegenerator'),
+ 'optionsheader' => get_string('optionsheader', 'local_feedbackchoicegenerator'),
+ 'description' => get_string('description', 'local_feedbackchoicegenerator'),
'size' => $size,
'filename' => $filename,
'options' => $options,
'maxoptionslength' => $maxoptionslength,
'textareacontent' => $textareacontent,
- 'buttonlabel' => get_string('buttonlabel', 'report_feedbackchoicegenerator'),
- 'downloadbuttonlabel' => get_string('downloadbuttonlabel', 'report_feedbackchoicegenerator'),
- 'resetbuttonlabel' => get_string('resetbuttonlabel', 'report_feedbackchoicegenerator'),
+ 'buttonlabel' => get_string('buttonlabel', 'local_feedbackchoicegenerator'),
+ 'downloadbuttonlabel' => get_string('downloadbuttonlabel', 'local_feedbackchoicegenerator'),
+ 'resetbuttonlabel' => get_string('resetbuttonlabel', 'local_feedbackchoicegenerator'),
'dataurl' => $dataurl
]
);
- echo $this->getPage()->getOutput()->footer();
+ echo $this->get_page()->get_output()->footer();
}
/**
* generates the xml-content and returns the content as string
- * @param array $optionsArray Array contains all options
+ * @param array $optionsarray Array contains all options
* @return string xml-code to add into textarea in htmlpage
*/
- public function textareagenerator($optionsArray): string
- {
- // define the itemnumber to start with (maybe later I will set it to 1 instead of 367)
+ public function textareagenerator($optionsarray): string {
+ // Define the itemnumber to start with (maybe later I will set it to 1 instead of 367).
$itemnumber = 367;
- // we need $itemnumberFirstChoice as reference for the second choice
- $itemnumberFirstChoice = $itemnumber + 1;
+ // We need $itemnumberfirstchoice as reference for the second choice.
+ $itemnumberfirstchoice = $itemnumber + 1;
- // A. head of document
+ // A. head of document.
$helper = new Helper();
- $textareacontent = $helper->generateDocumentHeaderOpeninglines();
- $textareacontent = $textareacontent . $helper->generateDocumentHeader($itemnumber);
-
- // B. generate first choice
- $selectedoption = "alleOptionenNutzenFürErstwahl"; // bei der erstwahl ist keine auswahl vorhanden, also werden dann einfach alle genutzt
- $level = 1; // first selectionoverview with all options
- // @todo $option has to be set -> use of pattern SOLID
- $textareacontent = $textareacontent . $helper->generateSelectionOverview(
+ $textareacontent = $helper->generate_document_header_openinglines();
+ $textareacontent = $textareacontent . $helper->generate_document_header($itemnumber);
+
+ // B. generate first choice.
+ // Bei der erstwahl ist keine auswahl vorhanden, also werden dann einfach alle genutzt.
+ $selectedoption = "alleOptionenNutzenFürErstwahl";
+ // First selectionoverview with all options is level=1.
+ $level = 1;
+ // ToDo: $option has to be set -> use of pattern SOLID.
+ $option = '';
+ $textareacontent = $textareacontent . $helper->generate_selection_overview(
$level,
++$itemnumber,
- $itemnumberFirstChoice,
- $helper->generateOptionsList($optionsArray, $selectedoption),
+ $itemnumberfirstchoice,
+ $helper->generate_options_list($optionsarray, $selectedoption),
$option
);
- // C. generate pagebreak to seperate first choice
- $textareacontent = $textareacontent . $helper->generatePagebreak(++$itemnumber);
+ // C. generate pagebreak to seperate first choice.
+ $textareacontent = $textareacontent . $helper->generate_pagebreak(++$itemnumber);
- // D. generate second choice
- foreach ($optionsArray as $option) {
- $textareacontent = $textareacontent . $helper->generateLabel(++$itemnumber, $itemnumberFirstChoice, $option);
+ // D. generate second choice.
+ foreach ($optionsarray as $option) {
+ $textareacontent = $textareacontent . $helper->generate_label(++$itemnumber, $itemnumberfirstchoice, $option);
$selectedoption = $option;
- $level = 2; // second selectionoverview
- $textareacontent = $textareacontent . $helper->generateSelectionOverview(
+ // Second selectionoverview is level = 2.
+ $level = 2;
+ $textareacontent = $textareacontent . $helper->generate_selection_overview(
$level,
++$itemnumber,
- $itemnumberFirstChoice,
- $helper->generateOptionsList($optionsArray, $selectedoption),
+ $itemnumberfirstchoice,
+ $helper->generate_options_list($optionsarray, $selectedoption),
$option
);
- $textareacontent = $textareacontent . $helper->generatePagebreak(++$itemnumber);
+ $textareacontent = $textareacontent . $helper->generate_pagebreak(++$itemnumber);
}
- $textareacontent = $textareacontent . $helper->generateDocumentLastlines();
+ $textareacontent = $textareacontent . $helper->generate_document_last_lines();
return $textareacontent;
}
diff --git a/classes/View/Page.php b/classes/View/Page.php
index b1a187f..07ec31f 100644
--- a/classes/View/Page.php
+++ b/classes/View/Page.php
@@ -1,6 +1,21 @@
.
+namespace local_feedbackchoicegenerator\View;
+defined('MOODLE_INTERNAL') || die;
use moodle_url;
class Page
@@ -13,49 +28,42 @@ class Page
/**
* @param moodle_page $page
* @param $course
- * @param int $courseId
+ * @param int $courseid
* @param bootstrap_renderer $output
*/
- public function __construct($page, $course, $courseId, $output)
- {
+ public function __construct($page, $course, $courseid, $output) {
$this->page = $page;
$this->output = $output;
$this->course = $course;
- $this->title = get_string('pluginname', 'report_feedbackchoicegenerator');
+ $this->title = get_string('pluginname', 'local_feedbackchoicegenerator');
- $page->set_url(new moodle_url('/report/feedbackchoicegenerator/index.php', ['id' => $courseId]));
- $page->set_title($this->getTitle());
+ $page->set_url(new moodle_url('/local/feedbackchoicegenerator/index.php', ['id' => $courseid]));
+ $page->set_title($this->get_title());
$page->set_heading($course->fullname);
$page->set_pagelayout('incourse');
}
- public function getOutput()
- {
+ public function get_output() {
return $this->output;
}
- public function getTitle()
- {
+ public function get_title() {
return $this->title;
}
- public function getCourse()
- {
+ public function get_course() {
return $this->course;
}
- public function getCourseInfo()
- {
- return get_fast_modinfo($this->getCourse());
+ public function get_course_info() {
+ return get_fast_modinfo($this->get_course());
}
- protected function getPage()
- {
+ protected function get_page() {
return $this->page;
}
- public function getIconURLlöschen($instance)
- {
- return $this->getPage()->theme->image_url('icon', $instance->modname)->out();
+ public function get_icon_url_löschen($instance) {
+ return $this->get_page()->theme->image_url('icon', $instance->modname)->out();
}
}
diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php
new file mode 100644
index 0000000..e88765b
--- /dev/null
+++ b/classes/privacy/provider.php
@@ -0,0 +1,19 @@
+ [
+ 'local/feedbackchoicegenerator:view' => [
'captype' => 'read',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => [
diff --git a/index.php b/index.php
index 9d5673d..00212e7 100644
--- a/index.php
+++ b/index.php
@@ -1,26 +1,36 @@
.
require_once(__DIR__ . '/../../config.php');
+require_login();
+use local_feedbackchoicegenerator\View\FeedbackChoiceGenerator;
-use report_feedbackchoicegenerator\View\FeedbackChoiceGenerator;
-
-/*
- * @todo Assign global variables to local (parameter) variables.
- * At the moment, this approach is used for documentation purposes.
- */
-
-$courseId = required_param('id', PARAM_INT);
+// Assign global variables to local (parameter) variables.
+// At the moment, this approach is used for documentation purposes.
+$courseid = required_param('id', PARAM_INT);
$page = $PAGE;
$output = $OUTPUT;
-$user = $USER;
$db = $DB;
-$feedbackChoiceGeneratorInstance = new FeedbackChoiceGenerator($db, $courseId, $page, $output, $user);
+$feedbackchoicegeneratorinstance = new FeedbackChoiceGenerator($db, $courseid, $page, $output);
global $CFG;
-$isactive = $CFG->report_feedbackchoicegenerator_isactive;
+$isactive = true;
+// $isactive = $CFG->local_feedbackchoicegenerator_isactive;
if ($isactive) {
- $feedbackChoiceGeneratorInstance->init();
+ $feedbackchoicegeneratorinstance->init();
} else {
echo "is not activ";
}
diff --git a/lang/de/report_feedbackchoicegenerator.php b/lang/de/local_feedbackchoicegenerator.php
similarity index 98%
rename from lang/de/report_feedbackchoicegenerator.php
rename to lang/de/local_feedbackchoicegenerator.php
index 59bcd73..414eba4 100644
--- a/lang/de/report_feedbackchoicegenerator.php
+++ b/lang/de/local_feedbackchoicegenerator.php
@@ -17,7 +17,7 @@
/**
* Plugin strings are defined here.
*
- * @package report_feedbackchoicegenerator
+ * @package local_feedbackchoicegenerator
* @category string
* @copyright Andreas Schenkel
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
diff --git a/lang/en/report_feedbackchoicegenerator.php b/lang/en/local_feedbackchoicegenerator.php
similarity index 97%
rename from lang/en/report_feedbackchoicegenerator.php
rename to lang/en/local_feedbackchoicegenerator.php
index da524c4..7209204 100644
--- a/lang/en/report_feedbackchoicegenerator.php
+++ b/lang/en/local_feedbackchoicegenerator.php
@@ -17,7 +17,7 @@
/**
* Plugin strings are defined here.
*
- * @package report_feedbackchoicegenerator
+ * @package local_feedbackchoicegenerator
* @category string
* @copyright Andreas Schenkel
* @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
diff --git a/lib.php b/lib.php
index 356146e..4e0ce48 100755
--- a/lib.php
+++ b/lib.php
@@ -20,43 +20,37 @@
* This function extends the navigation with the report items
*
* @param navigation_node $navigation The navigation node to extend
- * @param stdClass $course The course to object for the report
+ * @param stdClass $course The course to object for the generator
* @param stdClass $context The context of the course
*/
-function report_feedbackchoicegenerator_extend_navigation_course($navigation, $course, $context)
-{
+function local_feedbackchoicegenerator_extend_navigation_course($navigation, $course, $context) {
global $CFG;
$page = $GLOBALS['PAGE'];
- $url = new moodle_url('/report/feedbackchoicegenerator/index.php', array('id' => $course->id));
+ $url = new moodle_url('/local/feedbackchoicegenerator/index.php', array('id' => $course->id));
- $feedbackchoicegeneratorNode = $page->navigation->find($course->id, navigation_node::TYPE_COURSE);
+ $feedbackchoicegeneratornode = $page->navigation->find($course->id, navigation_node::TYPE_COURSE);
- $collection = $feedbackchoicegeneratorNode->children;
+ $collection = $feedbackchoicegeneratornode->children;
foreach ($collection->getIterator() as $child) {
$key = $child->key;
- break;
+ // position of node before this note
+ if ($key === 'participants') {
+ break;
+ }
}
- if ($CFG->report_feedbackchoicegenerator_isactive == true) {
- $isactive = true;
- } else {
- $isactive = false;
- }
-
- if ($isactive) {
- $node = $feedbackchoicegeneratorNode->create(get_string('pluginname', 'report_feedbackchoicegenerator'), $url, navigation_node::NODETYPE_LEAF, null, 'gradebook', new pix_icon('i/report', 'grades'));
- $feedbackchoicegeneratorNode->add_node($node, $key);
- }
-
- if (has_capability('moodle/feedbackchoicegenerator:view', $context)) {
+ $node = $feedbackchoicegeneratornode->create(get_string('pluginname', 'local_feedbackchoicegenerator'),
+ $url, navigation_node::NODETYPE_LEAF, null, 'feedbackchoicegenerator', new pix_icon('i/report', 'grades'));
+ $feedbackchoicegeneratornode->add_node($node, $key);
+
$navigation->add(
- get_string('pluginname', 'report_feedbackchoicegenerator'),
+ get_string('pluginname', 'local_feedbackchoicegenerator'),
$url,
navigation_node::TYPE_SETTING,
null,
null,
new pix_icon('i/report', '')
);
- }
+
}
diff --git a/settings.php b/settings.php
index d7a54ac..b92e805 100644
--- a/settings.php
+++ b/settings.php
@@ -15,37 +15,43 @@
// along with Moodle. If not, see .
/**
- * @package report_feedbackchoicegenerator
+ * @package local_feedbackchoicegenerator
* @copyright Andreas Schenkel
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
+$settings = new admin_settingpage( 'local_feedbackchoicegenerator', 'Feedbackchoice generator' );
+
+// Create
+$ADMIN->add( 'localplugins', $settings );
+
+
if ($ADMIN->fulltree) {
-
+
$settings->add(new admin_setting_configcheckbox(
- 'report_feedbackchoicegenerator_isactive',
- get_string('isactive', 'report_feedbackchoicegenerator'),
- get_string('configisactive', 'report_feedbackchoicegenerator'),
+ 'local_feedbackchoicegenerator_isactive',
+ get_string('isactive', 'local_feedbackchoicegenerator'),
+ get_string('configisactive', 'local_feedbackchoicegenerator'),
0
));
$options = array(5 => '5', 10 => '10', 20 => '20', 30 => '30', 40 => '40', 50 => '50', 100 => '100', 200 => '200');
$settings->add(new admin_setting_configselect(
- 'report_feedbackchoicegenerator_maxlength',
- get_string('maxlength', 'report_feedbackchoicegenerator'),
- get_string('configmaxlength', 'report_feedbackchoicegenerator'),
+ 'local_feedbackchoicegenerator_maxlength',
+ get_string('maxlength', 'local_feedbackchoicegenerator'),
+ get_string('configmaxlength', 'local_feedbackchoicegenerator'),
'40',
$options
));
$options = array(5 => '5', 10 => '10', 20 => '20', 30 => '30', 40 => '40', 50 => '50');
$settings->add(new admin_setting_configselect(
- 'report_feedbackchoicegenerator_maxoptionslength',
- get_string('maxoptionslength', 'report_feedbackchoicegenerator'),
- get_string('configmaxoptionslength', 'report_feedbackchoicegenerator'),
+ 'local_feedbackchoicegenerator_maxoptionslength',
+ get_string('maxoptionslength', 'local_feedbackchoicegenerator'),
+ get_string('configmaxoptionslength', 'local_feedbackchoicegenerator'),
'30',
$options
));
diff --git a/templates/reportgenerator.mustache b/templates/mainpage.mustache
similarity index 96%
rename from templates/reportgenerator.mustache
rename to templates/mainpage.mustache
index 144f778..e6fd00b 100644
--- a/templates/reportgenerator.mustache
+++ b/templates/mainpage.mustache
@@ -1,5 +1,5 @@
{{!
- @template report_feedbackchoicegenerator/report
+ @template local_feedbackchoicegenerator/mainpage
}}
diff --git a/version.php b/version.php
index cafd014..83d7044 100644
--- a/version.php
+++ b/version.php
@@ -1,5 +1,5 @@
.
+// along with Moodle. If not, see .
/**
- * @package report_feedbackchoicegenerator
- * @author Andreas Schenkel
- * @copyright Andreas Schenkel
- * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ * Version details.
+ *
+ * @package local_feedbackchoicegenerator
+ * @copyright 2021 Andreas Schenkel
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
-defined('MOODLE_INTERNAL') || die();
+defined('MOODLE_INTERNAL') || die;
-$plugin->component = 'report_feedbackchoicegenerator';
-$plugin->release = '1.0.5';
-$plugin->version = 2021120303;
-$plugin->requires = 2020061500;
-$plugin->maturity = MATURITY_RC;
+$plugin->maturity = MATURITY_BETA;
+$plugin->version = 2021121301;
+$plugin->component = 'local_feedbackchoicegenerator';
+$plugin->requires = 2017111300;
+$plugin->release = 'v0.0.1';