mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 14:27:22 +01:00
MDL-34375 Choice: Display choice on 'my home'
This commit is contained in:
parent
7357af2b0c
commit
c04b66a564
@ -39,12 +39,14 @@ $string['atleastoneoption'] = 'You need to provide at least one possible answer.
|
||||
$string['full'] = '(Full)';
|
||||
$string['havetologin'] = 'You have to log in before you can submit your choice';
|
||||
$string['choice'] = 'Choice';
|
||||
$string['choiceactivityname'] = 'Choice: {$a}';
|
||||
$string['choice:addinstance'] = 'Add a new choice';
|
||||
$string['choiceclose'] = 'Until';
|
||||
$string['choice:deleteresponses'] = 'Delete responses';
|
||||
$string['choice:downloadresponses'] = 'Download responses';
|
||||
$string['choicefull'] = 'This choice is full and there are no available places.';
|
||||
$string['choice:choose'] = 'Record a choice';
|
||||
$string['choicecloseson'] = 'Choice closes on {$a}';
|
||||
$string['choicename'] = 'Choice name';
|
||||
$string['choiceopen'] = 'Open';
|
||||
$string['choiceoptions'] = 'Choice options';
|
||||
|
@ -813,3 +813,76 @@ function choice_page_type_list($pagetype, $parentcontext, $currentcontext) {
|
||||
$module_pagetype = array('mod-choice-*'=>get_string('page-mod-choice-x', 'choice'));
|
||||
return $module_pagetype;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints choice summaries on MyMoodle Page
|
||||
*
|
||||
* Prints choice name, due date and attempt information on
|
||||
* choice activities that have a deadline that has not already passed
|
||||
* and it is available for completing.
|
||||
* @uses CONTEXT_MODULE
|
||||
* @param array $courses An array of course objects to get choice instances from.
|
||||
* @param array $htmlarray Store overview output array( course ID => 'choice' => HTML output )
|
||||
*/
|
||||
function choice_print_overview($courses, &$htmlarray) {
|
||||
global $USER, $DB, $OUTPUT;
|
||||
|
||||
if (empty($courses) || !is_array($courses) || count($courses) == 0) {
|
||||
return;
|
||||
}
|
||||
if (!$choices = get_all_instances_in_courses('choice', $courses)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$now = time();
|
||||
foreach ($choices as $choice) {
|
||||
if ($choice->timeclose != 0 // If this choice is scheduled.
|
||||
and $choice->timeclose >= $now // And the deadline has not passed.
|
||||
and ($choice->timeopen == 0 or $choice->timeopen <= $now)) { // And the choice is available.
|
||||
|
||||
// Visibility.
|
||||
$class = (!$choice->visible) ? 'dimmed' : '';
|
||||
|
||||
// Link to activity.
|
||||
$url = new moodle_url('/mod/choice/view.php', array('id' => $choice->coursemodule));
|
||||
$url = html_writer::link($url, format_string($choice->name), array('class' => $class));
|
||||
$str = $OUTPUT->box(get_string('choiceactivityname', 'choice', $url), 'name');
|
||||
|
||||
// Deadline.
|
||||
$str .= $OUTPUT->box(get_string('choicecloseson', 'choice', userdate($choice->timeclose)), 'info');
|
||||
|
||||
// Display relevant info based on permissions.
|
||||
if (has_capability('mod/choice:readresponses', context_module::instance($choice->coursemodule))) {
|
||||
$attempts = $DB->count_records('choice_answers', array('choiceid' => $choice->id));
|
||||
$str .= $OUTPUT->box(get_string('viewallresponses', 'choice', $attempts), 'info');
|
||||
|
||||
} else if (has_capability('mod/choice:choose', context_module::instance($choice->coursemodule))) {
|
||||
// See if the user has submitted anything.
|
||||
$answers = $DB->count_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $USER->id));
|
||||
if ($answers > 0) {
|
||||
// User has already selected an answer, nothing to show.
|
||||
$str = '';
|
||||
} else {
|
||||
// User has not made a selection yet.
|
||||
$str .= $OUTPUT->box(get_string('notanswered', 'choice'), 'info');
|
||||
}
|
||||
} else {
|
||||
// Does not have permission to do anything on this choice activity.
|
||||
$str = '';
|
||||
}
|
||||
|
||||
// Make sure we have something to display.
|
||||
if (!empty($str)) {
|
||||
// Generate the containing div.
|
||||
$str = $OUTPUT->box($str, 'choice overview');
|
||||
|
||||
if (empty($htmlarray[$choice->course]['choice'])) {
|
||||
$htmlarray[$choice->course]['choice'] = $str;
|
||||
} else {
|
||||
$htmlarray[$choice->course]['choice'] .= $str;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
73
mod/choice/tests/behat/my_home.feature
Normal file
73
mod/choice/tests/behat/my_home.feature
Normal file
@ -0,0 +1,73 @@
|
||||
@mod @mod_choice @javascript
|
||||
Feature: Test the display of the choice module on my home
|
||||
In order to know my status in a choice activity
|
||||
As a user
|
||||
I need to see it in My home.
|
||||
|
||||
Background:
|
||||
Given the following "users" exist:
|
||||
| username | firstname | lastname | email |
|
||||
| teacher1 | Teacher | 1 | teacher1@asd.com |
|
||||
| student1 | Student | 1 | student1@asd.com |
|
||||
And the following "courses" exist:
|
||||
| fullname | shortname | category |
|
||||
| Course 1 | C1 | 0 |
|
||||
And the following "course enrolments" exist:
|
||||
| user | course | role |
|
||||
| teacher1 | C1 | editingteacher |
|
||||
| student1 | C1 | student |
|
||||
And I log in as "teacher1"
|
||||
And I follow "Course 1"
|
||||
And I turn editing mode on
|
||||
And I add a "Choice" to section "1"
|
||||
And I expand all fieldsets
|
||||
And I click on "id_timerestrict" "checkbox"
|
||||
And I set the following fields to these values:
|
||||
| Choice name | Test choice name |
|
||||
| Description | Test choice description |
|
||||
| timeclose[day] | 1 |
|
||||
| timeclose[month] | January |
|
||||
| timeclose[year] | 2030 |
|
||||
| timeclose[hour] | 08 |
|
||||
| timeclose[minute] | 00 |
|
||||
| Allow choice to be updated | No |
|
||||
| option[0] | Option 1 |
|
||||
| option[1] | Option 2 |
|
||||
And I press "Save and return to course"
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: View my home as a student before answering the choice
|
||||
Given I log in as "student1"
|
||||
When I click on "My home" "link" in the "Navigation" "block"
|
||||
Then I should see "You have Choices that need attention"
|
||||
And I click on ".collapsibleregioncaption" "css_element"
|
||||
And I should see "Not answered yet"
|
||||
And I log out
|
||||
|
||||
Scenario: View my home as a student after answering the choice
|
||||
Given I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
And I choose "Option 1" from "Test choice name" choice activity
|
||||
And I should see "Your selection: Option 1"
|
||||
And I should see "Your choice has been saved"
|
||||
And "Save my choice" "button" should not exist
|
||||
When I click on "My home" "link" in the "Navigation" "block"
|
||||
Then I should not see "You have Choices that need attention"
|
||||
And I log out
|
||||
|
||||
@javascript
|
||||
Scenario: View my home as a teacher
|
||||
Given I log in as "student1"
|
||||
And I follow "Course 1"
|
||||
And I choose "Option 1" from "Test choice name" choice activity
|
||||
And I should see "Your selection: Option 1"
|
||||
And I should see "Your choice has been saved"
|
||||
And "Save my choice" "button" should not exist
|
||||
And I log out
|
||||
When I log in as "teacher1"
|
||||
And I click on "My home" "link" in the "Navigation" "block"
|
||||
Then I should see "You have Choices that need attention"
|
||||
And I click on ".collapsibleregioncaption" "css_element"
|
||||
And I should see "View 1 responses"
|
||||
And I log out
|
Loading…
x
Reference in New Issue
Block a user