Skip to content
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

WIP: feature #116 - show author of note #117

Open
wants to merge 6 commits into
base: MOODLE_401_STABLE
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion amd/build/board.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion amd/build/board.min.js.map

Large diffs are not rendered by default.

33 changes: 30 additions & 3 deletions amd/src/board.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,13 @@ export default function(settings) {
isEditor = options.isEditor || false,
usersCanEdit = options.usersCanEdit,
userId = parseInt(options.userId) || -1,
userFullname = options.userFullname,
ownerId = parseInt(options.ownerId),
mediaSelection = options.mediaselection || MEDIA_SELECTION_BUTTONS,
editingNote = 0,
isReadOnlyBoard = options.readonly || false,
showauthorofnote = options.showauthorofnote || false,
allowshowauthorofnoteonboard = options.allowshowauthorofnoteonboard || false,
ratingenabled = options.ratingenabled,
sortby = options.sortby || SORTBY_DATE,
editModal = null,
Expand Down Expand Up @@ -753,7 +756,7 @@ export default function(settings) {
* @param {string} heading
* @param {string} content
* @param {object} attachment
* @param {object} owner
* @param {object} owner the owner of the note containing the userid as id and the owner fullname
* @param {number} sortorder
* @param {string} rating
*/
Expand Down Expand Up @@ -795,12 +798,31 @@ export default function(settings) {
var notecontent = $('<div class="mod_board_note_content"></div>'),
notecontrols = $('<div class="mod_board_note_controls"></div>'),
noteHeading = $('<div class="mod_board_note_heading" tabindex="0">' + (heading ? heading : '') + '</div>'),
noteAuthorusername = $(''),
noteBorder = $('<div class="mod_board_note_border"></div>'),
noteText = $('<div class="mod_board_note_text" tabindex="0">' + (content ? content : '') + '</div>'),
noteAriaText = $('<div class="note_ariatext hidden" role="heading" aria-level="4" tabindex="0"></div>'),
attachmentPreview = $('<div class="mod_board_preview"></div>');

if (allowshowauthorofnoteonboard == true && showauthorofnote == true) {
let fullname = '';
if (ismynote) {
// Use the Name of the user itself. We do not need to get this information from somewhere else.
fullname = userFullname;
} else {
fullname = owner.fullname;
}

noteAuthorusername = '<div class="mod_board_note_author">' +
'<i class="fa fa-user" title="' + fullname + '"></i> ' +
'<span class="mod_board_note_author_fullname">' +
fullname +
'</span>' +
'</div>' ;
}

notecontent.append(noteHeading);
notecontent.append(noteAuthorusername);
notecontent.append(noteBorder);
notecontent.append(noteText);
notecontent.append(noteAriaText);
Expand Down Expand Up @@ -1019,6 +1041,7 @@ export default function(settings) {
newNoteButton.addClass('d-none');
}
handleAction(columnNewContent.find('.newnote'), function() {
// We do not need to add fullname to the owner because we use ismynote and the fullname of the actual board user.
addNote(ident, 0, null, null, null, {id: userId}, 0, 0);
});
}
Expand All @@ -1033,9 +1056,11 @@ export default function(settings) {
if (notes) {
for (var index in notes) {
let sortorder = sortby == 3 ? notes[index].sortorder : notes[index].timecreated;

addNote(ident, notes[index].id, notes[index].heading, notes[index].content,
{type: notes[index].type, info: notes[index].info, url: notes[index].url},
{id: notes[index].userid}, sortorder, notes[index].rating);
{id: notes[index].userid, fullname: notes[index].fullname},
sortorder, notes[index].rating);
}
}
sortNotes(columnContent);
Expand Down Expand Up @@ -1146,12 +1171,14 @@ export default function(settings) {

var data = JSON.parse(item.content);
if (item.action == 'add_note') {
// This is called on a board if someone else has added a note in a different browser.
let sortorder = sortby == 3 ? data.sortorder : data.timecreated;
addNote(data.columnid, data.id, data.heading, data.content, data.attachment,
{id: item.userid}, sortorder, data.rating);
{id: item.userid , fullname: item.userid + " " + item.fullname}, sortorder, data.rating);
updateNoteAria(data.id);
sortNotes($('.board_column[data-ident=' + data.columnid + '] .board_column_content'));
} else if (item.action == 'update_note') {
// This is called on a board if someone else has updated a note in a different browser.
let note = getNote(data.id),
formModal = editModal,
historyData = data;
Expand Down
7 changes: 3 additions & 4 deletions backup/moodle2/backup_board_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ protected function define_structure() {

$userinfo = $this->get_setting_value('userinfo');

$board = new backup_nested_element('board', array('id'), array(
'course', 'name', 'timemodified', 'intro', 'introformat', 'historyid',
'background_color', 'addrating', 'hideheaders', 'sortby', 'postby', 'userscanedit', 'singleusermode',
'completionnotes'));
$board = new backup_nested_element('board', array('id'), array('course', 'name', 'timemodified', 'intro', 'introformat',
'historyid', 'background_color', 'showauthorofnote', 'addrating', 'hideheaders', 'sortby', 'postby',
'userscanedit', 'singleusermode', 'completionnotes'));

$columns = new backup_nested_element('columns');
$column = new backup_nested_element('column', array('id'), array('boardid', 'name', 'sortorder'));
Expand Down
57 changes: 55 additions & 2 deletions classes/board.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@

namespace mod_board;

use tool_brickfield\local\areas\core_course\fullname;
use core_user;

/**
* The main board class functions.
*
* @package mod_board
* @author Jay Churchward <[email protected]>
* @copyright 2021 Brickfield Education Labs <https://www.brickfield.ie/>
Expand Down Expand Up @@ -73,6 +77,8 @@ class board {
/** @var int Value for the singleusermode setting in public mode*/
const SINGLEUSER_PUBLIC = 2;

static $alluserids = [];

/**
* Retrieves the course module for the board
*
Expand Down Expand Up @@ -101,6 +107,7 @@ public static function get_configuration($id, $ownerid) {
'isEditor' => self::board_is_editor($board->id),
'usersCanEdit' => self::board_users_can_edit($board->id),
'userId' => $USER->id,
'userFullname' => fullname($USER),
'ownerId' => $ownerid,
'readonly' => (self::board_readonly($board->id) || !self::can_post($board->id, $USER->id, $ownerid)),
'columnicon' => $config->new_column_icon,
Expand All @@ -113,6 +120,8 @@ public static function get_configuration($id, $ownerid) {
'size_min' => self::ACCEPTED_FILE_MIN_SIZE,
'size_max' => self::ACCEPTED_FILE_MAX_SIZE
],
'allowshowauthorofnoteonboard' => isset($config->allowshowauthorofnoteonboard) ? $config->allowshowauthorofnoteonboard : false,
'showauthorofnote' => self::board_show_authorofnote($board->id),
'ratingenabled' => self::board_rating_enabled($board->id),
'hideheaders' => self::board_hide_headers($board->id),
'sortby' => $board->sortby,
Expand Down Expand Up @@ -372,6 +381,23 @@ public static function board_get(int $boardid, int $ownerid = 0): array {

$column->notes = $DB->get_records('board_notes', $params, 'sortorder',
'id, userid, heading, content, type, info, url, timecreated, sortorder');

$config = get_config('mod_board');
$allowshowauthorofnoteonboard = isset($config->allowshowauthorofnoteonboard) ? $config->allowshowauthorofnoteonboard : false;
// Add fullname of author to each note if author of should be visible.
foreach ($column->notes as $colid => $note) {
if ($allowshowauthorofnoteonboard && self::board_show_authorofnote($board->id)) {
// Only add missing userids and fullnames to reduce calls of get_user().
if (!self::$alluserids[$note->userid]) {
$user = core_user::get_user($note->userid);
self::$alluserids[$note->userid] = fullname($user);
}
$note->fullname =self::$alluserids[$note->userid];
} else {
$note->fullname = '';
}
}

foreach ($column->notes as $colid => $note) {
$note->rating = static::get_note_rating($note->id);
}
Expand Down Expand Up @@ -414,8 +440,20 @@ public static function board_history(int $boardid, int $ownerid, int $since): ar
$params['ownerid'] = $ownerid;
}
}

return $DB->get_records_select('board_history', $condition, $params);
$history_items = $DB->get_records_select('board_history', $condition, $params);
// Add fullname to each item in history if author should be displayed.
$config = get_config('mod_board');
$allowshowauthorofnoteonboard = isset($config->allowshowauthorofnoteonboard) ? $config->allowshowauthorofnoteonboard : false;
if ($allowshowauthorofnoteonboard && self::board_show_authorofnote($board->id)) {
foreach ($history_items as $history_item) {
if (!self::$alluserids[$history_item->userid]) {
$user = core_user::get_user($history_item->userid);
self::$alluserids[$history_item->userid] = fullname($user);
}
$history_item->fullname =self::$alluserids[$history_item->userid];
}
}
return $history_items;
}

/**
Expand Down Expand Up @@ -1147,6 +1185,21 @@ public static function board_move_note_log($boardid, $columnid, $noteid) {
$event->trigger();
}

/**
* Checks to see if showauthorofnote has been enabled for the board.
*
* @param int $boardid
* @return bool
*/
public static function board_show_authorofnote($boardid) {
$board = static::get_board($boardid);
if (!$board) {
return false;
}

return !empty($board->showauthorofnote);
}

/**
* Checks to see if the user can rate the note.
*
Expand Down
1 change: 1 addition & 0 deletions db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<FIELD NAME="introformat" TYPE="int" LENGTH="4" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="historyid" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="background_color" TYPE="char" LENGTH="10" NOTNULL="false" SEQUENCE="false"/>
<FIELD NAME="showauthorofnote" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="show author of note to students"/>
<FIELD NAME="addrating" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="hideheaders" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="show headers to students"/>
<FIELD NAME="sortby" TYPE="int" LENGTH="1" NOTNULL="false" DEFAULT="1" SEQUENCE="false"/>
Expand Down
15 changes: 15 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,20 @@ function xmldb_board_upgrade(int $oldversion) {
upgrade_mod_savepoint(true, 2022040110, 'board');
}

if ($oldversion < 2022040112) {

// Define field showauthorofnote to be added to board_notes.
$table = new xmldb_table('board');
$field = new xmldb_field('showauthorofnote', XMLDB_TYPE_INTEGER, '1', null, null, null, '0', 'background_color');

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

// Board savepoint reached.
upgrade_mod_savepoint(true, 2022040112, 'board');
}

return true;
}
2 changes: 2 additions & 0 deletions external.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static function board_history_returns(): external_multiple_structure {
'boardid' => new external_value(PARAM_INT, 'boardid'),
'action' => new external_value(PARAM_TEXT, 'action'),
'userid' => new external_value(PARAM_INT, 'userid'),
'fullname' => new external_value(PARAM_TEXT, 'user fullname', VALUE_DEFAULT, ''),
'content' => new external_value(PARAM_RAW, 'content')
)
)
Expand Down Expand Up @@ -129,6 +130,7 @@ public static function get_board_returns(): external_multiple_structure {
array(
'id' => new external_value(PARAM_INT, 'post id'),
'userid' => new external_value(PARAM_INT, 'user id'),
'fullname' => new external_value(PARAM_TEXT, 'user fullname', VALUE_DEFAULT, ''),
'heading' => new external_value(PARAM_TEXT, 'post heading'),
'content' => new external_value(PARAM_RAW, 'post content'),
'type' => new external_value(PARAM_INT, 'type'),
Expand Down
12 changes: 12 additions & 0 deletions lang/en/board.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,15 @@
$string['singleusermodenotembed'] = 'Board does not allow a single user board to be embedded. Please change your settings.';
$string['allowed_singleuser_modes'] = 'Enabled single user modes';
$string['allowed_singleuser_modes_desc'] = 'Allow/Disallow usage of certain single user modes. Does not affect already created boards';

$string['showauthorofnoteinfoenabled'] = 'Show author of note is enabled.';
$string['showauthorofnoteinfodisabled'] = 'Show author of note is disabled but can be later activated to see the owner of notes.';

$string['showauthorofnote'] = 'Show author of notes.';
$string['showauthorofnote_help'] = 'If activated, then the information, that authors of notes are displayed will be show above the board. If inactive, then the information "showauthorofnoteinfodisabled" is displayed to inform the user that the authot of a note might be visible if teacher later activates the feature.';

$string['adminsetting:allowshowauthorofnoteonboard'] = 'Allow to activate to show author of note on boards';
$string['adminsetting:allowshowauthorofnoteonboard_desc'] = 'If activated the board can be configured to show the author of a note on the board or the author can be hidden to students (Teacher can see owner of note by using the export).';

$string['allowshowauthorofnoteonboardenabled'] = 'This moodle <b>DOES</b> support to show author of notes.';
$string['allowshowauthorofnoteonboarddisabled'] = 'This moodle does <b>NOT</b> support to show author of notes.';
5 changes: 5 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ public function definition() {
$mform->addElement('filemanager', 'background_image',
get_string('background_image', 'mod_board'), null, $filemanageroptions);

$mform->addElement('advcheckbox', 'showauthorofnote', get_string('showauthorofnote', 'mod_board'));
$mform->addHelpButton('showauthorofnote', 'showauthorofnote', 'mod_board');
$mform->setDefault('showauthorofnote', 0);
$mform->setType('showauthorofnote', PARAM_INT);

$mform->addElement('select', 'addrating', get_string('addrating', 'mod_board'),
array(
board::RATINGDISABLED => get_string('addrating_none', 'mod_board'),
Expand Down
8 changes: 8 additions & 0 deletions scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@
padding: 0;
margin: 0;
}

.mod_board_note_author {
.mod_board_note_author_fullname {
margin-left: 3px;
color: #12129a;
}
}

.mod_board_note_attachment {
padding-top: 10px;
margin: 0;
Expand Down
7 changes: 7 additions & 0 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@
'1'
));

$settings->add(new admin_setting_configcheckbox(
'mod_board/allowshowauthorofnoteonboard',
get_string('adminsetting:allowshowauthorofnoteonboard', 'mod_board'),
get_string('adminsetting:allowshowauthorofnoteonboard_desc', 'mod_board'),
'0'
));

$settings->add(new admin_setting_configtext('mod_board/embed_width', get_string('embed_width', 'mod_board'),
get_string('embed_width_desc', 'mod_board'), '99%', PARAM_TEXT));

Expand Down
5 changes: 5 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@
max-width: initial;
}

.mod_board .mod_board_note_content .mod_board_note_author .mod_board_note_author_fullname {
margin-left: 3px;
color: #12129a;
}

.mod_board .mod_board_rating {
color: #333;
margin-top: 10px;
Expand Down
1 change: 1 addition & 0 deletions tests/board_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,7 @@ private static function add_board(int $courseid) {
'intro' => '',
'historyid' => 3,
'background_color' => null,
'showauthorofnote' => 0,
'addrating' => 3,
'hideheaders' => 0,
'sortby' => 2,
Expand Down
7 changes: 4 additions & 3 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
defined('MOODLE_INTERNAL') || die;

$plugin->component = 'mod_board'; // Full name of the plugin (used for diagnostics).
$plugin->version = 2022040110; // The current module version Use 2022.04.01 as base for 4.00.
$plugin->requires = 2022041900; // Moodle 4.00 and up.
// $plugin->version = 2022040110; // The current module version Use 2022.04.01 as base for 4.00.
$plugin->version = 2022040112; // 2022040112 for developing the new feature "show author of note", should be adapted
$plugin->requires = 2022041900; // Moodle 4.00 and up.
$plugin->release = '1.401.00 (Build 2022121200)';
$plugin->maturity = MATURITY_BETA;
$plugin->maturity = MATURITY_BETA;
16 changes: 14 additions & 2 deletions view.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
$PAGE->requires->js_call_amd('mod_board/main', 'initialize',
[
'boardid' => $board->id,
'ownerid' => $ownerid
'ownerid' => $ownerid,
]
);

Expand Down Expand Up @@ -142,6 +142,18 @@
$extrabackground = "background:url({$url}) no-repeat center center; -webkit-background-size: cover;
-moz-background-size: cover; -o-background-size: cover; background-size: cover;";
}

$config = get_config('mod_board');
$allowshowauthorofnoteonboard = isset($config->allowshowauthorofnoteonboard) ? $config->allowshowauthorofnoteonboard : false;

if ($allowshowauthorofnoteonboard ) {
if ($board->showauthorofnote) {
echo html_writer::tag('div', get_string('showauthorofnoteinfoenabled', 'mod_board'), ['class' => 'mod_board_showauthorofnoteinfoenabled']);
} else {
echo html_writer::tag('div', get_string('showauthorofnoteinfodisabled', 'mod_board'), ['class' => 'mod_board_showauthorofnoteinfodisabled']);
}
}

echo '<div class="mod_board_wrapper">';
echo '<div class="mod_board flex-fill" style="' . $extrabackground . '"></div>';
if (has_capability('mod/board:manageboard', $context)) {
Expand All @@ -150,7 +162,7 @@
['style' => 'display: block !important; width: 140px;']);
$img .= html_writer::tag('span', get_string('opensinnewwindow', 'mod_board'), ['class' => 'sr-only']);
echo html_writer::link('https://www.brickfield.ie/docs/mod_board/', $img, ['target' => '_blank',
'style' => 'margin-left: auto; margin-right: 90px; display: block !important; width: 140px;']);
'style' => 'margin-left: auto; margin-right: 90px; display: block !important; width: 140px;', ]);
}
echo '</div>';
}
Expand Down