Skip to content

Commit

Permalink
Let students view questions after "close time"
Browse files Browse the repository at this point in the history
  • Loading branch information
Kemmotar83 committed Jan 11, 2023
1 parent 1b1788f commit d82e763
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 26 deletions.
13 changes: 0 additions & 13 deletions classes/local/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,6 @@ public static function hotquestion_update_calendar(stdClass $hotquestion, $cmid)
return true;
}

/**
* Returns availability status.
*
* Added 10/2/16. Called from view.php file.
* Moved 20210226.
* @param var $hotquestion
*/
public static function hq_available($hotquestion) {
$timeopen = $hotquestion->timeopen;
$timeclose = $hotquestion->timeclose;
return (($timeopen == 0 || time() >= $timeopen) && ($timeclose == 0 || time() < $timeclose));
}

/**
* Returns the hotquestion instance course_module id
*
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="timeopen" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Date HQ opens."/>
<FIELD NAME="timeclose" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Date HQ closes."/>
<FIELD NAME="viewaftertimeclose" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="questionlabel" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="Questions" SEQUENCE="false" COMMENT="Change default heading label as desired."/>
<FIELD NAME="teacherpriorityvisibility" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="1" SEQUENCE="false" COMMENT="Teacher priority column visibility."/>
<FIELD NAME="teacherprioritylabel" TYPE="char" LENGTH="20" NOTNULL="true" DEFAULT="Priority" SEQUENCE="false" COMMENT="Change the default heading label as desired."/>
Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,5 +554,20 @@ function xmldb_hotquestion_upgrade($oldversion=0) {
// Hotquestion savepoint reached.
upgrade_mod_savepoint(true, 2022070701, 'hotquestion');
}
// 4.1.0 Upgrade starts here.
if ($oldversion < 2022122300) {

// Redefine field comments to be added to hotquestion.
$table = new xmldb_table('hotquestion');
$field = new xmldb_field('viewaftertimeclose', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timeclose');

// Conditionally launch add field assessedtimestart.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Hotquestion savepoint reached.
upgrade_mod_savepoint(true, 2022122300, 'hotquestion');
}
return true;
}
2 changes: 2 additions & 0 deletions lang/en/hotquestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@
$string['totalcomments'] = 'Total comments';
$string['userid'] = 'Userid';
$string['valueinterror'] = 'The factor must be a positive integer number';
$string['viewaftertimeclose'] = 'View after close time';
$string['viewaftertimeclose_help'] = 'If enabled, students will be able to view questions also after close time, otherwise they will be hidden';
$string['viewallentries'] = '{$a->ucount} user(s) posted {$a->qcount} question(s).';
$string['viewallhotquestions'] = 'View all Hot Questions';
$string['viewentries'] = 'Participation in current round';
Expand Down
25 changes: 25 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,31 @@ public function __construct($cmid, $roundid = -1) {
$this->instance->cmidumber = $this->cm->idnumber;
}

/**
* Return whether the hotquestion is available due to open time and close time
*
* @return bool
*/
public function is_hotquestion_active() {
$open = ($this->instance->timeopen !== '0' && time() > $this->instance->timeopen) || $this->instance->timeopen === '0';
$close = ($this->instance->timeclose !== '0' && time() < $this->instance->timeclose) || $this->instance->timeclose === '0';
return $open && $close;
}

/**
* @return bool
*/
public function is_hotquestion_ended() {
return $this->instance->timeclose !== 0 && time() > $this->instance->timeclose;
}

/**
* @return bool
*/
public function is_hotquestion_yet_to_start() {
return $this->instance->timeopen !== 0 && time() < $this->instance->timeopen;
}

/**
* Return whether the user has voted on specified question.
*
Expand Down
4 changes: 4 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ public function definition() {
$mform->addElement('date_time_selector', 'timeclose',
get_string('hotquestionclosetime', 'hotquestion'),
array('optional' => true, 'step' => 1));
$mform->addElement('selectyesno', 'viewaftertimeclose',
get_string('viewaftertimeclose', 'hotquestion'));
$mform->addHelpButton('viewaftertimeclose', 'viewaftertimeclose', 'hotquestion');
$mform->disabledIf('viewaftertimeclose', 'timeclose[enabled]');

// Contrib by ecastro ULPGC.
// Add standard grading elements, common to all modules.
Expand Down
50 changes: 50 additions & 0 deletions tests/behat/behat_mod_hotquestion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
// This file is part of the mod_coursecertificate plugin for 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/>.

/**
* mod_hotquestion steps definitions.
*
* @package mod_hotquestion
* @category test
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once(__DIR__ . '/../../../../lib/behat/behat_base.php');

/**
* Steps definitions for mod_hotquestion.
*
* @package mod_hotquestion
* @category test
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_mod_hotquestion extends behat_base {

/**
* Step to open current course or activity settings page (language string changed between 3.11 and 4.0)
*
* @When /^I open course or activity settings page$/
* @return void
*/
public function i_open_course_or_activity_settings_page(): void {
global $CFG;
if ($CFG->version < 2022012100) {
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", ['Edit settings']);
} else {
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", ['Settings']);
}
}
}
File renamed without changes.
89 changes: 89 additions & 0 deletions tests/behat/questions_visibility_after_closing_time.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
@mod @mod_hotquestion
Feature: Set entry visibility after close time for HotQuestion
In order to control if a student can HotQuestion entries after closing time
As a teacher
I need to be able to set availability dates and viewaftertimeclose flag for a hotquestion.

Background:
Given the following "courses" exist:
| fullname | shortname | category | groupmode |
| Course 1 | C1 | 0 | 1 |
And the following "users" exist:
| username | firstname | lastname | email |
| teacher1 | Teacher | 1 | teacher1@asd.com |
| student1 | Student | 1 | student1@asd.com |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And the following "activity" exists:
| activity | hotquestion |
| course | C1 |
| idnumber | hotquestion1 |
| name | Test hotquestion name |
| intro | Test hotquestion description |
| grade | 0 |
| timeopen | 0 |
| timeclose | 0 |
| viewaftertimeclose | 0 |
Scenario: Student doesn't see questions after close time
#Teacher 1 posts an entry
Given I log in as "teacher1"
When I am on "Course 1" course homepage
And I follow "Test hotquestion name"
And I set the following fields to these values:
| Submit your question here | First question |
And I press "Click to post"
And I should not see "No entries yet."
And I should see "First question"
Then I log out
#Student 1 views and posts the questions
Given I log in as "student1"
When I am on "Course 1" course homepage
And I follow "Test hotquestion name"
And I should see "First question"
Then I log out
#Teacher 1 set time close
Given I log in as "teacher1"
When I am on "Course 1" course homepage
And I follow "Test hotquestion name"
And I open course or activity settings page
And I set the following fields to these values:
| timeclose[enabled] | 1 |
| timeclose[day] | 1 |
| timeclose[month] | 2 |
| timeclose[year] | 2017 |
And I press "Save and return to course"
Then I log out
#Student 1 cannot view questions
Given I log in as "student1"
When I am on "Course 1" course homepage
And I follow "Test hotquestion name"
And I should see "Not currently available!"
Then I log out
Scenario: Student do see questions after close time when "View after close time" is set
#Teacher 1 posts an entry, set close time and enables "View after close time"
Given I log in as "teacher1"
When I am on "Course 1" course homepage
And I follow "Test hotquestion name"
And I set the following fields to these values:
| Submit your question here | First question |
And I press "Click to post"
And I should not see "No entries yet."
And I should see "First question"
Then I open course or activity settings page
And I set the following fields to these values:
| timeclose[enabled] | 1 |
| timeclose[day] | 1 |
| timeclose[month] | 2 |
| timeclose[year] | 2017 |
| viewaftertimeclose | 1 |
And I press "Save and return to course"
Then I log out
#Student 1 views questions
Given I log in as "student1"
When I am on "Course 1" course homepage
And I follow "Test hotquestion name"
And I should see "First question"
And I should not see "Submit your question here"
Then I log out
2 changes: 1 addition & 1 deletion version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022121900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2023011100; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2021051700; // Requires Moodle 3.11 version.
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_hotquestion';
Expand Down
30 changes: 18 additions & 12 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,20 +227,23 @@
echo $OUTPUT->heading($hotquestionname);
}
// Allow access at any time to manager and editing teacher but prevent access to students.
if (!(has_capability('mod/hotquestion:manage', $context))) {
// Check availability timeopen and timeclose. Added 10/2/16.
if (!(results::hq_available($hotquestion))) { // Availability restrictions.
if ($hotquestion->timeclose != 0 && time() > $hotquestion->timeclose) {
echo $output->hotquestion_inaccessible(get_string('hotquestionclosed',
'hotquestion', userdate($hotquestion->timeclose)));
} else {
echo $output->hotquestion_inaccessible(get_string('hotquestionopen',
'hotquestion', userdate($hotquestion->timeopen)));
}
// Check availability timeopen and timeclose. Added 10/2/16.
if (!(has_capability('mod/hotquestion:manage', $context)) && !$hq->is_hotquestion_active()) { // Availability restrictions.
$inaccessible = '';
if ($hq->is_hotquestion_ended() && !$hotquestion->viewaftertimeclose) {
$inaccessible = $output->hotquestion_inaccessible(get_string('hotquestionclosed',
'hotquestion', userdate($hotquestion->timeclose)));
}
if ($hq->is_hotquestion_yet_to_start()) {
$inaccessible = $output->hotquestion_inaccessible(get_string('hotquestionopen',
'hotquestion', userdate($hotquestion->timeopen)));
}
if ($inaccessible !== '') {
echo $inaccessible;
echo $OUTPUT->footer();
exit();
// Password code can go here. e.g. // } else if {.
}
// Password code can go here. e.g. // } else if {.
}
// 20220301 Added activity completion to the hotquestion description.
$cminfo = cm_info::create($cm);
Expand Down Expand Up @@ -270,11 +273,14 @@
echo groups_print_activity_menu($cm, $CFG->wwwroot.'/mod/hotquestion/view.php?id='.$cm->id);

// Print the textarea box for typing submissions in.
if (has_capability('mod/hotquestion:ask', $context)) {
if (has_capability('mod/hotquestion:ask', $context) &&
$hq->is_hotquestion_active()) {
$mform->display();
}
}

//die("EDDIE");

echo $output->container_start(null, 'questions_list');
// Print toolbar.
echo $output->container_start("toolbar");
Expand Down

0 comments on commit d82e763

Please sign in to comment.