Skip to content

Commit

Permalink
Worked on bgc and toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
drachels committed Feb 6, 2024
1 parent 971dbef commit f760bbf
Show file tree
Hide file tree
Showing 18 changed files with 283 additions and 31 deletions.
1 change: 1 addition & 0 deletions backup/moodle2/backup_diary_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ protected function define_structure() {
'title',
'text',
'format',
'promptbgc',
'rating',
'entrycomment',
'teacher',
Expand Down
1 change: 0 additions & 1 deletion backup/moodle2/restore_diary_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ protected function define_structure() {
$paths[] = new restore_path_element('diary_entry_rating', '/activity/diary/entries/entry/ratings/rating');
$paths[] = new restore_path_element('diary_entry_tag', '/activity/diary/entriestags/tag');
$paths[] = new restore_path_element('diary_prompt', '/activity/diary/prompts/prompt');

}

// Return the paths wrapped into standard activity structure.
Expand Down
9 changes: 5 additions & 4 deletions classes/local/prompts.php
Original file line number Diff line number Diff line change
Expand Up @@ -553,8 +553,8 @@ public static function diary_format_entry_text($entry, $course = false, $cm = fa
* @return array $attachmentoptions Array containing the editor and attachment options.
*/
public static function diary_get_editor_and_attachment_options($course, $context, $diary, $entry, $action, $firstkey) {
$maxfiles = 99; // TODO: add some setting.
$maxbytes = $course->maxbytes; // TODO: add some setting.
$maxfiles = 99; // Need to add some setting.
$maxbytes = $course->maxbytes; // Need to add some setting.

// 20210613 Added more custom data to use in edit_form.php to prevent illegal access.
$editoroptions = [
Expand Down Expand Up @@ -726,6 +726,7 @@ public static function prompts_viewcurrent($diary) {
$data->datestop = $prompts->datestop;
$data->text = $prompts->text;
$data->format = FORMAT_HTML;
$data->promptbgc = $prompts->promptbgc;
$data->minchar = $prompts->minchar;
$data->maxchar = $prompts->maxchar;
$data->minmaxcharpercent = $prompts->minmaxcharpercent;
Expand All @@ -742,7 +743,7 @@ public static function prompts_viewcurrent($diary) {
$start = '<td>'.userdate($data->datestart).'</td>';
$stop = '<td>'.userdate($data->datestop).'</td>';

$prompttext = '<b><td>'.
$prompttext = '<div class="promptentry" style="background: '.$data->promptbgc.';"><b><td>'.
get_string('writingpromptlable', 'diary',
['counter' => $counter,
'entryid' => $data->entryid,
Expand All @@ -766,7 +767,7 @@ public static function prompts_viewcurrent($diary) {
$paragraphs = '<td>'.get_string('paragraphs', 'diary')
.get_string('minc', 'diary').$data->minparagraph
.get_string('maxc', 'diary').$data->maxparagraph
.get_string('errp', 'diary').$data->minmaxparagraphpercent.'</td>';
.get_string('errp', 'diary').$data->minmaxparagraphpercent.'</td></div>';
$status .= $status.$prompttext.$characters.$words.$sentences.$paragraphs;
if ($status) {
$diary->intro .= $status.'</b><hr>';
Expand Down
34 changes: 31 additions & 3 deletions classes/local/results.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
define('DIARY_EVENT_TYPE_OPEN', 'open');
define('DIARY_EVENT_TYPE_CLOSE', 'close');
use mod_diary\local\results;
use mod_diary\local\prompts;
use stdClass;
use csv_export_writer;
use html_writer;
Expand Down Expand Up @@ -537,6 +538,21 @@ public static function diary_print_user_entry($context, $course, $diary, $user,
echo '</tr>';
}

// 20240206 Somehow, I lost this block of code and have just recreated it.
// 20230314 If one exists, display the apllicable prompt.
if ($entry->promptid > 0) {
$promptused = get_string('writingpromptused', 'diary', $entry->promptid);
$prompt = $DB->get_record('diary_prompts', ['id' => $entry->promptid, 'diaryid' => $diary->id]);
// 20230321 Added capability to use contrasting color for the prompt background.
// 20240116 Added code to use a prompt background color.
// 20240117 Gave promptentry it's own class name to enable
echo '<tr>';
echo '<td style="width:35px;"><h6>'.get_string('prompttext', 'diary').':</h6></td>';
echo '<td><div class="promptentry" style="background: '.$prompt->promptbgc.';">'.$prompt->text.'</div></td>';
echo '<td></td>';
echo '</tr>';
}

// Add an entry label followed by the date of the entry.
echo '<tr>';
echo '<td style="width:35px;">'.get_string('entry', 'diary').':</td><td>';
Expand Down Expand Up @@ -601,7 +617,19 @@ public static function diary_print_user_entry($context, $course, $diary, $user,
);

} else {
print_string("noentry", "diary");
// 20231209 changed from print_string to echo get_string.
// ...echo get_string('noentry', 'diary');...
// 20231209 This is a good place to add code that checks for an end date and then
// automatically create an entry for the student and mark it as a zero rating.
if (prompts::diary_available($diary)) {
echo get_string('noentry', 'diary').
'The student can still write because the diary activity is available.';
} else {
echo get_string('noentry', 'diary').
'The student did not complete the writing assignment and this diary activity is no longer
available because the activity is currently closed.';
}

// 20210701 Moved copy 2 of 2 here due to new stats.
echo '</div></td><td style="width:55px;"></td></tr>';
}
Expand Down Expand Up @@ -883,8 +911,8 @@ public static function diary_format_entry_text($entry, $course = false, $cm = fa
* @return array $attachmentoptions Array containing the editor and attachment options.
*/
public static function diary_get_editor_and_attachment_options($course, $context, $diary, $entry, $action, $firstkey) {
$maxfiles = 99; // TODO: add some setting.
$maxbytes = $course->maxbytes; // TODO: add some setting.
$maxfiles = 99; // Need to add some setting.
$maxbytes = $course->maxbytes; // Need to add some setting.

// 20210613 Added more custom data to use in edit_form.php to prevent illegal access.
$editoroptions = [
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/diary/db" VERSION="20231109" COMMENT="XMLDB file for Moodle mod/diary"
<XMLDB PATH="mod/diary/db" VERSION="20240116" COMMENT="XMLDB file for Moodle mod/diary"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
Expand Down Expand Up @@ -90,6 +90,7 @@
<FIELD NAME="datestop" TYPE="int" LENGTH="10" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Date for this prompt to end."/>
<FIELD NAME="text" TYPE="text" NOTNULL="false" SEQUENCE="false" COMMENT="Text of this prompt."/>
<FIELD NAME="format" TYPE="int" LENGTH="2" NOTNULL="true" DEFAULT="0" SEQUENCE="false"/>
<FIELD NAME="promptbgc" TYPE="char" LENGTH="25" NOTNULL="true" DEFAULT="#93FC84" SEQUENCE="false"/>
<FIELD NAME="minchar" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Minimum required character count."/>
<FIELD NAME="maxchar" TYPE="int" LENGTH="10" NOTNULL="false" SEQUENCE="false" COMMENT="Maximum allowed character count."/>
<FIELD NAME="minmaxcharpercent" TYPE="int" LENGTH="6" NOTNULL="false" DEFAULT="0" SEQUENCE="false" COMMENT="Each character error percentage off."/>
Expand Down
18 changes: 17 additions & 1 deletion db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Upgrade code for install
* Upgrade code for install.
*
* @package mod_diary
* @copyright 2019 AL Rachels [email protected]
Expand Down Expand Up @@ -530,5 +530,21 @@ function xmldb_diary_upgrade($oldversion = 0) {
// Diary savepoint reached.
upgrade_mod_savepoint(true, 2023110900, 'diary');
}

// New field for prompt background color in version 3.7.8.
if ($oldversion < 2024020200) {

// Define field promptbgc to be added to diary_prompts.
$table = new xmldb_table('diary_prompts');
$field = new xmldb_field('promptbgc', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, '#93FC84', 'format');

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

// Diary savepoint reached.
upgrade_mod_savepoint(true, 2024020200, 'diary');
}
return true;
}
2 changes: 1 addition & 1 deletion edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
}

// 20210619 If user tries to change timecreated, prevent it.
// TODO: Need to move new code to up to just after getting $entry, to make a nested if.
// Need to move new code to up to just after getting $entry, to make a nested if.
// Currently not taking effect on the overall user grade unless the teacher rates it.
if ($fromform->entryid) {
$newentry->id = $fromform->entryid;
Expand Down
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* This page lists all the instances of diary in a particular course
* This page lists all the instances of diary in a particular course.
*
* @package mod_diary
* @copyright 2019 AL Rachels ([email protected])
Expand Down
5 changes: 4 additions & 1 deletion lang/en/diary.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@
$string['nextentry'] = 'Next entry';
$string['nodeadline'] = 'Always open';
$string['noentriesmanagers'] = 'There are no teachers';
$string['noentry'] = 'No entry';
$string['noentry'] = 'No entry. ';
$string['noratinggiven'] = 'No rating given';
$string['notextdetected'] = '<b>No text detected!</b>';
$string['notopenuntil'] = 'This diary won\'t be open until';
Expand Down Expand Up @@ -352,6 +352,8 @@
$string['privacy:metadata:diary_entries:userid'] = 'ID of the user.';
$string['privacy:metadata:diary_entries'] = 'A record of a diary entry.';
$string['prompt'] = 'Enter your writing prompt';
$string['promptbgc'] = 'Background color for this prompt';
$string['promptbgc_help'] = 'This sets the overall background color for this prompt.';
$string['promptid'] = 'Prompt id';
$string['promptinfo'] = 'There are {$a->past} past prompts, {$a->current} current prompt, and {$a->future} future prompts for this diary activity.<br>';
$string['promptmaxc'] = 'Char max';
Expand Down Expand Up @@ -427,6 +429,7 @@
$string['tablecolumncharacters'] = 'Characters';
$string['tablecolumnedit'] = 'Edit&nbsp;&nbsp;&nbsp;&nbsp;';
$string['tablecolumnparagraphs'] = 'Paragraphs';
$string['tablecolumnpromptsbgc'] = 'Prompt background color';
$string['tablecolumnprompts'] = 'Prompts';
$string['tablecolumnsentences'] = 'Sentences';
$string['tablecolumnstart'] = 'Start';
Expand Down
14 changes: 14 additions & 0 deletions mod_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,13 @@ public function definition() {
$mform->setType('text_editor', PARAM_RAW);
$mform->addRule('text_editor', null, 'required', null, 'client');

// Diary prompt background colour setting.
$name = 'promptbgc';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_NOTAGS);

// 20220923 Added minimum character count setting.
$name = 'minchar';
$label = get_string($name, $plugin);
Expand Down Expand Up @@ -684,6 +691,13 @@ public function definition() {
$mform->setType($name, PARAM_RAW);
$mform->addRule($name, null, 'required', null, 'client');

// Diary prompt background colour setting.
$name = 'promptbgc';
$label = get_string($name, $plugin);
$mform->addElement('text', $name, $label, $ratingoptions);
$mform->addHelpButton($name, $name, $plugin);
$mform->setType($name, PARAM_NOTAGS);

// 20220923 Added minimum character count setting.
$name = 'minchar';
$label = get_string($name, $plugin);
Expand Down
15 changes: 11 additions & 4 deletions prompt_edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@
$table->head = [
get_string('tablecolumnstatus', 'diary'),
get_string('tablecolumnprompts', 'diary'),
get_string('tablecolumnpromptsbgc', 'diary'),
get_string('tablecolumnstart', 'diary'),
get_string('tablecolumnstop', 'diary'),
get_string('tablecolumncharacters', 'diary'),
Expand Down Expand Up @@ -174,6 +175,7 @@
$data->datestop = $prompt->datestop;
$data->text = $prompt->text;
$data->format = FORMAT_HTML;
$data->promptbgc = $prompt->promptbgc;
$data->minchar = $prompt->minchar;
$data->maxchar = $prompt->maxchar;
$data->minmaxcharpercent = $prompt->minmaxcharpercent;
Expand Down Expand Up @@ -204,10 +206,12 @@
$jlink2 = '<a href="'.$url->out(false).'"><img src="pix/edit.png" alt='
.get_string('eeditlabel', 'diary').'></a>';
$counter++;
$prompttext = '<td>'.get_string('writingpromptlable2', 'diary')
$prompttext = '<td bgcolor="'.$data->promptbgc.'">'
.get_string('writingpromptlable2', 'diary')
.$counter
.get_string('idlable', 'diary', $data->entryid)
.'<br>'.$data->text.'</td>';
$promptbgc = '<td>'.$data->promptbgc.'</td>';
$start = '<td>'.userdate($data->datestart).'</td>';
$stop = '<td>'.userdate($data->datestop).'</td>';
$characters = '<td>'.get_string('chars', 'diary').'<br>'
Expand All @@ -228,7 +232,7 @@
.get_string('errp', 'diary').$data->minmaxparagraphpercent.'</td>';
$edit = '<td>'.$jlink2.' | '.$jlink1.'</td></tr>';
// Create a line containing the data for our current prompt.
$line[] = $status.$prompttext.$start.$stop.$characters.$words.$sentences.$paragraphs.$edit;
$line[] = $status.$prompttext.$promptbgc.$start.$stop.$characters.$words.$sentences.$paragraphs.$edit;
}

// Now print out all the prompts for this diary.
Expand All @@ -250,11 +254,12 @@
$data->id = $cm->id;
$data->textformat = FORMAT_HTML;

$maxfiles = 99; // TODO: add some setting.
$maxbytes = $course->maxbytes; // TODO: add some setting.
$maxfiles = 99; // Need to add some setting.
$maxbytes = $course->maxbytes; // Need to add some setting.
$editoroptions = [
'promptid' => $data->entryid,
'format' => $data->textformat,
'promptbgc' => $data->promptbgc,
'timeopen' => $diary->timeopen,
'timeclose' => $diary->timeclose,
'editall' => $diary->editall,
Expand Down Expand Up @@ -303,6 +308,7 @@
$newentry->datestop = $fromform->datestop;
$newentry->text = $fromform->text_editor['text'];
$newentry->format = $fromform->text_editor['format'];
$newentry->promptbgc = $fromform->promptbgc;
$newentry->minchar = $fromform->minchar;
$newentry->maxchar = $fromform->maxchar;
$newentry->minmaxcharpercent = $fromform->minmaxcharpercent;
Expand Down Expand Up @@ -337,6 +343,7 @@
$newentry->datestop = $fromform->datestop;
$newentry->text = $fromform->text;
$newentry->format = FORMAT_HTML;
$newentry->promptbgc = $fromform->promptbgc;
$newentry->minchar = $fromform->minchar;
$newentry->maxchar = $fromform->maxchar;
$newentry->minmaxcharpercent = $fromform->minmaxcharpercent;
Expand Down
Loading

0 comments on commit f760bbf

Please sign in to comment.