Skip to content

Commit b529e22

Browse files
committed
Release 2025112400
1 parent a94e98c commit b529e22

File tree

7 files changed

+79
-21
lines changed

7 files changed

+79
-21
lines changed

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,46 @@
1-
# moodle-local_table_sql
1+
# local_table_sql Moodle Plugin
2+
**Enhanced table_sql functionality with advanced features and a modern, responsive interface**
23

3-
TODO
4+
Moodle provides a `table_sql` class for building tables through a unified API. However, it lacks modern features such as AJAX-based pagination and filtering.
45

5-
## Licenses for JavaScripts
6+
`local_table_sql` is a drop-in replacement for Moodle’s core `table_sql` class and adds a wide range of powerful enhancements, including AJAX navigation, full-text search and advanced filtering for each column.
67

7-
see: LICENSE.js.txt
8+
Plugins can declare this plugin as a dependency in their `version.php`.
9+
Tables built using `local_table_sql` provide the following features:
10+
11+
## Key Features
12+
13+
- **AJAX-driven data loading** – Load only the data that is needed, improving performance.
14+
- **Built-in filtering and sorting** – Global search or column-specific filters included.
15+
- **Full-text search support**
16+
- **Dynamic column visibility** – Show or hide columns instantly.
17+
- **Customizable UI actions** – Add action buttons or context menus for each row.
18+
- **Row selection and bulk actions**
19+
- **SQL-based data source** – Provide your own SQL query as input.
20+
- **Custom form integration** – Display forms for adding or editing rows.
21+
22+
23+
## Usage
24+
25+
See the demo folder for example usage of the `local_table_sql` plugin.
26+
27+
## Information for developers regarding the react-app directory
28+
29+
The `react-app` directory contains the React frontend responsible for rendering table data, built using **Material React Table**.
30+
31+
To build the React app (only needed if you made changes to the react code, a precompiled version is included in the plugin):
32+
33+
1. Run the script:
34+
```bash
35+
cd react-table
36+
./build.sh
37+
```
38+
39+
2. The compiled output will be copied into the js/main.js directory.
40+
41+
The react-app directory is not required for normal plugin usage**—only for development**.
42+
It is included in the repository for transparency and open-source collaboration.
43+
44+
## JavaScript Licenses
45+
46+
See: LICENSE.js.txt

classes/privacy/provider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
namespace local_table_sql\privacy;
2525

26-
defined('MOODLE_INTERNAL') || die;
26+
defined('MOODLE_INTERNAL') || die();
2727

2828
class provider implements \core_privacy\local\metadata\null_provider {
2929
/**

classes/table_sql.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,12 @@ public function __construct($uniqueid = null) {
8686

8787
if ($uniqueid === null) {
8888
// use the whole classname and namespace, then create an md5 to hide implementation details to the client
89-
$uniqueid = str_replace('\\', '.', get_class($this));
89+
$uniqueid = str_replace('\\', '.', $this->get_class_name());
90+
$uniqueid = md5($uniqueid);
9091
} elseif (is_array($uniqueid)) {
9192
// create a uniqueid of the parameters and the current class
92-
// don't use __CLASS__, because it will give you local_table_sql/sql_table
93-
$uniqueid = join('-', array_merge([str_replace('\\', '.', get_class($this))], $uniqueid));
93+
$uniqueid = join('-', array_merge([str_replace('\\', '.', $this->get_class_name())], $uniqueid));
94+
$uniqueid = md5($uniqueid);
9495
} elseif (is_string($uniqueid)) {
9596
// ok
9697
} else {
@@ -175,6 +176,32 @@ public function __construct($uniqueid = null) {
175176
}
176177
}
177178

179+
/**
180+
* Returns a class name. For anonymous classes, it returns the file path and line number, which IS NOT stable against code changes above the class definition.
181+
* But good enough for us
182+
* PHP's get_class() on anonymous functions also returns file + line number, but also adds some random string
183+
* And that is not exactly defined in the PHP manual
184+
*
185+
* @return string The class name
186+
*/
187+
function get_class_name(): string {
188+
$reflection = new \ReflectionClass($this);
189+
190+
// 1. Handle Named Classes
191+
if (!$reflection->isAnonymous()) {
192+
return $reflection->getName();
193+
}
194+
195+
// 2. Handle Anonymous Classes (MD5 of Location)
196+
$fileName = $reflection->getFileName();
197+
$startLine = $reflection->getStartLine();
198+
199+
// Create the volatile location string
200+
$locationString = $fileName . ':' . $startLine;
201+
202+
return $locationString;
203+
}
204+
178205
/**
179206
* Add a single header.
180207
*/
@@ -473,14 +500,6 @@ protected function sql_format_timestamp(string $column, ?string $format = null)
473500
}
474501
}
475502

476-
private function _uniqueid(string $prefix = 'unique') {
477-
static $uniqueid = 0;
478-
479-
$uniqueid++;
480-
481-
return $prefix . $uniqueid;
482-
}
483-
484503
protected function no_filter($column) {
485504
$this->column_nofilter[] = $column;
486505
}

classes/table_sql_form.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use local_table_sql\local\js_call_amd;
2727

28-
defined('MOODLE_INTERNAL') || die;
28+
defined('MOODLE_INTERNAL') || die();
2929

3030
require_once("$CFG->libdir/tablelib.php");
3131

classes/table_sql_subform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
use moodleform;
2727

28-
defined('MOODLE_INTERNAL') || die;
28+
defined('MOODLE_INTERNAL') || die();
2929

3030
global $CFG;
3131
require_once($CFG->libdir . "/formslib.php");

db/upgrade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*/
2424

2525

26-
defined('MOODLE_INTERNAL') || die;
26+
defined('MOODLE_INTERNAL') || die();
2727

2828
function xmldb_local_table_sql_upgrade($oldversion) {
2929
global $DB;

version.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
2222
*/
2323

24-
defined('MOODLE_INTERNAL') || die;
24+
defined('MOODLE_INTERNAL') || die();
2525

26-
$plugin->version = 2025111701;
26+
$plugin->version = 2025112400;
2727
$plugin->requires = 2022041900;
2828
$plugin->component = 'local_table_sql';
2929
$plugin->release = '1.0';

0 commit comments

Comments
 (0)