Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enrolled users & enrolment method pages not reachable by the commander #20 #21

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions classes/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,15 @@ public function initialise() {
*
* @return string
*/
public function get_menu_for_js() {
public function get_menu_for_js(): string {

// TODO Add custom commands actions enrolling, creating course and more.
// Convert and output the branch as JSON.

$courseadminnode = $this->get('courseadmin');
$courseadminnode->children->remove('users');
$courseadminlinks = $this->convert($courseadminnode);
$courseadminlinks['children'][] = $this->get_groups_links();

$rootlinks = $this->convert($this->get('root'));

return json_encode([
'admin' => $rootlinks,
'courseadmin' => $courseadminlinks,
]);
'admin' => $this->convert($this->get('root')),
'courseadmin' => $this->get_courseadmin_nodes(),
], JSON_THROW_ON_ERROR);
}

/**
Expand Down Expand Up @@ -142,8 +135,8 @@ protected function convert($child, int $depth = 1): array {
}

$attributes['hidden'] = ($child->hidden);
$attributes['haschildren'] = ($child->children->count() > 0 || $child->type == navigation_node::TYPE_CATEGORY);
$attributes['haschildren'] = $attributes['haschildren'] || $child->type == navigation_node::TYPE_MY_CATEGORY;
$attributes['haschildren'] = ($child->children->count() > 0 || (int) $child->type === navigation_node::TYPE_CATEGORY);
$attributes['haschildren'] = $attributes['haschildren'] || (int) $child->type === navigation_node::TYPE_MY_CATEGORY;

if ($child->children->count() > 0) {
$attributes['children'] = [];
Expand All @@ -159,45 +152,52 @@ protected function convert($child, int $depth = 1): array {
}

/**
* Get groups links.
* Get course admin nodes.
*
* @return array[]
*/
public function get_groups_links(): array {
private function get_courseadmin_nodes(): array {

$attributes = [];
$attributes['id'] = null;
$attributes['name'] = get_string('users');
$attributes['haschildren'] = true;

$firstchild = $this->get_child_node(
null,
get_string('groups', 'group'),
(new moodle_url('/group/index.php', [
'id' => $this->courseid,
]))->out(false),
);
$firstchild['haschildren'] = true;

$firstchild['children'][] = $this->get_child_node(
1,
get_string('overview', 'group'),
(new moodle_url('/group/overview.php', [
'id' => $this->courseid,
]))->out(false),
);

$firstchild['children'][] = $this->get_child_node(
2,
get_string('groupings', 'group'),
(new moodle_url('/group/groupings.php', [
'id' => $this->courseid,
]))->out(false),
);

$attributes['children'][] = $firstchild;
$courseadminnode = $this->get('courseadmin');

return $attributes;
$nodes = $this->convert($courseadminnode);

foreach ($nodes['children'] as $key => $value) {
if ($value['name'] === get_string('users')) {

foreach ($value['children'] as $i => $child) {

if ($child['name'] === get_string('groups', 'group')) {

$child['children'] = [];

$child['haschildren'] = true;

$child['children'][] = $this->get_child_node(
1,
get_string('overview', 'group'),
(new moodle_url('/group/overview.php', [
'id' => $this->courseid,
]))->out(false),
);
$child['children'][] = $this->get_child_node(
2,
get_string('groupings', 'group'),
(new moodle_url('/group/groupings.php', [
'id' => $this->courseid,
]))->out(false),
);
$nodes['children'][$key]['children'][$i] = $child;

break;
}
}

break;
}
}

return $nodes;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

$plugin->release = '4.4.0 (2024042600)';
$plugin->maturity = MATURITY_STABLE;
$plugin->version = 2024042600;
$plugin->version = 2024080600;
$plugin->requires = 2015111602;
$plugin->component = 'local_commander';
$plugin->supported = [39, 404];
Loading