Skip to content

Commit

Permalink
Refactor for MOODLE41 & PHP 7.4
Browse files Browse the repository at this point in the history
  • Loading branch information
luukverhoeven committed Dec 18, 2023
1 parent d5533c2 commit 64257c7
Show file tree
Hide file tree
Showing 27 changed files with 100 additions and 73 deletions.
1 change: 0 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ jobs:
disable_grunt: true
disable_phpunit: true
disable_phpcpd: true # Old code we don't going to rewrite everything for now.
disable_phpdoc: true # Old code we don't going to rewrite everything for now.
disable_release : true
release_branches: main
min_php : 7.4
8 changes: 7 additions & 1 deletion components/competencytemplates/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ public function summary(object $data): string {
return get_string('filtercompetencytemplates_summary', 'block_configurable_reports');
}

public function execute($finalelements, $data) {
/**
* Execute
*
* @param string $finalelements
* @return array|string|string[]
*/
public function execute($finalelements) {

$filtercompetencytemplates = optional_param('filter_competencytemplates', 0, PARAM_INT);
if (!$filtercompetencytemplates) {
Expand Down
7 changes: 3 additions & 4 deletions components/conditions/cuserfield/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,11 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $data
* @param $user
* @param $courseid
* @param object $data
* @param object $user
* @return array|int[]|string[]
*/
public function execute($data, $user, $courseid) {
public function execute($data, $user) {
global $DB;
// Data -> Plugin configuration data.
// TODO - Use $DB->sql_like().
Expand Down
2 changes: 1 addition & 1 deletion components/conditions/parentcategory/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $data
* @param object $data
* @return array
*/
public function execute($data) {
Expand Down
2 changes: 1 addition & 1 deletion components/conditions/usersincohorts/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $data
* @param object $data
* @return array|int[]|string[]
*/
public function execute($data) {
Expand Down
6 changes: 3 additions & 3 deletions components/conditions/usersincurrentcourse/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $data
* @param $user
* @param $courseid
* @param object $data
* @param object $user
* @param int $courseid
* @return array|int[]|string[]
*/
public function execute($data, $user, $courseid) {
Expand Down
8 changes: 4 additions & 4 deletions components/customsql/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ public function validation($data, $files): array {
/**
* validation_high_security
*
* @param $data
* @param $files
* @param array $data
* @param array $files
* @return array
*/
public function validation_high_security($data, $files): array {
Expand Down Expand Up @@ -166,8 +166,8 @@ public function validation_high_security($data, $files): array {
/**
* validation_low_security
*
* @param $data
* @param $files
* @param array $data
* @param array $files
* @return array
*/
public function validation_low_security($data, $files) {
Expand Down
8 changes: 7 additions & 1 deletion components/filters/categories/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public function summary(object $data): string {
return get_string('filtercategories_summary', 'block_configurable_reports');
}

public function execute($finalelements, $data) {
/**
* Execute
*
* @param string $finalelements
* @return array|string|string[]
*/
public function execute($finalelements) {

$filtercategories = optional_param('filter_categories', 0, PARAM_INT);
if (!$filtercategories) {
Expand Down
3 changes: 1 addition & 2 deletions components/filters/coursecategories/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,9 @@ public function summary(object $data): string {
* Execute
*
* @param string $finalelements
* @param $data
* @return mixed
*/
public function execute($finalelements, $data) {
public function execute($finalelements) {
global $remotedb, $CFG;
require_once($CFG->dirroot . "/course/lib.php");

Expand Down
2 changes: 1 addition & 1 deletion components/filters/fcoursefield/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function summary(object $data): string {
* Execute
*
* @param string $finalelements
* @param $data
* @param object $data
* @return int[]|mixed|string[]
*/
public function execute($finalelements, $data) {
Expand Down
13 changes: 7 additions & 6 deletions components/filters/fuserfield/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function summary(object $data): string {
* Execute
*
* @param string $finalelements
* @param $data
* @param object $data
* @return array|int[]|mixed|string|string[]
*/
public function execute($finalelements, $data) {
Expand All @@ -74,7 +74,7 @@ public function execute($finalelements, $data) {
* execute_sql
*
* @param string $finalelements
* @param $data
* @param object $data
* @return array|mixed|string|string[]
*/
private function execute_sql($finalelements, $data) {
Expand All @@ -97,7 +97,7 @@ private function execute_sql($finalelements, $data) {
* execute_users
*
* @param string $finalelements
* @param $data
* @param object $data
* @return array|int[]|mixed|string[]
*/
private function execute_users($finalelements, $data) {
Expand Down Expand Up @@ -217,12 +217,12 @@ public function print_filter(MoodleQuickForm $mform, $formdata = false): void {
/**
* sql_replace
*
* @param $filtersearchtext
* @param $filterstrmatch
* @param string $filtersearchtext
* @param string $filterstrmatch
* @param string $finalelements
* @return array|mixed|string|string[]
*/
private function sql_replace($filtersearchtext, $filterstrmatch, $finalelements) {
private function sql_replace(string $filtersearchtext, $filterstrmatch, $finalelements) {
$operators = ['=', '<', '>', '<=', '>=', '~', 'in'];

// TODO this function is 2 times in the code, should be refactored.
Expand All @@ -235,6 +235,7 @@ private function sql_replace($filtersearchtext, $filterstrmatch, $finalelements)
throw new moodle_exception('nosuchoperator');
}
if ($operator === '~') {
// TODO can be improved by more native PDO approach.
$replace = " AND " . $field . " LIKE '%" . $filtersearchtext . "%'";
} else if ($operator === 'in') {
$processeditems = [];
Expand Down
8 changes: 7 additions & 1 deletion components/filters/role/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public function summary(object $data): string {
return get_string('filterrole_summary', 'block_configurable_reports');
}

public function execute($finalelements, $data) {
/**
* Execute
*
* @param string $finalelements
* @return array|string|string[]
*/
public function execute($finalelements) {

$filterrole = optional_param('filter_role', 0, PARAM_INT);
if (!$filterrole) {
Expand Down
1 change: 1 addition & 0 deletions components/filters/searchtext/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Form for searchtext filter
*
* @copyright 2020 David Saylor
* @package block_configurable_reports
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author David Saylor <[email protected]>
*/
Expand Down
11 changes: 6 additions & 5 deletions components/filters/searchtext/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
/**
* Configurable Reports a Moodle block for creating customizable reports
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php');
Expand Down Expand Up @@ -116,8 +117,8 @@ public function print_filter(MoodleQuickForm $mform, $formdata = false): void {
/**
* sql_replace
*
* @param $filtersearchtext
* @param $filterstrmatch
* @param string $filtersearchtext
* @param string $filterstrmatch
* @param string $finalelements
* @return array|mixed|string|string[]
*/
Expand Down
8 changes: 7 additions & 1 deletion components/filters/startendtime/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public function summary(object $data): string {
return get_string('filterstartendtime_summary', 'block_configurable_reports');
}

public function execute($finalelements, $data) {
/**
* Execute
*
* @param string $finalelements
* @return array|string|string[]
*/
public function execute($finalelements) {
global $CFG;

if ($this->report->type !== 'sql') {
Expand Down
18 changes: 12 additions & 6 deletions components/filters/users/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,13 @@ public function summary(object $data): string {
return get_string('filterusers_summary', 'block_configurable_reports');
}

public function execute($finalelements, $data) {
/**
* Execute
*
* @param string $finalelements
* @return string|array
*/
public function execute($finalelements) {

$filterusers = optional_param('filter_users', 0, PARAM_INT);
if (!$filterusers) {
Expand All @@ -64,12 +70,12 @@ public function execute($finalelements, $data) {

if ($this->report->type !== 'sql') {
return [$filterusers];
} else {
if (preg_match("/%%FILTER_SYSTEMUSER:([^%]+)%%/i", $finalelements, $output)) {
$replace = ' AND ' . $output[1] . ' = ' . $filterusers;
}

return str_replace('%%FILTER_SYSTEMUSER:' . $output[1] . '%%', $replace, $finalelements);
}
if (preg_match("/%%FILTER_SYSTEMUSER:([^%]+)%%/i", $finalelements, $output)) {
$replace = ' AND ' . $output[1] . ' = ' . $filterusers;

return str_replace('%%FILTER_SYSTEMUSER:' . $output[1] . '%%', $replace, $finalelements);
}

return $finalelements;
Expand Down
7 changes: 2 additions & 5 deletions components/permissions/anyone/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $userid
* @param $context
* @param $data
* @return true
* @return bool
*/
public function execute($userid, $context, $data) {
public function execute() {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $userid
* @param int $userid
* @return bool
*/
public function execute($userid): bool {
Expand Down
6 changes: 3 additions & 3 deletions components/permissions/roleincourse/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $userid
* @param $context
* @param $data
* @param int $userid
* @param context $context
* @param object $data
* @return bool
*/
public function execute($userid, $context, $data): bool {
Expand Down
5 changes: 2 additions & 3 deletions components/permissions/usersincoursereport/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,10 @@ public function summary(object $data): string {
* execute
*
* @param int $userid
* @param $context
* @param $data
* @param context $context
* @return bool
*/
public function execute(int $userid, $context, $data) {
public function execute(int $userid, $context) {

// Everyone should be enrolled at the system level.
if ($context === context_system::instance()) {
Expand Down
4 changes: 3 additions & 1 deletion components/plot/bar/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ public function definition(): void {
}

/**
* @param $mform
* add_formatting_elements
*
* @param moodleform $mform
* @return void
*/
public function add_formatting_elements($mform): void {
Expand Down
6 changes: 3 additions & 3 deletions components/plot/bar/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $id
* @param $data
* @param $finalreport
* @param int $id
* @param object $data
* @param array $finalreport
* @return string
*/
public function execute($id, $data, $finalreport) {
Expand Down
6 changes: 3 additions & 3 deletions components/plot/line/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $id
* @param $data
* @param $finalreport
* @param int $id
* @param object $data
* @param array $finalreport
* @return string
*/
public function execute($id, $data, $finalreport) {
Expand Down
Loading

0 comments on commit 64257c7

Please sign in to comment.