Browse Source

Fix issue#129 - Notify error for empty acronym or description

MOODLE_28_STABLE
Barry Oosthuizen 10 years ago
parent
commit
f62a93bd86
  1. 2
      lang/en/attendance.php
  2. 4
      locallib.php
  3. 6
      preferences.php
  4. 5
      renderables.php
  5. 29
      renderer.php

2
lang/en/attendance.php

@ -103,6 +103,8 @@ $string['downloadtext'] = 'Download in text format';
$string['donotusepaging'] = 'Do not use paging'; $string['donotusepaging'] = 'Do not use paging';
$string['duration'] = 'Duration'; $string['duration'] = 'Duration';
$string['editsession'] = 'Edit Session'; $string['editsession'] = 'Edit Session';
$string['emptyacronym'] = 'Empty acronyms are not allowed. Status record not updated.';
$string['emptydescription'] = 'Empty descriptions are not allowed. Status record not updated.';
$string['edituser'] = 'Edit user'; $string['edituser'] = 'Edit user';
$string['endtime'] = 'Session end time'; $string['endtime'] = 'Session end time';
$string['endofperiod'] = 'End of period'; $string['endofperiod'] = 'End of period';

4
locallib.php

@ -1596,6 +1596,10 @@ class attendance {
public function update_status($status, $acronym, $description, $grade, $visible) { public function update_status($status, $acronym, $description, $grade, $visible) {
global $DB; global $DB;
if (empty($acronym) || empty($description)) {
return array('acronym' => $acronym, 'description' => $description);
}
$updated = array(); $updated = array();
if ($acronym) { if ($acronym) {

6
preferences.php

@ -55,6 +55,8 @@ $PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance')); $PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attendance'));
$PAGE->navbar->add(get_string('settings', 'attendance')); $PAGE->navbar->add(get_string('settings', 'attendance'));
$errors = array();
switch ($att->pageparams->action) { switch ($att->pageparams->action) {
case att_preferences_page_params::ACTION_ADD: case att_preferences_page_params::ACTION_ADD:
$newacronym = optional_param('newacronym', null, PARAM_TEXT); $newacronym = optional_param('newacronym', null, PARAM_TEXT);
@ -112,7 +114,7 @@ switch ($att->pageparams->action) {
foreach ($acronym as $id => $v) { foreach ($acronym as $id => $v) {
$status = $statuses[$id]; $status = $statuses[$id];
$att->update_status($status, $acronym[$id], $description[$id], $grade[$id], null); $errors[$id] = $att->update_status($status, $acronym[$id], $description[$id], $grade[$id], null);
} }
if ($att->grade > 0) { if ($att->grade > 0) {
att_update_all_users_grades($att->id, $att->course, $att->context, $cm); att_update_all_users_grades($att->id, $att->course, $att->context, $cm);
@ -122,7 +124,7 @@ switch ($att->pageparams->action) {
$output = $PAGE->get_renderer('mod_attendance'); $output = $PAGE->get_renderer('mod_attendance');
$tabs = new attendance_tabs($att, attendance_tabs::TAB_PREFERENCES); $tabs = new attendance_tabs($att, attendance_tabs::TAB_PREFERENCES);
$prefdata = new attendance_preferences_data($att); $prefdata = new attendance_preferences_data($att, array_filter($errors));
$setselector = new attendance_set_selector($att, $maxstatusset); $setselector = new attendance_set_selector($att, $maxstatusset);
// Output starts here. // Output starts here.

5
renderables.php

@ -548,8 +548,11 @@ class attendance_preferences_data implements renderable {
private $att; private $att;
public function __construct(attendance $att) { public $errors;
public function __construct(attendance $att, $errors) {
$this->statuses = $att->get_statuses(false); $this->statuses = $att->get_statuses(false);
$this->errors = $errors;
foreach ($this->statuses as $st) { foreach ($this->statuses as $st) {
$st->haslogs = att_has_logs_for_status ($st->id); $st->haslogs = att_has_logs_for_status ($st->id);

29
renderer.php

@ -963,10 +963,21 @@ class mod_attendance_renderer extends plugin_renderer_base {
$i = 1; $i = 1;
foreach ($prefdata->statuses as $st) { foreach ($prefdata->statuses as $st) {
$emptyacronym = '';
$emptydescription = '';
if (array_key_exists($st->id, $prefdata->errors)) {
if (empty($prefdata->errors[$st->id]['acronym'])) {
$emptyacronym = $this->construct_notice(get_string('emptyacronym', 'mod_attendance'), 'notifyproblem');
}
if (empty($prefdata->errors[$st->id]['description'])) {
$emptydescription = $this->construct_notice(get_string('emptydescription', 'mod_attendance') , 'notifyproblem');
}
}
$table->data[$i][] = $i; $table->data[$i][] = $i;
$table->data[$i][] = $this->construct_text_input('acronym['.$st->id.']', 2, 2, $st->acronym); $table->data[$i][] = $this->construct_text_input('acronym['.$st->id.']', 2, 2, $st->acronym) . $emptyacronym;
$table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description); $table->data[$i][] = $this->construct_text_input('description['.$st->id.']', 30, 30, $st->description) . $emptydescription;
$table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, format_float($st->grade)); $table->data[$i][] = $this->construct_text_input('grade['.$st->id.']', 4, 4, $st->grade);
$table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata); $table->data[$i][] = $this->construct_preferences_actions_icons($st, $prefdata);
$i++; $i++;
@ -1040,6 +1051,18 @@ class mod_attendance_renderer extends plugin_renderer_base {
return html_writer::empty_tag('input', $attributes); return html_writer::empty_tag('input', $attributes);
} }
/**
* Construct a notice message
*
* @param string $text
* @param string $class
* @return string
*/
private function construct_notice($text, $class = 'notifymessage') {
$attributes = array('class' => $class);
return html_writer::tag('p', $text, $attributes);
}
// Show different picture if it is a temporary user. // Show different picture if it is a temporary user.
protected function user_picture($user, array $opts = null) { protected function user_picture($user, array $opts = null) {
if ($user->type == 'temporary') { if ($user->type == 'temporary') {

Loading…
Cancel
Save