Skip to content

Commit

Permalink
Refactor for MOODLE41
Browse files Browse the repository at this point in the history
  • Loading branch information
luukverhoeven committed Dec 6, 2023
1 parent 9db8f36 commit 0065562
Show file tree
Hide file tree
Showing 142 changed files with 1,683 additions and 1,035 deletions.
9 changes: 9 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------------------------------------------------------
Expand Down
11 changes: 1 addition & 10 deletions block_configurable_reports.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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)
*
Expand Down
16 changes: 10 additions & 6 deletions component.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@
* @date 2009
*/

// TODO namespace

/**
* Class component_base
*
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @date 2009
*/
class component_base {
abstract class component_base {

public $plugins = false;
public $ordering = false;
Expand All @@ -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 {

}

}
10 changes: 8 additions & 2 deletions components/calcs/average/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down
38 changes: 29 additions & 9 deletions components/calcs/component.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,53 @@
* Configurable Reports
* A Moodle block for creating customizable reports
*
* @package block_configurablereports
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @date 2009
* @date 2009
*/

/**
* Class component_calcs
*
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @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) {
Expand All @@ -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)) {

Expand Down
18 changes: 12 additions & 6 deletions components/calcs/max/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,35 @@
* Configurable Reports
* A Moodle block for creating customizable reports
*
* @package block_configurablereports
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @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'];
Expand Down
23 changes: 13 additions & 10 deletions components/calcs/min/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,28 @@
* Configurable Reports
* A Moodle block for creating customizable reports
*
* @package block_configurablereports
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @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 <http://www.twitter.com/jleyvadelgado>
* @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.
Expand Down
18 changes: 12 additions & 6 deletions components/calcs/min/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,35 @@
* Configurable Reports
* A Moodle block for creating customizable reports
*
* @package block_configurablereports
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @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'];
Expand Down
7 changes: 3 additions & 4 deletions components/calcs/percent/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 11 additions & 5 deletions components/calcs/percent/plugin.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -83,7 +89,7 @@ public function summary($data) {
return '';
}

public function execute($rows) {
public function execute($rows): string {
$result = 0;
$totalrows = 0;
$resultrows = 0;
Expand Down
7 changes: 7 additions & 0 deletions components/calcs/sum/form.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@

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

/**
* Class sum_form
*
* @package block_configurablereports
* @author Juan leyva <http://www.twitter.com/jleyvadelgado>
* @date 2009
*/
class sum_form extends moodleform {

/**
Expand Down
Loading

0 comments on commit 0065562

Please sign in to comment.