Skip to content

Commit

Permalink
Implemented viewaftertimeclose
Browse files Browse the repository at this point in the history
  • Loading branch information
drachels committed Jan 24, 2023
1 parent af15ea8 commit e84d957
Show file tree
Hide file tree
Showing 11 changed files with 122 additions and 32 deletions.
1 change: 1 addition & 0 deletions backup/moodle2/backup_hotquestion_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ protected function define_structure() {
'timemodified',
'timeopen',
'timeclose',
'viewaftertimeclose',
'questionlabel',
'teacherpriorityvisibility',
'teacherprioritylabel',
Expand Down
9 changes: 7 additions & 2 deletions classes/local/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,17 @@ public static function hotquestion_update_calendar(stdClass $hotquestion, $cmid)
* Moved 20210226.
* @param var $hotquestion
*/
// Temporary disable for testing new contributed code for viewing after time close.
/*
public static function hq_available($hotquestion) {
$timeopen = $hotquestion->timeopen;
$timeclose = $hotquestion->timeclose;
return (($timeopen == 0 || time() >= $timeopen) && ($timeclose == 0 || time() < $timeclose));
$viewwochanging = $hotquestion->viewaftertimeclose;
return (($timeopen == 0 || time() >= $timeopen) &&
($timeclose == 0 || time() < $timeclose) ||
(time() < $timeclose && $viewwochanging));
}

*/
/**
* Returns the hotquestion instance course_module id
*
Expand Down
3 changes: 2 additions & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="mod/hotquestion/db" VERSION="20220508" COMMENT="XMLDB file for Moodle mod/hotquestion"
<XMLDB PATH="mod/hotquestion/db" VERSION="20230120" COMMENT="XMLDB file for Moodle mod/hotquestion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand All @@ -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" COMMENT="Allow question viewing after activity is closed."/>
<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
13 changes: 11 additions & 2 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ function xmldb_hotquestion_upgrade($oldversion=0) {
}

// 4.1.5 Upgrade starts here.
if ($oldversion < 2023011900) {
if ($oldversion < 2023012000) {
// If they exist, need code to drop two fields, assessedtimefinish and assessedtimestart.
// Define field assessedtimefinish to be dropped from hotquestion.
$table = new xmldb_table('hotquestion');
Expand All @@ -575,8 +575,17 @@ function xmldb_hotquestion_upgrade($oldversion=0) {
$dbman->drop_field($table, $field);
}

// Define field viewaftertimeclose 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 viewaftertimeclose.
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}

// Hotquestion savepoint reached.
upgrade_mod_savepoint(true, XXXXXXXXXX, 'hotquestion');
upgrade_mod_savepoint(true, 2023012000, '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, but not alter, questions and heat 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
27 changes: 26 additions & 1 deletion 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 Expand Up @@ -115,8 +140,8 @@ public function vote_on($question) {
$votes = new StdClass();
$context = context_module::instance($this->cm->id);
$question = $DB->get_record('hotquestion_questions', array('id' => $question));
if ($question && $this->can_vote_on($question)) {

if ($question && $this->can_vote_on($question)) {
// Trigger and log a vote event.
if ($CFG->version > 2014051200) { // If newer than Moodle 2.7+ use new event logging.
$params = array(
Expand Down
13 changes: 9 additions & 4 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,16 @@ public function definition() {
$mform->addElement('header', 'availabilityhdr', get_string('availability'));

$mform->addElement('date_time_selector', 'timeopen',
get_string('hotquestionopentime', 'hotquestion'),
array('optional' => true, 'step' => 1));
get_string('hotquestionopentime', 'hotquestion'),
array('optional' => true, 'step' => 1));
$mform->addElement('date_time_selector', 'timeclose',
get_string('hotquestionclosetime', 'hotquestion'),
array('optional' => true, 'step' => 1));
get_string('hotquestionclosetime', 'hotquestion'),
array('optional' => true, 'step' => 1));
// Contrib by Kemmotar83.
$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
2 changes: 1 addition & 1 deletion tests/behat/behat_mod_hotquestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ public function i_open_course_or_activity_settings_page(): void {
$this->execute("behat_navigation::i_navigate_to_in_current_page_administration", ['Settings']);
}
}
}
}
13 changes: 12 additions & 1 deletion upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,18 @@ This files describes changes in the Hot Question code.
assestimestart and assesstimefinish are required for ratings, but assessedtimefinish
and assessedtimestart are not used at all, so I need to see about dropping them.
I have included code in upgrade.php that will drop the fields, if they exist.

20230122 HotQuestion_989 - Issue #68 at github, Let students view questions after "close time."
I have all the contributed code integrated, but it needs more work. WIll need to hide the
capability for students to change votes when the activity is closed. Right now a studet
can still change their votes after the activity has closed.
20230123 HotQuestion_997 - When set, open and close times should show on the view.php page.
I have added code that will show the open and/or close times, if either one of them is
set and being used. The code is down around line 285 of the view.php file.
20230124 HotQuestion_999 - Need to prevent students from changing vote when viewing after
close time. Modified the case 'vote" and case 'remove' in the view.php file. Student
clicks on the heat vote icon are ignored. Clicks by anyone with manage capabilities
can change and/or remove their votes, as I can see a case for teachers catching up
with grading, after the activity has closed.

=== 4.1.4 === 20221219 Only for M3.11 and above.
20221126 HotQuestion_959v - Need to make sure the new rating data is being added to
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@

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

$plugin->version = 2023011900; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2023012000; // 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';
$plugin->maturity = MATURITY_BETA;
$plugin->release = "4.1.5 (Build: 2023011900)"; // User-friendly version number.
$plugin->release = "4.1.5 (Build: 2023012000)"; // User-friendly version number.
67 changes: 49 additions & 18 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,16 +160,24 @@
break;
case 'vote':
if (has_capability('mod/hotquestion:vote', $context)) {
$q = required_param('q', PARAM_INT); // Question id to vote.
$hq->vote_on($q);
redirect('view.php?id='.$hq->cm->id, null); // Needed to prevent heat toggle on page reload.
// 20230122 Prevent voting when closed.
if (($hq->is_hotquestion_ended() && !$hotquestion->viewaftertimeclose) ||
(has_capability('mod/hotquestion:manageentries', $context))) {
$q = required_param('q', PARAM_INT); // Question id to vote.
$hq->vote_on($q);
redirect('view.php?id='.$hq->cm->id, null); // Needed to prevent heat toggle on page reload.
}
}
break;
case 'removevote':
if (has_capability('mod/hotquestion:vote', $context)) {
$q = required_param('q', PARAM_INT); // Question id to vote.
$hq->remove_vote($q);
redirect('view.php?id='.$hq->cm->id, null); // Needed to prevent heat toggle on page reload.
// 20230122 Prevent vote remove when closed.
if (($hq->is_hotquestion_ended() && !$hotquestion->viewaftertimeclose) ||
(has_capability('mod/hotquestion:manageentries', $context))) {
$q = required_param('q', PARAM_INT); // Question id to vote.
$hq->remove_vote($q);
redirect('view.php?id='.$hq->cm->id, null); // Needed to prevent heat toggle on page reload.
}
}
break;
case 'newround':
Expand Down Expand Up @@ -226,22 +234,27 @@
if ($CFG->branch < 400) {
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. Modified 20230120.
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);
$completiondetails = \core_completion\cm_completion_details::get_instance($cminfo, $USER->id);
Expand All @@ -252,6 +265,22 @@
echo $output->introduction($cminfo, $completiondetails, $activitydates);
}

// 20230123 Added open and close times, if set.
if (($hotquestion->timeopen) && (($hotquestion->timeopen) > time())) {
echo '<strong>'.get_string('hotquestionopen', 'hotquestion', date("l, d M Y, G:i A", $hotquestion->timeopen)).
'</strong><br>';
} else if ($hotquestion->timeopen) {
echo '<strong>'.get_string('hotquestionopentime', 'hotquestion').
':</strong> '.date("l, d M Y, G:i A", $hotquestion->timeopen).'<br>';
}
if (($hotquestion->timeclose) && (($hotquestion->timeclose) < time())) {
echo '<strong>'.get_string('hotquestionclosed', 'hotquestion', date("l, d M Y, G:i A", $hotquestion->timeclose)).
'</strong>';
} else if ($hotquestion->timeclose) {
echo '<strong>'.get_string('hotquestionclosetime', 'hotquestion').
':</strong> '.date("l, d M Y, G:i A", $hotquestion->timeclose);
}

// 20211219 Added link to all HotQuestion activities. 20221031 Added link to hide unapproved questions.
echo '<span style="float:right"><a href="index.php?id='
.$course->id
Expand All @@ -270,7 +299,9 @@
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:manage', $context) ||
(has_capability('mod/hotquestion:ask', $context) &&
$hq->is_hotquestion_active())) {
$mform->display();
}
}
Expand Down

0 comments on commit e84d957

Please sign in to comment.