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 28e6f99 commit d5533c2
Show file tree
Hide file tree
Showing 45 changed files with 346 additions and 141 deletions.
2 changes: 2 additions & 0 deletions components/calcs/percent/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
* @copyright 2020 Juan Leyva <[email protected]>
* @package block_configurable_reports
* @author David Pesce <[email protected]>
* @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
4 changes: 3 additions & 1 deletion components/columns/categoryfield/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
class plugin_categoryfield extends plugin_base {

/**
* Init
*
* @return void
*/
public function init(): void {
Expand All @@ -56,7 +58,7 @@ public function summary(object $data): string {
/**
* Execute
*
* @param array $data
* @param object $data
* @param object $row
* @return string
*/
Expand Down
22 changes: 18 additions & 4 deletions components/columns/coursefield/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@
defined('MOODLE_INTERNAL') || die;
require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php');

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

/**
* Init
*
* @return void
*/
public function init(): void {
Expand All @@ -47,11 +55,17 @@ public function summary(object $data): string {
return format_string($data->columname);
}

/**
* Execute
*
* @param object $data
* @param object $row
* @return string
*/
public function execute($data, $row) {

// Data -> Plugin configuration data.
// Row -> Complet course row c->id, c->fullname, etc...
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {

// Data -> Plugin configuration data.
// Row -> Complet course row c->id, c->fullname, etc...
if (isset($row->{$data->column})) {
switch ($data->column) {
case 'enrolstartdate':
Expand Down
23 changes: 17 additions & 6 deletions components/columns/coursestats/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_coursestats
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
*/
class plugin_coursestats extends plugin_base {

/**
* Init
*
* @return void
*/
public function init(): void {
$this->fullname = get_string('coursestats', 'block_configurable_reports');
$this->type = 'undefined';
Expand All @@ -47,12 +58,12 @@ public function summary(object $data): string {
/**
* execute
*
* @param $data
* @param $row
* @param $user
* @param $courseid
* @param $starttime
* @param $endtime
* @param object $data
* @param object $row
* @param object $user
* @param int $courseid
* @param int $starttime
* @param int $endtime
* @return int|string
*/
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
Expand Down
12 changes: 5 additions & 7 deletions components/columns/date/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,13 @@ public function summary(object $data): string {
}

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

// Data -> Plugin configuration data.
// Row -> Complet course row c->id, c->fullname, etc...
Expand Down
7 changes: 6 additions & 1 deletion components/columns/finalgradeincurrentcourse/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@

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

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

/**
* Form definition
*/
public function definition(): void {
global $DB, $USER, $CFG;
$mform =& $this->_form;
$this->_customdata['compclass']->add_form_elements($mform, $this);
// Buttons.
Expand Down
2 changes: 1 addition & 1 deletion components/columns/reportcolumn/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function get_user_reports(): array {
/**
* get_current_report
*
* @param $report
* @param object $report
* @return false|int
*/
public function get_current_report($report) {
Expand Down
28 changes: 23 additions & 5 deletions components/columns/roleusersn/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,22 @@
* @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
*/

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

/**
* Init
*
* @return void
*/
public function init(): void {
$this->fullname = get_string('roleusersn', 'block_configurable_reports');
$this->type = 'numeric';
Expand All @@ -40,11 +53,16 @@ public function summary(object $data): string {
return format_string($data->columname);
}



// Data -> Plugin configuration data.
// Row -> Full course row c->id, c->fullname, etc...
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
/**
* Execute
*
* @param object $data
* @param object $row
* @return int
*/
public function execute($data, $row) {
// Data -> Plugin configuration data.
// Row -> Full course row c->id, c->fullname, etc...
$courseid = $row->id;
$context = cr_get_context(CONTEXT_COURSE, $courseid);

Expand Down
12 changes: 6 additions & 6 deletions components/columns/usermodoutline/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,12 @@ public function summary(object $data): string {
/**
* Execute
*
* @param $data
* @param $row
* @param $user
* @param $courseid
* @param $starttime
* @param $endtime
* @param object $data
* @param object $row
* @param object $user
* @param int $courseid
* @param int $starttime
* @param int $endtime
* @return string
*/
public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime = 0) {
Expand Down
11 changes: 8 additions & 3 deletions components/columns/userstats/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,18 @@

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

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

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

$mform =& $this->_form;

Expand Down Expand Up @@ -78,12 +83,12 @@ public function definition(): void {
* or an empty array if everything is OK (true allowed for backwards compatibility too).
*/
public function validation($data, $files): array {
global $DB, $CFG;
global $CFG;
$errors = parent::validation($data, $files);

$errors = $this->_customdata['compclass']->validate_form_elements($data, $errors);

if ($data['stat'] != 'coursededicationtime' && (!isset($CFG->enablestats) || !$CFG->enablestats)) {
if ($data['stat'] !== 'coursededicationtime' && (!isset($CFG->enablestats) || !$CFG->enablestats)) {
$errors['stat'] = get_string('globalstatsshouldbeenabled', 'block_configurable_reports');
}

Expand Down
35 changes: 28 additions & 7 deletions components/columns/userstats/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_userstats
*
* @package block_configurable_reports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
*/
class plugin_userstats extends plugin_base {

/**
* Init
*
* @return void
*/
public function init(): void {
$this->fullname = get_string('userstats', 'block_configurable_reports');
$this->type = 'undefined';
Expand All @@ -44,11 +55,21 @@ public function summary(object $data): string {
return format_string($data->columname);
}

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

// Data -> Plugin configuration data.
// Row -> Complet user row c->id, c->fullname, etc.
$stat = '--';

$filterstarttime = optional_param('filter_starttime', 0, PARAM_RAW);
Expand All @@ -68,7 +89,7 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
$starttime = ($filterstarttime) ? $filterstarttime : $starttime;
$endtime = ($filterendtime) ? $filterendtime : $endtime;

if ($data->stat == 'coursededicationtime') {
if ($data->stat === 'coursededicationtime') {
$sql = "userid = ?";
$params = [$row->id];

Expand Down Expand Up @@ -160,7 +181,7 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
$sql = "SELECT SUM($total) as total FROM {stats_user_daily} WHERE stattype = ? AND userid = ?";
$params = [$stattype, $row->id];

if ($courseid != SITEID && $data->stat != 'logins') {
if ($courseid != SITEID && $data->stat !== 'logins') {
$sql .= " AND courseid = ?";
$params[] = $courseid;
}
Expand All @@ -176,9 +197,9 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime
$res = array_shift($res);
if ($res->total != null) {
return $res->total;
} else {
return 0;
}

return 0;
}

return $stat;
Expand Down
3 changes: 1 addition & 2 deletions components/competencyframeworks/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ public function summary(object $data): string {
* execute
*
* @param string $finalelements
* @param $data
* @return array|string|string[]
*/
public function execute($finalelements, $data) {
public function execute($finalelements) {

$filtercompetencyframeworks = optional_param('filter_competencyframeworks', 0, PARAM_INT);
if (!$filtercompetencyframeworks) {
Expand Down
Loading

0 comments on commit d5533c2

Please sign in to comment.