-
Notifications
You must be signed in to change notification settings - Fork 197
Activities Course overview integration, resolves #668 #669
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
Merged
mchurchward
merged 1 commit into
PoetOS:MOODLE_500_STABLE
from
lucaboesch:activitiespage
Nov 21, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| <?php | ||
| // 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/>. | ||
|
|
||
| namespace mod_questionnaire\courseformat; | ||
|
|
||
| use cm_info; | ||
| use core\output\pix_icon; | ||
| use mod_questionnaire\manager; | ||
| use core\activity_dates; | ||
| use core\output\action_link; | ||
| use core_calendar\output\humandate; | ||
| use core\output\local\properties\button; | ||
| use core\output\local\properties\text_align; | ||
| use core_courseformat\local\overview\overviewitem; | ||
|
|
||
| /** | ||
| * Questionnaire overview integration. | ||
| * | ||
| * @package mod_questionnaire | ||
| * @copyright 2025 Luca Bösch <luca.boesch@bfh.ch> | ||
| * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
| */ | ||
| class overview extends \core_courseformat\activityoverviewbase { | ||
| /** | ||
| * @var manager the questionnaire manager. | ||
| */ | ||
| private manager $manager; | ||
|
|
||
| /** | ||
| * Constructor. | ||
| * | ||
| * @param cm_info $cm the course module instance. | ||
| * @param \core\output\renderer_helper $rendererhelper the renderer helper. | ||
| */ | ||
| public function __construct( | ||
| cm_info $cm, | ||
| /** @var \core\output\renderer_helper $rendererhelper the renderer helper */ | ||
| protected readonly \core\output\renderer_helper $rendererhelper, | ||
| ) { | ||
| parent::__construct($cm); | ||
| $this->manager = manager::create_from_coursemodule($cm); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function get_due_date_overview(): ?overviewitem { | ||
| global $USER; | ||
|
|
||
| $dates = activity_dates::get_dates_for_module($this->cm, $USER->id); | ||
| $closedate = null; | ||
| foreach ($dates as $date) { | ||
| if ($date['dataid'] === 'timeclose') { | ||
| $closedate = $date['timestamp']; | ||
| break; | ||
| } | ||
| } | ||
| if (empty($closedate)) { | ||
| return new overviewitem( | ||
| name: get_string('duedate', 'questionnaire'), | ||
| value: null, | ||
| content: '-', | ||
| ); | ||
| } | ||
|
|
||
| $content = humandate::create_from_timestamp($closedate); | ||
|
|
||
| return new overviewitem( | ||
| name: get_string('duedate', 'questionnaire'), | ||
| value: $closedate, | ||
| content: $content, | ||
| ); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function get_actions_overview(): ?overviewitem { | ||
| if (!has_capability('mod/questionnaire:viewsingleresponse', $this->context)) { | ||
| return null; | ||
| } | ||
|
|
||
| $currentanswerscount = $this->manager->count_all_users_answered(); | ||
|
|
||
| $content = new action_link( | ||
| url: new \moodle_url('/mod/questionnaire/report.php', ['instance' => $this->cm->instance]), | ||
| text: get_string('view', 'core'), | ||
| attributes: ['class' => button::SECONDARY_OUTLINE->classes()], | ||
| ); | ||
|
|
||
| return new overviewitem( | ||
| name: get_string('actions'), | ||
| value: get_string('viewallxresponses', 'questionnaire', $currentanswerscount), | ||
| content: $content, | ||
| textalign: text_align::CENTER, | ||
| ); | ||
| } | ||
|
|
||
| #[\Override] | ||
| public function get_extra_overview_items(): array { | ||
| return [ | ||
| 'studentwhoresponded' => $this->get_extra_students_who_responded_overview(), | ||
| 'responded' => $this->get_extra_status_for_user(), | ||
| ]; | ||
| } | ||
|
|
||
| /** | ||
| * Get the response status overview item. | ||
| * | ||
| * @return overviewitem|null An overview item or null for teachers. | ||
| */ | ||
| private function get_extra_status_for_user(): ?overviewitem { | ||
| if (has_capability('mod/questionnaire:viewsingleresponse', $this->cm->context)) { | ||
| return null; | ||
| } | ||
|
|
||
| $status = $this->manager->has_answered(); | ||
| $statustext = get_string('notanswered', 'questionnaire'); | ||
| if ($status) { | ||
| $statustext = get_string('answered', 'questionnaire'); | ||
| } | ||
| $submittedstatuscontent = "-"; | ||
| if ($status) { | ||
| $submittedstatuscontent = new pix_icon( | ||
| pix: 'i/checkedcircle', | ||
| alt: $statustext, | ||
| component: 'core', | ||
| attributes: ['class' => 'text-success'], | ||
| ); | ||
| } | ||
| return new overviewitem( | ||
| name: get_string('responded', 'questionnaire'), | ||
| value: $status, | ||
| content: $submittedstatuscontent, | ||
| textalign: text_align::CENTER, | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the count of student who responded. | ||
| * | ||
| * @return overviewitem|null An overview item or null if for students. | ||
| */ | ||
| private function get_extra_students_who_responded_overview(): ?overviewitem { | ||
| if (!has_capability('mod/questionnaire:viewsingleresponse', $this->cm->context)) { | ||
| return null; | ||
| } | ||
|
|
||
| if (is_callable([$this, 'get_groups_for_filtering'])) { | ||
| $groupids = array_keys($this->get_groups_for_filtering()); | ||
| } else { | ||
| $groupids = []; | ||
| } | ||
| $studentswhoresponded = $this->manager->count_all_users_answered($groupids); | ||
|
|
||
| return new overviewitem( | ||
| name: get_string('studentwhoresponded', 'questionnaire'), | ||
| value: $studentswhoresponded, | ||
| content: $studentswhoresponded, | ||
| textalign: text_align::END, | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| <?php | ||
| // 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/>. | ||
|
|
||
| /** | ||
| * Contains the class for fetching the important dates in mod_questionnaire for a given module instance and a user. | ||
| * | ||
| * @package mod_questionnaire | ||
| * @copyright Luca Bösch <luca.boesch@bfh.ch> | ||
| * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace mod_questionnaire; | ||
|
|
||
| use core\activity_dates; | ||
|
|
||
| /** | ||
| * Class for fetching the important dates in mod_questionnaire for a given module instance and a user. | ||
| * | ||
| * @copyright Luca Bösch <luca.boesch@bfh.ch> | ||
| * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
| */ | ||
| class dates extends activity_dates { | ||
| /** | ||
| * Returns a list of important dates in mod_questionnaire | ||
| * | ||
| * @return array | ||
| */ | ||
| protected function get_dates(): array { | ||
| $timeopen = $this->cm->customdata['timeopen'] ?? null; | ||
| $timeclose = $this->cm->customdata['timeclose'] ?? null; | ||
| $now = time(); | ||
| $dates = []; | ||
| if ($timeopen) { | ||
| $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; | ||
| $dates[] = [ | ||
| 'dataid' => 'timeopen', | ||
| 'label' => get_string($openlabelid, 'course'), | ||
| 'timestamp' => (int) $timeopen, | ||
| ]; | ||
| } | ||
|
|
||
| if ($timeclose) { | ||
| $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; | ||
| $dates[] = [ | ||
| 'dataid' => 'timeclose', | ||
| 'label' => get_string($closelabelid, 'course'), | ||
| 'timestamp' => (int) $timeclose, | ||
| ]; | ||
| } | ||
|
|
||
| return $dates; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.