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 4ac64a4 commit 28e6f99
Show file tree
Hide file tree
Showing 30 changed files with 225 additions and 104 deletions.
1 change: 1 addition & 0 deletions components/calcs/average/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
/**
* Configurable Reports a Moodle block for creating customizable reports
*
* @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
Expand Down
4 changes: 3 additions & 1 deletion components/calcs/average/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
class plugin_average extends plugin_base {

/**
* Init
*
* @return void
*/
public function init(): void {
Expand Down Expand Up @@ -101,7 +103,7 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $rows
* @param array $rows
* @return float
*/
public function execute($rows): float {
Expand Down
4 changes: 2 additions & 2 deletions components/calcs/percent/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public function summary(object $data): string {
}

/**
* execute
* Execute
*
* @param $rows
* @param array $rows
* @return string
*/
public function execute($rows): string {
Expand Down
8 changes: 5 additions & 3 deletions components/cohorts/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @author François Parlant <https://www.linkedin.com/in/francois-parlant/>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die;
Expand All @@ -35,6 +36,8 @@
class plugin_cohorts extends plugin_base {

/**
* Init
*
* @return void
*/
public function init(): void {
Expand All @@ -55,13 +58,12 @@ public function summary(object $data): string {
}

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

$filtercohorts = optional_param('filter_cohorts', 0, PARAM_INT);
if (!$filtercohorts) {
Expand Down
16 changes: 12 additions & 4 deletions components/columns/categoryfield/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,19 @@ public function summary(object $data): string {
return format_string($data->columname);
}

// Data -> Plugin configuration data.
// Row -> Complet course row c->id, c->fullname, etc...
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
/**
* Execute
*
* @param array $data
* @param object $row
* @return string
*/
public function execute($data, $row) {
global $DB;

// Data -> Plugin configuration data.
// Row -> Complet course row c->id, c->fullname, etc...

if (isset($row->{$data->column})) {
switch ($data->column) {
case 'timemodified':
Expand All @@ -73,7 +81,7 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
}
}

return (isset($row->{$data->column})) ? $row->{$data->column} : '';
return $row->{$data->column} ?? '';
}

}
2 changes: 1 addition & 1 deletion components/columns/component.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function process_form() {
* add_form_elements
*
* @param MoodleQuickForm $mform
* @param $components
* @param string|object $components
*/
public function add_form_elements(MoodleQuickForm $mform, $components): void {

Expand Down
8 changes: 7 additions & 1 deletion components/columns/coursefield/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@

require_once($CFG->libdir . '/formslib.php');

/**
* Class coursefield_form
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
*/
class coursefield_form extends moodleform {

/**
* Form definition
*/
public function definition(): void {
global $DB, $USER, $CFG;
global $DB;

$mform =& $this->_form;

Expand Down
13 changes: 5 additions & 8 deletions components/columns/currentuserfinalgrade/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ public function summary(object $data): string {
}

/**
* execute
* Execute
*
* @param $data
* @param $row
* @param $user
* @param $courseid
* @param $starttime
* @param $endtime
* @param array $data
* @param object $row
* @param object $user
* @return string
*/
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
public function execute($data, $row, $user) {
global $CFG;

// Data -> Plugin configuration data.
Expand Down
28 changes: 24 additions & 4 deletions components/columns/finalgradeincurrentcourse/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,19 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php');

/**
* Class plugin_finalgradeincurrentcourse
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
*/
class plugin_finalgradeincurrentcourse extends plugin_base {

/**
* Init
*
* @return void
*/
public function init(): void {
$this->fullname = get_string('finalgradeincurrentcourse', 'block_configurable_reports');
$this->form = true;
Expand All @@ -43,11 +54,20 @@ public function summary(object $data): string {
return format_string($data->columname);
}

// Data -> Plugin configuration data
// Row -> Complet course row c->id, c->fullname, etc...
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
global $DB, $USER, $CFG;
/**
* Execute
*
* @param array $data
* @param object $row
* @param object $user
* @param int $courseid
* @return string
*/
public function execute($data, $row, $user, $courseid) {
global $CFG;

// Data -> Plugin configuration data.
// Row -> Complet course row c->id, c->fullname, etc.
$userid = $row->id;
require_once($CFG->libdir . '/gradelib.php');
require_once($CFG->dirroot . '/grade/querylib.php');
Expand Down
87 changes: 68 additions & 19 deletions components/columns/reportcolumn/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,24 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php');

/**
* Class plugin_reportcolumn
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
*/
class plugin_reportcolumn extends plugin_base {

public $reportcache = [];
/**
* @var array
*/
public array $reportcache = [];

/**
* Init
*
* @return void
*/
public function init(): void {
$this->fullname = get_string('reportcolumn', 'block_configurable_reports');
$this->type = 'undefined';
Expand All @@ -46,8 +60,13 @@ public function summary(object $data): string {
return format_string($data->columname);
}

public function get_user_reports() {
global $DB, $USER;
/**
* get_user_reports
*
* @return array
*/
public function get_user_reports(): array {
global $USER;

$supported = [
'courses' => ['users'],
Expand All @@ -68,6 +87,12 @@ public function get_user_reports() {
return $reports;
}

/**
* get_current_report
*
* @param $report
* @return false|int
*/
public function get_current_report($report) {
$components = cr_unserialize($report->components);

Expand All @@ -85,7 +110,13 @@ public function get_current_report($report) {
return 0;
}

public function get_report_columns($reportid) {
/**
* get_report_columns
*
* @param int $reportid
* @return array
*/
public function get_report_columns(int $reportid) {
global $DB;

$columns = [];
Expand All @@ -107,11 +138,17 @@ public function get_report_columns($reportid) {
return $columns;
}

public function fix_condition_expr($condition, $count) {
/**
* fix_condition_expr
*
* @param string $condition
* @param int $count
* @return string
*/
public function fix_condition_expr($condition, $count): string {
switch ($count) {
case 0:
return '';
case 1:
case 0:
return '';
case 2:
return 'c1 and c2';
Expand All @@ -120,11 +157,23 @@ public function fix_condition_expr($condition, $count) {
}
}

// Data -> Plugin configuration data.
// Row -> Complet course/user row c->id, c->fullname, etc...
/**
* Execute
*
* @param array $data
* @param object $row
* @param object $user
* @param int $courseid
* @param int $starttime
* @param int $endtime
* @return array|string
*/
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
global $DB, $CFG;

// Data -> Plugin configuration data.
// Row -> Complet course/user row c->id, c->fullname, etc...

if (!$report = $DB->get_record('block_configurable_reports', ['id' => $data->reportid])) {
throw new moodle_exception('reportdoesnotexists', 'block_configurable_reports');
}
Expand All @@ -137,16 +186,16 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
$reportclassname = 'report_' . $report->type;
$reportclass = new $reportclassname($report);

// Delete conditions - TODO
// Add new condition
// User report -> New condition "User courses"
// TODO Delete conditions.
// Add new condition.
// User report -> New condition "User courses".
// Course report -> New condition "Course users".
if ($this->report->type == 'users') {
if ($this->report->type === 'users') {
$reportclass->currentuser = $row;
$reportclass->starttime = $starttime;
$reportclass->endtime = $endtime;

if ($report->type == 'courses') {
if ($report->type === 'courses') {
$components = cr_unserialize($reportclass->config->components);
$newplugin = [
'pluginname' => 'currentusercourses',
Expand All @@ -165,12 +214,12 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
);
$reportclass->config->components = cr_serialize($components);
}
} else if ($this->report->type == 'courses') {
} else if ($this->report->type === 'courses') {
$reportclass->currentcourseid = $row->id;
$reportclass->starttime = $starttime;
$reportclass->endtime = $endtime;

if ($report->type == 'users') {
if ($report->type === 'users') {
$components = cr_unserialize($reportclass->config->components);

$roles = $DB->get_records('role');
Expand All @@ -193,14 +242,14 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
}
$reportclass->config->components = cr_serialize($components);
}
} else if ($this->report->type == 'timeline') {
} else if ($this->report->type === 'timeline') {
$reportclass->starttime = $row->starttime;
$reportclass->endtime = $row->endtime;
} else if ($this->report->type == 'categories') {
} else if ($this->report->type === 'categories') {
$reportclass->starttime = $starttime;
$reportclass->endtime = $endtime;

if ($report->type == 'courses') {
if ($report->type === 'courses') {
$components = cr_unserialize($reportclass->config->components);

$formdata = new stdclass;
Expand Down
8 changes: 7 additions & 1 deletion components/columns/roleusersn/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@

require_once($CFG->libdir . '/formslib.php');

/**
* Class roleusersn_form
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
*/
class roleusersn_form extends moodleform {

/**
* Form definition
*/
public function definition(): void {
global $DB, $USER, $CFG;
global $DB;

$mform =& $this->_form;

Expand Down
Loading

0 comments on commit 28e6f99

Please sign in to comment.