Skip to content

Commit

Permalink
DASH-718 : Dash MSSQL support.
Browse files Browse the repository at this point in the history
  • Loading branch information
vasanthlmsace committed Mar 16, 2024
1 parent 17fbd4f commit 582ebf3
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 16 deletions.
11 changes: 6 additions & 5 deletions classes/local/dash_framework/structure/field.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ public function __construct(string $name,
$select = null,
array $attributes = [],
$options = [],
$visibility = self::VISIBILITY_VISIBLE) {
$visibility = self::VISIBILITY_VISIBLE,
$sortselect = null) {
$this->name = $name;
$this->title = $title;
$this->table = $table;
$this->select = $select;
$this->visibility = $visibility;
$this->options = $options;
$this->sortselect = $sortselect;

foreach ($attributes as $attribute) {
$this->add_attribute($attribute);
Expand Down Expand Up @@ -394,11 +396,10 @@ public function set_sort_select($select) {
*/
public function get_sort_select() {
$sort = $this->sortselect;
if (!is_null($sort)) {
return $sort;
if (is_null($sort)) {
return $this->get_select();
}

return $this->get_alias();
return empty($sort) ? $this->get_alias() : '';
}

// Endregion.
Expand Down
11 changes: 5 additions & 6 deletions classes/local/dash_framework/structure/user_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function get_title(): string {
*/
public function get_fields(): array {
global $DB, $CFG;

$groupconcat = $DB->sql_group_concat('g200.id', ',');
$fields = [
new field('id', new lang_string('user'), $this, null, [
new identifier_attribute(),
Expand Down Expand Up @@ -128,17 +128,15 @@ public function get_fields(): array {
]),
]),
new field('group_names', new lang_string('group'), $this, [
'select' => "(SELECT group_concat(g200.id, ',') FROM {groups} g200
'select' => "(SELECT $groupconcat FROM {groups} g200
JOIN {groups_members} gm200 ON gm200.groupid = g200.id WHERE gm200.userid = u.id)",
'select_pgsql' => "(SELECT string_agg(g200.id::text, ',') FROM {groups} g200
JOIN {groups_members} gm200 ON gm200.groupid = g200.id AND gm200.userid = u.id)",
], [
new rename_group_ids_attribute([
'table' => 'groups',
'field' => 'name',
'delimiter' => ',', // Separator between each ID in SQL select.
]),
]),
], [], field_interface::VISIBILITY_VISIBLE, ''),
];

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

$i++;
Expand Down
2 changes: 1 addition & 1 deletion classes/local/data_source/abstract_data_source.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ final public function get_query(): builder {
if (is_null($this->get_field($field))) {
continue;
}
$this->query->orderby($this->get_field($field)->get_select(), $direction);
$this->query->orderby($this->get_field($field)->get_sort_select(), $direction);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions field_definitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

global $DB;

$groupconcat = $DB->sql_group_concat('g200.id', ',');

$definitions = [
[
'name' => 'u_id',
Expand Down Expand Up @@ -284,10 +286,8 @@
],
[
'name' => 'u_group_names',
'select' => "(SELECT group_concat(g200.id, ',') FROM {groups} g200
'select' => "(SELECT $groupconcat FROM {groups} g200
JOIN {groups_members} gm200 ON gm200.groupid = g200.id WHERE gm200.userid = u.id)",
'select_pgsql' => "(SELECT string_agg(g200.id::text, ',') FROM {groups} g200
JOIN {groups_members} gm200 ON gm200.groupid = g200.id AND gm200.userid = u.id)",
'title' => get_string('group'),
'tables' => ['u'],
'attributes' => [
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

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

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

0 comments on commit 582ebf3

Please sign in to comment.