Skip to content

Commit 582ebf3

Browse files
committed
DASH-718 : Dash MSSQL support.
1 parent 17fbd4f commit 582ebf3

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

classes/local/dash_framework/structure/field.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ public function __construct(string $name,
106106
$select = null,
107107
array $attributes = [],
108108
$options = [],
109-
$visibility = self::VISIBILITY_VISIBLE) {
109+
$visibility = self::VISIBILITY_VISIBLE,
110+
$sortselect = null) {
110111
$this->name = $name;
111112
$this->title = $title;
112113
$this->table = $table;
113114
$this->select = $select;
114115
$this->visibility = $visibility;
115116
$this->options = $options;
117+
$this->sortselect = $sortselect;
116118

117119
foreach ($attributes as $attribute) {
118120
$this->add_attribute($attribute);
@@ -394,11 +396,10 @@ public function set_sort_select($select) {
394396
*/
395397
public function get_sort_select() {
396398
$sort = $this->sortselect;
397-
if (!is_null($sort)) {
398-
return $sort;
399+
if (is_null($sort)) {
400+
return $this->get_select();
399401
}
400-
401-
return $this->get_alias();
402+
return empty($sort) ? $this->get_alias() : '';
402403
}
403404

404405
// Endregion.

classes/local/dash_framework/structure/user_table.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function get_title(): string {
6666
*/
6767
public function get_fields(): array {
6868
global $DB, $CFG;
69-
69+
$groupconcat = $DB->sql_group_concat('g200.id', ',');
7070
$fields = [
7171
new field('id', new lang_string('user'), $this, null, [
7272
new identifier_attribute(),
@@ -128,17 +128,15 @@ public function get_fields(): array {
128128
]),
129129
]),
130130
new field('group_names', new lang_string('group'), $this, [
131-
'select' => "(SELECT group_concat(g200.id, ',') FROM {groups} g200
131+
'select' => "(SELECT $groupconcat FROM {groups} g200
132132
JOIN {groups_members} gm200 ON gm200.groupid = g200.id WHERE gm200.userid = u.id)",
133-
'select_pgsql' => "(SELECT string_agg(g200.id::text, ',') FROM {groups} g200
134-
JOIN {groups_members} gm200 ON gm200.groupid = g200.id AND gm200.userid = u.id)",
135133
], [
136134
new rename_group_ids_attribute([
137135
'table' => 'groups',
138136
'field' => 'name',
139137
'delimiter' => ',', // Separator between each ID in SQL select.
140138
]),
141-
]),
139+
], [], field_interface::VISIBILITY_VISIBLE, ''),
142140
];
143141

144142
require_once("$CFG->dirroot/user/profile/lib.php");
@@ -148,7 +146,8 @@ public function get_fields(): array {
148146
$fields[] = new field('pf_' . strtolower($customfield->shortname),
149147
new lang_string('customfield', 'block_dash', ['name' => format_string($customfield->name)]),
150148
$this, "(SELECT profile$i.data FROM {user_info_data} profile$i
151-
WHERE profile$i.userid = u.id AND profile$i.fieldid = $customfield->id)"
149+
WHERE profile$i.userid = u.id AND profile$i.fieldid = $customfield->id)",
150+
[], [],field_interface::VISIBILITY_VISIBLE , '',
152151
);
153152

154153
$i++;

classes/local/data_source/abstract_data_source.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ final public function get_query(): builder {
268268
if (is_null($this->get_field($field))) {
269269
continue;
270270
}
271-
$this->query->orderby($this->get_field($field)->get_select(), $direction);
271+
$this->query->orderby($this->get_field($field)->get_sort_select(), $direction);
272272
}
273273
}
274274
}

field_definitions.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
global $DB;
2828

29+
$groupconcat = $DB->sql_group_concat('g200.id', ',');
30+
2931
$definitions = [
3032
[
3133
'name' => 'u_id',
@@ -284,10 +286,8 @@
284286
],
285287
[
286288
'name' => 'u_group_names',
287-
'select' => "(SELECT group_concat(g200.id, ',') FROM {groups} g200
289+
'select' => "(SELECT $groupconcat FROM {groups} g200
288290
JOIN {groups_members} gm200 ON gm200.groupid = g200.id WHERE gm200.userid = u.id)",
289-
'select_pgsql' => "(SELECT string_agg(g200.id::text, ',') FROM {groups} g200
290-
JOIN {groups_members} gm200 ON gm200.groupid = g200.id AND gm200.userid = u.id)",
291291
'title' => get_string('group'),
292292
'tables' => ['u'],
293293
'attributes' => [

version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
defined('MOODLE_INTERNAL') || die();
2626

27-
$plugin->version = 2024030601; // The current plugin version (Date: YYYYMMDDXX).
27+
$plugin->version = 2024031600; // The current plugin version (Date: YYYYMMDDXX).
2828
$plugin->requires = 2021051700; // Requires this Moodle version.
2929
$plugin->component = 'block_dash'; // Full name of the plugin (used for diagnostics).
3030
$plugin->maturity = MATURITY_STABLE;

0 commit comments

Comments
 (0)