Skip to content

Commit

Permalink
Added editor capability
Browse files Browse the repository at this point in the history
Added editor capability to the question input text area.
  • Loading branch information
drachels committed Mar 23, 2021
1 parent 71f9bc6 commit 8c1e732
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 25 deletions.
2 changes: 1 addition & 1 deletion backup/moodle2/backup_hotquestion_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function define_structure() {
$questions = new backup_nested_element('questions');

$question = new backup_nested_element('question', array('id'), array(
'content', 'userid', 'time', 'anonymous', 'approved', 'tpriority'));
'content', 'format', 'userid', 'time', 'anonymous', 'approved', 'tpriority'));

$rounds = new backup_nested_element('rounds');

Expand Down
5 changes: 3 additions & 2 deletions 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="20201217" COMMENT="XMLDB file for Moodle mod/hotquestion"
<XMLDB PATH="mod/hotquestion/db" VERSION="20210323" COMMENT="XMLDB file for Moodle mod/hotquestion"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -40,6 +40,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="hotquestion" TYPE="int" LENGTH="10" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="The ID of the &quot;hotquestion&quot; that this question belongs to."/>
<FIELD NAME="content" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="The question content."/>
<FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false" COMMENT="Editor to use."/>
<FIELD NAME="userid" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="time" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false"/>
<FIELD NAME="anonymous" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
Expand Down Expand Up @@ -84,4 +85,4 @@
</INDEXES>
</TABLE>
</TABLES>
</XMLDB>
</XMLDB>
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,5 +274,20 @@ function xmldb_hotquestion_upgrade($oldversion=0) {
// Hotquestion savepoint reached.
upgrade_mod_savepoint(true, 2020121700, 'hotquestion');
}

if ($oldversion < 2021032300) {

// Define field format to be added to hotquestion_questions.
$table = new xmldb_table('hotquestion_questions');
$field = new xmldb_field('format', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'content');

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

// Hotquestion savepoint reached.
upgrade_mod_savepoint(true, 2021032300, 'hotquestion');
}
return $result;
}
6 changes: 4 additions & 2 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ public function add_new_question($fromform) {
global $USER, $CFG, $DB;
$data = new StdClass();
$data->hotquestion = $this->instance->id;
$data->content = trim($fromform->question);
// 20210218 Switched code to use text editor instead of text area.
$data->content = ($fromform->text_editor['text']);
$data->format = ($fromform->text_editor['format']);
$data->userid = $USER->id;
$data->time = time();
$data->tpriority = 0;
Expand Down Expand Up @@ -329,7 +331,7 @@ public function set_currentround($roundid = -1) {
// 20210214 Get total number of rounds for the current Hot Question activity.
$this->roundcount = (count($rounds));

// If there are no rounds, it is a new Hot Question activity and we need to create the first round for it.
// If there are no rounds, it is a new Hot Question activity and we need to create the first round for it.
if (empty($rounds)) {
// Create the first round.
$round = new StdClass();
Expand Down
6 changes: 3 additions & 3 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ public function definition() {

$mform =& $this->_form;

// Next line is to retrieve submit instruction setting and creates the text post area.
$mform->addElement('textarea', 'question', $temp->submitdirections, 'wrap="virtual" rows="3" cols="50"');
$mform->setType('question', PARAM_TEXT);
// 20210218 Changed to using a text editor instead of textarea.
$mform->addElement('editor', 'text_editor', $temp->submitdirections, 'wrap="virtual" rows="5"');
$mform->setType('text_editor', PARAM_RAW);

$mform->addElement('hidden', 'id', $cm->id, 'id="hotquestion_courseid"');
$mform->setType('id', PARAM_INT);
Expand Down
38 changes: 23 additions & 15 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,40 +83,46 @@ public function toolbar($shownew = true) {
$options['id'] = $this->hotquestion->cm->id;
$options['action'] = 'download';
$url = new moodle_url('/mod/hotquestion/view.php', $options);
$toolbuttons[] = html_writer::link($url, $this->pix_icon('a/download_all'
, get_string('csvexport', 'hotquestion'))
, array('class' => 'toolbutton'));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('a/download_all',
get_string('csvexport', 'hotquestion')),
array('class' => 'toolbutton'));
}

// Print prev/next round toolbuttons.
if ($this->hotquestion->get_prevround() != null) {
$roundp = $this->hotquestion->get_prevround()->id;
$roundn = '';
$url = new moodle_url('/mod/hotquestion/view.php', array('id' => $this->hotquestion->cm->id, 'round' => $roundp));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed_rtl'
, get_string('previousround', 'hotquestion')), array('class' => 'toolbutton'));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed_rtl',
get_string('previousround', 'hotquestion')),
array('class' => 'toolbutton'));
} else {
$toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty_rtl', '')
, array('class' => 'dis_toolbutton'));
$toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty_rtl', ''),
array('class' => 'dis_toolbutton'));
}

// 20200215 Text added to show x of n display in toolbar.
if (($this->hotquestion->get_roundcount() != null) && ($this->hotquestion->get_currentroundx() != null)) {
$cx = $this->hotquestion->get_currentroundx();
// Showing round x of n rounds. X = current round being looked at and n = total number of rounds.
$toolbuttons[] = $cx.get_string('xofn', 'hotquestion').$this->hotquestion->get_roundcount();
} else {
$toolbuttons[] = $this->hotquestion->get_roundcount().get_string('xofn', 'hotquestion').$this->hotquestion->get_roundcount();
}
$toolbuttons[] = $cx.get_string('xofn', 'hotquestion').
$this->hotquestion->get_roundcount();
} else {
$toolbuttons[] = $this->hotquestion->get_roundcount().
get_string('xofn', 'hotquestion').
$this->hotquestion->get_roundcount();
}

if ($this->hotquestion->get_nextround() != null) {
$roundn = $this->hotquestion->get_nextround()->id;
$roundp = '';
$url = new moodle_url('/mod/hotquestion/view.php', array('id' => $this->hotquestion->cm->id, 'round' => $roundn));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed'
, get_string('nextround', 'hotquestion')), array('class' => 'toolbutton'));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/collapsed',
get_string('nextround', 'hotquestion')),
array('class' => 'toolbutton'));
} else {
$toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty', ''), array('class' => 'dis_toolbutton'));
$toolbuttons[] = html_writer::tag('span', $this->pix_icon('t/collapsed_empty', ''),
array('class' => 'dis_toolbutton'));
}

// Print new round toolbutton.
Expand Down Expand Up @@ -164,7 +170,9 @@ public function toolbar($shownew = true) {

// Print refresh toolbutton.
$url = new moodle_url('/mod/hotquestion/view.php', array('id' => $this->hotquestion->cm->id));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/reload', get_string('reload')), array('class' => 'toolbutton'));
$toolbuttons[] = html_writer::link($url, $this->pix_icon('t/reload',
get_string('reload')),
array('class' => 'toolbutton'));

// Return all available toolbuttons.
$output .= html_writer::alist($toolbuttons, array('id' => 'toolbar'));
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 = 2021021501; // The current module version (Date: YYYYMMDDXX).
$plugin->version = 2021032300; // The current module version (Date: YYYYMMDDXX).
$plugin->requires = 2014111000; // Requires Moodle 2.8 version.
$plugin->cron = 0; // Period for cron to check this module (secs).
$plugin->component = 'mod_hotquestion';
$plugin->maturity = MATURITY_STABLE;
$plugin->release = "3.9.2 (Build: 2021021501)"; // User-friendly version number.
$plugin->release = "4.0.0 (Build: 2021032300)"; // User-friendly version number.

0 comments on commit 8c1e732

Please sign in to comment.