Skip to content

Commit

Permalink
Merge pull request #277 from learnweb/feature/improve_ratingallocate_…
Browse files Browse the repository at this point in the history
…navigation

Feature/improve ratingallocate navigation
  • Loading branch information
Laur0r authored May 7, 2024
2 parents 188c17f + e9c9a28 commit 83ef413
Show file tree
Hide file tree
Showing 12 changed files with 168 additions and 83 deletions.
12 changes: 0 additions & 12 deletions .github/workflows/moodle-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,18 +115,6 @@ jobs:
- php: '8.2'
moodle-branch: 'MOODLE_401_STABLE'
include:
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'mariadb'
- php: '7.4'
moodle-branch: 'MOODLE_39_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'mariadb'
- php: '8.0'
moodle-branch: 'MOODLE_311_STABLE'
database: 'pgsql'
- php: '8.0'
moodle-branch: 'MOODLE_400_STABLE'
database: 'mariadb'
Expand Down
1 change: 1 addition & 0 deletions lang/en/ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@
$string['edit_choice'] = 'Edit choice';
$string['rating_endtime'] = 'Rating ends at';
$string['rating_begintime'] = 'Rating begins at';
$string['choice_navigation'] = 'Choices';
$string['newchoicetitle'] = 'New choice {$a}';
$string['deletechoice'] = 'Delete choice';
$string['publishdate'] = 'Estimated publication date';
Expand Down
18 changes: 18 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
// define('NEWMODULE_ULTIMATE_ANSWER', 42);

require_once(dirname(__FILE__) . '/db/db_structure.php');
require_once(dirname(__FILE__) . '/locallib.php');

use mod_ratingallocate\db as this_db;

Expand Down Expand Up @@ -381,6 +382,23 @@ function ratingallocate_extend_navigation(navigation_node $navref, stdclass $cou
* {@link navigation_node}
*/
function ratingallocate_extend_settings_navigation(settings_navigation $settingsnav, navigation_node $ratingallocatenode = null) {
$hassecondary = $settingsnav->get_page()->has_secondary_navigation();
if (!$context = context_module::instance($settingsnav->get_page()->cm->id, IGNORE_MISSING)) {
throw new \moodle_exception('badcontext');
}
if (has_capability('mod/ratingallocate:modify_choices', $context)) {
$choicenode = navigation_node::create(get_string('choice_navigation', RATINGALLOCATE_MOD_NAME),
new moodle_url('/mod/ratingallocate/view.php', ['id' => $settingsnav->get_page()->cm->id, 'action' => ACTION_SHOW_CHOICES]),
navigation_node::TYPE_CUSTOM, null, 'mod_ratingallocate_choices');
$ratingallocatenode->add_node($choicenode);
}

if (has_capability('mod/ratingallocate:start_distribution', $context)) {
$reportsnode = navigation_node::create(get_string('reports_group', RATINGALLOCATE_MOD_NAME),
new moodle_url('/mod/ratingallocate/view.php', ['id' => $settingsnav->get_page()->cm->id, 'action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE]),
navigation_node::TYPE_CUSTOM, null, 'mod_ratingallocate_reports');
$ratingallocatenode->add_node($reportsnode);
}

}

Expand Down
47 changes: 27 additions & 20 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,10 @@ private function process_action_delete_rating() {
private function process_action_show_choices() {

if (has_capability('mod/ratingallocate:modify_choices', $this->context)) {
global $OUTPUT;
global $OUTPUT, $PAGE;
$PAGE->set_secondary_active_tab('mod_ratingallocate_choices');
$renderer = $this->get_renderer();
$status = $this->get_status();

// Notifications if no choices exist or too few in comparison to strategy settings.
$availablechoices = $this->get_rateable_choices();
Expand All @@ -409,6 +411,11 @@ private function process_action_show_choices() {
echo $renderer->render_header($this->ratingallocate, $this->context, $this->coursemodule->id);
echo $OUTPUT->heading(get_string('show_choices_header', RATINGALLOCATE_MOD_NAME));

// Get description dependent on status
$descriptionbaseid = 'modify_choices_group_desc_';
$description = get_string($descriptionbaseid . $status, RATINGALLOCATE_MOD_NAME);
echo $renderer->format_text($description);

$renderer->ratingallocate_show_choices_table($this, true);
echo $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php',
array('id' => $this->coursemodule->id)), get_string('back'), 'get');
Expand All @@ -422,7 +429,8 @@ private function process_action_edit_choice() {

$output = '';
if (has_capability('mod/ratingallocate:modify_choices', $this->context)) {
global $OUTPUT;
global $OUTPUT, $PAGE;
$PAGE->set_secondary_active_tab('mod_ratingallocate_choices');
$choiceid = optional_param('choiceid', 0, PARAM_INT);

if ($choiceid) {
Expand Down Expand Up @@ -506,6 +514,7 @@ private function process_action_upload_choices() {
$output = '';
if (has_capability('mod/ratingallocate:modify_choices', $this->context)) {
global $OUTPUT;
$PAGE->set_secondary_active_tab('mod_ratingallocate_choices');

$url = new moodle_url('/mod/ratingallocate/view.php',
array('id' => $this->coursemodule->id,
Expand Down Expand Up @@ -959,20 +968,21 @@ public function distribute_users_without_choice(string $distributionalgorithm):

private function process_action_show_ratings_and_alloc_table() {
$output = '';

// Print ratings table.
if (has_capability('mod/ratingallocate:start_distribution', $this->context)) {
global $OUTPUT;
global $OUTPUT, $PAGE;
$PAGE->set_secondary_active_tab('mod_ratingallocate_reports');
$renderer = $this->get_renderer();
$status = $this->get_status();
$output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, $status, $this->context, ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE);

$output .= $renderer->ratings_table_for_ratingallocate($this->get_rateable_choices(),
$this->get_ratings_for_rateable_choices(), $this->get_raters_in_course(),
$this->get_allocations(), $this);

$output = html_writer::div($output, 'ratingallocate_ratings_table_container');

$output .= html_writer::empty_tag('br', array());
$output .= $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php', array(
'id' => $this->coursemodule->id)), get_string('back'), 'get');

// Logging.
$event = \mod_ratingallocate\event\ratings_and_allocation_table_viewed::create_simple(
context_module::instance($this->coursemodule->id), $this->ratingallocateid);
Expand All @@ -983,16 +993,17 @@ private function process_action_show_ratings_and_alloc_table() {

private function process_action_show_allocation_table() {
$output = '';

// Print ratings table.
if (has_capability('mod/ratingallocate:start_distribution', $this->context)) {
global $OUTPUT;
global $OUTPUT, $PAGE;
$PAGE->set_secondary_active_tab('mod_ratingallocate_reports');
$renderer = $this->get_renderer();
$status = $this->get_status();
$output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, $status, $this->context, ACTION_SHOW_ALLOCATION_TABLE);

$output .= $renderer->allocation_table_for_ratingallocate($this);

$output .= html_writer::empty_tag('br', array());
$output .= $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php',
array('id' => $this->coursemodule->id)), get_string('back'), 'get');
// Logging.
$event = \mod_ratingallocate\event\allocation_table_viewed::create_simple(
context_module::instance($this->coursemodule->id), $this->ratingallocateid);
Expand All @@ -1005,14 +1016,14 @@ private function process_action_show_statistics() {
$output = '';
// Print ratings table.
if (has_capability('mod/ratingallocate:start_distribution', $this->context)) {
global $OUTPUT;
global $OUTPUT, $PAGE;
$PAGE->set_secondary_active_tab('mod_ratingallocate_reports');
$renderer = $this->get_renderer();
$status = $this->get_status();
$output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, $status, $this->context, ACTION_SHOW_STATISTICS);

$output .= $renderer->statistics_table_for_ratingallocate($this);

$output .= html_writer::empty_tag('br', array());
$output .= $OUTPUT->single_button(new moodle_url('/mod/ratingallocate/view.php',
array('id' => $this->coursemodule->id)), get_string('back'), 'get');
// Logging.
$event = \mod_ratingallocate\event\allocation_statistics_viewed::create_simple(
context_module::instance($this->coursemodule->id), $this->ratingallocateid);
Expand Down Expand Up @@ -1070,10 +1081,6 @@ private function process_default() {
}
}
}
// Print data and controls to edit the choices.
if (has_capability('mod/ratingallocate:modify_choices', $this->context)) {
$output .= $renderer->modify_choices_group($this->ratingallocateid, $this->coursemodule->id, $status);
}

// Print data and controls for teachers.
if (has_capability('mod/ratingallocate:start_distribution', $this->context)) {
Expand All @@ -1082,7 +1089,7 @@ private function process_default() {
$undistributeduserscount, (int) $this->ratingallocate->algorithmstatus,
(boolean) $this->ratingallocate->runalgorithmbycron);
$output .= $renderer->publish_allocation_group($this->ratingallocateid, $this->coursemodule->id, $status);
$output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, $status, $this->context);
// $output .= $renderer->reports_group($this->ratingallocateid, $this->coursemodule->id, $status, $this->context);
}

// Logging.
Expand Down
25 changes: 10 additions & 15 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,25 +405,20 @@ public function publish_allocation_group($ratingallocateid, $coursemoduleid, $st
/**
* Output the ratingallocate modfify allocation
*/
public function reports_group($ratingallocateid, $coursemoduleid, $status, $context) {
public function reports_group($ratingallocateid, $coursemoduleid, $status, $context, $action = '') {
$output = '';
$output .= $this->heading(get_string('reports_group', RATINGALLOCATE_MOD_NAME), 2);
$output .= $this->box_start();

$tableurl = new moodle_url($this->page->url, array('action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE));

// Button with link to display information about the allocations and ratings.
$output .= $this->single_button($tableurl, get_string('show_table', RATINGALLOCATE_MOD_NAME), 'get');

$tableurl = new moodle_url($this->page->url, array('action' => ACTION_SHOW_ALLOCATION_TABLE));

// Button with link to display information about the allocations and ratings.
$output .= $this->single_button($tableurl, get_string('show_allocation_table', RATINGALLOCATE_MOD_NAME), 'get');

$tableurl = new moodle_url($this->page->url, array('action' => ACTION_SHOW_STATISTICS));

// Buttton with link to display statistical information about the allocations.
$output .= $this->single_button($tableurl, get_string('show_allocation_statistics', RATINGALLOCATE_MOD_NAME), 'get');
$output .= $this->output->single_select(
new moodle_url('/mod/ratingallocate/view.php', array('id' => $coursemoduleid)),
'action', array(
ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE => get_string('show_table', RATINGALLOCATE_MOD_NAME),
ACTION_SHOW_ALLOCATION_TABLE => get_string('show_allocation_table', RATINGALLOCATE_MOD_NAME),
ACTION_SHOW_STATISTICS => get_string('show_allocation_statistics', RATINGALLOCATE_MOD_NAME)
),
$action
);

/* TODO: File not readable
$output .= html_writer::empty_tag('br', array());
Expand Down
17 changes: 8 additions & 9 deletions tests/behat/allocation_status.feature
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,51 @@ Feature: Students should get status information according to their rating and th
| activity | course | idnumber | name | accesstimestart |
| ratingallocate | C1 | ra1 | My Fair Allocation | ##yesterday## |
And I log in as "teacher1"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I press "Edit Choices"
And I am on the "My Fair Allocation" "mod_ratingallocate > Choices" page
And I add a new choice with the values:
| title | My only choice |
| Description (optional) | Test |
| maxsize | 1 |
And I log out
And I log in as "student1"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I am on the "My Fair Allocation" "mod_ratingallocate > View" page
And I press "Edit Rating"
And I press "Save changes"
And I log out
And I log in as "student2"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I am on the "My Fair Allocation" "mod_ratingallocate > View" page
And I press "Edit Rating"
And I click on "Deny" "radio"
And I press "Save changes"
And I log out
And I log in as "teacher1"
And I am on the "My Fair Allocation" "ratingallocate activity editing" page
And I am on the "My Fair Allocation" "mod_ratingallocate > Edit" page
And I set the following fields to these values:
| Rating begins at | ##2 days ago## |
| Rating ends at | ##yesterday## |
And I press "id_submitbutton"
And I run the scheduled task "mod_ratingallocate\task\cron_task"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I am on the "My Fair Allocation" "mod_ratingallocate > View" page
And I press "Publish Allocation"
And I log out

@javascript
Scenario: As a user, who rated and was allocated, I should see my allocated choice.
When I log in as "student1"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I am on the "My Fair Allocation" "mod_ratingallocate > View" page
Then I should see "My only choice" in the "//*[contains(@class, 'allocation')]" "xpath_element"
And I should see "My only choice" in the "//*[contains(@class, 'alert-success')]" "xpath_element"

@javascript
Scenario: As a user, who rated and was not allocated, I should see a warning.
When I log in as "student2"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I am on the "My Fair Allocation" "mod_ratingallocate > View" page
Then I should see "You were not allocated to any choice!" in the "//*[contains(@class, 'allocation')]" "xpath_element"
And I should see "You could not be allocated to any choice." in the "//*[contains(@class, 'alert-danger')]" "xpath_element"

@javascript
Scenario: As a user, who did not rate, I should not see my allocated choice
When I log in as "student3"
And I am on the "My Fair Allocation" "ratingallocate activity" page
And I am on the "My Fair Allocation" "mod_ratingallocate > View" page
Then I should not see "Your Allocation"
And I should see "The rating is over." in the "//*[contains(@class, 'alert-info')]" "xpath_element"
81 changes: 81 additions & 0 deletions tests/behat/behat_mod_ratingallocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -572,4 +572,85 @@ public function i_rate_choices_with_the_following_points(TableNode $ratingdata)
}
}

/**
* Convert page names to URLs for steps like 'When I am on the "mod_ratingallocate > [page name]" page'.
*
* Recognised page names are:
* | None so far! | |
*
* @param string $page name of the page, with the component name removed e.g. 'Edit'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_url(string $page): moodle_url {
switch (strtolower($page)) {
default:
throw new Exception('Unrecognised mod_ratingallocate page type "' . $page . '."');
}
}

/**
* Convert page names to URLs for steps like 'When I am on the "[identifier]" "[page type]" page'.
*
* Recognised page names are:
* | pagetype | name meaning | description |
* | View | Ratingallocate name | The ratingallocate info page |
* | Edit | Ratingallocate name | The edit ratingallocate page |
* | Choices | Ratingallocate name | The page for editing choices |
* | Reports | Ratingallocate name | The page for reports and statistics |
*
* @param string $type identifies which type of page this is, e.g. 'mod_ratingallocate > Choices'.
* @param string $identifier identifies the particular page, e.g. 'My Fair Allocation'.
* @return moodle_url the corresponding URL.
* @throws Exception with a meaningful error message if the specified page cannot be found.
*/
protected function resolve_page_instance_url(string $type, string $identifier): moodle_url {

switch (strtolower($type)) {
case 'view':
return new moodle_url('/mod/ratingallocate/view.php',
['id' => $this->get_cm_by_ratingallocate_name($identifier)->id]);

case 'edit':
return new moodle_url('/course/modedit.php', [
'update' => $this->get_cm_by_ratingallocate_name($identifier)->id]);

case 'choices':
return new moodle_url('/mod/ratingallocate/view.php', [
'id' => $this->get_cm_by_ratingallocate_name($identifier)->id, 'action' => ACTION_SHOW_CHOICES
]);

case 'reports':
return new moodle_url('/mod/ratingallocate/view.php', [
'id' => $this->get_cm_by_ratingallocate_name($identifier)->id,
'action' => ACTION_SHOW_RATINGS_AND_ALLOCATION_TABLE
]);

default:
throw new Exception('Unrecognised ratingallocate page type "' . $type . '."');
}
}

/**
* Get a ratingallocate instance by name.
*
* @param string $name ratingallocate name.
* @return stdClass the corresponding DB row.
*/
protected function get_ratingallocate_by_name(string $name): stdClass {
global $DB;
return $DB->get_record('ratingallocate', ['name' => $name], '*', MUST_EXIST);
}

/**
* Get a ratingallocate cmid from the ratingallocate name.
*
* @param string $name ratingallocate name.
* @return stdClass cm from get_coursemodule_from_instance.
*/
protected function get_cm_by_ratingallocate_name(string $name): stdClass {
$ratingallocate = $this->get_ratingallocate_by_name($name);
return get_coursemodule_from_instance('ratingallocate', $ratingallocate->id, $ratingallocate->course);
}

}
Loading

0 comments on commit 83ef413

Please sign in to comment.