Browse Source

Implemented adding of sessions with enhancement: HTML-editor for session description with ability to add links, files, formatting, etc

MOODLE_23_STABLE
Artem Andreev 14 years ago
parent
commit
345b969c6f
  1. 30
      add_form.php
  2. 2
      db/install.xml
  3. 10
      db/upgrade.php
  4. 0
      duration_form.php
  5. 13
      lang/en/attforblock.php
  6. 6
      lang/ru/attforblock.php
  7. 44
      lib.php
  8. 150
      locallib.php
  9. 9
      manage.php
  10. 65
      renderables.php
  11. 114
      renderer.php
  12. 75
      sessions.php
  13. 23
      update_form.php
  14. 4
      version.php
  15. 9
      view.php

30
_add_form.php → add_form.php

@ -11,10 +11,7 @@ class mod_attforblock_add_form extends moodleform {
$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
@ -26,21 +23,21 @@ class mod_attforblock_add_form extends moodleform {
$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) {
@ -55,7 +52,7 @@ class mod_attforblock_add_form extends moodleform {
}
$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'));
@ -67,7 +64,7 @@ class mod_attforblock_add_form extends moodleform {
}
$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'));
@ -109,24 +106,19 @@ class mod_attforblock_add_form extends moodleform {
$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;

2
db/install.xml

@ -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"/>

10
db/upgrade.php

@ -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;
}

0
_duration_form.php → duration_form.php

13
lang/en/attforblock.php

@ -48,6 +48,13 @@ $string['commonsessions'] = 'Common';
$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';
@ -124,6 +131,12 @@ $string['sessionscompleted'] = 'Sessions completed';
$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';

6
lang/ru/attforblock.php

@ -115,6 +115,12 @@ $string['sessionscompleted'] = 'Прошло занятий';
$string['sessionsgenerated'] = 'Занятия успешно созданы';
$string['sessionstartdate'] = 'Дата начала занятий';
$string['sessiontype'] = 'Тип занятия';
$string['sessiontype_help'] = 'Существует 2 типа занятий: общие и групповые. Возможность добавлять события различных типов зависит от группового режима элемента курса.
* В групповом режиме "Нет групп" можно добавлять только общие события.
* В групповом режиме "Доступные группы" можно добавлять и общие и групповые события.
* В групповом режиме "Отдельные группы" можно добавлять только групповые события.
';
$string['sessiontypeshort'] = 'Тип';
$string['sessionupdated'] = 'Занятие успешно изменено';
$string['settings'] = 'Настройки';

44
lib.php

@ -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_

150
locallib.php

@ -55,6 +55,10 @@ class attforblock_permissions {
return $this->canmanage;
}
public function require_manage_capability() {
require_capability('mod/attforblock:manageattendances', $this->context);
}
public function can_change_preferences() {
if (is_null($this->canchangepreferences))
$this->canchangepreferences = has_capability('mod/attforblock:changepreferences', $this->context);
@ -84,7 +88,7 @@ class attforblock_permissions {
}
}
class attforblock_view_params {
class att_manage_page_params {
const VIEW_DAYS = 1;
const VIEW_WEEKS = 2;
const VIEW_MONTHS = 3;
@ -95,11 +99,7 @@ class attforblock_view_params {
const SELECTOR_GROUP = 2;
const SELECTOR_SESS_TYPE = 3;
const SORTED_LIST = 1;
const SORTED_GRID = 2;
const DEFAULT_VIEW = self::VIEW_WEEKS;
const DEFAULT_VIEW_TAKE = self::SORTED_LIST;
const DEFAULT_SHOWENDTIME = 0;
/** @var int current view mode */
@ -114,39 +114,37 @@ class attforblock_view_params {
/** @var int end date of displayed date range */
public $enddate;
/** @var int view mode of taking attendance page*/
public $view_take;
/** @var int whether sessions end time will be displayed on manage.php */
public $show_endtime;
public $showendtime;
public $students_sort;
public $studentssort;
public $student_id;
public $studentid;
private $courseid;
public function init_defaults($courseid) {
$this->view = self::DEFAULT_VIEW;
$this->curdate = time();
$this->view_take = self::DEFAULT_VIEW_TAKE;
$this->show_endtime = self::DEFAULT_SHOWENDTIME;
public static function create_default() {
$instance = new att_manage_page_params();
$this->courseid = $courseid;
$instance->view = self::DEFAULT_VIEW;
$instance->curdate = time();
$instance->showendtime = self::DEFAULT_SHOWENDTIME;
return $instance;
}
public function init(attforblock_view_params $view_params) {
public function init(att_manage_page_params $view_params, $courseid) {
$this->courseid = $courseid;
$this->init_view($view_params->view);
$this->init_curdate($view_params->curdate);
$this->init_view_take($view_params->view_take);
$this->init_show_endtime($view_params->show_endtime);
$this->init_show_endtime($view_params->showendtime);
$this->students_sort = $view_params->students_sort;
$this->studentssort = $view_params->studentssort;
$this->student_id = $view_params->student_id;
$this->studentid = $view_params->studentid;
$this->init_start_end_date();
}
@ -175,27 +173,15 @@ class attforblock_view_params {
}
}
private function init_view_take($view_take) {
global $SESSION;
if (isset($view_take)) {
set_user_preference("attforblock_view_take", $view_take);
$this->view_take = $view_take;
}
else {
$this->view_take = get_user_preferences("attforblock_view_take", $this->view_take);
}
}
private function init_show_endtime($show_endtime) {
global $SESSION;
if (isset($show_endtime)) {
set_user_preference("attforblock_showendtime", $show_endtime);
$this->show_endtime = $show_endtime;
$this->showendtime = $show_endtime;
}
else {
$this->show_endtime = get_user_preferences("attforblock_showendtime", $this->show_endtime);
$this->showendtime = get_user_preferences("attforblock_showendtime", $this->showendtime);
}
}
@ -231,6 +217,51 @@ class attforblock_view_params {
}
}
class att_sessions_page_params {
const ACTION_ADD = 1;
const ACTION_UPDATE = 2;
const ACTION_DELETE = 3;
const ACTION_DELETE_SELECTED = 4;
const ACTION_CHANGE_DURATION = 5;
/** @var int view mode of taking attendance page*/
public $action;
}
class att_take_page_params {
const SORTED_LIST = 1;
const SORTED_GRID = 2;
const DEFAULT_VIEW_MODE = self::SORTED_LIST;
/** @var int view mode of taking attendance page*/
public $view_mode;
public static function create_default() {
$instance = new att_take_page_params();
$instance->view_mode = self::DEFAULT_VIEW_MODE;
return $instance;
}
public function init(att_manage_page_params $view_params, $courseid) {
$this->init_view_mode($view_params->view_mode);
}
private function init_view_mode($view_mode) {
global $SESSION;
if (isset($view_mode)) {
set_user_preference("attforblock_take_view_mode", $view_mode);
$this->view_mode = $view_mode;
}
else {
$this->view_mode = get_user_preferences("attforblock_take_view_mode", $this->view_mode);
}
}
}
class attforblock {
const SESSION_COMMON = 0;
const SESSION_GROUP = 1;
@ -257,8 +288,8 @@ class attforblock {
/** @var float number (10, 5) unsigned, the maximum grade for attendance */
public $grade;
/** @var attforblock_view_params view parameters current attendance instance*/
public $view_params;
/** current page parameters */
public $pageparams;
/** @var attforblock_permissions permission of current user for attendance instance*/
public $perm;
@ -280,7 +311,7 @@ class attforblock {
* @param stdClass $course Course record from {course} table
* @param stdClass $context The context of the workshop instance
*/
public function __construct(stdclass $dbrecord, stdclass $cm, stdclass $course, stdclass $context=null) {
public function __construct(stdclass $dbrecord, stdclass $cm, stdclass $course, stdclass $context=NULL, $view_params=NULL) {
foreach ($dbrecord as $field => $value) {
if (property_exists('attforblock', $field)) {
$this->{$field} = $value;
@ -297,8 +328,7 @@ class attforblock {
$this->context = $context;
}
$this->view_params = new attforblock_view_params();
$this->view_params->init_defaults($this->course->id);
$this->pageparams = $view_params;
$this->perm = new attforblock_permissions($this->context);
}
@ -357,8 +387,8 @@ class attforblock {
/**
* @return moodle_url of sessions.php for attendance instance
*/
public function url_sessions() {
$params = array('id' => $this->cm->id);
public function url_sessions($params=array()) {
$params = array_merge(array('id' => $this->cm->id), $params);
return new moodle_url('/mod/attforblock/sessions.php', $params);
}
@ -493,6 +523,38 @@ class attforblock {
return $this->currentgroup;
}
public function add_session_from_form_data($formdata) {
global $DB;
$duration = $formdata->durtime['hours']*HOURSECS + $formdata->durtime['minutes']*MINSECS;
$rec->courseid = $this->course->id;
$rec->attendanceid = $this->id;
$rec->sessdate = $formdata->sessiondate;
$rec->duration = $duration;
$rec->description = $formdata->sdescription['text'];
$rec->timemodified = time();
if ($formdata->sessiontype == self::SESSION_COMMON) {
$rec->id = $DB->insert_record('attendance_sessions', $rec);
$description = file_save_draft_area_files($formdata->sdescription['itemid'],
$this->context->id, 'mod_attforblock', 'session', $rec->id,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $rec->id));
} else {
foreach ($formdata->groups as $groupid) {
$rec->groupid = $groupid;
$rec->id = $DB->insert_record('attendance_sessions', $rec);
$description = file_save_draft_area_files($formdata->sdescription['itemid'],
$this->context->id, 'mod_attforblock', 'session', $rec->id,
array('subdirs' => false, 'maxfiles' => -1, 'maxbytes' => 0), $formdata->sdescription['text']);
$DB->set_field('attendance_sessions', 'description', $description, array('id' => $rec->id));
}
}
// TODO: log
//add_to_log($course->id, 'attendance', 'one session added', 'mod/attforblock/manage.php?id='.$id, $user->lastname.' '.$user->firstname);
}
}

9
manage.php

@ -12,9 +12,9 @@
require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php');
$view_params = new attforblock_view_params();
$view_params = new att_manage_page_params();
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$id = required_param('id', PARAM_INT);
$from = optional_param('from', NULL, PARAM_ACTION);
$view_params ->view = optional_param('view', NULL, PARAM_INT); // which page to show
$view_params ->curdate = optional_param('curdate', NULL, PARAM_INT);
@ -26,11 +26,11 @@ $att = $DB->get_record('attforblock', array('id' => $cm->instance), '
require_login($course, true, $cm);
$att = new attforblock($att, $cm, $course, $PAGE->context);
$att = new attforblock($att, $cm, $course, $PAGE->context, att_manage_page_params::create_default());
if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change())
redirect("view.php?id=$cm->id");
$att->view_params->init($view_params);
$att->pageparams->init($view_params, $course->id);
// if teacher is coming from block, then check for a session exists for today
if ($from === 'block') {
@ -52,7 +52,6 @@ if ($from === 'block') {
$PAGE->set_url($att->url_manage());
$PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_focuscontrol('');
$PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock'));
$PAGE->navbar->add($att->name);

65
renderables.php

@ -20,11 +20,11 @@ require_once(dirname(__FILE__).'/locallib.php');
*
*/
class attforblock_tabs implements renderable {
const TAB_SESSIONS = 'sessions';
const TAB_ADD = 'add';
const TAB_REPORT = 'report';
const TAB_EXPORT = 'export';
const TAB_SETTINGS = 'settings';
const TAB_SESSIONS = 1;
const TAB_ADD = 2;
const TAB_REPORT = 3;
const TAB_EXPORT = 4;
const TAB_SETTINGS = 5;
public $currenttab;
@ -51,12 +51,12 @@ class attforblock_tabs implements renderable {
if ($this->att->perm->can_manage() or
$this->att->perm->can_take() or
$this->att->perm->can_change()) {
$toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_sessions()->out(),
$toprow[] = new tabobject(self::TAB_SESSIONS, $this->att->url_manage()->out(),
get_string('sessions','attforblock'));
}
if ($this->att->perm->can_manage()) {
$toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => 'add')),
$toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => att_sessions_page_params::ACTION_ADD)),
get_string('add','attforblock'));
}
@ -90,66 +90,66 @@ class attforblock_filter_controls implements renderable {
public $nextcur;
public $curdatetxt;
private $url_path;
private $url_params;
private $urlpath;
private $urlparams;
private $att;
public function __construct(attforblock $att) {
global $PAGE;
$this->view = $att->view_params->view;
$this->view = $att->pageparams->view;
$this->curdate = $att->view_params->curdate;
$this->curdate = $att->pageparams->curdate;
$date = usergetdate($att->view_params->curdate);
$date = usergetdate($att->pageparams->curdate);
$mday = $date['mday'];
$wday = $date['wday'];
$mon = $date['mon'];
$year = $date['year'];
switch ($this->view) {
case attforblock_view_params::VIEW_DAYS:
case att_manage_page_params::VIEW_DAYS:
$format = get_string('strftimedm', 'attforblock');
$this->prevcur = make_timestamp($year, $mon, $mday - 1);
$this->nextcur = make_timestamp($year, $mon, $mday + 1);
$this->curdatetxt = userdate($att->view_params->startdate, $format);
$this->curdatetxt = userdate($att->pageparams->startdate, $format);
break;
case attforblock_view_params::VIEW_WEEKS:
case att_manage_page_params::VIEW_WEEKS:
$format = get_string('strftimedm', 'attforblock');
$this->prevcur = $att->view_params->startdate - WEEKSECS;
$this->nextcur = $att->view_params->startdate + WEEKSECS;
$this->curdatetxt = userdate($att->view_params->startdate, $format)." - ".userdate($att->view_params->enddate, $format);
$this->prevcur = $att->pageparams->startdate - WEEKSECS;
$this->nextcur = $att->pageparams->startdate + WEEKSECS;
$this->curdatetxt = userdate($att->pageparams->startdate, $format)." - ".userdate($att->pageparams->enddate, $format);
break;
case attforblock_view_params::VIEW_MONTHS:
case att_manage_page_params::VIEW_MONTHS:
$format = '%B';
$this->prevcur = make_timestamp($year, $mon - 1);
$this->nextcur = make_timestamp($year, $mon + 1);
$this->curdatetxt = userdate($att->view_params->startdate, $format);
$this->curdatetxt = userdate($att->pageparams->startdate, $format);
break;
}
$this->url_path = $PAGE->url->out_omit_querystring();
$this->urlpath = $PAGE->url->out_omit_querystring();
$params = array('id' => $att->cm->id);
if (isset($att->view_params->students_sort)) $params['sort'] = $att->view_params->students_sort;
if (isset($att->view_params->student_id)) $params['studentid'] = $att->view_params->student_id;
$this->url_params = $params;
if (isset($att->pageparams->studentssort)) $params['sort'] = $att->pageparams->studentssort;
if (isset($att->pageparams->studentid)) $params['studentid'] = $att->pageparams->studentid;
$this->urlparams = $params;
$this->att = $att;
}
public function url($params=array()) {
$params = array_merge($this->url_params, $params);
$params = array_merge($this->urlparams, $params);
return new moodle_url($this->url_path, $params);
return new moodle_url($this->urlpath, $params);
}
public function url_path() {
return $this->url_path;
return $this->urlpath;
}
public function url_params($params=array()) {
$params = array_merge($this->url_params, $params);
$params = array_merge($this->urlparams, $params);
return $params;
}
@ -206,10 +206,10 @@ class attforblock_sessions_manage_data implements renderable {
$this->perm = $att->perm;
$this->showendtime = $att->view_params->show_endtime;
$this->showendtime = $att->pageparams->showendtime;
$this->startdate = $att->view_params->startdate;
$this->enddate = $att->view_params->enddate;
$this->startdate = $att->pageparams->startdate;
$this->enddate = $att->pageparams->enddate;
if ($this->startdate && $this->enddate) {
$where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate AND sessdate >= :sdate AND sessdate < :edate";
@ -227,6 +227,9 @@ class attforblock_sessions_manage_data implements renderable {
'edate' => $this->enddate,
'cgroup' => $att->get_current_group());
$this->sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc');
foreach ($this->sessions as $sess) {
$sess->description = file_rewrite_pluginfile_urls($sess->description, 'pluginfile.php', $att->context->id, 'mod_attforblock', 'session', $sess->id);
}
$where = "courseid = :cid AND attendanceid = :aid AND sessdate < :csdate";
$params = array(

114
renderer.php

@ -58,7 +58,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o;
}
private function render_sess_group_selector(attforblock_filter_controls $fcontrols) {
protected function render_sess_group_selector(attforblock_filter_controls $fcontrols) {
if ($fcontrols->get_group_mode() == NOGROUPS)
return '';
@ -68,100 +68,9 @@ class mod_attforblock_renderer extends plugin_renderer_base {
$output = $this->output->render($select);
return html_writer::tag('div', $output, array('class' => 'groupselector'));
/*$currentgroup = -1;
$sessiontypeselector = '';
if ($printselector === GROUP_SELECTOR) {
$groupmode = groups_get_activity_groupmode($cm);
$currentgroup = groups_get_activity_group($cm, true);
$groupselector = '';
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($groupmode == VISIBLEGROUPS ||
($groupmode && has_capability('moodle/site:accessallgroups', $context))) {
$groupselector = groups_print_activity_menu($cm, $CFG->wwwroot . '/mod/attforblock/' . $link, true);
}
} elseif ($printselector === SESSION_TYPE_SELECTOR and $groupmode = groups_get_activity_groupmode($cm)) {
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
if ($groupmode == VISIBLEGROUPS or has_capability('moodle/site:accessallgroups', $context)) {
$allowedgroups = groups_get_all_groups($cm->course, 0, $cm->groupingid); // any group in grouping (all if groupings not used)
// detect changes related to groups and fix active group
if (!empty($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid])) {
if (!array_key_exists($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid]);
}
}
if (!empty($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid])) {
if (!array_key_exists($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid], $allowedgroups)) {
// active group does not exist anymore
unset($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid]);
}
}
} else {
$allowedgroups = groups_get_all_groups($cm->course, $USER->id, $cm->groupingid); // only assigned groups
// detect changes related to groups and fix active group
if (isset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid])) {
if ($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid] == 0) {
if ($allowedgroups) {
// somebody must have assigned at least one group, we can select it now - yay!
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
}
} else {
if (!array_key_exists($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid], $allowedgroups)) {
// active group not allowed or does not exist anymore
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
}
}
}
}
$group = optional_param('group', -2, PARAM_INT);
if (!array_key_exists('attsessiontype', $SESSION)) {
$SESSION->attsessiontype = array();
}
if ($group > -2) {
$SESSION->attsessiontype[$cm->course] = $group;
} elseif (!array_key_exists($cm->course, $SESSION->attsessiontype)) {
$SESSION->attsessiontype[$cm->course] = -1;
}
if ($group == -1) {
$currentgroup = $group;
unset($SESSION->activegroup[$cm->course][VISIBLEGROUPS][$cm->groupingid]);
unset($SESSION->activegroup[$cm->course]['aag'][$cm->groupingid]);
unset($SESSION->activegroup[$cm->course][SEPARATEGROUPS][$cm->groupingid]);
} else {
$currentgroup = groups_get_activity_group($cm, true);
if ($currentgroup == 0 and $SESSION->attsessiontype[$cm->course] == -1) {
$currentgroup = -1;
}
}
$selector = array();
if ($allowedgroups or $groupmode == VISIBLEGROUPS or
has_capability('moodle/site:accessallgroups', $context)) {
$selector[-1] = get_string('all', 'attforblock');
}
if ($groupmode == VISIBLEGROUPS) {
$selector[0] = get_string('commonsessions', 'attforblock');
}
if ($allowedgroups) {
foreach ($allowedgroups as $group) {
$selector[$group->id] = format_string($group->name);
}
}
if (count($selector) > 1) {
$sessiontypeselector = popup_form($url.'?id='.$cm->id.'&amp;group=', $selector, 'selectgroup', $currentgroup, '', '', '', true, 'self', get_string('sessions', 'attforblock'));
}
$sessiontypeselector = '<div class="groupselector">'.$sessiontypeselector.'</div>';
}*/
}
private function render_curdate_controls(attforblock_filter_controls $fcontrols) {
protected function render_curdate_controls(attforblock_filter_controls $fcontrols) {
global $CFG;
$curdate_controls = '';
@ -207,12 +116,12 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $curdate_controls;
}
private function render_view_controls(attforblock_filter_controls $fcontrols) {
$views[attforblock_view_params::VIEW_ALL] = get_string('all', 'attforblock');
$views[attforblock_view_params::VIEW_ALLTAKEN] = get_string('alltaken', 'attforblock');
$views[attforblock_view_params::VIEW_MONTHS] = get_string('months', 'attforblock');
$views[attforblock_view_params::VIEW_WEEKS] = get_string('weeks', 'attforblock');
$views[attforblock_view_params::VIEW_DAYS] = get_string('days', 'attforblock');
protected function render_view_controls(attforblock_filter_controls $fcontrols) {
$views[att_manage_page_params::VIEW_ALL] = get_string('all', 'attforblock');
$views[att_manage_page_params::VIEW_ALLTAKEN] = get_string('alltaken', 'attforblock');
$views[att_manage_page_params::VIEW_MONTHS] = get_string('months', 'attforblock');
$views[att_manage_page_params::VIEW_WEEKS] = get_string('weeks', 'attforblock');
$views[att_manage_page_params::VIEW_DAYS] = get_string('days', 'attforblock');
$viewcontrols = '';
foreach ($views as $key => $sview) {
if ($key != $fcontrols->view) {
@ -233,7 +142,8 @@ class mod_attforblock_renderer extends plugin_renderer_base {
* @return string html code
*/
protected function render_attforblock_sessions_manage_data(attforblock_sessions_manage_data $sessdata) {
// TODO: nosessionexists
// TODO: log
$o = $this->render_sess_manage_table($sessdata) . $this->render_sess_control_table($sessdata);
$o = html_writer::tag('form', $o, array('method' => 'post', 'action' => $sessdata->url_sessions()->out()));
$o = $this->output->container($o, 'generalbox attwidth');
@ -242,7 +152,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return $o;
}
private function render_sess_manage_table(attforblock_sessions_manage_data $sessdata) {
protected function render_sess_manage_table(attforblock_sessions_manage_data $sessdata) {
$sesstable = new html_table();
$sesstable->width = '100%';
$sesstable->head = array(
@ -310,7 +220,7 @@ class mod_attforblock_renderer extends plugin_renderer_base {
return html_writer::table($sesstable);
}
private function render_sess_control_table(attforblock_sessions_manage_data $sessdata) {
protected function render_sess_control_table(attforblock_sessions_manage_data $sessdata) {
$controltable = new html_table();
$controltable->attributes['class'] = ' ';
$controltable->width = '100%';

75
sessions.php

@ -0,0 +1,75 @@
<?php
require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php');
require_once(dirname(__FILE__).'/add_form.php');
require_once(dirname(__FILE__).'/update_form.php');
require_once(dirname(__FILE__).'/duration_form.php');
$pageparams = new att_sessions_page_params();
$id = required_param('id', PARAM_INT);
$pageparams->action = required_param('action', PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$att = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST);
require_login($course, true, $cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams);
$att->perm->require_manage_capability();
$PAGE->set_url($att->url_sessions());
$PAGE->set_title($course->shortname. ": ".$att->name);
$PAGE->set_heading($course->fullname);
$PAGE->set_cacheable(true);
$PAGE->set_button($OUTPUT->update_module_button($cm->id, 'attforblock'));
$PAGE->navbar->add($att->name);
$formparams = array('course' => $course, 'cm' => $cm, 'modcontext' => $PAGE->context);
switch ($att->pageparams->action) {
case 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);
if ($mform->is_submitted()) {
$formdata = $mform->get_data();
if (isset($formdata->addmultiply)) {
notice(get_string('sessionsgenerated','attforblock'), $url);
}
else {
$att->add_session_from_form_data($formdata);
notice(get_string('sessionadded','attforblock'), $url);
}
}
break;
case att_sessions_page_params::ACTION_UPDATE:
$sessionid = required_param('sessionid');
$url = $att->url_sessions(array('action' => att_sessions_page_params::ACTION_UPDATE, 'sessionid' => $sessionid));
$formparams['sessionid'] = $sessionid;
$mform = new mod_attforblock_update_form($url, $formparams);
if ($mform_update->is_cancelled()) {
redirect($att->url_manage());
}
if ($mform->is_submitted()) {
}
break;
}
$output = $PAGE->get_renderer('mod_attforblock');
$tabs = new attforblock_tabs($att, attforblock_tabs::TAB_ADD);
echo $output->header();
echo $output->heading(get_string('attendanceforthecourse','attforblock').' :: ' .$course->fullname);
echo $output->render($tabs);
$mform->display();
echo $OUTPUT->footer();
?>

23
_update_form.php → update_form.php

@ -11,18 +11,17 @@ class mod_attforblock_update_form extends moodleform {
$course = $this->_customdata['course'];
$cm = $this->_customdata['cm'];
// $coursecontext = $this->_customdata['coursecontext'];
$modcontext = $this->_customdata['modcontext'];
$sessionid = $this->_customdata['sessionid'];
if (!$att = $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');
}
$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($att->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'));
for ($i=0; $i<=23; $i++) {
@ -35,25 +34,19 @@ class mod_attforblock_update_form extends moodleform {
$durselect[] =& MoodleQuickForm::createElement('select', 'minutes', '', $minutes, false, true);
$mform->addGroup($durselect, 'durtime', get_string('duration','attforblock'), array(' '), true);
$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);
$dhours = floor($att->duration / HOURSECS);
$dmins = floor(($att->duration - $dhours * HOURSECS) / MINSECS);
$mform->setDefaults(array('sessiondate' => $att->sessdate,
$dhours = floor($sess->duration / HOURSECS);
$dmins = floor(($sess->duration - $dhours * HOURSECS) / MINSECS);
$mform->setDefaults(array('sessiondate' => $sess->sessdate,
'durtime' => array('hours'=>$dhours, 'minutes'=>$dmins),
'sdescription' => $att->description));
'sdescription' => $sess->description));
//-------------------------------------------------------------------------------
// buttons
$submit_string = get_string('update', 'attforblock');
$this->add_action_buttons(true, $submit_string);
$mform->addElement('hidden', 'id', $cm->id);
$mform->addElement('hidden', 'sessionid', $sessionid);
$mform->addElement('hidden', 'action', 'update');
}
// function validation($data, $files) {

4
version.php

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

9
view.php

@ -12,23 +12,16 @@
require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php');
$id = optional_param('id', 0, PARAM_INT); // Course Module ID, or
$a = optional_param('a', 0, PARAM_INT); // attforblock instance ID
$id = required_param('id', PARAM_INT); // Course Module ID, or
$studentid = optional_param('student', 0, PARAM_INT);
$printing = optional_param('printing', 0, PARAM_INT);
$mode = optional_param('mode', 'thiscourse', PARAM_ALPHA);
$view = optional_param('view', NULL, PARAM_INT); // which page to show
$current = optional_param('current', 0, PARAM_INT);
if ($id) {
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
$attforblock = $DB->get_record('attforblock', array('id' => $cm->instance), '*', MUST_EXIST);
} else {
$attforblock = $DB->get_record('attforblock', array('id' => $a), '*', MUST_EXIST);
$course = $DB->get_record('course', array('id' => $workshop->course), '*', MUST_EXIST);
$cm = get_coursemodule_from_instance('attforblock', $attforblock->id, $course->id, false, MUST_EXIST);
}
require_login($course, true, $cm);

Loading…
Cancel
Save