From d5533c27353b3d791dc2bc5eb16adb06aafc1500 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Mon, 18 Dec 2023 14:05:29 +0100 Subject: [PATCH] Refactor for MOODLE41 & PHP 7.4 --- components/calcs/percent/plugin.class.php | 2 + .../columns/categoryfield/plugin.class.php | 4 +- .../columns/coursefield/plugin.class.php | 22 +++++++++-- .../columns/coursestats/plugin.class.php | 23 ++++++++--- components/columns/date/plugin.class.php | 12 +++--- .../finalgradeincurrentcourse/form.php | 7 +++- .../columns/reportcolumn/plugin.class.php | 2 +- .../columns/roleusersn/plugin.class.php | 28 +++++++++++--- .../columns/usermodoutline/plugin.class.php | 12 +++--- components/columns/userstats/form.php | 11 ++++-- components/columns/userstats/plugin.class.php | 35 +++++++++++++---- .../competencyframeworks/plugin.class.php | 3 +- .../competencytemplates/plugin.class.php | 38 +++++++++---------- .../conditions/ccoursefield/plugin.class.php | 3 +- components/conditions/component.class.php | 2 +- .../coursecategory/plugin.class.php | 6 +-- .../conditions/coursechild/plugin.class.php | 8 ++-- .../conditions/courseparent/plugin.class.php | 6 +-- .../currentreportcourse/plugin.class.php | 6 +-- .../conditions/currentuser/plugin.class.php | 7 ++-- .../currentusercourses/plugin.class.php | 7 ++-- .../filters/enrolledstudents/plugin.class.php | 5 ++- .../filters/fsearchuserfield/plugin.class.php | 16 +++++--- components/filters/role/plugin.class.php | 11 ++++++ components/filters/semester/plugin.class.php | 29 +++++++++++--- .../filters/startendtime/plugin.class.php | 11 ++++++ .../filters/subcategories/plugin.class.php | 19 +++++++++- components/filters/user/plugin.class.php | 19 +++++++++- components/filters/users/plugin.class.php | 11 ++++++ components/permissions/component.class.php | 6 ++- .../permissions/puserfield/plugin.class.php | 6 +-- components/plot/line/form.php | 19 +++++++++- components/plot/pie/plugin.class.php | 11 ++++-- edit_form.php | 10 ++++- export/csv/export.php | 2 +- export/ods/export.php | 2 +- export/xls/export.php | 2 +- lang/en/block_configurable_reports.php | 9 +++++ locallib.php | 4 +- managereport.php | 3 ++ plugin.class.php | 14 ++++--- report.class.php | 6 +-- reports/evalwise.class.php | 14 +++---- reports/sql/report.class.php | 5 ++- settings.php | 9 +++++ 45 files changed, 346 insertions(+), 141 deletions(-) diff --git a/components/calcs/percent/plugin.class.php b/components/calcs/percent/plugin.class.php index a8377518..5414883d 100644 --- a/components/calcs/percent/plugin.class.php +++ b/components/calcs/percent/plugin.class.php @@ -20,7 +20,9 @@ * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author David Pesce + * @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'); diff --git a/components/columns/categoryfield/plugin.class.php b/components/columns/categoryfield/plugin.class.php index 74961ee3..5765220a 100755 --- a/components/columns/categoryfield/plugin.class.php +++ b/components/columns/categoryfield/plugin.class.php @@ -34,6 +34,8 @@ class plugin_categoryfield extends plugin_base { /** + * Init + * * @return void */ public function init(): void { @@ -56,7 +58,7 @@ public function summary(object $data): string { /** * Execute * - * @param array $data + * @param object $data * @param object $row * @return string */ diff --git a/components/columns/coursefield/plugin.class.php b/components/columns/coursefield/plugin.class.php index 1e0f7ee4..41c777ca 100755 --- a/components/columns/coursefield/plugin.class.php +++ b/components/columns/coursefield/plugin.class.php @@ -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 + */ class plugin_coursefield extends plugin_base { /** + * Init + * * @return void */ public function init(): void { @@ -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': diff --git a/components/columns/coursestats/plugin.class.php b/components/columns/coursestats/plugin.class.php index d17bbefc..4a204a99 100755 --- a/components/columns/coursestats/plugin.class.php +++ b/components/columns/coursestats/plugin.class.php @@ -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 + */ class plugin_coursestats extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->fullname = get_string('coursestats', 'block_configurable_reports'); $this->type = 'undefined'; @@ -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) { diff --git a/components/columns/date/plugin.class.php b/components/columns/date/plugin.class.php index bc60c42e..6d90aaa1 100755 --- a/components/columns/date/plugin.class.php +++ b/components/columns/date/plugin.class.php @@ -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... diff --git a/components/columns/finalgradeincurrentcourse/form.php b/components/columns/finalgradeincurrentcourse/form.php index b7493ae9..5ae31014 100755 --- a/components/columns/finalgradeincurrentcourse/form.php +++ b/components/columns/finalgradeincurrentcourse/form.php @@ -27,13 +27,18 @@ require_once($CFG->libdir . '/formslib.php'); +/** + * Class finalgradeincurrentcourse_form + * + * @package block_configurable_reports + * @author Juan leyva + */ 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. diff --git a/components/columns/reportcolumn/plugin.class.php b/components/columns/reportcolumn/plugin.class.php index 0818b7e5..3e4e215c 100755 --- a/components/columns/reportcolumn/plugin.class.php +++ b/components/columns/reportcolumn/plugin.class.php @@ -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) { diff --git a/components/columns/roleusersn/plugin.class.php b/components/columns/roleusersn/plugin.class.php index 61a3c178..130aaefc 100755 --- a/components/columns/roleusersn/plugin.class.php +++ b/components/columns/roleusersn/plugin.class.php @@ -20,9 +20,22 @@ * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Class plugin_roleusersn + * + * @package block_configurable_reports + * @author Juan leyva */ class plugin_roleusersn extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->fullname = get_string('roleusersn', 'block_configurable_reports'); $this->type = 'numeric'; @@ -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); diff --git a/components/columns/usermodoutline/plugin.class.php b/components/columns/usermodoutline/plugin.class.php index a69972b4..a391688c 100755 --- a/components/columns/usermodoutline/plugin.class.php +++ b/components/columns/usermodoutline/plugin.class.php @@ -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) { diff --git a/components/columns/userstats/form.php b/components/columns/userstats/form.php index 2abbed95..bed2cc7c 100755 --- a/components/columns/userstats/form.php +++ b/components/columns/userstats/form.php @@ -27,13 +27,18 @@ require_once($CFG->libdir . '/formslib.php'); +/** + * Class userstats_form + * + * @package block_configurable_reports + * @author Juan leyva + */ class userstats_form extends moodleform { /** * Form definition */ public function definition(): void { - global $DB, $USER, $CFG; $mform =& $this->_form; @@ -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'); } diff --git a/components/columns/userstats/plugin.class.php b/components/columns/userstats/plugin.class.php index 393dabcb..7aaf970f 100755 --- a/components/columns/userstats/plugin.class.php +++ b/components/columns/userstats/plugin.class.php @@ -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 + */ class plugin_userstats extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->fullname = get_string('userstats', 'block_configurable_reports'); $this->type = 'undefined'; @@ -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); @@ -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]; @@ -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; } @@ -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; diff --git a/components/competencyframeworks/plugin.class.php b/components/competencyframeworks/plugin.class.php index e216aabe..1854f663 100644 --- a/components/competencyframeworks/plugin.class.php +++ b/components/competencyframeworks/plugin.class.php @@ -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) { diff --git a/components/competencytemplates/plugin.class.php b/components/competencytemplates/plugin.class.php index 0065d2d3..4caf05fe 100644 --- a/components/competencytemplates/plugin.class.php +++ b/components/competencytemplates/plugin.class.php @@ -20,29 +20,26 @@ * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva + * @author François Parlant * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -/** - * COMPETENCY TEMPLATE FILTER - * A filter for configurable reports - * - * @author François Parlant - */ - -/* example of report query -*********** -* Display the courses in which the competencies of a template are used -*********** - - -*/ - defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_competencytemplates - Display the courses in which the competencies of a template are used + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_competencytemplates extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; @@ -69,12 +66,12 @@ public function execute($finalelements, $data) { if ($this->report->type !== 'sql') { return [$filtercompetencytemplates]; - } else { - if (preg_match("/%%FILTER_COMPETENCYTEMPLATES:([^%]+)%%/i", $finalelements, $output)) { - $replace = ' AND ' . $output[1] . ' = ' . $filtercompetencytemplates; + } - return str_replace('%%FILTER_COMPETENCYTEMPLATES:' . $output[1] . '%%', $replace, $finalelements); - } + if (preg_match("/%%FILTER_COMPETENCYTEMPLATES:([^%]+)%%/i", $finalelements, $output)) { + $replace = ' AND ' . $output[1] . ' = ' . $filtercompetencytemplates; + + return str_replace('%%FILTER_COMPETENCYTEMPLATES:' . $output[1] . '%%', $replace, $finalelements); } return $finalelements; @@ -107,7 +104,6 @@ public function print_filter(MoodleQuickForm $mform, $formdata = false): void { foreach ($studentlist as $student) { $competencytemplateslist[] = $student->userid; } - } $competencytemplatesoptions = []; diff --git a/components/conditions/ccoursefield/plugin.class.php b/components/conditions/ccoursefield/plugin.class.php index 62d11097..04f68d51 100755 --- a/components/conditions/ccoursefield/plugin.class.php +++ b/components/conditions/ccoursefield/plugin.class.php @@ -30,7 +30,6 @@ * Class plugin_ccoursefield * * @package block_configurable_reports - * * @author Juan leyva */ class plugin_ccoursefield extends plugin_base { @@ -60,7 +59,7 @@ public function summary(object $data): string { /** * Execute * - * @param $data + * @param object $data * @return array|int[]|string[] */ public function execute($data) { diff --git a/components/conditions/component.class.php b/components/conditions/component.class.php index 6f6ecb35..fe7688b1 100755 --- a/components/conditions/component.class.php +++ b/components/conditions/component.class.php @@ -63,7 +63,7 @@ public function form_process_data(moodleform $cform): void { /** * add_missing_conditions * - * @param $cond + * @param string $cond * @return array|mixed|string|string[]|null */ public function add_missing_conditions($cond) { diff --git a/components/conditions/coursecategory/plugin.class.php b/components/conditions/coursecategory/plugin.class.php index 027fe3e4..9edf8ef6 100755 --- a/components/conditions/coursecategory/plugin.class.php +++ b/components/conditions/coursecategory/plugin.class.php @@ -66,12 +66,10 @@ public function summary(object $data): string { /** * Execute * - * @param $data - * @param $user - * @param $courseid + * @param object $data * @return array|int[]|string[] */ - public function execute($data, $user, $courseid) { + public function execute($data) { global $DB; // Data -> Plugin configuration data. diff --git a/components/conditions/coursechild/plugin.class.php b/components/conditions/coursechild/plugin.class.php index 1a5375b3..fdf8c16f 100755 --- a/components/conditions/coursechild/plugin.class.php +++ b/components/conditions/coursechild/plugin.class.php @@ -64,12 +64,10 @@ public function summary(object $data): string { /** * Execute * - * @param $data - * @param $user - * @param $courseid - * @return array + * @param object $data + * @return array|int[]|string[] */ - public function execute($data, $user, $courseid) { + public function execute($data) { global $DB; // Data -> Plugin configuration data. $finalcourses = []; diff --git a/components/conditions/courseparent/plugin.class.php b/components/conditions/courseparent/plugin.class.php index a193d96d..1eac9284 100755 --- a/components/conditions/courseparent/plugin.class.php +++ b/components/conditions/courseparent/plugin.class.php @@ -65,12 +65,10 @@ public function summary(object $data): string { /** * Execute * - * @param $data - * @param $user - * @param $courseid + * @param object $data * @return array */ - public function execute($data, $user, $courseid) { + public function execute($data) { global $DB; // Data -> Plugin configuration data. $finalcourses = []; diff --git a/components/conditions/currentreportcourse/plugin.class.php b/components/conditions/currentreportcourse/plugin.class.php index 42376bbc..d38ac5a1 100755 --- a/components/conditions/currentreportcourse/plugin.class.php +++ b/components/conditions/currentreportcourse/plugin.class.php @@ -58,9 +58,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 */ public function execute($data, $user, $courseid) { diff --git a/components/conditions/currentuser/plugin.class.php b/components/conditions/currentuser/plugin.class.php index f0a0501b..c1cb3b4f 100755 --- a/components/conditions/currentuser/plugin.class.php +++ b/components/conditions/currentuser/plugin.class.php @@ -58,12 +58,11 @@ public function summary(object $data): string { /** * Execute * - * @param $data - * @param $user - * @param $courseid + * @param object $data + * @param object $user * @return array */ - public function execute($data, $user, $courseid) { + public function execute($data, $user) { // Data -> Plugin configuration data. return [$user->id]; } diff --git a/components/conditions/currentusercourses/plugin.class.php b/components/conditions/currentusercourses/plugin.class.php index 196a3953..c1a87128 100755 --- a/components/conditions/currentusercourses/plugin.class.php +++ b/components/conditions/currentusercourses/plugin.class.php @@ -58,12 +58,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 $CFG; // Data -> Plugin configuration data. diff --git a/components/filters/enrolledstudents/plugin.class.php b/components/filters/enrolledstudents/plugin.class.php index 52982f11..e5911fc3 100644 --- a/components/filters/enrolledstudents/plugin.class.php +++ b/components/filters/enrolledstudents/plugin.class.php @@ -56,11 +56,12 @@ 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) { $filterenrolledstudents = optional_param('filter_enrolledstudents', 0, PARAM_INT); if (!$filterenrolledstudents) { return $finalelements; diff --git a/components/filters/fsearchuserfield/plugin.class.php b/components/filters/fsearchuserfield/plugin.class.php index 4b36c82d..4e1c2fbc 100755 --- a/components/filters/fsearchuserfield/plugin.class.php +++ b/components/filters/fsearchuserfield/plugin.class.php @@ -14,9 +14,10 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -/** Configurable Reports - * A Moodle block for creating customizable reports +/** + * Configurable Reports A Moodle block for creating customizable reports * + * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -33,6 +34,8 @@ class plugin_fsearchuserfield extends plugin_base { /** + * Init + * * @return void */ public function init(): void { @@ -55,8 +58,8 @@ public function summary(object $data): string { /** * execute * - * @param string $finalelements - * @param $data + * @param string|array $finalelements + * @param object $data * @return array|int[]|mixed|string|string[] */ public function execute($finalelements, $data) { @@ -68,6 +71,8 @@ public function execute($finalelements, $data) { } /** + * execute_sql + * * @param string $finalelements * @param object $data * @return array|string|string[] @@ -168,7 +173,7 @@ public function print_filter(MoodleQuickForm $mform, $formdata = false): void { $userlist = array_keys($remotedb->get_records('user')); } else { $components = cr_unserialize($this->report->components); - $conditions = array_key_exists('conditions', $components) ? $components['conditions'] : null; + $conditions = $components['conditions'] ?? null; $userlist = $reportclass->elements_by_conditions($conditions); } @@ -184,7 +189,6 @@ public function print_filter(MoodleQuickForm $mform, $formdata = false): void { $params = array_merge([$field->id], $params); if ($infodata = $remotedb->get_records_sql($sql, $params)) { - $finalusersid = []; foreach ($infodata as $d) { $filteroptions[base64_encode($d->data)] = $d->data; } diff --git a/components/filters/role/plugin.class.php b/components/filters/role/plugin.class.php index a8110e0d..7aabda07 100755 --- a/components/filters/role/plugin.class.php +++ b/components/filters/role/plugin.class.php @@ -25,8 +25,19 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_role + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_role extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; diff --git a/components/filters/semester/plugin.class.php b/components/filters/semester/plugin.class.php index d93cedfb..79bc8185 100755 --- a/components/filters/semester/plugin.class.php +++ b/components/filters/semester/plugin.class.php @@ -25,8 +25,19 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_semester + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_semester extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; @@ -44,7 +55,13 @@ public function summary(object $data): string { return get_string('filtersemester_summary', 'block_configurable_reports'); } - public function execute($finalelements, $data) { + /** + * Execute + * + * @param string $finalelements + * @return array|string|string[] + */ + public function execute($finalelements) { $filtersemester = optional_param('filter_semester', '', PARAM_RAW); if (!$filtersemester) { @@ -53,12 +70,12 @@ public function execute($finalelements, $data) { if ($this->report->type !== 'sql') { return [$filtersemester]; - } else { - if (preg_match("/%%FILTER_SEMESTER:([^%]+)%%/i", $finalelements, $output)) { - $replace = ' AND ' . $output[1] . ' LIKE \'%' . $filtersemester . '%\''; + } - return str_replace('%%FILTER_SEMESTER:' . $output[1] . '%%', $replace, $finalelements); - } + if (preg_match("/%%FILTER_SEMESTER:([^%]+)%%/i", $finalelements, $output)) { + $replace = ' AND ' . $output[1] . ' LIKE \'%' . $filtersemester . '%\''; + + return str_replace('%%FILTER_SEMESTER:' . $output[1] . '%%', $replace, $finalelements); } return $finalelements; diff --git a/components/filters/startendtime/plugin.class.php b/components/filters/startendtime/plugin.class.php index 444cb7ef..2be2d7b3 100755 --- a/components/filters/startendtime/plugin.class.php +++ b/components/filters/startendtime/plugin.class.php @@ -25,8 +25,19 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_startendtime + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_startendtime extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; diff --git a/components/filters/subcategories/plugin.class.php b/components/filters/subcategories/plugin.class.php index 91fb7d4f..38ca7f0f 100755 --- a/components/filters/subcategories/plugin.class.php +++ b/components/filters/subcategories/plugin.class.php @@ -25,8 +25,19 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_subcategories + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_subcategories extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; @@ -44,7 +55,13 @@ public function summary(object $data): string { return get_string('filtersubcategories_summary', 'block_configurable_reports'); } - public function execute($finalelements, $data) { + /** + * Execute + * + * @param string $finalelements + * @return array|string|string[] + */ + public function execute($finalelements) { $filtersubcategories = optional_param('filter_subcategories', 0, PARAM_INT); if (!$filtersubcategories) { return $finalelements; diff --git a/components/filters/user/plugin.class.php b/components/filters/user/plugin.class.php index 46373b42..6dcf8c01 100644 --- a/components/filters/user/plugin.class.php +++ b/components/filters/user/plugin.class.php @@ -25,8 +25,19 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_user + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_user extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; @@ -44,7 +55,13 @@ public function summary(object $data): string { return get_string('filteruser_summary', 'block_configurable_reports'); } - public function execute($finalelements, $data) { + /** + * Execute + * + * @param string $finalelements + * @return array|string|string[] + */ + public function execute($finalelements) { $filteruser = optional_param('filter_user', 0, PARAM_INT); if (!$filteruser) { return $finalelements; diff --git a/components/filters/users/plugin.class.php b/components/filters/users/plugin.class.php index 897ac0fe..f4159977 100755 --- a/components/filters/users/plugin.class.php +++ b/components/filters/users/plugin.class.php @@ -25,8 +25,19 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_users + * + * @package block_configurable_reports + * @author Juan leyva + */ class plugin_users extends plugin_base { + /** + * Init + * + * @return void + */ public function init(): void { $this->form = false; $this->unique = true; diff --git a/components/permissions/component.class.php b/components/permissions/component.class.php index 49556540..fbfa1eb5 100755 --- a/components/permissions/component.class.php +++ b/components/permissions/component.class.php @@ -70,7 +70,7 @@ public function form_process_data(moodleform $cform) { /** * Add missing conditions. * - * @param $cond + * @param string $cond * @return array|mixed|string|string[]|null */ public function add_missing_conditions($cond) { @@ -106,7 +106,9 @@ public function add_missing_conditions($cond) { } /** - * @param $cform + * Form set data + * + * @param moodleform $cform * @return void */ public function form_set_data(moodleform $cform) { diff --git a/components/permissions/puserfield/plugin.class.php b/components/permissions/puserfield/plugin.class.php index de2da076..a9629991 100755 --- a/components/permissions/puserfield/plugin.class.php +++ b/components/permissions/puserfield/plugin.class.php @@ -66,9 +66,9 @@ public function summary(object $data): string { /** * Execute * - * @param $userid - * @param $context - * @param $data + * @param int $userid + * @param object $context + * @param object $data * @return bool */ public function execute($userid, $context, $data): bool { diff --git a/components/plot/line/form.php b/components/plot/line/form.php index fc1f1b22..fc8b845a 100755 --- a/components/plot/line/form.php +++ b/components/plot/line/form.php @@ -14,24 +14,39 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Configurable Reports a Moodle block for creating customizable reports + * + * @copyright 2020 Juan Leyva + * @package block_configurable_reports + * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class line_form + * + * @package block_configurable_reports + * @author Juan leyva + */ class line_form extends moodleform { /** * Form definition */ public function definition(): void { - global $DB, $USER, $CFG; + global $CFG; $mform =& $this->_form; $options = [0 => get_string('choose')]; $report = $this->_customdata['report']; - if ($report->type != 'sql') { + if ($report->type !== 'sql') { $components = cr_unserialize($this->_customdata['report']->components); if (!is_array($components) || empty($components['columns']['elements'])) { diff --git a/components/plot/pie/plugin.class.php b/components/plot/pie/plugin.class.php index cff9cc05..737343ab 100755 --- a/components/plot/pie/plugin.class.php +++ b/components/plot/pie/plugin.class.php @@ -22,6 +22,7 @@ * @author Juan leyva * @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'); @@ -58,9 +59,9 @@ public function summary(object $data): string { /** * Execute * - * @param $id - * @param $data - * @param $finalreport + * @param int $id + * @param object $data + * @param object $finalreport * @return string */ public function execute($id, $data, $finalreport) { @@ -151,6 +152,8 @@ public function execute($id, $data, $finalreport) { } /** + * get_series + * * @return array */ public function get_series(): array { @@ -161,6 +164,8 @@ public function get_series(): array { } /** + * get_color_palette + * * @return array|string[]|null */ public function get_color_palette(): ?array { diff --git a/edit_form.php b/edit_form.php index 5a3360d5..220cb4a8 100644 --- a/edit_form.php +++ b/edit_form.php @@ -20,13 +20,21 @@ * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Class block_configurable_reports_edit_form + * + * @package block_configurable_reports + * @author Juan leyva */ class block_configurable_reports_edit_form extends block_edit_form { /** * specific_definition * - * @param $mform + * @param moodleform $mform * @return void */ protected function specific_definition($mform) { diff --git a/export/csv/export.php b/export/csv/export.php index bd2fce1f..3f411cba 100755 --- a/export/csv/export.php +++ b/export/csv/export.php @@ -26,7 +26,7 @@ /** * export_report * - * @param $report + * @param object $report * @return void */ function export_report($report) { diff --git a/export/ods/export.php b/export/ods/export.php index b24306fb..6a4538f1 100755 --- a/export/ods/export.php +++ b/export/ods/export.php @@ -26,7 +26,7 @@ /** * Export report * - * @param $report + * @param object $report * @return void */ function export_report($report) { diff --git a/export/xls/export.php b/export/xls/export.php index 504ca343..253f5997 100755 --- a/export/xls/export.php +++ b/export/xls/export.php @@ -26,7 +26,7 @@ /** * Export report * - * @param $report + * @param object $report * @return void */ function export_report($report) { diff --git a/lang/en/block_configurable_reports.php b/lang/en/block_configurable_reports.php index a43ce57b..e9fd3c2c 100644 --- a/lang/en/block_configurable_reports.php +++ b/lang/en/block_configurable_reports.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Configurable Reports a Moodle block for creating customizable reports + * + * @copyright 2020 Juan Leyva + * @package block_configurable_reports + * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + $string['pluginname'] = "Configurable Reports"; $string['blockname'] = "Configurable Reports"; $string['report_courses'] = "Courses report"; diff --git a/locallib.php b/locallib.php index caa9261f..eae262b2 100755 --- a/locallib.php +++ b/locallib.php @@ -457,7 +457,7 @@ class=\"$table->class boxalign$table->tablealign\" $tableid>\n"; * table_to_excel * * @param string $filename - * @param $table + * @param object $table * @return void */ function table_to_excel(string $filename, $table) { @@ -677,7 +677,7 @@ function cr_logging_info(): array { /** * Check if the current user is allowed to manage sql reports. * - * @param $context + * @param context $context * @return bool */ function block_configurable_reports_can_managesqlreports($context): bool { diff --git a/managereport.php b/managereport.php index 3345b496..08abd4b7 100755 --- a/managereport.php +++ b/managereport.php @@ -15,6 +15,9 @@ // along with Moodle. If not, see . /** + * Configurable Reports a Moodle block for creating customizable reports + * + * @copyright 2020 Juan Leyva * @package block_configurable_reports * @author Juan leyva * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later diff --git a/plugin.class.php b/plugin.class.php index 46cae01b..44ff2a40 100755 --- a/plugin.class.php +++ b/plugin.class.php @@ -37,7 +37,7 @@ abstract class plugin_base { /** * @var string */ - public $fullname = ''; + public string $fullname = ''; /** * @var string @@ -52,7 +52,7 @@ abstract class plugin_base { /** * @var bool */ - public $form = false; + public bool $form = false; /** * @var array @@ -62,12 +62,12 @@ abstract class plugin_base { /** * @var bool */ - public $unique = false; + public bool $unique = false; /** * @var array */ - public $reporttypes = []; + public array $reporttypes = []; /** * @var true @@ -75,7 +75,9 @@ abstract class plugin_base { public bool $ordering; /** - * @param $report + * __construct + * + * @param int|object $report */ public function __construct($report) { global $DB; @@ -110,7 +112,7 @@ public function init(): void { /** * colformat * - * @param object| null $data + * @param object|null $data * @return string[] */ public function colformat(?object $data): array { diff --git a/report.class.php b/report.class.php index 833276d4..3ea79c0e 100755 --- a/report.class.php +++ b/report.class.php @@ -418,7 +418,7 @@ public function evaluate_conditions(array $data, string $logic) { /** * get_graphs * - * @param $finalreport + * @param array $finalreport * @return array */ public function get_graphs($finalreport): array { @@ -511,7 +511,7 @@ public function get_calcs(array $finaltable, array $tablehead): array { /** * elements_by_conditions * - * @param $conditions + * @param array $conditions * @return bool|mixed|null */ public function elements_by_conditions($conditions) { @@ -768,7 +768,7 @@ public function add_jsordering(moodle_page $moodlepage): void { /** * print_template * - * @param $config + * @param object $config * @param moodle_page $moodlepage * @return void */ diff --git a/reports/evalwise.class.php b/reports/evalwise.class.php index 28517eab..a99f8649 100755 --- a/reports/evalwise.class.php +++ b/reports/evalwise.class.php @@ -54,10 +54,10 @@ public function set_data($data): void { * pfx * * @param $tokens - * @param $vars + * @param array $vars * @return array|false|mixed|null */ - public function pfx($tokens, $vars = []) { + public function pfx($tokens, array $vars = []) { if ($tokens === false) { return false; @@ -108,7 +108,8 @@ public function pfx($tokens, $vars = []) { return $this->trigger("internal error"); } $stack->push($res); - } else if (array_key_exists($fnn, $this->f)) { // User function. + } else if (array_key_exists($fnn, $this->f)) { + // User function. // Get args. $args = []; for ($i = count($this->f[$fnn]['args']) - 1; $i >= 0; $i--) { @@ -117,7 +118,7 @@ public function pfx($tokens, $vars = []) { } } - // Yay...recursion! + // Yay recursion! $stack->push($this->pfx($this->f[$fnn]['func'], $args)); } } else if (in_array($token, ['+', '-', '*', '/', '^'], true)) { @@ -169,11 +170,8 @@ public function pfx($tokens, $vars = []) { } $last = $stack->pop(); - if (isset($this->data[$last])) { - return $this->data[$last]; - } - return false; + return $this->data[$last] ?? false; } } diff --git a/reports/sql/report.class.php b/reports/sql/report.class.php index 3e110438..bf8f347e 100644 --- a/reports/sql/report.class.php +++ b/reports/sql/report.class.php @@ -75,6 +75,8 @@ public function init(): void { } /** + * prepare_sql + * * @param string $sql * @return array|string|string[] */ @@ -144,6 +146,8 @@ public function execute_query($sql) { } /** + * create_report + * * @return bool */ public function create_report(): bool { @@ -224,4 +228,3 @@ public function create_report(): bool { } } - diff --git a/settings.php b/settings.php index b94d172f..ae3a27f4 100755 --- a/settings.php +++ b/settings.php @@ -14,6 +14,15 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . +/** + * Configurable Reports a Moodle block for creating customizable reports + * + * @copyright 2020 Juan Leyva + * @package block_configurable_reports + * @author Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + defined('MOODLE_INTERNAL') || die; if ($ADMIN->fulltree) {