diff --git a/add_form.php b/add_form.php
index ffe2b51..2e3cae8 100644
--- a/add_form.php
+++ b/add_form.php
@@ -6,7 +6,7 @@ class mod_attforblock_add_form extends moodleform {
function definition() {
- global $CFG;
+ global $CFG, $USER;
$mform =& $this->_form;
$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
//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->setHelpButton('addmultiply', array('createmultiplesessions', get_string('createmultiplesessions','attforblock'), 'attforblock'));
@@ -76,14 +123,14 @@ class mod_attforblock_add_form extends moodleform {
}
-// function validation($data, $files) {
-// $errors = parent::validation($data, $files);
-// if (($data['timeend']!=0) && ($data['timestart']!=0)
-// && $data['timeend'] <= $data['timestart']) {
-// $errors['timeend'] = get_string('timestartenderror', 'forum');
-// }
-// return $errors;
-// }
+ function validation($data, $files) {
+ $errors = parent::validation($data, $files);
+
+ if ($data['sessiontype'] == GROUPSESSION and empty($data['groups'])) {
+ $errors['groups'] = get_string('errorgroupsnotselected','attforblock');
+ }
+ return $errors;
+ }
}
?>
diff --git a/db/install.xml b/db/install.xml
index 0974663..d4a7667 100644
--- a/db/install.xml
+++ b/db/install.xml
@@ -21,8 +21,9 @@
-
-
+
+
+
@@ -33,8 +34,9 @@
-
-
+
+
+
diff --git a/db/upgrade.php b/db/upgrade.php
index cc16f38..8b4cc7a 100644
--- a/db/upgrade.php
+++ b/db/upgrade.php
@@ -215,6 +215,19 @@ function xmldb_attforblock_upgrade($oldversion=0) {
$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;
}
diff --git a/lang/en_utf8/attforblock.php b/lang/en_utf8/attforblock.php
index cee5f09..c693e6b 100644
--- a/lang/en_utf8/attforblock.php
+++ b/lang/en_utf8/attforblock.php
@@ -33,6 +33,7 @@ $string['attforblock:viewreports'] = 'Viewing Reports';
$string['attrecords'] = 'Attendances records';
$string['changeduration'] = 'Change duration';
$string['changesession'] = 'Change session';
+$string['commonsession'] = 'Common';
$string['countofselected'] = 'Count of selected';
$string['createmultiplesessions'] = 'Create multiple sessions';
$string['createonesession'] = 'Create one session for the course';
@@ -52,8 +53,10 @@ $string['downloadtext'] = 'Download in text format';
$string['duration'] = 'Duration';
$string['editsession'] = 'Edit Session';
$string['endofperiod'] = 'End of period';
+$string['errorgroupsnotselected'] = 'Select one or more groups';
$string['errorinaddingsession'] = 'Error in adding session';
$string['erroringeneratingsessions'] = 'Error in generating sessions ';
+$string['groupsession'] = 'Group';
$string['hiddensessions'] = 'Hidden sessions';
$string['identifyby'] = 'Identify student by';
$string['includenottaken'] = 'Include not taken sessions';
@@ -68,6 +71,7 @@ $string['newduration'] = 'New duration';
$string['noattforuser'] = 'No attendance records exist for the user';
$string['nodescription'] = 'Regular class session';
$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['noofdaysexcused'] = 'No of days excused';
$string['noofdayslate'] = 'No of days late';
@@ -94,6 +98,8 @@ $string['sessions'] = 'Sessions';
$string['sessionscompleted'] = 'Sessions completed';
$string['sessionsgenerated'] = 'Sessions successfully generated';
$string['sessionstartdate'] = 'Session start date';
+$string['sessiontype'] = 'Session type';
+$string['sessiontypeshort'] = 'Type';
$string['sessionupdated'] = 'Session successfully updated';
$string['settings'] = 'Settings';
$string['showdefaults'] = 'Show defaults';
diff --git a/lang/ru_utf8/attforblock.php b/lang/ru_utf8/attforblock.php
index ad2f73a..4d07759 100644
--- a/lang/ru_utf8/attforblock.php
+++ b/lang/ru_utf8/attforblock.php
@@ -32,6 +32,7 @@ $string['attforblock:viewreports'] = 'Просмотр отчетов';
$string['attrecords'] = 'Отметок о посещаемости';
$string['changeduration'] = 'Изменить продолжительность';
$string['changesession'] = 'Изменить занятие';
+$string['commonsession'] = 'Общее';
$string['countofselected'] = 'Выбрано занятий';
$string['createmultiplesessions'] = 'Создать несколько занятий';
$string['createonesession'] = 'Создать одно занятие для курса';
@@ -49,8 +50,10 @@ $string['downloadtext'] = 'Скачать в текстовом формате';
$string['duration'] = 'Продолжительность';
$string['editsession'] = 'Редактировать занятие';
$string['endofperiod'] = 'Конец периода';
+$string['errorgroupsnotselected'] = 'Выберите одну или более групп';
$string['errorinaddingsession'] = 'Ошибка при добавлении занятия';
$string['erroringeneratingsessions'] = 'Ошибка при создании занятий';
+$string['groupsession'] = 'Групповое';
$string['hiddensessions'] = 'Скрытых занятий';
$string['identifyby'] = 'Идентифицировать студентов по';
$string['includenottaken'] = 'Включить не прошедшие занятия';
@@ -65,6 +68,7 @@ $string['newduration'] = 'New duration';
$string['noattforuser'] = 'Нет отметок посещаемости для этого пользователя';
$string['nodescription'] = 'Для этого занятия нет описания';
$string['noguest'] = 'Гость не может видеть информацию о посещаемости';
+$string['nogroups'] = 'Вы не можете добавлять групповые занятия. В курсе не определено ни одной группы.';
$string['noofdaysabsent'] = 'Пропущено';
$string['noofdaysexcused'] = 'Пропущено по ув. причине';
$string['noofdayslate'] = 'Опозданий';
@@ -89,6 +93,8 @@ $string['sessions'] = 'Занятия';
$string['sessionscompleted'] = 'Прошло занятий';
$string['sessionsgenerated'] = 'Занятия успешно созданы';
$string['sessionstartdate'] = 'Дата начала занятий';
+$string['sessiontype'] = 'Тип занятия';
+$string['sessiontypeshort'] = 'Тип';
$string['sessionupdated'] = 'Занятие успешно изменено';
$string['settings'] = 'Настройки';
$string['showdefaults'] = 'Показать значения по-умолчанию';
diff --git a/lib.php b/lib.php
index eabf781..97cdb59 100644
--- a/lib.php
+++ b/lib.php
@@ -4,6 +4,9 @@
$attforblock_CONSTANT = 7; /// for example
+define('COMMONSESSION', 0);
+define('GROUPSESSION', 1);
+
function attforblock_install() {
$result = true;
diff --git a/manage.php b/manage.php
index 5e20c21..9d78af0 100644
--- a/manage.php
+++ b/manage.php
@@ -87,9 +87,9 @@ function print_sessions_list($course) {
$i = 0;
$table->width = '100%';
//$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->size = array('1px', '1px', '1px', '1px', '*', '1px', '1px');
+ $table->size = array('1px', '', '1px', '1px', '1px', '*', '1px', '1px');
$allowtake = has_capability('mod/attforblock:takeattendances', $context);
$allowchange = has_capability('mod/attforblock:changeattendances', $context);
@@ -127,6 +127,8 @@ function print_sessions_list($course) {
}
$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('strftimehm', 'attforblock'));
$hours = floor($sessdata->duration / HOURSECS);
@@ -140,7 +142,6 @@ function print_sessions_list($course) {
}
echo '';
diff --git a/sessions.php b/sessions.php
index adc98d1..e33ed48 100644
--- a/sessions.php
+++ b/sessions.php
@@ -95,8 +95,16 @@
$rec->duration = $duration;
$rec->description = $fromform->sdescription;
$rec->timemodified = $now;
- if(!insert_record('attendance_sessions', $rec))
- error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&action=add");
+ if ($fromform->sessiontype === COMMONSESSION) {
+ if(!insert_record('attendance_sessions', $rec))
+ error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&action=add");
+ } else {
+ foreach ($fromform->groups as $groupid) {
+ $rec->groupid = $groupid;
+ if(!insert_record('attendance_sessions', $rec))
+ error(get_string('erroringeneratingsessions','attforblock'), "sessions.php?id=$id&action=add");
+ }
+ }
}
$sdate += ONE_DAY;
} else {
@@ -113,11 +121,21 @@
$rec->duration = $duration;
$rec->description = $fromform->sdescription;
$rec->timemodified = $now;
- 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);
- notice(get_string('sessionadded','attforblock'));
- } else
- error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&action=add");
+ if ($fromform->sessiontype == COMMONSESSION) {
+ 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);
+ notice(get_string('sessionadded','attforblock'));
+ } else
+ error(get_string('errorinaddingsession','attforblock'), "sessions.php?id=$id&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&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();
diff --git a/version.php b/version.php
index b213430..f2b017b 100644
--- a/version.php
+++ b/version.php
@@ -5,7 +5,7 @@
/// This fragment is called by moodle_needs_upgrading() and /admin/index.php
/////////////////////////////////////////////////////////////////////////////////
-$module->version = 2009022800; // The current module version (Date: YYYYMMDDXX)
-$module->release = '2.1.1';
+$module->version = 2010070900; // The current module version (Date: YYYYMMDDXX)
+$module->release = '2.2.0';
$module->cron = 0; // Period for cron to check this module (secs)
?>