Skip to content

Commit

Permalink
Fix #86bzw1vva course admin nodes.
Browse files Browse the repository at this point in the history
  • Loading branch information
hamzatamyachte committed Aug 6, 2024
1 parent 904614f commit 7517e69
Showing 1 changed file with 47 additions and 47 deletions.
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

0 comments on commit 7517e69

Please sign in to comment.