From 006556218e0f41df4def5f58a18dfb0f07bb07d8 Mon Sep 17 00:00:00 2001 From: Luuk Verhoeven Date: Wed, 6 Dec 2023 23:01:33 +0100 Subject: [PATCH] Refactor for MOODLE41 --- README.txt | 9 + block_configurable_reports.php | 11 +- component.class.php | 16 +- components/calcs/average/plugin.class.php | 10 +- components/calcs/component.class.php | 38 +++- components/calcs/max/plugin.class.php | 18 +- components/calcs/min/form.php | 23 ++- components/calcs/min/plugin.class.php | 18 +- components/calcs/percent/form.php | 7 +- components/calcs/percent/plugin.class.php | 16 +- components/calcs/sum/form.php | 7 + components/calcs/sum/plugin.class.php | 27 ++- components/cohorts/plugin.class.php | 109 ++++++----- components/columns/categoryfield/form.php | 2 +- .../columns/categoryfield/plugin.class.php | 30 ++- components/columns/component.class.php | 6 +- components/columns/coursefield/form.php | 17 +- .../columns/coursefield/plugin.class.php | 12 +- components/columns/coursestats/form.php | 24 +-- .../columns/coursestats/plugin.class.php | 14 +- .../columns/currentuserfinalgrade/form.php | 17 +- .../currentuserfinalgrade/plugin.class.php | 14 +- components/columns/date/form.php | 15 +- components/columns/date/plugin.class.php | 14 +- .../finalgradeincurrentcourse/form.php | 17 +- .../plugin.class.php | 14 +- components/columns/form.php | 17 +- components/columns/reportcolumn/form.php | 19 +- .../columns/reportcolumn/plugin.class.php | 16 +- components/columns/roleusersn/form.php | 17 +- .../columns/roleusersn/plugin.class.php | 14 +- components/columns/usercompletion/form.php | 29 +-- .../columns/usercompletion/plugin.class.php | 14 +- components/columns/userfield/form.php | 28 +-- components/columns/userfield/plugin.class.php | 14 +- components/columns/usermodactions/form.php | 17 +- .../columns/usermodactions/plugin.class.php | 14 +- components/columns/usermodoutline/form.php | 17 +- .../columns/usermodoutline/plugin.class.php | 14 +- components/columns/userstats/form.php | 17 +- components/columns/userstats/plugin.class.php | 14 +- .../competencyframeworks/plugin.class.php | 48 +++-- .../competencytemplates/plugin.class.php | 18 +- components/conditions/ccoursefield/form.php | 12 +- .../conditions/ccoursefield/plugin.class.php | 14 +- components/conditions/component.class.php | 6 +- components/conditions/coursecategory/form.php | 10 +- .../coursecategory/plugin.class.php | 14 +- components/conditions/coursechild/form.php | 19 +- .../conditions/coursechild/plugin.class.php | 14 +- components/conditions/courseparent/form.php | 10 +- .../conditions/courseparent/plugin.class.php | 14 +- .../currentreportcourse/plugin.class.php | 14 +- .../conditions/currentuser/plugin.class.php | 14 +- .../currentusercourses/plugin.class.php | 14 +- components/conditions/cuserfield/form.php | 17 +- .../conditions/cuserfield/plugin.class.php | 14 +- components/conditions/form.php | 17 +- components/conditions/parentcategory/form.php | 15 +- .../parentcategory/plugin.class.php | 14 +- components/conditions/usersincohorts/form.php | 15 +- .../usersincohorts/plugin.class.php | 14 +- .../conditions/usersincurrentcourse/form.php | 15 +- .../usersincurrentcourse/plugin.class.php | 14 +- components/customsql/component.class.php | 6 +- components/customsql/form.php | 19 +- .../filters/categories/plugin.class.php | 18 +- components/filters/component.class.php | 6 +- .../filters/coursecategories/plugin.class.php | 14 +- .../filters/coursemodules/plugin.class.php | 18 +- components/filters/courses/plugin.class.php | 18 +- .../filters/enrolledstudents/plugin.class.php | 37 ++-- components/filters/fcoursefield/form.php | 20 +- .../filters/fcoursefield/plugin.class.php | 16 +- components/filters/fsearchuserfield/form.php | 27 +-- .../filters/fsearchuserfield/plugin.class.php | 16 +- components/filters/fuserfield/form.php | 18 +- .../filters/fuserfield/plugin.class.php | 18 +- components/filters/role/plugin.class.php | 22 ++- components/filters/searchtext/form.php | 11 +- .../filters/searchtext/plugin.class.php | 26 ++- components/filters/semester/plugin.class.php | 18 +- .../filters/startendtime/plugin.class.php | 20 +- .../filters/subcategories/plugin.class.php | 18 +- components/filters/user/plugin.class.php | 18 +- components/filters/users/plugin.class.php | 18 +- .../filters/yearhebrew/plugin.class.php | 18 +- .../filters/yearnumeric/plugin.class.php | 18 +- .../ordering/categoryfieldorder/form.php | 15 +- .../categoryfieldorder/plugin.class.php | 14 +- components/ordering/component.class.php | 6 +- components/ordering/coursefieldorder/form.php | 15 +- .../coursefieldorder/plugin.class.php | 14 +- components/ordering/userfieldorder/form.php | 15 +- .../ordering/userfieldorder/plugin.class.php | 14 +- .../permissions/anyone/plugin.class.php | 14 +- components/permissions/component.class.php | 23 ++- components/permissions/form.php | 17 +- components/permissions/puserfield/form.php | 17 +- .../permissions/puserfield/plugin.class.php | 14 +- .../reportscapabilities/plugin.class.php | 14 +- components/permissions/roleincourse/form.php | 15 +- .../permissions/roleincourse/plugin.class.php | 14 +- .../usersincoursereport/plugin.class.php | 38 +++- components/plot/bar/form.php | 13 +- components/plot/bar/graph.php | 10 +- components/plot/bar/plugin.class.php | 14 +- components/plot/component.class.php | 6 +- components/plot/line/form.php | 15 +- components/plot/line/graph.php | 10 +- components/plot/line/plugin.class.php | 14 +- components/plot/pie/form.php | 13 +- components/plot/pie/graph.php | 10 +- components/plot/pie/plugin.class.php | 14 +- components/template/component.class.php | 6 +- components/template/form.php | 17 +- components/timeline/component.class.php | 6 +- components/timeline/form.php | 17 +- db/access.php | 9 +- db/upgrade.php | 6 + edit_form.php | 8 +- editcomp.php | 11 +- editplugin.php | 5 +- editreport.php | 93 +++------ environment.xml | 6 + export.php | 6 +- filter_form.php | 32 +++- get_remote_report.php | 2 +- import_form.php | 25 +-- locallib.php | 181 +++++++++++++----- managereport.php | 2 +- plugin.class.php | 54 +++++- report.class.php | 136 +++++++++---- reports/categories/report.class.php | 14 +- reports/courses/report.class.php | 2 +- reports/evalwise.class.php | 54 +++++- reports/sql/report.class.php | 8 +- reports/timeline/report.class.php | 13 +- reports/users/report.class.php | 43 ++++- send_emails.php | 12 +- tabs.php | 5 +- viewreport.php | 7 - 142 files changed, 1683 insertions(+), 1035 deletions(-) create mode 100644 environment.xml diff --git a/README.txt b/README.txt index ea63174c..d03bffb3 100644 --- a/README.txt +++ b/README.txt @@ -36,9 +36,18 @@ Release date: 06.12.2023 - Add PHP 8.1 support - Move repository to https://github.com/Lesterhuis-Training-en-Consultancy/moodle-block_configurablereports - Original repository (https://github.com/jleyva/moodle-block_configurablereports) can be used for older release or use the old branches within this repository +- removed cr_add_to_log not used anymore Thanks to Lesterhuis Training & Consultancy for the contribution / Updated by Ldesign Media +TODOS: +- Namespaces for classes & autoloading +- Move all to `classe`s to `classes/` directory +- Clean up code +- Add tests +- AJAX_SCRIPT move to webservice +- unserialize() to json_decode() + 3.9.0 (2019122000) for Moodle 3.4, 3.5, 3.6, 3.7, 3.8, 3.9 Release date: Tuesday, 3 November 2020 ---------------------------------------------------------------------- diff --git a/block_configurable_reports.php b/block_configurable_reports.php index 9f536d9b..20a81cac 100755 --- a/block_configurable_reports.php +++ b/block_configurable_reports.php @@ -36,7 +36,7 @@ public function init(): void { /** * Act on instance data. */ - public function specialization() { + public function specialization() : void{ if ($this->config) { $this->title = $this->config->title ? $this->config->title : get_string('pluginname', 'block_configurable_reports'); @@ -78,15 +78,6 @@ public function has_config(): bool { return true; } - /** - * More than one instance per page? - * - * @return boolean - **/ - public function instance_allow_multiple(): bool { - return false; - } - /** * Gets the contents of the block (course view) * diff --git a/component.class.php b/component.class.php index 7677ff55..32c69e74 100755 --- a/component.class.php +++ b/component.class.php @@ -23,6 +23,8 @@ * @date 2009 */ +// TODO namespace + /** * Class component_base * @@ -30,7 +32,7 @@ * @author Juan leyva * @date 2009 */ -class component_base { +abstract class component_base { public $plugins = false; public $ordering = false; @@ -57,12 +59,14 @@ public function __construct($report) { } /** - * @param $mform - * @param $fullform - * @return bool + * add_form_elements + * + * @param MoodleQuickForm $mform + * @param string $components + * @return void */ - public function add_form_elements(&$mform, $fullform): bool { - return false; + public function add_form_elements(MoodleQuickForm $mform, string $components): void { + } } \ No newline at end of file diff --git a/components/calcs/average/plugin.class.php b/components/calcs/average/plugin.class.php index 0b98f35a..ce648af5 100755 --- a/components/calcs/average/plugin.class.php +++ b/components/calcs/average/plugin.class.php @@ -42,13 +42,19 @@ public function init(): void { $this->reporttypes = ['courses', 'users', 'sql', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $CFG; if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; diff --git a/components/calcs/component.class.php b/components/calcs/component.class.php index 830378ae..a67c085d 100755 --- a/components/calcs/component.class.php +++ b/components/calcs/component.class.php @@ -18,33 +18,53 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 + */ + +/** + * Class component_calcs + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 */ class component_calcs extends component_base { - public function init() : void { + /** + * Init + * + * @return void + */ + public function init(): void { $this->plugins = true; $this->ordering = false; $this->form = false; $this->help = true; } - public function add_form_elements(&$mform, $components) { - global $DB, $CFG; + /** + * add_form_elements + * + * @param MoodleQuickForm $mform + * @param string $components + * @return void + */ + public function add_form_elements(MoodleQuickForm $mform, string $components): void { + global $CFG; $components = cr_unserialize($components); $options = []; - if ($this->config->type != 'sql') { + if ($this->config->type !== 'sql') { if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; - $calcs = isset($components['calcs']['elements']) ? $components['calcs']['elements'] : []; + $calcs = $components['calcs']['elements'] ?? []; $columnsused = []; if ($calcs) { foreach ($calcs as $c) { @@ -67,7 +87,7 @@ public function add_form_elements(&$mform, $components) { $reportclass = new $reportclassname($this->config); $components = cr_unserialize($this->config->components); - $config = (isset($components['customsql']['config'])) ? $components['customsql']['config'] : new stdclass; + $config = $components['customsql']['config'] ?? (object) []; if (isset($config->querysql)) { diff --git a/components/calcs/max/plugin.class.php b/components/calcs/max/plugin.class.php index dc83508a..bb8173b6 100755 --- a/components/calcs/max/plugin.class.php +++ b/components/calcs/max/plugin.class.php @@ -18,29 +18,35 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_max extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('max', 'block_configurable_reports'); $this->reporttypes = ['courses', 'users', 'sql', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB, $CFG; - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; diff --git a/components/calcs/min/form.php b/components/calcs/min/form.php index f32f0b45..ce80f887 100755 --- a/components/calcs/min/form.php +++ b/components/calcs/min/form.php @@ -18,25 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class sum_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class min_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { $mform =& $this->_form; $this->_customdata['compclass']->add_form_elements($mform, $this->_customdata['report']->components); // Buttons. diff --git a/components/calcs/min/plugin.class.php b/components/calcs/min/plugin.class.php index 157e3069..5c1f6c7a 100755 --- a/components/calcs/min/plugin.class.php +++ b/components/calcs/min/plugin.class.php @@ -18,29 +18,35 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_min extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('min', 'block_configurable_reports'); $this->reporttypes = ['courses', 'users', 'sql', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB, $CFG; - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; diff --git a/components/calcs/percent/form.php b/components/calcs/percent/form.php index c80688ef..d6967b3d 100644 --- a/components/calcs/percent/form.php +++ b/components/calcs/percent/form.php @@ -33,10 +33,9 @@ class percent_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { $mform =& $this->_form; $this->_customdata['compclass']->add_form_elements($mform, $this->_customdata['report']->components); diff --git a/components/calcs/percent/plugin.class.php b/components/calcs/percent/plugin.class.php index 9220d8bb..52d987b6 100644 --- a/components/calcs/percent/plugin.class.php +++ b/components/calcs/percent/plugin.class.php @@ -27,20 +27,26 @@ class plugin_percent extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('percent', 'block_configurable_reports'); $this->reporttypes = ['courses', 'users', 'sql', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $CFG; - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; @@ -83,7 +89,7 @@ public function summary($data) { return ''; } - public function execute($rows) { + public function execute($rows): string { $result = 0; $totalrows = 0; $resultrows = 0; diff --git a/components/calcs/sum/form.php b/components/calcs/sum/form.php index 9421bdaa..72495ead 100755 --- a/components/calcs/sum/form.php +++ b/components/calcs/sum/form.php @@ -27,6 +27,13 @@ require_once($CFG->libdir . '/formslib.php'); +/** + * Class sum_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class sum_form extends moodleform { /** diff --git a/components/calcs/sum/plugin.class.php b/components/calcs/sum/plugin.class.php index 7d40895e..ccaa38b1 100755 --- a/components/calcs/sum/plugin.class.php +++ b/components/calcs/sum/plugin.class.php @@ -18,29 +18,40 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ - throw new \moodle_exception - +/** + * Class plugin_sum + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class plugin_sum extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('sum', 'block_configurable_reports'); $this->reporttypes = ['courses', 'users', 'sql', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB, $CFG; - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; diff --git a/components/cohorts/plugin.class.php b/components/cohorts/plugin.class.php index ccab19b2..6d501508 100644 --- a/components/cohorts/plugin.class.php +++ b/components/cohorts/plugin.class.php @@ -18,58 +18,49 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @author : François Parlant + * @date : 2020 */ -/** - * COHORT FILTER - * A filter for configurable reports - * - * @author: François Parlant - * @date : 2020 - */ - -/* example of report query -*********** -* Display the students from a cohort and all the courses they are enrolled in -*********** -SELECT -u.firstname AS Firstname, -u.lastname AS Lastname, -u.email AS Email, -c.fullname AS Course - -FROM prefix_course AS c -JOIN prefix_enrol AS en ON en.courseid = c.id -JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id -JOIN prefix_user AS u ON ue.userid = u.id -WHERE u.id in (SELECT u.id -FROM prefix_cohort AS h -JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid -JOIN prefix_user AS u ON hm.userid = u.id -WHERE 1=1 -%%FILTER_COHORTS:h.id%% -ORDER BY u.firstname) - -*/ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_cohorts + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class plugin_cohorts extends plugin_base { - public function init() : void { + /** + * @return void + */ + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercohorts', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercohorts_summary', 'block_configurable_reports'); } + /** + * @param $finalelements + * @param $data + * @return array|string|string[] + */ public function execute($finalelements, $data) { $filtercohorts = optional_param('filter_cohorts', 0, PARAM_INT); @@ -77,26 +68,59 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtercohorts]; - } else { - if (preg_match("/%%FILTER_COHORTS:([^%]+)%%/i", $finalelements, $output)) { - $replace = ' AND ' . $output[1] . ' = ' . $filtercohorts; + } - return str_replace('%%FILTER_COHORTS:' . $output[1] . '%%', $replace, $finalelements); - } + /** + * COHORT FILTER + * A filter for configurable reports + */ + /* example of report query + *********** + * Display the students from a cohort and all the courses they are enrolled in + *********** + SELECT + u.firstname AS Firstname, + u.lastname AS Lastname, + u.email AS Email, + c.fullname AS Course + + FROM prefix_course AS c + JOIN prefix_enrol AS en ON en.courseid = c.id + JOIN prefix_user_enrolments AS ue ON ue.enrolid = en.id + JOIN prefix_user AS u ON ue.userid = u.id + WHERE u.id in (SELECT u.id + FROM prefix_cohort AS h + JOIN prefix_cohort_members AS hm ON h.id = hm.cohortid + JOIN prefix_user AS u ON hm.userid = u.id + WHERE 1=1 + %%FILTER_COHORTS:h.id%% + ORDER BY u.firstname) + */ + + if (preg_match("/%%FILTER_COHORTS:([^%]+)%%/i", $finalelements, $output)) { + $replace = ' AND ' . $output[1] . ' = ' . $filtercohorts; + + return str_replace('%%FILTER_COHORTS:' . $output[1] . '%%', $replace, $finalelements); } return $finalelements; } + /** + * print_filter + * + * @param $mform + * @return void + */ public function print_filter(&$mform) { global $remotedb; $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; @@ -109,7 +133,6 @@ public function print_filter(&$mform) { foreach ($studentlist as $student) { $cohortslist[] = $student->userid; } - } $cohortsoptions = []; diff --git a/components/columns/categoryfield/form.php b/components/columns/categoryfield/form.php index ae7b407b..f188cdc8 100755 --- a/components/columns/categoryfield/form.php +++ b/components/columns/categoryfield/form.php @@ -38,7 +38,7 @@ class categoryfield_form extends moodleform { /** * Form definition */ - public function definition():void { + public function definition(): void { global $DB; $mform =& $this->_form; diff --git a/components/columns/categoryfield/plugin.class.php b/components/columns/categoryfield/plugin.class.php index 7e17d025..4f4ec2f5 100755 --- a/components/columns/categoryfield/plugin.class.php +++ b/components/columns/categoryfield/plugin.class.php @@ -18,30 +18,46 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_categoryfield + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class plugin_categoryfield extends plugin_base { - public function init() : void { + /** + * @return void + */ + public function init(): void { $this->fullname = get_string('categoryfield', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } public function colformat($data) { - $align = (isset($data->align)) ? $data->align : ''; - $size = (isset($data->size)) ? $data->size : ''; - $wrap = (isset($data->wrap)) ? $data->wrap : ''; + $align = $data->align ?? ''; + $size = $data->size ?? ''; + $wrap = $data->wrap ?? ''; return [$align, $size, $wrap]; } diff --git a/components/columns/component.class.php b/components/columns/component.class.php index 49568201..3eff3fb3 100755 --- a/components/columns/component.class.php +++ b/components/columns/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_columns extends component_base { - public function init() : void { + public function init(): void { $this->plugins = true; $this->ordering = true; $this->form = true; diff --git a/components/columns/coursefield/form.php b/components/columns/coursefield/form.php index 5a3bfce1..1ae27b6f 100755 --- a/components/columns/coursefield/form.php +++ b/components/columns/coursefield/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class coursefield_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -58,7 +55,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/coursefield/plugin.class.php b/components/columns/coursefield/plugin.class.php index e81553b1..79cce718 100755 --- a/components/columns/coursefield/plugin.class.php +++ b/components/columns/coursefield/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); @@ -30,7 +30,7 @@ class plugin_coursefield extends plugin_base { /** * @return void */ - public function init() : void { + public function init(): void { $this->fullname = get_string('coursefield', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; @@ -38,10 +38,12 @@ public function init() : void { } /** - * @param $data + * Summary + * + * @param object $data * @return string */ - public function summary($data) { + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/coursestats/form.php b/components/columns/coursestats/form.php index 4c36eb99..9cdcfb86 100755 --- a/components/columns/coursestats/form.php +++ b/components/columns/coursestats/form.php @@ -18,25 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} - +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class coursestats_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { + global $DB; $mform =& $this->_form; @@ -67,8 +63,8 @@ public function definition():void { } - public function validation($data, $files) : array{ - global $DB, $CFG; + public function validation($data, $files): array { + global $CFG; $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); @@ -77,7 +73,7 @@ public function validation($data, $files) : array{ $errors['stat'] = get_string('globalstatsshouldbeenabled', 'block_configurable_reports'); } - if (($data['stat'] == 'activityview' || $data['stat'] == 'activitypost') && !isset($data['roles'])) { + if (($data['stat'] === 'activityview' || $data['stat'] === 'activitypost') && !isset($data['roles'])) { $errors['roles'] = get_string('youmustselectarole', 'block_configurable_reports'); } diff --git a/components/columns/coursestats/plugin.class.php b/components/columns/coursestats/plugin.class.php index 7b6a4cbb..7b13dbed 100755 --- a/components/columns/coursestats/plugin.class.php +++ b/components/columns/coursestats/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_coursestats extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('coursestats', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/currentuserfinalgrade/form.php b/components/columns/currentuserfinalgrade/form.php index 5340299f..404a81c3 100755 --- a/components/columns/currentuserfinalgrade/form.php +++ b/components/columns/currentuserfinalgrade/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class currentuserfinalgrade_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; $this->_customdata['compclass']->add_form_elements($mform, $this); @@ -44,7 +41,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/currentuserfinalgrade/plugin.class.php b/components/columns/currentuserfinalgrade/plugin.class.php index 64272bc7..b600992c 100755 --- a/components/columns/currentuserfinalgrade/plugin.class.php +++ b/components/columns/currentuserfinalgrade/plugin.class.php @@ -18,22 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_currentuserfinalgrade extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('currentuserfinalgrade', 'block_configurable_reports'); $this->form = true; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/date/form.php b/components/columns/date/form.php index b0789be6..411c4818 100755 --- a/components/columns/date/form.php +++ b/components/columns/date/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class date_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/columns/date/plugin.class.php b/components/columns/date/plugin.class.php index 51855400..5be44a51 100755 --- a/components/columns/date/plugin.class.php +++ b/components/columns/date/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_date extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('date', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['timeline']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/finalgradeincurrentcourse/form.php b/components/columns/finalgradeincurrentcourse/form.php index 956e89a6..d95a9fd7 100755 --- a/components/columns/finalgradeincurrentcourse/form.php +++ b/components/columns/finalgradeincurrentcourse/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class finalgradeincurrentcourse_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; $this->_customdata['compclass']->add_form_elements($mform, $this); @@ -44,7 +41,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/finalgradeincurrentcourse/plugin.class.php b/components/columns/finalgradeincurrentcourse/plugin.class.php index f402c053..8d74b020 100755 --- a/components/columns/finalgradeincurrentcourse/plugin.class.php +++ b/components/columns/finalgradeincurrentcourse/plugin.class.php @@ -18,22 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_finalgradeincurrentcourse extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('finalgradeincurrentcourse', 'block_configurable_reports'); $this->form = true; $this->reporttypes = ['users']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/form.php b/components/columns/form.php index e4aa6578..609386bd 100755 --- a/components/columns/form.php +++ b/components/columns/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class columns_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -71,7 +68,7 @@ public function definition():void { $this->add_action_buttons(true, get_string('update')); } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); if (!preg_match("/^\d+%?$/i", trim($data['tablewidth']))) { diff --git a/components/columns/reportcolumn/form.php b/components/columns/reportcolumn/form.php index 40689f86..14373a5f 100755 --- a/components/columns/reportcolumn/form.php +++ b/components/columns/reportcolumn/form.php @@ -18,25 +18,22 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class reportcolumn_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { + global $CFG; $mform =& $this->_form; $mform->addElement('header', 'crformheader', get_string('reportcolumn', 'block_configurable_reports'), ''); @@ -75,7 +72,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/reportcolumn/plugin.class.php b/components/columns/reportcolumn/plugin.class.php index a2e7d48e..3b8ed689 100755 --- a/components/columns/reportcolumn/plugin.class.php +++ b/components/columns/reportcolumn/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); @@ -29,14 +29,20 @@ class plugin_reportcolumn extends plugin_base { public $reportcache = []; - public function init() : void { + public function init(): void { $this->fullname = get_string('reportcolumn', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['courses', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } @@ -128,7 +134,7 @@ public function execute($data, $row, $user, $courseid, $starttime = 0, $endtime global $DB, $CFG; if (!$report = $DB->get_record('block_configurable_reports', ['id' => $data->reportid])) { - throw new \moodle_exception('reportdoesnotexists', 'block_configurable_reports'); + throw new moodle_exception('reportdoesnotexists', 'block_configurable_reports'); } require_once($CFG->dirroot . '/blocks/configurable_reports/report.class.php'); diff --git a/components/columns/roleusersn/form.php b/components/columns/roleusersn/form.php index d6abab32..b8ad8b80 100755 --- a/components/columns/roleusersn/form.php +++ b/components/columns/roleusersn/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class roleusersn_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -58,7 +55,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/roleusersn/plugin.class.php b/components/columns/roleusersn/plugin.class.php index b372b7b2..6c3b21c4 100755 --- a/components/columns/roleusersn/plugin.class.php +++ b/components/columns/roleusersn/plugin.class.php @@ -18,20 +18,26 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class plugin_roleusersn extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('roleusersn', 'block_configurable_reports'); $this->type = 'numeric'; $this->form = true; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/usercompletion/form.php b/components/columns/usercompletion/form.php index 1008157f..82e06469 100755 --- a/components/columns/usercompletion/form.php +++ b/components/columns/usercompletion/form.php @@ -18,25 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class userstats_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class userstats_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { $mform =& $this->_form; @@ -57,11 +60,11 @@ public function definition():void { $this->add_action_buttons(true, get_string('add')); } - public function validation($data, $files) : array{ - global $DB, $CFG; + public function validation($data, $files): array { + 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/usercompletion/plugin.class.php b/components/columns/usercompletion/plugin.class.php index ee2a5639..775593d6 100755 --- a/components/columns/usercompletion/plugin.class.php +++ b/components/columns/usercompletion/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_usercompletion extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('usercompletion', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = false; $this->reporttypes = ['users']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('usercompletionsummary', 'block_configurable_reports'); } diff --git a/components/columns/userfield/form.php b/components/columns/userfield/form.php index b31d0dab..d4fcfe47 100755 --- a/components/columns/userfield/form.php +++ b/components/columns/userfield/form.php @@ -18,24 +18,27 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} - +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class userfield_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class userfield_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; $mform->addElement('header', 'crformheader', get_string('userfield', 'block_configurable_reports'), ''); @@ -52,8 +55,7 @@ public function definition():void { } } - unset($usercolumns['password']); - unset($usercolumns['sesskey']); + unset($usercolumns['password'], $usercolumns['sesskey']); $mform->addElement('select', 'column', get_string('column', 'block_configurable_reports'), $usercolumns); $this->_customdata['compclass']->add_form_elements($mform, $this); @@ -62,7 +64,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/userfield/plugin.class.php b/components/columns/userfield/plugin.class.php index 05abff58..e183367a 100755 --- a/components/columns/userfield/plugin.class.php +++ b/components/columns/userfield/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_userfield extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('userfield', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['users']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/columns/usermodactions/form.php b/components/columns/usermodactions/form.php index 5baff887..aa24750a 100755 --- a/components/columns/usermodactions/form.php +++ b/components/columns/usermodactions/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class usermodactions_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -61,7 +58,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/usermodactions/plugin.class.php b/components/columns/usermodactions/plugin.class.php index cb05df47..90b84ed2 100755 --- a/components/columns/usermodactions/plugin.class.php +++ b/components/columns/usermodactions/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_usermodactions extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('usermodactions', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['users']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; // Should be a better way to do this. if ($cm = $DB->get_record('course_modules', ['id' => $data->cmid])) { diff --git a/components/columns/usermodoutline/form.php b/components/columns/usermodoutline/form.php index 48fa03e5..9ed042e1 100755 --- a/components/columns/usermodoutline/form.php +++ b/components/columns/usermodoutline/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class usermodoutline_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -62,7 +59,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); $errors = $this->_customdata['compclass']->validate_form_elements($data, $errors); diff --git a/components/columns/usermodoutline/plugin.class.php b/components/columns/usermodoutline/plugin.class.php index d9b70efb..14f68007 100755 --- a/components/columns/usermodoutline/plugin.class.php +++ b/components/columns/usermodoutline/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_usermodoutline extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('usermodoutline', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['users']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; // Should be a better way to do this. if ($cm = $DB->get_record('course_modules', ['id' => $data->cmid])) { diff --git a/components/columns/userstats/form.php b/components/columns/userstats/form.php index d95cea84..ec367d53 100755 --- a/components/columns/userstats/form.php +++ b/components/columns/userstats/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class userstats_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -72,7 +69,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { global $DB, $CFG; $errors = parent::validation($data, $files); diff --git a/components/columns/userstats/plugin.class.php b/components/columns/userstats/plugin.class.php index f4f78195..5bc2d90b 100755 --- a/components/columns/userstats/plugin.class.php +++ b/components/columns/userstats/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_userstats extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('userstats', 'block_configurable_reports'); $this->type = 'undefined'; $this->form = true; $this->reporttypes = ['users']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return format_string($data->columname); } diff --git a/components/competencyframeworks/plugin.class.php b/components/competencyframeworks/plugin.class.php index b25482e7..9c1e346a 100644 --- a/components/competencyframeworks/plugin.class.php +++ b/components/competencyframeworks/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ /** @@ -50,19 +50,37 @@ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_competencyframeworks + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class plugin_competencyframeworks extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercompetencyframeworks', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercompetencyframeworks_summary', 'block_configurable_reports'); } + /** + * @param $finalelements + * @param $data + * @return array|string|string[] + */ public function execute($finalelements, $data) { $filtercompetencyframeworks = optional_param('filter_competencyframeworks', 0, PARAM_INT); @@ -70,26 +88,32 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtercompetencyframeworks]; - } else { - if (preg_match("/%%FILTER_COMPETENCYFRAMEWORKS:([^%]+)%%/i", $finalelements, $output)) { - $replace = ' AND ' . $output[1] . ' = ' . $filtercompetencyframeworks; + } - return str_replace('%%FILTER_COMPETENCYFRAMEWORKS:' . $output[1] . '%%', $replace, $finalelements); - } + if (preg_match("/%%FILTER_COMPETENCYFRAMEWORKS:([^%]+)%%/i", $finalelements, $output)) { + $replace = ' AND ' . $output[1] . ' = ' . $filtercompetencyframeworks; + + return str_replace('%%FILTER_COMPETENCYFRAMEWORKS:' . $output[1] . '%%', $replace, $finalelements); } return $finalelements; } + /** + * print_filter + * + * @param $mform + * @return void + */ public function print_filter(&$mform) { - global $remotedb, $COURSE, $PAGE, $CFG; + global $remotedb; $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/competencytemplates/plugin.class.php b/components/competencytemplates/plugin.class.php index 8d5e8aa2..be916d56 100644 --- a/components/competencytemplates/plugin.class.php +++ b/components/competencytemplates/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ /** @@ -44,14 +44,20 @@ class plugin_competencytemplates extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercompetencytemplates', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercompetencytemplates_summary', 'block_configurable_reports'); } @@ -62,7 +68,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtercompetencytemplates]; } else { if (preg_match("/%%FILTER_COMPETENCYTEMPLATES:([^%]+)%%/i", $finalelements, $output)) { @@ -81,7 +87,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/conditions/ccoursefield/form.php b/components/conditions/ccoursefield/form.php index 3a3fb60d..85326856 100755 --- a/components/conditions/ccoursefield/form.php +++ b/components/conditions/ccoursefield/form.php @@ -28,7 +28,7 @@ class ccoursefield_form extends moodleform { - public $allowedops = [ + public array $allowedops = [ '=' => '=', '>' => '>', '<' => '<', @@ -44,7 +44,7 @@ class ccoursefield_form extends moodleform { * Form definition */ public function definition(): void { - global $DB, $USER, $CFG; + global $DB; $mform =& $this->_form; @@ -67,6 +67,14 @@ public function definition(): void { } + /** + * Server side rules do not work for uploaded files, implement serverside rules here if needed. + * + * @param array $data array of ("fieldname"=>value) of submitted data + * @param array $files array of uploaded files "element_name"=>tmp_file_path + * @return array of "element_name"=>"error_description" if there are errors, + * or an empty array if everything is OK (true allowed for backwards compatibility too). + */ public function validation($data, $files): array { global $DB; diff --git a/components/conditions/ccoursefield/plugin.class.php b/components/conditions/ccoursefield/plugin.class.php index 7702e787..1bfa9591 100755 --- a/components/conditions/ccoursefield/plugin.class.php +++ b/components/conditions/ccoursefield/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -28,13 +28,19 @@ class plugin_ccoursefield extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('ccoursefield', 'block_configurable_reports'); $this->reporttypes = ['courses']; $this->form = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string($data->field) . ' ' . $data->operator . ' ' . $data->value; } diff --git a/components/conditions/component.class.php b/components/conditions/component.class.php index 464b23b7..ce735d5d 100755 --- a/components/conditions/component.class.php +++ b/components/conditions/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_conditions extends component_base { - public function init() : void { + public function init(): void { $this->plugins = true; $this->ordering = false; $this->form = true; diff --git a/components/conditions/coursecategory/form.php b/components/conditions/coursecategory/form.php index 87f664e0..6285dfff 100755 --- a/components/conditions/coursecategory/form.php +++ b/components/conditions/coursecategory/form.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -29,9 +29,9 @@ class coursecategory_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; require_once($CFG->dirroot . '/course/lib.php'); diff --git a/components/conditions/coursecategory/plugin.class.php b/components/conditions/coursecategory/plugin.class.php index 840daf69..02a3fd35 100755 --- a/components/conditions/coursecategory/plugin.class.php +++ b/components/conditions/coursecategory/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -28,14 +28,20 @@ class plugin_coursecategory extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('coursecategory', 'block_configurable_reports'); $this->type = 'text'; $this->form = true; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; $cat = $DB->get_record('course_categories', ['id' => $data->categoryid]); diff --git a/components/conditions/coursechild/form.php b/components/conditions/coursechild/form.php index 2b18267f..0083a813 100755 --- a/components/conditions/coursechild/form.php +++ b/components/conditions/coursechild/form.php @@ -18,21 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class coursechild_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class coursechild_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { + global $DB; $mform =& $this->_form; diff --git a/components/conditions/coursechild/plugin.class.php b/components/conditions/coursechild/plugin.class.php index c02c7392..8f43545d 100755 --- a/components/conditions/coursechild/plugin.class.php +++ b/components/conditions/coursechild/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -28,13 +28,19 @@ class plugin_coursechild extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('coursechild', 'block_configurable_reports'); $this->form = true; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; $course = $DB->get_record('course', ['id' => $data->courseid]); if ($course) { diff --git a/components/conditions/courseparent/form.php b/components/conditions/courseparent/form.php index 2ba2df67..7d4e1976 100755 --- a/components/conditions/courseparent/form.php +++ b/components/conditions/courseparent/form.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -29,9 +29,9 @@ class courseparent_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/conditions/courseparent/plugin.class.php b/components/conditions/courseparent/plugin.class.php index 2f756b20..b84e7cb4 100755 --- a/components/conditions/courseparent/plugin.class.php +++ b/components/conditions/courseparent/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -28,13 +28,19 @@ class plugin_courseparent extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('courseparent', 'block_configurable_reports'); $this->form = true; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; $course = $DB->get_record('course', ['id' => $data->courseid]); diff --git a/components/conditions/currentreportcourse/plugin.class.php b/components/conditions/currentreportcourse/plugin.class.php index 0eb68731..8289bfcf 100755 --- a/components/conditions/currentreportcourse/plugin.class.php +++ b/components/conditions/currentreportcourse/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -28,13 +28,19 @@ class plugin_currentreportcourse extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('currentreportcourse', 'block_configurable_reports'); $this->form = false; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('currentreportcourse_summary', 'block_configurable_reports'); } diff --git a/components/conditions/currentuser/plugin.class.php b/components/conditions/currentuser/plugin.class.php index bbf14286..63ba383b 100755 --- a/components/conditions/currentuser/plugin.class.php +++ b/components/conditions/currentuser/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -28,13 +28,19 @@ class plugin_currentuser extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('currentuser', 'block_configurable_reports'); $this->reporttypes = ['users']; $this->form = false; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('currentuser_summary', 'block_configurable_reports'); } diff --git a/components/conditions/currentusercourses/plugin.class.php b/components/conditions/currentusercourses/plugin.class.php index 509df05c..b7f766b0 100755 --- a/components/conditions/currentusercourses/plugin.class.php +++ b/components/conditions/currentusercourses/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; @@ -35,13 +35,19 @@ */ class plugin_currentusercourses extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('currentusercourses', 'block_configurable_reports'); $this->form = false; $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('currentusercourses_summary', 'block_configurable_reports'); } diff --git a/components/conditions/cuserfield/form.php b/components/conditions/cuserfield/form.php index 4ad1d585..141b0b9b 100755 --- a/components/conditions/cuserfield/form.php +++ b/components/conditions/cuserfield/form.php @@ -18,15 +18,12 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); @@ -45,9 +42,9 @@ class cuserfield_form extends moodleform { ]; /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -77,7 +74,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { global $DB, $db, $CFG; $errors = parent::validation($data, $files); diff --git a/components/conditions/cuserfield/plugin.class.php b/components/conditions/cuserfield/plugin.class.php index 7c5d98e8..626dd85a 100755 --- a/components/conditions/cuserfield/plugin.class.php +++ b/components/conditions/cuserfield/plugin.class.php @@ -18,22 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_cuserfield extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('cuserfield', 'block_configurable_reports'); $this->reporttypes = ['users']; $this->form = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; if (strpos($data->field, 'profile_') === 0) { diff --git a/components/conditions/form.php b/components/conditions/form.php index 3efbdb8c..75035528 100755 --- a/components/conditions/form.php +++ b/components/conditions/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class conditions_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -50,7 +47,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); // TODO - this reg expr can be improved. if (!preg_match( diff --git a/components/conditions/parentcategory/form.php b/components/conditions/parentcategory/form.php index b2ecfbbb..af179ae0 100755 --- a/components/conditions/parentcategory/form.php +++ b/components/conditions/parentcategory/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class parentcategory_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; require_once($CFG->dirroot . '/course/lib.php'); diff --git a/components/conditions/parentcategory/plugin.class.php b/components/conditions/parentcategory/plugin.class.php index c9c3da4c..70617e81 100755 --- a/components/conditions/parentcategory/plugin.class.php +++ b/components/conditions/parentcategory/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_parentcategory extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('parentcategory', 'block_configurable_reports'); $this->type = 'text'; $this->form = true; $this->reporttypes = ['categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; $cat = $DB->get_record('course_categories', ['id' => $data->categoryid]); diff --git a/components/conditions/usersincohorts/form.php b/components/conditions/usersincohorts/form.php index 81860032..77ed43ee 100755 --- a/components/conditions/usersincohorts/form.php +++ b/components/conditions/usersincohorts/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class usersincohorts_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/conditions/usersincohorts/plugin.class.php b/components/conditions/usersincohorts/plugin.class.php index ca5059c3..80f2470d 100755 --- a/components/conditions/usersincohorts/plugin.class.php +++ b/components/conditions/usersincohorts/plugin.class.php @@ -18,22 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_usersincohorts extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('usersincohorts', 'block_configurable_reports'); $this->reporttypes = ['users']; $this->form = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('usersincohorts_summary', 'block_configurable_reports'); } diff --git a/components/conditions/usersincurrentcourse/form.php b/components/conditions/usersincurrentcourse/form.php index 5397ea59..62c8297c 100755 --- a/components/conditions/usersincurrentcourse/form.php +++ b/components/conditions/usersincurrentcourse/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class usersincurrentcourse_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/conditions/usersincurrentcourse/plugin.class.php b/components/conditions/usersincurrentcourse/plugin.class.php index 33970717..a8207556 100755 --- a/components/conditions/usersincurrentcourse/plugin.class.php +++ b/components/conditions/usersincurrentcourse/plugin.class.php @@ -18,22 +18,28 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_usersincurrentcourse extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('usersincurrentcourse', 'block_configurable_reports'); $this->reporttypes = ['users']; $this->form = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('usersincurrentcourse_summary', 'block_configurable_reports'); } diff --git a/components/customsql/component.class.php b/components/customsql/component.class.php index 55b09c1c..c4ac3a9a 100755 --- a/components/customsql/component.class.php +++ b/components/customsql/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_customsql extends component_base { - public function init() : void { + public function init(): void { global $PAGE; $this->plugins = false; diff --git a/components/customsql/form.php b/components/customsql/form.php index a96fb32d..61a3894f 100644 --- a/components/customsql/form.php +++ b/components/customsql/form.php @@ -18,28 +18,25 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ // Based on Custom SQL Reports Plugin // See http://moodle.org/mod/data/view.php?d=13&rid=2884. -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class customsql_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $CFG, $COURSE; + * Form definition + */ + public function definition(): void { + global $COURSE; $mform =& $this->_form; @@ -89,7 +86,7 @@ public function definition():void { } } - public function validation($data, $files) : array{ + public function validation($data, $files): array { if (get_config('block_configurable_reports', 'sqlsecurity')) { return $this->validation_high_security($data, $files); } else { diff --git a/components/filters/categories/plugin.class.php b/components/filters/categories/plugin.class.php index 07ea35b7..3a5b68ef 100755 --- a/components/filters/categories/plugin.class.php +++ b/components/filters/categories/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_categories extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercategories', 'block_configurable_reports'); $this->reporttypes = ['categories', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercategories_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtercategories]; } else { if (preg_match("/%%FILTER_CATEGORIES:([^%]+)%%/i", $finalelements, $output)) { @@ -66,7 +72,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/component.class.php b/components/filters/component.class.php index b5c347a6..cca14b2f 100755 --- a/components/filters/component.class.php +++ b/components/filters/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_filters extends component_base { - public function init() : void { + public function init(): void { $this->plugins = true; $this->ordering = true; $this->form = false; diff --git a/components/filters/coursecategories/plugin.class.php b/components/filters/coursecategories/plugin.class.php index ff67a496..36af1f56 100755 --- a/components/filters/coursecategories/plugin.class.php +++ b/components/filters/coursecategories/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_coursecategories extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercoursecategories', 'block_configurable_reports'); $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercoursecategories_summary', 'block_configurable_reports'); } diff --git a/components/filters/coursemodules/plugin.class.php b/components/filters/coursemodules/plugin.class.php index 151f7750..c0925e36 100755 --- a/components/filters/coursemodules/plugin.class.php +++ b/components/filters/coursemodules/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_coursemodules extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercoursemodules', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercoursemodules_summary', 'block_configurable_reports'); } @@ -46,7 +52,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtercoursemoduleid]; } else { if (preg_match("/%%FILTER_COURSEMODULEID:([^%]+)%%/i", $finalelements, $output)) { @@ -75,7 +81,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/courses/plugin.class.php b/components/filters/courses/plugin.class.php index 5a7b06c9..7728e1ea 100755 --- a/components/filters/courses/plugin.class.php +++ b/components/filters/courses/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_courses extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtercourses', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtercourses_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtercourses]; } else { if (preg_match("/%%FILTER_COURSES:([^%]+)%%/i", $finalelements, $output)) { @@ -66,7 +72,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/enrolledstudents/plugin.class.php b/components/filters/enrolledstudents/plugin.class.php index 9b3f9592..3fd454af 100644 --- a/components/filters/enrolledstudents/plugin.class.php +++ b/components/filters/enrolledstudents/plugin.class.php @@ -18,23 +18,36 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_enrolledstudents + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class plugin_enrolledstudents extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filterenrolledstudents', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filterenrolledstudents_summary', 'block_configurable_reports'); } @@ -44,14 +57,14 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filterenrolledstudents]; - } else { - if (preg_match("/%%FILTER_COURSEENROLLEDSTUDENTS:([^%]+)%%/i", $finalelements, $output)) { - $replace = ' AND ' . $output[1] . ' = ' . $filterenrolledstudents; + } - return str_replace('%%FILTER_COURSEENROLLEDSTUDENTS:' . $output[1] . '%%', $replace, $finalelements); - } + if (preg_match("/%%FILTER_COURSEENROLLEDSTUDENTS:([^%]+)%%/i", $finalelements, $output)) { + $replace = ' AND ' . $output[1] . ' = ' . $filterenrolledstudents; + + return str_replace('%%FILTER_COURSEENROLLEDSTUDENTS:' . $output[1] . '%%', $replace, $finalelements); } return $finalelements; @@ -63,7 +76,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; @@ -90,7 +103,7 @@ public function print_filter(&$mform) { $nameformat = $CFG->fullnamedisplay; } - if ($nameformat == 'language') { + if ($nameformat === 'language') { $nameformat = get_string('fullnamedisplay'); } diff --git a/components/filters/fcoursefield/form.php b/components/filters/fcoursefield/form.php index 65792240..27355f3e 100755 --- a/components/filters/fcoursefield/form.php +++ b/components/filters/fcoursefield/form.php @@ -18,25 +18,22 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class fcoursefield_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $remotedb, $course, $CFG; + * Form definition + */ + public function definition(): void { + global $remotedb; $mform =& $this->_form; @@ -51,8 +48,7 @@ public function definition():void { $coursecolumns[$c->name] = $c->name; } - unset($coursecolumns['password']); - unset($coursecolumns['sesskey']); + unset($coursecolumns['password'], $coursecolumns['sesskey']); $mform->addElement('select', 'field', get_string('field', 'block_configurable_reports'), $coursecolumns); diff --git a/components/filters/fcoursefield/plugin.class.php b/components/filters/fcoursefield/plugin.class.php index 6011f51c..d65ff17c 100755 --- a/components/filters/fcoursefield/plugin.class.php +++ b/components/filters/fcoursefield/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_fcoursefield extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = true; $this->fullname = get_string('fcoursefield', 'block_configurable_reports'); $this->reporttypes = ['courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return $data->field; } @@ -68,7 +74,7 @@ public function print_filter(&$mform, $data) { } if (!isset($coursecolumns[$data->field])) { - throw new \moodle_exception('nosuchcolumn'); + throw new moodle_exception('nosuchcolumn'); } $reportclassname = 'report_' . $this->report->type; diff --git a/components/filters/fsearchuserfield/form.php b/components/filters/fsearchuserfield/form.php index dbdc8bfe..70f8a703 100755 --- a/components/filters/fsearchuserfield/form.php +++ b/components/filters/fsearchuserfield/form.php @@ -18,25 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class fsearchuserfield_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class fsearchuserfield_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $remotedb, $USER, $CFG; + * Form definition + */ + public function definition(): void { + global $remotedb; $mform =& $this->_form; @@ -57,8 +61,7 @@ public function definition():void { } } - unset($usercolumns['password']); - unset($usercolumns['sesskey']); + unset($usercolumns['password'], $usercolumns['sesskey']); $mform->addElement('select', 'field', get_string('field', 'block_configurable_reports'), $usercolumns); diff --git a/components/filters/fsearchuserfield/plugin.class.php b/components/filters/fsearchuserfield/plugin.class.php index e0c7439b..b2afcfb5 100755 --- a/components/filters/fsearchuserfield/plugin.class.php +++ b/components/filters/fsearchuserfield/plugin.class.php @@ -17,23 +17,29 @@ /** Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_fsearchuserfield extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = true; $this->fullname = get_string('fsearchuserfield', 'block_configurable_reports'); $this->reporttypes = ['users', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return $data->field; } @@ -114,7 +120,7 @@ public function print_filter(&$mform, $data) { } if (!isset($usercolumns[$data->field])) { - throw new \moodle_exception('nosuchcolumn'); + throw new moodle_exception('nosuchcolumn'); } $reportclassname = 'report_' . $this->report->type; diff --git a/components/filters/fuserfield/form.php b/components/filters/fuserfield/form.php index 4b4153cb..0b1dc9fa 100755 --- a/components/filters/fuserfield/form.php +++ b/components/filters/fuserfield/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class fuserfield_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $remotedb; @@ -58,8 +55,7 @@ public function definition():void { } } - unset($usercolumns['password']); - unset($usercolumns['sesskey']); + unset($usercolumns['password'], $usercolumns['sesskey']); $mform->addElement('select', 'field', get_string('field', 'block_configurable_reports'), $usercolumns); diff --git a/components/filters/fuserfield/plugin.class.php b/components/filters/fuserfield/plugin.class.php index d6a86f18..71778a38 100755 --- a/components/filters/fuserfield/plugin.class.php +++ b/components/filters/fuserfield/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_fuserfield extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('fuserfield', 'block_configurable_reports'); $this->reporttypes = ['users', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return $data->field; } @@ -117,7 +123,7 @@ public function print_filter(&$mform, $data) { } if (!isset($usercolumns[$data->field])) { - throw new \moodle_exception('nosuchcolumn'); + throw new moodle_exception('nosuchcolumn'); } $reportclassname = 'report_' . $this->report->type; @@ -178,7 +184,7 @@ private function sql_replace($filtersearchtext, $filterstrmatch, $finalelements) if (empty($operator)) { $operator = '~'; } else if (!in_array($operator, $operators)) { - throw new \moodle_exception('nosuchoperator'); + throw new moodle_exception('nosuchoperator'); } if ($operator == '~') { $replace = " AND " . $field . " LIKE '%" . $filtersearchtext . "%'"; diff --git a/components/filters/role/plugin.class.php b/components/filters/role/plugin.class.php index 1e73a280..f2ebe582 100755 --- a/components/filters/role/plugin.class.php +++ b/components/filters/role/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_role extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filterrole', 'block_configurable_reports'); $this->reporttypes = ['categories', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filterrole_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filterrole]; } else { if (preg_match("/%%FILTER_ROLE:([^%]+)%%/i", $finalelements, $output)) { @@ -59,9 +65,7 @@ public function execute($finalelements, $data) { } public function print_filter(&$mform) { - global $remotedb, $CFG; - - $filterrole = optional_param('filter_role', 0, PARAM_INT); + global $remotedb; $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); @@ -72,7 +76,7 @@ public function print_filter(&$mform) { $roles[$role->id] = $role->shortname; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/searchtext/form.php b/components/filters/searchtext/form.php index e959b2f8..1762064b 100644 --- a/components/filters/searchtext/form.php +++ b/components/filters/searchtext/form.php @@ -22,19 +22,16 @@ * @author David Saylor */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class searchtext_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { $mform =& $this->_form; $mform->addElement('header', 'crformheader', get_string('filter_searchtext', 'block_configurable_reports'), ''); diff --git a/components/filters/searchtext/plugin.class.php b/components/filters/searchtext/plugin.class.php index 10d2b493..9dc3f735 100644 --- a/components/filters/searchtext/plugin.class.php +++ b/components/filters/searchtext/plugin.class.php @@ -17,23 +17,29 @@ /** Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_searchtext extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('filter_searchtext', 'block_configurable_reports'); $this->reporttypes = ['searchtext', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return empty($data->idnumber) ? get_string('filter_searchtext_summary', 'block_configurable_reports') : $data->idnumber; } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { $filtersearchtext = optional_param('filter_searchtext', '', PARAM_RAW); } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtersearchtext]; } else { if ($filtersearchtext) { @@ -85,12 +91,14 @@ private function sql_replace($filtersearchtext, $filterstrmatch, $finalelements) if (preg_match("/%%$filterstrmatch:([^%]+)%%/i", $finalelements, $output)) { [$field, $operator] = preg_split('/:/', $output[1]); - if (!in_array($operator, $operators)) { - throw new \moodle_exception('nosuchoperator'); + + if (!in_array($operator, $operators, true)) { + throw new moodle_exception('nosuchoperator'); } - if ($operator == '~') { + + if ($operator === '~') { $replace = " AND " . $field . " LIKE '%" . $filtersearchtext . "%'"; - } else if ($operator == 'in') { + } else if ($operator === 'in') { $processeditems = []; // Accept comma-separated values, allowing for '\,' as a literal comma. foreach (preg_split("/(? - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_semester extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtersemester', 'block_configurable_reports'); $this->reporttypes = ['categories', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtersemester_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtersemester]; } else { if (preg_match("/%%FILTER_SEMESTER:([^%]+)%%/i", $finalelements, $output)) { @@ -69,7 +75,7 @@ public function print_filter(&$mform) { $semester[$value] = $value; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/startendtime/plugin.class.php b/components/filters/startendtime/plugin.class.php index 78315f96..a8f85489 100755 --- a/components/filters/startendtime/plugin.class.php +++ b/components/filters/startendtime/plugin.class.php @@ -18,30 +18,36 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_startendtime extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('startendtime', 'block_configurable_reports'); $this->reporttypes = ['sql', 'timeline', 'users', 'courses']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filterstartendtime_summary', 'block_configurable_reports'); } public function execute($finalelements, $data) { global $CFG; - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return $finalelements; } @@ -77,7 +83,7 @@ public function execute($finalelements, $data) { if (preg_match("/%%FILTER_STARTTIME:([^%]+)%%/i", $finalelements, $output)) { [$field, $operator] = preg_split('/:/', $output[1]); if (!in_array($operator, $operators)) { - throw new \moodle_exception('nosuchoperator'); + throw new moodle_exception('nosuchoperator'); } $replace = ' AND ' . $field . ' ' . $operator . ' ' . $filterstarttime; $finalelements = str_replace('%%FILTER_STARTTIME:' . $output[1] . '%%', $replace, $finalelements); @@ -86,7 +92,7 @@ public function execute($finalelements, $data) { if (preg_match("/%%FILTER_ENDTIME:([^%]+)%%/i", $finalelements, $output)) { [$field, $operator] = preg_split('/:/', $output[1]); if (!in_array($operator, $operators)) { - throw new \moodle_exception('nosuchoperator'); + throw new moodle_exception('nosuchoperator'); } $replace = ' AND ' . $field . ' ' . $operator . ' ' . $filterendtime; $finalelements = str_replace('%%FILTER_ENDTIME:' . $output[1] . '%%', $replace, $finalelements); diff --git a/components/filters/subcategories/plugin.class.php b/components/filters/subcategories/plugin.class.php index 6441cbd7..ddc495ad 100755 --- a/components/filters/subcategories/plugin.class.php +++ b/components/filters/subcategories/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_subcategories extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filtersubcategories', 'block_configurable_reports'); $this->reporttypes = ['categories', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filtersubcategories_summary', 'block_configurable_reports'); } @@ -44,7 +50,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filtersubcategories]; } else { if (preg_match("/%%FILTER_SUBCATEGORIES:([^%]+)%%/i", $finalelements, $output)) { @@ -68,7 +74,7 @@ public function print_filter(&$mform) { $courseoptions = []; $courseoptions[0] = get_string('filter_all', 'block_configurable_reports'); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/user/plugin.class.php b/components/filters/user/plugin.class.php index 8de4df59..975e1d8a 100644 --- a/components/filters/user/plugin.class.php +++ b/components/filters/user/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_user extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filteruser', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filteruser_summary', 'block_configurable_reports'); } @@ -44,7 +50,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filteruser]; } else { if (preg_match("/%%FILTER_COURSEUSER:([^%]+)%%/i", $finalelements, $output)) { @@ -63,7 +69,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; $userlist = $reportclass->elements_by_conditions($conditions); diff --git a/components/filters/users/plugin.class.php b/components/filters/users/plugin.class.php index 1f61a36b..5aa8f28d 100755 --- a/components/filters/users/plugin.class.php +++ b/components/filters/users/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_users extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filterusers', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filterusers_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filterusers]; } else { if (preg_match("/%%FILTER_SYSTEMUSER:([^%]+)%%/i", $finalelements, $output)) { @@ -64,7 +70,7 @@ public function print_filter(&$mform) { $reportclassname = 'report_' . $this->report->type; $reportclass = new $reportclassname($this->report); - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/yearhebrew/plugin.class.php b/components/filters/yearhebrew/plugin.class.php index e703a4de..d1fcb9cd 100755 --- a/components/filters/yearhebrew/plugin.class.php +++ b/components/filters/yearhebrew/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_yearhebrew extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filteryearhebrew', 'block_configurable_reports'); $this->reporttypes = ['categories', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filteryearhebrew_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filteryearhebrew]; } else { if (preg_match("/%%FILTER_YEARHEBREW:([^%]+)%%/i", $finalelements, $output)) { @@ -69,7 +75,7 @@ public function print_filter(&$mform) { $yearhebrew[$value] = $value; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/filters/yearnumeric/plugin.class.php b/components/filters/yearnumeric/plugin.class.php index fce8945d..121cb255 100755 --- a/components/filters/yearnumeric/plugin.class.php +++ b/components/filters/yearnumeric/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_yearnumeric extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('filteryearnumeric', 'block_configurable_reports'); $this->reporttypes = ['categories', 'sql']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('filteryearnumeric_summary', 'block_configurable_reports'); } @@ -45,7 +51,7 @@ public function execute($finalelements, $data) { return $finalelements; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { return [$filteryearnumeric]; } else { if (preg_match("/%%FILTER_YEARNUMERIC:([^%]+)%%/i", $finalelements, $output)) { @@ -71,7 +77,7 @@ public function print_filter(&$mform) { $yearnumeric[$year] = $year; } - if ($this->report->type != 'sql') { + if ($this->report->type !== 'sql') { $components = cr_unserialize($this->report->components); $conditions = $components['conditions']; diff --git a/components/ordering/categoryfieldorder/form.php b/components/ordering/categoryfieldorder/form.php index d37cfcb5..e25fac0d 100755 --- a/components/ordering/categoryfieldorder/form.php +++ b/components/ordering/categoryfieldorder/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class categoryfieldorder_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/ordering/categoryfieldorder/plugin.class.php b/components/ordering/categoryfieldorder/plugin.class.php index 9d1c2197..c8e90866 100755 --- a/components/ordering/categoryfieldorder/plugin.class.php +++ b/components/ordering/categoryfieldorder/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); @@ -29,7 +29,7 @@ class plugin_categoryfieldorder extends plugin_base { public $sql = true; - public function init() : void { + public function init(): void { $this->fullname = get_string('categoryfield', 'block_configurable_reports'); $this->form = true; $this->unique = true; @@ -37,7 +37,13 @@ public function init() : void { $this->sql = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return $data->column . ' ' . (strtoupper($data->direction)); } diff --git a/components/ordering/component.class.php b/components/ordering/component.class.php index 14e5b517..cc395a32 100755 --- a/components/ordering/component.class.php +++ b/components/ordering/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_ordering extends component_base { - public function init() : void { + public function init(): void { $this->plugins = true; $this->ordering = false; $this->form = false; diff --git a/components/ordering/coursefieldorder/form.php b/components/ordering/coursefieldorder/form.php index 39ad7444..712d3f9c 100755 --- a/components/ordering/coursefieldorder/form.php +++ b/components/ordering/coursefieldorder/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class coursefieldorder_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/ordering/coursefieldorder/plugin.class.php b/components/ordering/coursefieldorder/plugin.class.php index 17c293dd..09bee0c6 100755 --- a/components/ordering/coursefieldorder/plugin.class.php +++ b/components/ordering/coursefieldorder/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); @@ -29,7 +29,7 @@ class plugin_coursefieldorder extends plugin_base { public $sql = true; - public function init() : void { + public function init(): void { $this->fullname = get_string('coursefield', 'block_configurable_reports'); $this->form = true; $this->unique = true; @@ -37,7 +37,13 @@ public function init() : void { $this->sql = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string($data->column) . ' ' . (strtoupper($data->direction)); } diff --git a/components/ordering/userfieldorder/form.php b/components/ordering/userfieldorder/form.php index a3381a71..3a9b8bb9 100755 --- a/components/ordering/userfieldorder/form.php +++ b/components/ordering/userfieldorder/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class userfieldorder_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/ordering/userfieldorder/plugin.class.php b/components/ordering/userfieldorder/plugin.class.php index 6752a263..cbca913e 100755 --- a/components/ordering/userfieldorder/plugin.class.php +++ b/components/ordering/userfieldorder/plugin.class.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); @@ -29,7 +29,7 @@ class plugin_userfieldorder extends plugin_base { public $sql = true; - public function init() : void { + public function init(): void { $this->fullname = get_string('userfield', 'block_configurable_reports'); $this->form = true; $this->unique = true; @@ -37,7 +37,13 @@ public function init() : void { $this->sql = true; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string($data->column) . ' ' . (strtoupper($data->direction)); } diff --git a/components/permissions/anyone/plugin.class.php b/components/permissions/anyone/plugin.class.php index 1bd4cd93..66f90086 100755 --- a/components/permissions/anyone/plugin.class.php +++ b/components/permissions/anyone/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_anyone extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('anyone', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('anyone_summary', 'block_configurable_reports'); } diff --git a/components/permissions/component.class.php b/components/permissions/component.class.php index bd11e36b..3df45079 100755 --- a/components/permissions/component.class.php +++ b/components/permissions/component.class.php @@ -18,13 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 + */ + +/** + * Class component_permissions + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 */ class component_permissions extends component_base { - public function init() : void { + public function init(): void { $this->plugins = true; $this->ordering = false; $this->form = true; @@ -79,14 +87,17 @@ public function add_missing_conditions($cond) { } + /** + * @param $cform + * @return void + */ public function form_set_data(&$cform) { global $DB; if ($this->form) { $fdata = new stdclass; $components = cr_unserialize($this->config->components); - $conditionsconfig = - (isset($components['permissions']['config'])) ? $components['permissions']['config'] : new stdclass; + $conditionsconfig = (object) ($components['permissions']['config'] ?? []); if (!isset($conditionsconfig->conditionexpr)) { $fdata->conditionexpr = ''; @@ -102,8 +113,8 @@ public function form_set_data(&$cform) { if (!array_key_exists('config', $components['permissions'])) { $components['permissions']['config'] = new StdClass; } - $components['permissions']['config']->conditionexpr = $fdata->conditionexpr; + $this->config->components = cr_serialize($components); $DB->update_record('block_configurable_reports', $this->config); diff --git a/components/permissions/form.php b/components/permissions/form.php index ff518fd7..5a479750 100755 --- a/components/permissions/form.php +++ b/components/permissions/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class permissions_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -49,7 +46,7 @@ public function definition():void { $this->add_action_buttons(true, get_string('update')); } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); // TODO - this reg expr can be improved. $regex = "/(\(*\s*\bc\d{1,2}\b\s*\(*\)*\s*(\(|and|or)\s*)+\(*\s*\bc\d{1,2}\b\s*\(*\)*\s*$/i"; diff --git a/components/permissions/puserfield/form.php b/components/permissions/puserfield/form.php index 1598340d..fb214795 100755 --- a/components/permissions/puserfield/form.php +++ b/components/permissions/puserfield/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class puserfield_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -69,7 +66,7 @@ public function definition():void { } - public function validation($data, $files) : array{ + public function validation($data, $files): array { global $DB, $db, $CFG; $errors = parent::validation($data, $files); diff --git a/components/permissions/puserfield/plugin.class.php b/components/permissions/puserfield/plugin.class.php index 91735feb..e3a50c04 100755 --- a/components/permissions/puserfield/plugin.class.php +++ b/components/permissions/puserfield/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_puserfield extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('puserfield', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; if (strpos($data->field, 'profile_') === 0) { diff --git a/components/permissions/reportscapabilities/plugin.class.php b/components/permissions/reportscapabilities/plugin.class.php index 3010b23a..7f488486 100755 --- a/components/permissions/reportscapabilities/plugin.class.php +++ b/components/permissions/reportscapabilities/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_reportscapabilities extends plugin_base { - public function init() : void { + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('reportscapabilities', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('reportscapabilities_summary', 'block_configurable_reports'); } diff --git a/components/permissions/roleincourse/form.php b/components/permissions/roleincourse/form.php index 42e2aaee..5bc2fb41 100755 --- a/components/permissions/roleincourse/form.php +++ b/components/permissions/roleincourse/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class roleincourse_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; diff --git a/components/permissions/roleincourse/plugin.class.php b/components/permissions/roleincourse/plugin.class.php index 3760caed..cbb6a954 100755 --- a/components/permissions/roleincourse/plugin.class.php +++ b/components/permissions/roleincourse/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_roleincourse extends plugin_base { - public function init() : void { + public function init(): void { $this->form = true; $this->unique = false; $this->fullname = get_string('roleincourse', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { global $DB; $rolename = $DB->get_field('role', 'shortname', ['id' => $data->roleid]); diff --git a/components/permissions/usersincoursereport/plugin.class.php b/components/permissions/usersincoursereport/plugin.class.php index 35fb8fa7..7a60c4b7 100755 --- a/components/permissions/usersincoursereport/plugin.class.php +++ b/components/permissions/usersincoursereport/plugin.class.php @@ -18,30 +18,56 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); +/** + * Class plugin_usersincoursereport + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class plugin_usersincoursereport extends plugin_base { - function init() { + /** + * Init + * + * @return void + */ + public function init(): void { $this->form = false; $this->unique = true; $this->fullname = get_string('usersincoursereport', 'block_configurable_reports'); $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('usersincoursereport_summary', 'block_configurable_reports'); } - public function execute($userid, $context, $data) { + /** + * execute + * + * @param int $userid + * @param $context + * @param $data + * @return bool + */ + public function execute(int $userid, $context, $data) { // Everyone should be enrolled at the system level. - if ($context == context_system::instance()) { + if ($context === context_system::instance()) { return true; } diff --git a/components/plot/bar/form.php b/components/plot/bar/form.php index 26f3063a..288c6106 100755 --- a/components/plot/bar/form.php +++ b/components/plot/bar/form.php @@ -14,19 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class bar_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -37,7 +34,7 @@ public function definition():void { $components = cr_unserialize($this->_customdata['report']->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; diff --git a/components/plot/bar/graph.php b/components/plot/bar/graph.php index 488c4a08..45ae2988 100644 --- a/components/plot/bar/graph.php +++ b/components/plot/bar/graph.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ require_once("../../../../../config.php"); @@ -32,13 +32,13 @@ $reportid = required_param('reportid', PARAM_INT); if (!$report = $DB->get_record('block_configurable_reports', ['id' => $reportid])) { - throw new \moodle_exception('reportdoesnotexists'); + throw new moodle_exception('reportdoesnotexists'); } $courseid = $report->courseid; if (!$course = $DB->get_record('course', ['id' => $courseid])) { - throw new \moodle_exception('No such course id'); + throw new moodle_exception('No such course id'); } // Force user login in course (SITE or Course). @@ -56,7 +56,7 @@ $reportclass = new $reportclassname($report); if (!$reportclass->check_permissions($USER->id, $context)) { - throw new \moodle_exception("No permissions"); + throw new moodle_exception("No permissions"); } else { $components = cr_unserialize($report->components); $graphs = $components['plot']['elements']; diff --git a/components/plot/bar/plugin.class.php b/components/plot/bar/plugin.class.php index 6b338343..5ee99cce 100755 --- a/components/plot/bar/plugin.class.php +++ b/components/plot/bar/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_bar extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = "Bar chart"; $this->form = true; $this->ordering = true; $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return "Bar chart summary"; } diff --git a/components/plot/component.class.php b/components/plot/component.class.php index a947a766..438811df 100755 --- a/components/plot/component.class.php +++ b/components/plot/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_plot extends component_base { - public function init() : void { + public function init(): void { $this->plugins = true; $this->ordering = true; $this->form = false; diff --git a/components/plot/line/form.php b/components/plot/line/form.php index d59b4952..e80eef2f 100755 --- a/components/plot/line/form.php +++ b/components/plot/line/form.php @@ -14,19 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class line_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -38,7 +35,7 @@ public function definition():void { $components = cr_unserialize($this->_customdata['report']->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; @@ -90,7 +87,7 @@ public function definition():void { $this->add_action_buttons(true, get_string('add')); } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); if ($data['xaxis'] == $data['yaxis']) { diff --git a/components/plot/line/graph.php b/components/plot/line/graph.php index 7357f125..d7f74012 100755 --- a/components/plot/line/graph.php +++ b/components/plot/line/graph.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ require_once("../../../../../config.php"); @@ -35,13 +35,13 @@ $reportid = required_param('reportid', PARAM_INT); if (!$report = $DB->get_record('block_configurable_reports', ['id' => $reportid])) { - throw new \moodle_exception('reportdoesnotexists'); + throw new moodle_exception('reportdoesnotexists'); } $courseid = $report->courseid; if (!$course = $DB->get_record('course', ['id' => $courseid])) { - throw new \moodle_exception('No such course id'); + throw new moodle_exception('No such course id'); } // Force user login in course (SITE or Course). @@ -60,7 +60,7 @@ $reportclass = new $reportclassname($report); if (!$reportclass->check_permissions($USER->id, $context)) { - throw new \moodle_exception("No permissions"); + throw new moodle_exception("No permissions"); } else { $components = cr_unserialize($report->components); diff --git a/components/plot/line/plugin.class.php b/components/plot/line/plugin.class.php index 2ced6dc5..a771fc3e 100755 --- a/components/plot/line/plugin.class.php +++ b/components/plot/line/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_line extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('line', 'block_configurable_reports'); $this->form = true; $this->ordering = true; $this->reporttypes = ['timeline', 'sql', 'timeline']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('linesummary', 'block_configurable_reports'); } diff --git a/components/plot/pie/form.php b/components/plot/pie/form.php index c1a398eb..5f5e172f 100755 --- a/components/plot/pie/form.php +++ b/components/plot/pie/form.php @@ -14,19 +14,16 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class pie_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $USER, $CFG; $mform =& $this->_form; @@ -38,7 +35,7 @@ public function definition():void { $components = cr_unserialize($this->_customdata['report']->components); if (!is_array($components) || empty($components['columns']['elements'])) { - throw new \moodle_exception('nocolumns'); + throw new moodle_exception('nocolumns'); } $columns = $components['columns']['elements']; diff --git a/components/plot/pie/graph.php b/components/plot/pie/graph.php index cb4ec4af..00597032 100755 --- a/components/plot/pie/graph.php +++ b/components/plot/pie/graph.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ require_once("../../../../../config.php"); @@ -35,13 +35,13 @@ $reportid = required_param('reportid', PARAM_INT); if (!$report = $DB->get_record('block_configurable_reports', ['id' => $reportid])) { - throw new \moodle_exception('reportdoesnotexists'); + throw new moodle_exception('reportdoesnotexists'); } $courseid = $report->courseid; if (!$course = $DB->get_record('course', ['id' => $courseid])) { - throw new \moodle_exception("No such course id"); + throw new moodle_exception("No such course id"); } // Force user login in course (SITE or Course). @@ -60,7 +60,7 @@ $reportclass = new $reportclassname($report); if (!$reportclass->check_permissions($USER->id, $context)) { - throw new \moodle_exception("No permissions"); + throw new moodle_exception("No permissions"); } else { $components = cr_unserialize($report->components); diff --git a/components/plot/pie/plugin.class.php b/components/plot/pie/plugin.class.php index 79ea646f..4c3fe0fc 100755 --- a/components/plot/pie/plugin.class.php +++ b/components/plot/pie/plugin.class.php @@ -18,23 +18,29 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ defined('MOODLE_INTERNAL') || die; require_once($CFG->dirroot . '/blocks/configurable_reports/plugin.class.php'); class plugin_pie extends plugin_base { - public function init() : void { + public function init(): void { $this->fullname = get_string('pie', 'block_configurable_reports'); $this->form = true; $this->ordering = true; $this->reporttypes = ['courses', 'sql', 'users', 'timeline', 'categories']; } - public function summary($data) { + /** + * Summary + * + * @param object $data + * @return string + */ + public function summary(object $data): string { return get_string('piesummary', 'block_configurable_reports'); } diff --git a/components/template/component.class.php b/components/template/component.class.php index fa55dba4..dc8a107a 100755 --- a/components/template/component.class.php +++ b/components/template/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_template extends component_base { - public function init() : void { + public function init(): void { $this->plugins = false; $this->ordering = false; $this->form = true; diff --git a/components/template/form.php b/components/template/form.php index 8be75dc8..c28d4034 100755 --- a/components/template/form.php +++ b/components/template/form.php @@ -18,24 +18,21 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class template_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $CFG; $mform =& $this->_form; @@ -115,7 +112,7 @@ public function definition():void { $this->add_action_buttons(); } - public function validation($data, $files) : array{ + public function validation($data, $files): array { global $DB, $CFG, $db, $USER; $errors = parent::validation($data, $files); if ($data['enabled']) { diff --git a/components/timeline/component.class.php b/components/timeline/component.class.php index fc70474f..dabe48a6 100755 --- a/components/timeline/component.class.php +++ b/components/timeline/component.class.php @@ -18,13 +18,13 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ class component_timeline extends component_base { - public function init() : void { + public function init(): void { $this->plugins = false; $this->ordering = false; $this->form = true; diff --git a/components/timeline/form.php b/components/timeline/form.php index d3341ead..fc46730e 100755 --- a/components/timeline/form.php +++ b/components/timeline/form.php @@ -18,27 +18,24 @@ * Configurable Reports * A Moodle block for creating customizable reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ // Based on Custom SQL Reports Plugin // See http://moodle.org/mod/data/view.php?d=13&rid=2884. -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); class timeline_form extends moodleform { /** -* Form definition -*/ -public function definition():void { + * Form definition + */ + public function definition(): void { global $DB, $CFG; $mform =& $this->_form; @@ -85,7 +82,7 @@ public function definition():void { $this->add_action_buttons(); } - public function validation($data, $files) : array{ + public function validation($data, $files): array { global $DB, $CFG, $db, $USER; $errors = parent::validation($data, $files); diff --git a/db/access.php b/db/access.php index 5d68d6d3..0c5aeb11 100644 --- a/db/access.php +++ b/db/access.php @@ -20,12 +20,11 @@ * * Configurable Reports - A Moodle block for creating customizable reports * - * @package block_configurable_reports + * @package block_configurable_reports * @author Juan leyva - * @date : 2013-09-07 - * - * @copyright Juan leyva - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + * @date 2013-09-07 + * @copyright Juan leyva + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $capabilities = [ diff --git a/db/upgrade.php b/db/upgrade.php index a9dc4b52..4f785dba 100644 --- a/db/upgrade.php +++ b/db/upgrade.php @@ -28,6 +28,12 @@ defined('MOODLE_INTERNAL') || die(); +/** + * Upgrade block configurable_reports + * + * @param int $oldversion + * @return bool + */ function xmldb_block_configurable_reports_upgrade($oldversion) { global $DB, $CFG; diff --git a/edit_form.php b/edit_form.php index f4c9b9f9..8bd49e97 100644 --- a/edit_form.php +++ b/edit_form.php @@ -24,12 +24,18 @@ */ class block_configurable_reports_edit_form extends block_edit_form { + /** + * specific_definition + * + * @param $mform + * @return void + */ protected function specific_definition($mform) { $mform->addElement('header', 'configheader', get_string('blocksettings', 'block')); $mform->addElement('text', 'config_title', get_string('name')); - $mform->setType('config_title', PARAM_MULTILANG); + $mform->setType('config_title', PARAM_TEXT); $mform->setDefault('config_title', get_string('pluginname', 'block_configurable_reports')); $mform->addElement( diff --git a/editcomp.php b/editcomp.php index c2d16725..e6e5cf76 100644 --- a/editcomp.php +++ b/editcomp.php @@ -72,7 +72,7 @@ throw new \moodle_exception('badpermissions'); } -if ($report->type == 'sql' && !block_configurable_reports_can_managesqlreports($context)) { +if ($report->type === 'sql' && !block_configurable_reports_can_managesqlreports($context)) { throw new \moodle_exception('nosqlpermissions'); } @@ -86,7 +86,7 @@ } $elements = cr_unserialize($report->components); -$elements = isset($elements[$comp]['elements']) ? $elements[$comp]['elements'] : []; +$elements = $elements[$comp]['elements'] ?? []; require_once($CFG->dirroot . '/blocks/configurable_reports/components/' . $comp . '/component.class.php'); $componentclassname = 'component_' . $comp; @@ -104,7 +104,6 @@ redirect($CFG->wwwroot . '/blocks/configurable_reports/editcomp.php?id=' . $id . '&comp=' . $comp); } else if ($data = $editform->get_data()) { $compclass->form_process_data($editform); - cr_add_to_log($courseid, 'configurable_reports', 'edit', '', $report->name); } $compclass->form_set_data($editform); @@ -197,10 +196,8 @@ $i++; } cr_print_table($table); -} else { - if ($compclass->plugins) { - echo $OUTPUT->heading(get_string('no' . $comp . 'yet', 'block_configurable_reports')); - } +} else if ($compclass->plugins) { + echo $OUTPUT->heading(get_string('no' . $comp . 'yet', 'block_configurable_reports')); } if ($compclass->plugins) { diff --git a/editplugin.php b/editplugin.php index aca91762..715d6b6d 100755 --- a/editplugin.php +++ b/editplugin.php @@ -84,7 +84,7 @@ $cdata = null; $plugin = ''; if (!$cid) { - if (filetype($CFG->dirroot . '/blocks/configurable_reports/components/' . $comp . '/' . $pname) == 'dir') { + if (filetype($CFG->dirroot . '/blocks/configurable_reports/components/' . $comp . '/' . $pname) === 'dir') { $plugin = $pname; } } else { @@ -123,7 +123,7 @@ } } -if (!$plugin || $plugin != $pname) { +if (!$plugin || $plugin !== $pname) { throw new \moodle_exception('nosuchplugin'); } defined('MOODLE_INTERNAL') || die; @@ -159,7 +159,6 @@ redirect($CFG->wwwroot . '/blocks/configurable_reports/editreport.php'); } } else if ($data = $editform->get_data()) { - cr_add_to_log($report->courseid, 'configurable_reports', 'edit', '', $report->name); if (!empty($cdata)) { $cdata['formdata'] = $data; $cdata['summary'] = $pluginclass->summary($data); diff --git a/editreport.php b/editreport.php index 4d1355c8..2cee4b48 100755 --- a/editreport.php +++ b/editreport.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ require_once("../../config.php"); @@ -42,7 +42,7 @@ } if (!$course = $DB->get_record('course', ['id' => $courseid])) { - throw new \moodle_exception('nosuchcourseid', 'block_configurable_reports'); + throw new \moodle_exception('nosuchcourseid', 'block_configurable_reports'); } // Force user login in course (SITE or Course). @@ -56,7 +56,7 @@ $hasmanagereportcap = has_capability('block/configurable_reports:managereports', $context); if (!$hasmanagereportcap && !has_capability('block/configurable_reports:manageownreports', $context)) { - throw new \moodle_exception('badpermissions', 'block_configurable_reports'); + throw new \moodle_exception('badpermissions', 'block_configurable_reports'); } $PAGE->set_context($context); @@ -64,22 +64,22 @@ if ($id) { if (!$report = $DB->get_record('block_configurable_reports', ['id' => $id])) { - throw new \moodle_exception('reportdoesnotexists', 'block_configurable_reports'); + throw new \moodle_exception('reportdoesnotexists', 'block_configurable_reports'); } if (!$hasmanagereportcap && $report->ownerid != $USER->id) { - throw new \moodle_exception('badpermissions', 'block_configurable_reports'); + throw new \moodle_exception('badpermissions', 'block_configurable_reports'); } // Extra check. if ($report->type == 'sql' && !block_configurable_reports_can_managesqlreports($context)) { - throw new \moodle_exception('nosqlpermissions'); + throw new \moodle_exception('nosqlpermissions'); } $title = format_string($report->name); $courseid = $report->courseid; if (!$course = $DB->get_record('course', ['id' => $courseid])) { - throw new \moodle_exception('nosuchcourseid', 'block_configurable_reports'); + throw new \moodle_exception('nosuchcourseid', 'block_configurable_reports'); } require_once($CFG->dirroot . '/blocks/configurable_reports/report.class.php'); @@ -116,36 +116,22 @@ if (($show || $hide) && confirm_sesskey()) { $visible = ($show) ? 1 : 0; if (!$DB->set_field('block_configurable_reports', 'visible', $visible, ['id' => $report->id])) { - throw new \moodle_exception('cannotupdatereport', 'block_configurable_reports'); + throw new \moodle_exception('cannotupdatereport', 'block_configurable_reports'); } $action = ($visible) ? 'showed' : 'hidden'; - cr_add_to_log( - $report->courseid, - 'configurable_reports', - 'report ' . $action, - '/block/configurable_reports/editreport.php?id=' . $report->id, - $report->id - ); + header("Location: $CFG->wwwroot/blocks/configurable_reports/managereport.php?courseid=$courseid"); die; } if ($duplicate && confirm_sesskey()) { - $newreport = new stdclass(); $newreport = $report; unset($newreport->id); $newreport->name = get_string('copyasnoun') . ' ' . $newreport->name; - $newreport->summary = $newreport->summary; if (!$newreportid = $DB->insert_record('block_configurable_reports', $newreport)) { - throw new \moodle_exception('cannotduplicate', 'block_configurable_reports'); + throw new \moodle_exception('cannotduplicate', 'block_configurable_reports'); } - cr_add_to_log( - $newreport->courseid, - 'configurable_reports', - 'report duplicated', - '/block/configurable_reports/editreport.php?id=' . $newreportid, - $id - ); + header("Location: $CFG->wwwroot/blocks/configurable_reports/managereport.php?courseid=$courseid"); die; } @@ -164,19 +150,11 @@ echo $OUTPUT->confirm($message, $buttoncontinue, $buttoncancel); echo $OUTPUT->footer(); exit; - } else { - if ($DB->delete_records('block_configurable_reports', ['id' => $report->id])) { - cr_add_to_log( - $report->courseid, - 'configurable_reports', - 'report deleted', - '/block/configurable_reports/editreport.php?id=' . $report->id, - $report->id - ); - } - header("Location: $CFG->wwwroot/blocks/configurable_reports/managereport.php?courseid=$courseid"); - die; } + + $DB->delete_records('block_configurable_reports', ['id' => $report->id]); + header("Location: $CFG->wwwroot/blocks/configurable_reports/managereport.php?courseid=$courseid"); + die; } require_once('editreport_form.php'); @@ -244,42 +222,29 @@ // Extra check. if ($data->type == 'sql' && !block_configurable_reports_can_managesqlreports($context)) { - throw new \moodle_exception('nosqlpermissions'); + throw new \moodle_exception('nosqlpermissions'); } if (!$lastid = $DB->insert_record('block_configurable_reports', $data)) { - throw new \moodle_exception('errorsavingreport', 'block_configurable_reports'); - } else { - cr_add_to_log( - $courseid, - 'configurable_reports', - 'report created', - '/block/configurable_reports/editreport.php?id=' . $lastid, - $data->name - ); - $reportclass = new $reportclassname($lastid); - redirect( - $CFG->wwwroot . '/blocks/configurable_reports/editcomp.php?id=' . $lastid . '&comp=' . $reportclass->components[0] - ); + throw new \moodle_exception('errorsavingreport', 'block_configurable_reports'); } - } else { - cr_add_to_log( - $report->courseid, - 'configurable_reports', - 'edit', - '/block/configurable_reports/editreport.php?id=' . $id, - $report->name + + $reportclass = new $reportclassname($lastid); + redirect( + $CFG->wwwroot . '/blocks/configurable_reports/editcomp.php?id=' . $lastid . '&comp=' . $reportclass->components[0] ); + } else { + $reportclass = new $reportclassname($data->id); $data->type = $report->type; if (!$DB->update_record('block_configurable_reports', $data)) { - throw new \moodle_exception('errorsavingreport', 'block_configurable_reports'); - } else { - redirect( - $CFG->wwwroot . '/blocks/configurable_reports/editcomp.php?id=' . $data->id . '&comp=' . $reportclass->components[0] - ); + throw new \moodle_exception('errorsavingreport', 'block_configurable_reports'); } + + redirect( + $CFG->wwwroot . '/blocks/configurable_reports/editcomp.php?id=' . $data->id . '&comp=' . $reportclass->components[0] + ); } } diff --git a/environment.xml b/environment.xml new file mode 100644 index 00000000..1ba25ba8 --- /dev/null +++ b/environment.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/export.php b/export.php index c8e3876b..8095f85c 100755 --- a/export.php +++ b/export.php @@ -18,9 +18,9 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ require_once("../../config.php"); @@ -38,7 +38,7 @@ } // Force user login in course (SITE or Course). -if ($course->id == SITEID) { +if ((int) $course->id === SITEID) { require_login(); $context = context_system::instance(); } else { diff --git a/filter_form.php b/filter_form.php index d3bc1007..4de38926 100644 --- a/filter_form.php +++ b/filter_form.php @@ -14,20 +14,34 @@ // You should have received a copy of the GNU General Public License // along with Moodle. If not, see . -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} - +/** + * Configurable Reports + * A Moodle block for creating Configurable Reports + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ + +defined('MOODLE_INTERNAL') || die; + +global $CFG; require_once($CFG->libdir . '/formslib.php'); +/** + * Class report_edit_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class report_edit_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG, $COURSE; + * Form definition + */ + public function definition(): void { + global $COURSE; $mform =& $this->_form; diff --git a/get_remote_report.php b/get_remote_report.php index a3e57ed1..89744799 100644 --- a/get_remote_report.php +++ b/get_remote_report.php @@ -24,7 +24,7 @@ */ define('AJAX_SCRIPT', true); -require(dirname(dirname(dirname(__FILE__))) . '/config.php'); +require(dirname(__FILE__, 3) . '/config.php'); require_once($CFG->libdir . '/filelib.php'); $reportname = required_param('reportname', PARAM_RAW); diff --git a/import_form.php b/import_form.php index a798db19..b28b659b 100755 --- a/import_form.php +++ b/import_form.php @@ -18,25 +18,28 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ -if (!defined('MOODLE_INTERNAL')) { - // It must be included from a Moodle page. - die('Direct access to this script is forbidden.'); -} +defined('MOODLE_INTERNAL') || die; require_once($CFG->libdir . '/formslib.php'); +/** + * Class import_form + * + * @package block_configurablereports + * @author Juan leyva + * @date 2009 + */ class import_form extends moodleform { /** -* Form definition -*/ -public function definition():void { - global $DB, $USER, $CFG; + * Form definition + */ + public function definition(): void { $mform =& $this->_form; @@ -53,7 +56,7 @@ public function definition():void { $this->add_action_buttons(false, get_string('importreport', 'block_configurable_reports')); } - public function validation($data, $files) : array{ + public function validation($data, $files): array { $errors = parent::validation($data, $files); return $errors; diff --git a/locallib.php b/locallib.php index 68f19154..d2923343 100755 --- a/locallib.php +++ b/locallib.php @@ -18,16 +18,19 @@ * Configurable Reports * A Moodle block for creating Configurable Reports * - * @package block_configurablereports + * @package block_configurablereports * @author Juan leyva - * @date 2009 + * @date 2009 */ +/** + * @return void + */ function cr_print_js_function() { ?> -