Browse Source

Implemented ability to add two types of sessions: common and group

MOODLE_23_STABLE
Artem Andreev 15 years ago
parent
commit
b354930490
  1. 65
      add_form.php
  2. 10
      db/install.xml
  3. 13
      db/upgrade.php
  4. 6
      lang/en_utf8/attforblock.php
  5. 6
      lang/ru_utf8/attforblock.php
  6. 3
      lib.php
  7. 8
      manage.php
  8. 18
      sessions.php
  9. 4
      version.php

65
add_form.php

@ -6,7 +6,7 @@ class mod_attforblock_add_form extends moodleform {
function definition() { function definition() {
global $CFG; global $CFG, $USER;
$mform =& $this->_form; $mform =& $this->_form;
$course = $this->_customdata['course']; $course = $this->_customdata['course'];
@ -19,6 +19,53 @@ class mod_attforblock_add_form extends moodleform {
$mform->addElement('header', 'general', get_string('addsession','attforblock'));//fill in the data depending on page params $mform->addElement('header', 'general', get_string('addsession','attforblock'));//fill in the data depending on page params
//later using set_data //later using set_data
$groupmode = groups_get_activity_groupmode($cm);
switch ($groupmode) {
case NOGROUPS:
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attforblock'),
get_string('commonsession', 'attforblock'));
$mform->setHelpButton('sessiontypedescription', array('sessiontypes', get_string('sessiontype','attforblock'), 'attforblock'));
$mform->addElement('hidden', 'sessiontype', COMMONSESSION);
break;
case SEPARATEGROUPS:
$mform->addElement('static', 'sessiontypedescription', get_string('sessiontype', 'attforblock'),
get_string('groupsession', 'attforblock'));
$mform->setHelpButton('sessiontypedescription', array('sessiontypes', get_string('sessiontype','attforblock'), 'attforblock'));
$mform->addElement('hidden', 'sessiontype', GROUPSESSION);
break;
case VISIBLEGROUPS:
$radio=array();
$radio[] = &MoodleQuickForm::createElement('radio', 'sessiontype', '', get_string('commonsession','attforblock'), COMMONSESSION);
$radio[] = &MoodleQuickForm::createElement('radio', 'sessiontype', '', get_string('groupsession','attforblock'), GROUPSESSION);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype','attforblock'), ' ', false);
$mform->setHelpButton('sessiontype', array('sessiontypes', get_string('sessiontypes','attforblock'), 'attforblock'));
$mform->setDefault('sessiontype', COMMONSESSION);
break;
}
if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) {
if ($groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $modcontext))
$groups = groups_get_all_groups ($course->id, $USER->id);
else
$groups = groups_get_all_groups($course->id);
if ($groups) {
$selectgroups = array();
foreach ($groups as $group) {
$selectgroups[$group->id] = $group->name;
}
$select = &$mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups);
$select->setMultiple(true);
$mform->disabledIf('groups','sessiontype','neq',GROUPSESSION);
}
else {
$mform->updateElementAttr($radio, array('disabled'=>'disabled'));
$mform->addElement('static', 'groups', get_string('groups', 'group'),
get_string('nogroups', 'attforblock'));
if ($groupmode == SEPARATEGROUPS)
return;
}
}
$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions','attforblock')); $mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions','attforblock'));
$mform->setHelpButton('addmultiply', array('createmultiplesessions', get_string('createmultiplesessions','attforblock'), 'attforblock')); $mform->setHelpButton('addmultiply', array('createmultiplesessions', get_string('createmultiplesessions','attforblock'), 'attforblock'));
@ -76,14 +123,14 @@ class mod_attforblock_add_form extends moodleform {
} }
// function validation($data, $files) { function validation($data, $files) {
// $errors = parent::validation($data, $files); $errors = parent::validation($data, $files);
// if (($data['timeend']!=0) && ($data['timestart']!=0)
// && $data['timeend'] <= $data['timestart']) { if ($data['sessiontype'] == GROUPSESSION and empty($data['groups'])) {
// $errors['timeend'] = get_string('timestartenderror', 'forum'); $errors['groups'] = get_string('errorgroupsnotselected','attforblock');
// } }
// return $errors; return $errors;
// } }
} }
?> ?>

10
db/install.xml

@ -21,8 +21,9 @@
<TABLE NAME="attendance_sessions" COMMENT="attendance_sessions table retrofitted from MySQL" PREVIOUS="attforblock" NEXT="attendance_log"> <TABLE NAME="attendance_sessions" COMMENT="attendance_sessions table retrofitted from MySQL" PREVIOUS="attforblock" NEXT="attendance_log">
<FIELDS> <FIELDS>
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/> <FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" SEQUENCE="true" ENUM="false" NEXT="courseid"/>
<FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="sessdate"/> <FIELD NAME="courseid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="groupid"/>
<FIELD NAME="sessdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="duration"/> <FIELD NAME="groupid" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="courseid" NEXT="sessdate"/>
<FIELD NAME="sessdate" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="groupid" NEXT="duration"/>
<FIELD NAME="duration" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="sessdate" NEXT="lasttaken"/> <FIELD NAME="duration" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="sessdate" NEXT="lasttaken"/>
<FIELD NAME="lasttaken" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="duration" NEXT="lasttakenby"/> <FIELD NAME="lasttaken" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" ENUM="false" PREVIOUS="duration" NEXT="lasttakenby"/>
<FIELD NAME="lasttakenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="lasttaken" NEXT="timemodified"/> <FIELD NAME="lasttakenby" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="lasttaken" NEXT="timemodified"/>
@ -33,8 +34,9 @@
<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"/>
</KEYS> </KEYS>
<INDEXES> <INDEXES>
<INDEX NAME="courseid" UNIQUE="false" FIELDS="courseid" NEXT="sessdate"/> <INDEX NAME="courseid" UNIQUE="false" FIELDS="courseid" NEXT="groupid"/>
<INDEX NAME="sessdate" UNIQUE="false" FIELDS="sessdate" PREVIOUS="courseid"/> <INDEX NAME="groupid" UNIQUE="false" FIELDS="groupid" PREVIOUS="courseid" NEXT="sessdate"/>
<INDEX NAME="sessdate" UNIQUE="false" FIELDS="sessdate" PREVIOUS="groupid"/>
</INDEXES> </INDEXES>
</TABLE> </TABLE>
<TABLE NAME="attendance_log" COMMENT="attendance_log table retrofitted from MySQL" PREVIOUS="attendance_sessions" NEXT="attendance_statuses"> <TABLE NAME="attendance_log" COMMENT="attendance_log table retrofitted from MySQL" PREVIOUS="attendance_sessions" NEXT="attendance_statuses">

13
db/upgrade.php

@ -215,6 +215,19 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$result = $result && drop_field($table, $field); $result = $result && drop_field($table, $field);
} }
if ($oldversion < 2010070900 and $result) {
$table = new XMLDBTable('attendance_sessions');
$field = new XMLDBField('groupid');
$field->setAttributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', 'courseid');
$result = $result && add_field($table, $field);
$index = new XMLDBIndex('groupid');
$index->setAttributes(XMLDB_INDEX_NOTUNIQUE, array('groupid'));
$result = $result && add_index($table, $index);
}
return $result; return $result;
} }

6
lang/en_utf8/attforblock.php

@ -33,6 +33,7 @@ $string['attforblock:viewreports'] = 'Viewing Reports';
$string['attrecords'] = 'Attendances records'; $string['attrecords'] = 'Attendances records';
$string['changeduration'] = 'Change duration'; $string['changeduration'] = 'Change duration';
$string['changesession'] = 'Change session'; $string['changesession'] = 'Change session';
$string['commonsession'] = 'Common';
$string['countofselected'] = 'Count of selected'; $string['countofselected'] = 'Count of selected';
$string['createmultiplesessions'] = 'Create multiple sessions'; $string['createmultiplesessions'] = 'Create multiple sessions';
$string['createonesession'] = 'Create one session for the course'; $string['createonesession'] = 'Create one session for the course';
@ -52,8 +53,10 @@ $string['downloadtext'] = 'Download in text format';
$string['duration'] = 'Duration'; $string['duration'] = 'Duration';
$string['editsession'] = 'Edit Session'; $string['editsession'] = 'Edit Session';
$string['endofperiod'] = 'End of period'; $string['endofperiod'] = 'End of period';
$string['errorgroupsnotselected'] = 'Select one or more groups';
$string['errorinaddingsession'] = 'Error in adding session'; $string['errorinaddingsession'] = 'Error in adding session';
$string['erroringeneratingsessions'] = 'Error in generating sessions '; $string['erroringeneratingsessions'] = 'Error in generating sessions ';
$string['groupsession'] = 'Group';
$string['hiddensessions'] = 'Hidden sessions'; $string['hiddensessions'] = 'Hidden sessions';
$string['identifyby'] = 'Identify student by'; $string['identifyby'] = 'Identify student by';
$string['includenottaken'] = 'Include not taken sessions'; $string['includenottaken'] = 'Include not taken sessions';
@ -68,6 +71,7 @@ $string['newduration'] = 'New duration';
$string['noattforuser'] = 'No attendance records exist for the user'; $string['noattforuser'] = 'No attendance records exist for the user';
$string['nodescription'] = 'Regular class session'; $string['nodescription'] = 'Regular class session';
$string['noguest'] = 'Guest can\'t see attendance'; $string['noguest'] = 'Guest can\'t see attendance';
$string['nogroups'] = 'You can\'t add group sessions. No groups exists in course.';
$string['noofdaysabsent'] = 'No of days absent'; $string['noofdaysabsent'] = 'No of days absent';
$string['noofdaysexcused'] = 'No of days excused'; $string['noofdaysexcused'] = 'No of days excused';
$string['noofdayslate'] = 'No of days late'; $string['noofdayslate'] = 'No of days late';
@ -94,6 +98,8 @@ $string['sessions'] = 'Sessions';
$string['sessionscompleted'] = 'Sessions completed'; $string['sessionscompleted'] = 'Sessions completed';
$string['sessionsgenerated'] = 'Sessions successfully generated'; $string['sessionsgenerated'] = 'Sessions successfully generated';
$string['sessionstartdate'] = 'Session start date'; $string['sessionstartdate'] = 'Session start date';
$string['sessiontype'] = 'Session type';
$string['sessiontypeshort'] = 'Type';
$string['sessionupdated'] = 'Session successfully updated'; $string['sessionupdated'] = 'Session successfully updated';
$string['settings'] = 'Settings'; $string['settings'] = 'Settings';
$string['showdefaults'] = 'Show defaults'; $string['showdefaults'] = 'Show defaults';

6
lang/ru_utf8/attforblock.php

@ -32,6 +32,7 @@ $string['attforblock:viewreports'] = 'Просмотр отчетов';
$string['attrecords'] = 'Отметок о посещаемости'; $string['attrecords'] = 'Отметок о посещаемости';
$string['changeduration'] = 'Изменить продолжительность'; $string['changeduration'] = 'Изменить продолжительность';
$string['changesession'] = 'Изменить занятие'; $string['changesession'] = 'Изменить занятие';
$string['commonsession'] = 'Общее';
$string['countofselected'] = 'Выбрано занятий'; $string['countofselected'] = 'Выбрано занятий';
$string['createmultiplesessions'] = 'Создать несколько занятий'; $string['createmultiplesessions'] = 'Создать несколько занятий';
$string['createonesession'] = 'Создать одно занятие для курса'; $string['createonesession'] = 'Создать одно занятие для курса';
@ -49,8 +50,10 @@ $string['downloadtext'] = 'Скачать в текстовом формате';
$string['duration'] = 'Продолжительность'; $string['duration'] = 'Продолжительность';
$string['editsession'] = 'Редактировать занятие'; $string['editsession'] = 'Редактировать занятие';
$string['endofperiod'] = 'Конец периода'; $string['endofperiod'] = 'Конец периода';
$string['errorgroupsnotselected'] = 'Выберите одну или более групп';
$string['errorinaddingsession'] = 'Ошибка при добавлении занятия'; $string['errorinaddingsession'] = 'Ошибка при добавлении занятия';
$string['erroringeneratingsessions'] = 'Ошибка при создании занятий'; $string['erroringeneratingsessions'] = 'Ошибка при создании занятий';
$string['groupsession'] = 'Групповое';
$string['hiddensessions'] = 'Скрытых занятий'; $string['hiddensessions'] = 'Скрытых занятий';
$string['identifyby'] = 'Идентифицировать студентов по'; $string['identifyby'] = 'Идентифицировать студентов по';
$string['includenottaken'] = 'Включить не прошедшие занятия'; $string['includenottaken'] = 'Включить не прошедшие занятия';
@ -65,6 +68,7 @@ $string['newduration'] = 'New duration';
$string['noattforuser'] = 'Нет отметок посещаемости для этого пользователя'; $string['noattforuser'] = 'Нет отметок посещаемости для этого пользователя';
$string['nodescription'] = 'Для этого занятия нет описания'; $string['nodescription'] = 'Для этого занятия нет описания';
$string['noguest'] = 'Гость не может видеть информацию о посещаемости'; $string['noguest'] = 'Гость не может видеть информацию о посещаемости';
$string['nogroups'] = 'Вы не можете добавлять групповые занятия. В курсе не определено ни одной группы.';
$string['noofdaysabsent'] = 'Пропущено'; $string['noofdaysabsent'] = 'Пропущено';
$string['noofdaysexcused'] = 'Пропущено по ув. причине'; $string['noofdaysexcused'] = 'Пропущено по ув. причине';
$string['noofdayslate'] = 'Опозданий'; $string['noofdayslate'] = 'Опозданий';
@ -89,6 +93,8 @@ $string['sessions'] = 'Занятия';
$string['sessionscompleted'] = 'Прошло занятий'; $string['sessionscompleted'] = 'Прошло занятий';
$string['sessionsgenerated'] = 'Занятия успешно созданы'; $string['sessionsgenerated'] = 'Занятия успешно созданы';
$string['sessionstartdate'] = 'Дата начала занятий'; $string['sessionstartdate'] = 'Дата начала занятий';
$string['sessiontype'] = 'Тип занятия';
$string['sessiontypeshort'] = 'Тип';
$string['sessionupdated'] = 'Занятие успешно изменено'; $string['sessionupdated'] = 'Занятие успешно изменено';
$string['settings'] = 'Настройки'; $string['settings'] = 'Настройки';
$string['showdefaults'] = 'Показать значения по-умолчанию'; $string['showdefaults'] = 'Показать значения по-умолчанию';

3
lib.php

@ -4,6 +4,9 @@
$attforblock_CONSTANT = 7; /// for example $attforblock_CONSTANT = 7; /// for example
define('COMMONSESSION', 0);
define('GROUPSESSION', 1);
function attforblock_install() { function attforblock_install() {
$result = true; $result = true;

8
manage.php

@ -87,9 +87,9 @@ function print_sessions_list($course) {
$i = 0; $i = 0;
$table->width = '100%'; $table->width = '100%';
//$table->tablealign = 'center'; //$table->tablealign = 'center';
$table->head = array('#', get_string('date'), get_string('time'), get_string('duration', 'attforblock'), get_string('description','attforblock'), get_string('actions'), get_string('select')); $table->head = array('#', get_string('sessiontypeshort', 'attforblock'), get_string('date'), get_string('time'), get_string('duration', 'attforblock'), get_string('description','attforblock'), get_string('actions'), get_string('select'));
$table->align = array('', '', '', 'right', 'left', 'center', 'center'); $table->align = array('', '', '', 'right', 'left', 'center', 'center');
$table->size = array('1px', '1px', '1px', '1px', '*', '1px', '1px'); $table->size = array('1px', '', '1px', '1px', '1px', '*', '1px', '1px');
$allowtake = has_capability('mod/attforblock:takeattendances', $context); $allowtake = has_capability('mod/attforblock:takeattendances', $context);
$allowchange = has_capability('mod/attforblock:changeattendances', $context); $allowchange = has_capability('mod/attforblock:changeattendances', $context);
@ -127,6 +127,8 @@ function print_sessions_list($course) {
} }
$table->data[$sessdata->id][] = $i; $table->data[$sessdata->id][] = $i;
$groups = groups_get_all_groups($course->id);
$table->data[$sessdata->id][] = $sessdata->groupid == 0 ? get_string('commonsession', 'attforblock') : $groups[$sessdata->groupid]->name;
$table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimedmyw', 'attforblock')); $table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimedmyw', 'attforblock'));
$table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimehm', 'attforblock')); $table->data[$sessdata->id][] = userdate($sessdata->sessdate, get_string('strftimehm', 'attforblock'));
$hours = floor($sessdata->duration / HOURSECS); $hours = floor($sessdata->duration / HOURSECS);
@ -140,7 +142,6 @@ function print_sessions_list($course) {
} }
echo '<div align="center"><div class="generalbox boxwidthwide">'; echo '<div align="center"><div class="generalbox boxwidthwide">';
echo "<form method=\"post\" action=\"sessions.php?id={$cm->id}\">"; //&amp;sessionid={$sessdata->id} echo "<form method=\"post\" action=\"sessions.php?id={$cm->id}\">"; //&amp;sessionid={$sessdata->id}
echo '<div align="right">'.helpbutton ('sessions', get_string('help'), 'attforblock', true, true, '', true).'</div>';
print_table($table); print_table($table);
$hiddensess = count_records_select('attendance_sessions', "courseid = $course->id AND sessdate < $course->startdate"); $hiddensess = count_records_select('attendance_sessions', "courseid = $course->id AND sessdate < $course->startdate");
echo '<table width="100%"><tr><td valign="top">'; echo '<table width="100%"><tr><td valign="top">';
@ -157,6 +158,7 @@ function print_sessions_list($course) {
} else { } else {
echo get_string('youcantdo', 'attforblock'); //You can't do anything echo get_string('youcantdo', 'attforblock'); //You can't do anything
} }
echo '<div align="right">'.helpbutton ('sessions', get_string('help'), 'attforblock', true, true, '', true).'</div>';
echo '</div></td></tr></table>'; echo '</div></td></tr></table>';
echo '</form></div></div>'; echo '</form></div></div>';

18
sessions.php

@ -95,9 +95,17 @@
$rec->duration = $duration; $rec->duration = $duration;
$rec->description = $fromform->sdescription; $rec->description = $fromform->sdescription;
$rec->timemodified = $now; $rec->timemodified = $now;
if ($fromform->sessiontype === COMMONSESSION) {
if(!insert_record('attendance_sessions', $rec))
error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add");
} else {
foreach ($fromform->groups as $groupid) {
$rec->groupid = $groupid;
if(!insert_record('attendance_sessions', $rec)) if(!insert_record('attendance_sessions', $rec))
error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add"); error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&amp;action=add");
} }
}
}
$sdate += ONE_DAY; $sdate += ONE_DAY;
} else { } else {
$startweek += ONE_WEEK * $fromform->period; $startweek += ONE_WEEK * $fromform->period;
@ -113,11 +121,21 @@
$rec->duration = $duration; $rec->duration = $duration;
$rec->description = $fromform->sdescription; $rec->description = $fromform->sdescription;
$rec->timemodified = $now; $rec->timemodified = $now;
if ($fromform->sessiontype == COMMONSESSION) {
if(insert_record('attendance_sessions', $rec)) { if(insert_record('attendance_sessions', $rec)) {
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);
notice(get_string('sessionadded','attforblock')); notice(get_string('sessionadded','attforblock'));
} else } else
error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&amp;action=add"); error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&amp;action=add");
} else {
foreach ($fromform->groups as $groupid) {
$rec->groupid = $groupid;
if(!insert_record('attendance_sessions', $rec))
error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&amp;action=add");
}
add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
notice(get_string('sessionadded','attforblock'));
}
} }
} }
$mform_add->display(); $mform_add->display();

4
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 = 2009022800; // The current module version (Date: YYYYMMDDXX) $module->version = 2010070900; // The current module version (Date: YYYYMMDDXX)
$module->release = '2.1.1'; $module->release = '2.2.0';
$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