Skip to content
This repository has been archived by the owner on Jun 15, 2020. It is now read-only.

Commit

Permalink
Implemented adding of sessions with enhancement: HTML-editor for sess…
Browse files Browse the repository at this point in the history
…ion description with ability to add links, files, formatting, etc
  • Loading branch information
andreev-artem committed May 14, 2011
1 parent 3c5459f commit 345b969
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 238 deletions.
30 changes: 11 additions & 19 deletions _add_form.php → add_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ function definition() {

$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
// $coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
// $forum = $this->_customdata['forum'];
// $post = $this->_customdata['post']; // hack alert


$mform->addElement('header', 'general', get_string('addsession','attforblock'));//fill in the data depending on page params
Expand All @@ -26,21 +23,21 @@ function definition() {
$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);
$mform->addElement('hidden', 'sessiontype', attforblock::SESSION_COMMON);
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);
$mform->addElement('hidden', 'sessiontype', attforblock::SESSION_GROUP);
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);
$radio[] = &MoodleQuickForm::createElement('radio', 'sessiontype', '', get_string('commonsession','attforblock'), attforblock::SESSION_COMMON);
$radio[] = &MoodleQuickForm::createElement('radio', 'sessiontype', '', get_string('groupsession','attforblock'), attforblock::SESSION_GROUP);
$mform->addGroup($radio, 'sessiontype', get_string('sessiontype','attforblock'), ' ', false);
$mform->setHelpButton('sessiontype', array('sessiontypes', get_string('sessiontypes','attforblock'), 'attforblock'));
$mform->setDefault('sessiontype', COMMONSESSION);
$mform->addHelpButton('sessiontype', 'sessiontype', 'attforblock');
$mform->setDefault('sessiontype', attforblock::SESSION_COMMON);
break;
}
if ($groupmode == SEPARATEGROUPS or $groupmode == VISIBLEGROUPS) {
Expand All @@ -55,7 +52,7 @@ function definition() {
}
$select = &$mform->addElement('select', 'groups', get_string('groups', 'group'), $selectgroups);
$select->setMultiple(true);
$mform->disabledIf('groups','sessiontype','neq',GROUPSESSION);
$mform->disabledIf('groups','sessiontype','neq', attforblock::SESSION_GROUP);
}
else {
$mform->updateElementAttr($radio, array('disabled'=>'disabled'));
Expand All @@ -67,7 +64,7 @@ function definition() {
}

$mform->addElement('checkbox', 'addmultiply', '', get_string('createmultiplesessions','attforblock'));
$mform->setHelpButton('addmultiply', array('createmultiplesessions', get_string('createmultiplesessions','attforblock'), 'attforblock'));
$mform->addHelpButton('addmultiply', 'createmultiplesessions', 'attforblock');

// $mform->addElement('date_selector', 'sessiondate', get_string('sessiondate','attforblock'));
$mform->addElement('date_time_selector', 'sessiondate', get_string('sessiondate','attforblock'));
Expand Down Expand Up @@ -109,24 +106,19 @@ function definition() {
$mform->addGroup($periodgroup, 'periodgroup', get_string('period','attforblock'), array(' '), false);
$mform->disabledIf('periodgroup', 'addmultiply', 'notchecked');

$mform->addElement('text', 'sdescription', get_string('description', 'attforblock'), 'size="48"');
$mform->setType('sdescription', PARAM_TEXT);
$mform->addRule('sdescription', get_string('maximumchars', '', 100), 'maxlength', 100, 'client');
$mform->addElement('editor', 'sdescription', get_string('description', 'attforblock'), null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$modcontext));
$mform->setType('sdescription', PARAM_RAW);

//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('addsession', 'attforblock');
$this->add_action_buttons(false, $submit_string);

$mform->addElement('hidden', 'id', $cm->id);
$mform->addElement('hidden', 'action', 'add');

}

function validation($data, $files) {
$errors = parent::validation($data, $files);

if ($data['sessiontype'] == GROUPSESSION and empty($data['groups'])) {
if ($data['sessiontype'] == attforblock::SESSION_GROUP and empty($data['groups'])) {
$errors['groups'] = get_string('errorgroupsnotselected','attforblock');
}
return $errors;
Expand Down
2 changes: 1 addition & 1 deletion db/install.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<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="timemodified" TYPE="int" LENGTH="10" NOTNULL="false" UNSIGNED="true" SEQUENCE="false" PREVIOUS="lasttakenby" NEXT="description"/>
<FIELD NAME="description" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified"/>
<FIELD NAME="description" TYPE="text" LENGTH="small" NOTNULL="true" SEQUENCE="false" PREVIOUS="timemodified"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for attendance_sessions"/>
Expand Down
10 changes: 10 additions & 0 deletions db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,16 @@ function xmldb_attforblock_upgrade($oldversion=0) {

upgrade_mod_savepoint(true, 2010123003, 'attforblock');
}

if ($oldversion < 2011053000) {
$table = new xmldb_table('attendance_sessions');

$field = new xmldb_field('description');
$field->set_attributes(XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'timemodified');
$dbman->change_field_type($table, $field);

upgrade_mod_savepoint(true, 2011053000, 'attforblock');
}
return $result;
}

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions lang/en/attforblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@
$string['countofselected'] = 'Count of selected';
$string['copyfrom'] = 'Copy attendance data from';
$string['createmultiplesessions'] = 'Create multiple sessions';
$string['createmultiplesessions_help'] = 'This function allows you to create multiple sessions in one simple step.
* <strong>Session Start Date</strong>: Select the start date of your course (the first day of class)
* <strong>Session End Date</strong>: Select the last day of class (the last day you want to take attendance).
* <strong>Session Days</strong>: Select the days of the week when your class will meet (for example, Monday/Wednesday/Friday).
* <strong>Frequency</strong>: This allows for a frequency setting. If your class will meet every week, select 1; if it will meet every other week, select 2; every 3rd week, select 3, etc.
';
$string['createonesession'] = 'Create one session for the course';
$string['days'] = 'Day';
$string['defaults'] = 'Defaults';
Expand Down Expand Up @@ -124,6 +131,12 @@
$string['sessionsgenerated'] = 'Sessions successfully generated';
$string['sessionstartdate'] = 'Session start date';
$string['sessiontype'] = 'Session type';
$string['sessiontype_help'] = 'There are two types of sessions: common and groups. Ability to add different types depends on activity group mode.
* In group mode "No groups" you can add only common sessions.
* In group mode "Visible groups" you can add common and group sessions.
* In group mode "Separate groups" you can add only group sessions.
';
$string['sessiontypeshort'] = 'Type';
$string['sessionupdated'] = 'Session successfully updated';
$string['settings'] = 'Settings';
Expand Down
6 changes: 6 additions & 0 deletions lang/ru/attforblock.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@
$string['sessionsgenerated'] = 'Занятия успешно созданы';
$string['sessionstartdate'] = 'Дата начала занятий';
$string['sessiontype'] = 'Тип занятия';
$string['sessiontype_help'] = 'Существует 2 типа занятий: общие и групповые. Возможность добавлять события различных типов зависит от группового режима элемента курса.
* В групповом режиме "Нет групп" можно добавлять только общие события.
* В групповом режиме "Доступные группы" можно добавлять и общие и групповые события.
* В групповом режиме "Отдельные группы" можно добавлять только групповые события.
';
$string['sessiontypeshort'] = 'Тип';
$string['sessionupdated'] = 'Занятие успешно изменено';
$string['settings'] = 'Настройки';
Expand Down
44 changes: 44 additions & 0 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,50 @@ function attforblock_scale_used ($attforblockid, $scaleid) {
return $return;
}

/**
* Serves the attendance sessions descriptions files.
*
* @param object $course
* @param object $cm
* @param object $context
* @param string $filearea
* @param array $args
* @param bool $forcedownload
* @return bool false if file not found, does not return if found - justsend the file
*/
function attforblock_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload) {
global $CFG, $DB;

if ($context->contextlevel != CONTEXT_MODULE) {
return false;
}

require_login($course, false, $cm);

if (!$att = $DB->get_record('attforblock', array('id' => $cm->instance))) {
return false;
}

// 'session' area is served by pluginfile.php
$fileareas = array('session');
if (!in_array($filearea, $fileareas)) {
return false;
}

$sessid = (int)array_shift($args);
if (!$sess = $DB->get_record('attendance_sessions', array('id' => $sessid))) {
return false;
}

$fs = get_file_storage();
$relativepath = implode('/', $args);
$fullpath = "/$context->id/mod_attforblock/$filearea/$sessid/$relativepath";
if (!$file = $fs->get_file_by_hash(sha1($fullpath)) or $file->is_directory()) {
return false;
}
send_stored_file($file, 0, 0, true);
}

//////////////////////////////////////////////////////////////////////////////////////
/// Any other attforblock functions go here. Each of them must have a name that
/// starts with attforblock_
Expand Down
Loading

0 comments on commit 345b969

Please sign in to comment.