Skip to content

Commit

Permalink
Merge pull request #6 from andreasschenkel/develop
Browse files Browse the repository at this point in the history
v2.0.0 changed from report to local
  • Loading branch information
andreasschenkel authored Dec 30, 2021
2 parents 9c2482f + 31ab3b4 commit 997a7d6
Show file tree
Hide file tree
Showing 17 changed files with 500 additions and 401 deletions.
43 changes: 24 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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
Expand All @@ -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.
Expand Down
68 changes: 33 additions & 35 deletions classes/Database/DataFiles.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
<?php
namespace report_feedbackchoicegenerator\Database;
// 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 local_feedbackchoicegenerator\Database;
defined('MOODLE_INTERNAL') || die();
use moodle_database;

/**
Expand All @@ -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);
Expand All @@ -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], '*');
}
}
43 changes: 25 additions & 18 deletions classes/Database/Factory.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
<?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 report_feedbackchoicegenerator\Database;

namespace local_feedbackchoicegenerator\Database;
defined('MOODLE_INTERNAL') || die;
use moodle_database;

/**
Expand All @@ -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;
}
}
Loading

0 comments on commit 997a7d6

Please sign in to comment.