Skip to content

Commit

Permalink
Merge branch 'MDL-72930-master' of git://github.com/abgreeve/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Jan 4, 2022
2 parents ed4c560 + 0a04ebd commit ec4fd41
Show file tree
Hide file tree
Showing 21 changed files with 404 additions and 337 deletions.
52 changes: 51 additions & 1 deletion badges/classes/output/base_action_bar.php
Expand Up @@ -17,8 +17,10 @@
namespace core_badges\output;

use renderable;
use templatable;
use renderer_base;
use moodle_page;
use navigation_node;
use templatable;

/**
* Abstract class for the badges tertiary navigation. The class initialises the page and type class variables.
Expand Down Expand Up @@ -50,4 +52,52 @@ public function __construct(moodle_page $page, int $type) {
* @return string
*/
abstract public function get_template(): string;

/**
* Gets additional third party navigation nodes for display.
*
* @param renderer_base $output The output
* @return array All that sweet third party navigation action.
*/
public function get_third_party_nav_action(renderer_base $output): array {
$badgenode = $this->page->settingsnav->find('coursebadges', navigation_node::TYPE_CONTAINER);
if (!$badgenode) {
return [];
}
$leftovernodes = [];
foreach ($badgenode->children as $key => $value) {
if (array_search($value->key, $this->expected_items()) === false) {
$leftovernodes[] = $value;
}
}
$result = \core\navigation\views\secondary::create_menu_element($leftovernodes);

if ($result == false) {
return [];
} else {
$data ['thirdpartybutton'] = true;
if (count($result) == 1) {
// Return a button.
$link = key($result);
$text = current($result);
$data['thirdpartynodes'] = ['link' => $link, 'text' => $text];
} else {
// Return a url_select.
$selectobject = new \url_select($result, $this->page->url, get_string('othernavigation', 'badges'));
$data['thirdpartynodes'] = $selectobject->export_for_template($output);
$data['thirdpartybutton'] = false;
}
}

return $data;
}

/**
* Expected navigation node keys for badges.
*
* @return array default badge navigation node keys.
*/
protected function expected_items(): array {
return ['coursebadges', 'newbadge'];
}
}
2 changes: 2 additions & 0 deletions badges/classes/output/manage_badge_action_bar.php
Expand Up @@ -71,6 +71,8 @@ public function export_for_template(renderer_base $output): array {
foreach ($elements as $key => $element) {
$elements[$key] = $element->export_for_template($output);
}
$additional = $this->get_third_party_nav_action($output);
$elements += $additional ?: [];

return $elements;
}
Expand Down
2 changes: 2 additions & 0 deletions badges/classes/output/recipients_action_bar.php
Expand Up @@ -53,6 +53,8 @@ public function export_for_template(renderer_base $output): array {
$button = new single_button($url, get_string('award', 'badges'), 'post', true);
$elements['awardbutton'] = $button->export_for_template($output);
}
$thirdpartynav = $this->get_third_party_nav_action($output);
$elements += $thirdpartynav ?: [];

return $elements;
}
Expand Down
6 changes: 5 additions & 1 deletion badges/classes/output/standard_action_bar.php
Expand Up @@ -96,6 +96,10 @@ public function export_for_template(renderer_base $output): array {
$buttons[$key] = $button->export_for_template($output);
}

return ['buttons' => $buttons];
$data = ['buttons' => $buttons];
$additional = $this->get_third_party_nav_action($output);
$data += $additional ?: [];

return $data;
}
}
1 change: 1 addition & 0 deletions badges/templates/award_badge.mustache
Expand Up @@ -103,5 +103,6 @@
{{> core/single_button }}
</div>
{{/awardbutton}}
{{> core_badges/badge_more_nav }}
</div>
</div>
37 changes: 37 additions & 0 deletions badges/templates/badge_more_nav.mustache
@@ -0,0 +1,37 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_badges/badge_more_nav
Example context (json):
{
"thirdpartybutton": true,
"thirdpartynodes": {
"link": "http://example.org/help",
"text": "Example text"
}
}
}}
{{#thirdpartybutton}}
{{#thirdpartynodes}}
<div>
<a href="{{link}}" class="btn btn-secondary">{{text}}</a>
</div>
{{/thirdpartynodes}}
{{/thirdpartybutton}}
{{^thirdpartybutton}}
{{#thirdpartynodes}}
{{> core/url_select}}
{{/thirdpartynodes}}
{{/thirdpartybutton}}
1 change: 1 addition & 0 deletions badges/templates/manage_badge.mustache
Expand Up @@ -83,5 +83,6 @@
{{> core/url_select }}
</div>
{{/urlselect}}
{{> core_badges/badge_more_nav }}
</div>
</div>
1 change: 1 addition & 0 deletions badges/templates/manage_badges.mustache
Expand Up @@ -59,5 +59,6 @@
{{> core/single_button }}
</div>
{{/buttons}}
{{> core_badges/badge_more_nav }}
</div>
</div>
22 changes: 1 addition & 21 deletions grade/grading/lib.php
Expand Up @@ -453,33 +453,13 @@ public function extend_settings_navigation(settings_navigation $settingsnav, nav
// no money, no funny
return;

} else if (count($areas) == 1) {
} else {
// make just a single node for the management screen
$areatitle = reset($areas);
$areaname = key($areas);
$this->set_area($areaname);
$method = $this->get_active_method();
$managementnode = $modulenode->add(get_string('gradingmanagement', 'core_grading'),
$this->get_management_url(), settings_navigation::TYPE_CUSTOM, null, 'advgrading');
if ($method) {
$controller = $this->get_controller($method);
$controller->extend_settings_navigation($settingsnav, $managementnode);
}

} else {
// make management screen node for each area
$managementnode = $modulenode->add(get_string('gradingmanagement', 'core_grading'),
null, settings_navigation::TYPE_CUSTOM, null, 'advgrading');
foreach ($areas as $areaname => $areatitle) {
$this->set_area($areaname);
$method = $this->get_active_method();
$node = $managementnode->add($areatitle,
$this->get_management_url(), settings_navigation::TYPE_CUSTOM);
if ($method) {
$controller = $this->get_controller($method);
$controller->extend_settings_navigation($settingsnav, $node);
}
}
}
}

Expand Down
1 change: 1 addition & 0 deletions lang/en/badges.php
Expand Up @@ -456,6 +456,7 @@
$string['openbadgesv1'] = 'Open Badges v1.0';
$string['openbadgesv2'] = 'Open Badges v2.0';
$string['openbadgesv2p1'] = 'Open Badges v2.1';
$string['othernavigation'] = 'Other navigation ...';
$string['potentialrecipients'] = 'Potential badge recipients';
$string['preferences'] = 'Badge preferences';
$string['privacy:metadata:backpack'] = 'A record of user\'s backpacks';
Expand Down

0 comments on commit ec4fd41

Please sign in to comment.