Browse Source

Implemented session editing

MOODLE_23_STABLE
Artem Andreev 14 years ago
parent
commit
9049a7f750
  1. 3
      db/install.xml
  2. 22
      db/upgrade.php
  3. 2
      lang/en/attforblock.php
  4. 2
      lang/ru/attforblock.php
  5. 21
      locallib.php
  6. 4
      renderer.php
  7. 9
      sessions.php
  8. 18
      update_form.php
  9. 2
      version.php

3
db/install.xml

@ -29,7 +29,8 @@
<FIELD NAME="lasttaken" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="duration" NEXT="lasttakenby"/> <FIELD NAME="lasttaken" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="duration" NEXT="lasttakenby"/>
<FIELD NAME="lasttakenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="lasttaken" NEXT="timemodified"/> <FIELD NAME="lasttakenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" PREVIOUS="lasttaken" NEXT="timemodified"/>
<FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="lasttakenby" NEXT="description"/> <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="lasttakenby" NEXT="description"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified"/> <FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified" NEXT="descriptionformat"/>
<FIELD NAME="descriptionformat" TYPE="int" LENGTH="2" NOTNULL="true" UNSIGNED="false" DEFAULT="0" SEQUENCE="false" PREVIOUS="description"/>
</FIELDS> </FIELDS>
<KEYS> <KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/> <KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/>

22
db/upgrade.php

@ -279,14 +279,32 @@ function xmldb_attforblock_upgrade($oldversion=0) {
upgrade_mod_savepoint(true, 2010123003, 'attforblock'); upgrade_mod_savepoint(true, 2010123003, 'attforblock');
} }
if ($oldversion < 2011053000) { if ($oldversion < 2011053006) {
$table = new xmldb_table('attendance_sessions'); $table = new xmldb_table('attendance_sessions');
$field = new xmldb_field('description'); $field = new xmldb_field('description');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified'); $field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified');
$dbman->change_field_type($table, $field); $dbman->change_field_type($table, $field);
upgrade_mod_savepoint(true, 2011053000, 'attforblock'); $field = new xmldb_field('descriptionformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'description');
if (!$dbman->field_exists($table, $field)) {
$dbman->add_field($table, $field);
}
// conditionally migrate to html format in intro
if ($CFG->texteditors !== 'textarea') {
$rs = $DB->get_recordset('attendance_sessions', array('descriptionformat' => FORMAT_MOODLE), '', 'id,description,descriptionformat');
foreach ($rs as $s) {
$s->description = text_to_html($s->description, false, false, true);
$s->descriptionformat = FORMAT_HTML;
$DB->update_record('attendance_sessions', $s);
upgrade_set_timeout();
}
$rs->close();
}
upgrade_mod_savepoint(true, 2011053006, 'attforblock');
} }
return $result; return $result;
} }

2
lang/en/attforblock.php

@ -112,7 +112,7 @@ $string['notfound'] = 'Attendance activity not found in this course!';
$string['olddate'] = 'Old date'; $string['olddate'] = 'Old date';
$string['period'] = 'Frequency'; $string['period'] = 'Frequency';
$string['pluginname'] = 'Attendance'; $string['pluginname'] = 'Attendance';
$string['pluginadministration'] = 'Attendance'; $string['pluginadministration'] = 'Attendance administration';
$string['report'] = 'Report'; $string['report'] = 'Report';
$string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!'; $string['resetdescription'] = 'Remember that deleting attendance data will erase information from database. You can just hide older sessions having changed start date of course!';
$string['resetstatuses'] = 'Reset statuses to default'; $string['resetstatuses'] = 'Reset statuses to default';

2
lang/ru/attforblock.php

@ -97,7 +97,7 @@ $string['notfound'] = 'Элемент курса - \"Посещаемость\"
$string['olddate'] = 'Старая дата'; $string['olddate'] = 'Старая дата';
$string['period'] = 'Периодичность'; $string['period'] = 'Периодичность';
$string['pluginname'] = 'Посещаемость'; $string['pluginname'] = 'Посещаемость';
$string['pluginadministration'] = 'Посещаемость'; $string['pluginadministration'] = 'Управление модулем «Посещаемость»';
$string['remarks'] = 'Заметка'; $string['remarks'] = 'Заметка';
$string['report'] = 'Отчет'; $string['report'] = 'Отчет';
$string['restoredefaults'] = 'Востановить значения по-умолчанию'; $string['restoredefaults'] = 'Востановить значения по-умолчанию';

21
locallib.php

@ -534,6 +534,7 @@ class attforblock {
$rec->sessdate = $formdata->sessiondate; $rec->sessdate = $formdata->sessiondate;
$rec->duration = $duration; $rec->duration = $duration;
$rec->description = $formdata->sdescription['text']; $rec->description = $formdata->sdescription['text'];
$rec->descriptionformat = $formdata->sdescription['format'];
$rec->timemodified = time(); $rec->timemodified = time();
if ($formdata->sessiontype == self::SESSION_COMMON) { if ($formdata->sessiontype == self::SESSION_COMMON) {
@ -555,6 +556,26 @@ class attforblock {
// TODO: log // TODO: log
//add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname); //add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
} }
public function update_session_from_form_data($formdata, $sessionid) {
global $DB;
if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessionid) )) {
print_error('No such session in this course');
}
$sess->sessdate = $formdata->sessiondate;
$sess->duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS;
$description = file_save_draft_area_files($formdata->sdescription['itemid'],
$this->context->id, 'mod_attforblock', 'session', $sessionid,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
$sess->description = $description;
$sess->descriptionformat = $formdata->sdescription['format'];
$sess->timemodified = time();
$DB->update_record('attendance_sessions', $sess);
// TODO: log
// add_to_log($course->id, 'attendance', 'Session updated', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
}
} }

4
renderer.php

@ -191,11 +191,11 @@ class mod_attforblock_renderer extends plugin_renderer_base {
} }
} }
if($sessdata->perm->can_manage()) { if($sessdata->perm->can_manage()) {
$url = $sessdata->url_sessions($sess->id, 'update'); $url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_UPDATE);
$title = get_string('editsession','attforblock'); $title = get_string('editsession','attforblock');
$actions .= $this->output->action_icon($url, new pix_icon('t/edit', $title)); $actions .= $this->output->action_icon($url, new pix_icon('t/edit', $title));
$url = $sessdata->url_sessions($sess->id, 'delete'); $url = $sessdata->url_sessions($sess->id, att_sessions_page_params::ACTION_DELETE);
$title = get_string('deletesession','attforblock'); $title = get_string('deletesession','attforblock');
$actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title)); $actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title));
} }

9
sessions.php

@ -33,6 +33,7 @@ switch ($att->pageparams->action) {
case att_sessions_page_params::ACTION_ADD: case att_sessions_page_params::ACTION_ADD:
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD)); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_ADD));
$mform = new mod_attforblock_add_form($url, $formparams); $mform = new mod_attforblock_add_form($url, $formparams);
if ($mform->is_submitted()) { if ($mform->is_submitted()) {
$formdata = $mform->get_data(); $formdata = $mform->get_data();
if (isset($formdata->addmultiply)) { if (isset($formdata->addmultiply)) {
@ -40,24 +41,26 @@ switch ($att->pageparams->action) {
} }
else { else {
$att->add_session_from_form_data($formdata); $att->add_session_from_form_data($formdata);
notice(get_string('sessionadded','attforblock'), $url); redirect($url, get_string('sessionadded','attforblock'), 3);
} }
} }
break; break;
case att_sessions_page_params::ACTION_UPDATE: case att_sessions_page_params::ACTION_UPDATE:
$sessionid = required_param('sessionid'); $sessionid = required_param('sessionid', PARAM_INT);
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid)); $url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid));
$formparams['sessionid'] = $sessionid; $formparams['sessionid'] = $sessionid;
$mform = new mod_attforblock_update_form($url, $formparams); $mform = new mod_attforblock_update_form($url, $formparams);
if ($mform_update->is_cancelled()) { if ($mform->is_cancelled()) {
redirect($att->url_manage()); redirect($att->url_manage());
} }
if ($mform->is_submitted()) { if ($mform->is_submitted()) {
$att->update_session_from_form_data($mform->get_data(), $sessionid);
redirect($att->url_manage(), get_string('sessionupdated','attforblock'), 3);
} }
break; break;
} }

18
update_form.php

@ -14,12 +14,18 @@ class mod_attforblock_update_form extends moodleform {
$modcontext = $this->_customdata['modcontext']; $modcontext = $this->_customdata['modcontext'];
$sessionid = $this->_customdata['sessionid']; $sessionid = $this->_customdata['sessionid'];
if (!$sess = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) { if (!$sess = $DB->get_record('attendance_sessions', array('id'=> $sessionid) )) {
error('No such session in this course'); error('No such session in this course');
} }
$dhours = floor($sess->duration / HOURSECS);
$dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS);
$defopts = array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext);
$sess = file_prepare_standard_editor($sess, 'description', $defopts, $modcontext, 'mod_attforblock', 'session', $sess->id);
$data = array('sessiondate' => $sess->sessdate,
'durtime' => array('hours' => $dhours, 'minutes' => $dmins),
'sdescription' => $sess->description_editor);
$mform->addElement('header', 'general', get_string('changesession','attforblock')); $mform->addElement('header', 'general', get_string('changesession','attforblock'));
$mform->setHelpButton('general', array('changesession', get_string('changesession','attforblock'), 'attforblock'));
$mform->addElement('static', 'olddate', get_string('olddate','attforblock'), userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock'))); $mform->addElement('static', 'olddate', get_string('olddate','attforblock'), userdate($sess->sessdate, get_string('strftimedmyhm', 'attforblock')));
$mform->addElement('date_time_selector', 'sessiondate', get_string('newdate','attforblock')); $mform->addElement('date_time_selector', 'sessiondate', get_string('newdate','attforblock'));
@ -34,14 +40,10 @@ class mod_attforblock_update_form extends moodleform {
$durselect[] =& MoodleQuickForm::createElement('select', 'minutes', '', $minutes, false, true); $durselect[] =& MoodleQuickForm::createElement('select', 'minutes', '', $minutes, false, true);
$mform->addGroup($durselect, 'durtime', get_string('duration','attforblock'), array(' '), true); $mform->addGroup($durselect, 'durtime', get_string('duration','attforblock'), array(' '), true);
$mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext)); $mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, $defopts);
$mform->setType('sdescription', PARAM_RAW); $mform->setType('sdescription', PARAM_RAW);
$dhours = floor($sess->duration / HOURSECS); $mform->setDefaults($data);
$dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS);
$mform->setDefaults(array('sessiondate' => $sess->sessdate,
'durtime' => array('hours'=>$dhours, 'minutes'=>$dmins),
'sdescription' => $sess->description));
//------------------------------------------------------------------------------- //-------------------------------------------------------------------------------
// buttons // buttons

2
version.php

@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php /// This fragment is called by moodle_needs_upgrading() and /admin/index.php
///////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////
$module->version = 2011053000; // The current module version (Date: YYYYMMDDXX) $module->version = 2011053006; // The current module version (Date: YYYYMMDDXX)
$module->release = '2.3.1'; $module->release = '2.3.1';
$module->cron = 0; // Period for cron to check this module (secs) $module->cron = 0; // Period for cron to check this module (secs)
?> ?>

Loading…
Cancel
Save