get_tabs(), $atttabs->currenttab, NULL, NULL, true);
}
/**
* Renders filter controls for attendance
*
* @param fcontrols - filter controls data to display
* @return string html code
*/
protected function render_attforblock_filter_controls(attforblock_filter_controls $fcontrols) {
$filtertable = new html_table();
$filtertable->attributes['class'] = ' ';
$filtertable->width = '100%';
$filtertable->align = array('left', 'center', 'right');
$filtertable->data[0][] = $this->render_sess_group_selector($fcontrols);
$filtertable->data[0][] = $this->render_curdate_controls($fcontrols);
$filtertable->data[0][] = $this->render_view_controls($fcontrols);
$o = html_writer::table($filtertable);
$o = $this->output->container($o, 'attfiltercontrols attwidth');
return $o;
}
private function render_sess_group_selector(attforblock_filter_controls $fcontrols) {
if ($fcontrols->get_group_mode() == NOGROUPS)
return '';
$select = new single_select($fcontrols->url(), 'group', $fcontrols->get_sess_groups_list(),
$fcontrols->get_current_group(), null, 'selectgroup');
$select->label = get_string('sessions', 'attforblock');
$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.'&group=', $selector, 'selectgroup', $currentgroup, '', '', '', true, 'self', get_string('sessions', 'attforblock'));
}
$sessiontypeselector = '
'.$sessiontypeselector.'
';
}*/
}
private function render_curdate_controls(attforblock_filter_controls $fcontrols) {
global $CFG;
$curdate_controls = '';
if ($fcontrols->curdatetxt) {
$this->page->requires->strings_for_js(array('calclose', 'caltoday'), 'attforblock');
$jsvals = array(
'cal_months' => explode(',', get_string('calmonths','attforblock')),
'cal_week_days' => explode(',', get_string('calweekdays','attforblock')),
'cal_start_weekday' => $CFG->calendar_startwday,
'cal_cur_date' => $fcontrols->curdate);
$curdate_controls = html_writer::script(js_writer::set_variable('M.attforblock', $jsvals));
$this->page->requires->yui2_lib('container');
$this->page->requires->yui2_lib('calendar');
$this->page->requires->js('/mod/attforblock/calendar.js');
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->prevcur)), $this->output->larrow());
$params = array(
'title' => get_string('calshow', 'attforblock'),
'id' => 'show',
'type' => 'button');
$button_form = html_writer::tag('button', $fcontrols->curdatetxt, $params);
foreach ($fcontrols->url_params(array('curdate' => '')) as $name => $value) {
$params = array(
'type' => 'hidden',
'id' => $name,
'name' => $name,
'value' => $value);
$button_form .= html_writer::empty_tag('input', $params);
}
$params = array(
'id' => 'currentdate',
'action' => $fcontrols->url_path(),
'method' => 'post'
);
$button_form = html_writer::tag('form', $button_form, $params);
$curdate_controls .= $button_form;
$curdate_controls .= html_writer::link($fcontrols->url(array('curdate' => $fcontrols->nextcur)), $this->output->rarrow());
}
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');
$viewcontrols = '';
foreach ($views as $key => $sview) {
if ($key != $fcontrols->view) {
$link = html_writer::link($fcontrols->url(array('view' => $key)), $sview);
$viewcontrols .= html_writer::tag('span', $link, array('class' => 'attbtn'));
}
else
$viewcontrols .= html_writer::tag('span', $sview, array('class' => 'attcurbtn'));
}
return html_writer::tag('nobr', $viewcontrols);
}
/**
* Renders attendance sessions managing table
*
* @param attforblock_sessions_manage_data $sessdata to display
* @return string html code
*/
protected function render_attforblock_sessions_manage_data(attforblock_sessions_manage_data $sessdata) {
$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');
$o = $this->output->container($o, 'attsessions_manage_table');
return $o;
}
private function render_sess_manage_table(attforblock_sessions_manage_data $sessdata) {
$sesstable = new html_table();
$sesstable->width = '100%';
$sesstable->head = array(
'#',
get_string('sessiontypeshort', 'attforblock'),
get_string('date'), get_string('from'),
($sessdata->showendtime == '0') ? get_string('duration', 'attforblock') : get_string('to'),
get_string('description','attforblock'),
get_string('actions'),
get_string('select')
);
$sesstable->align = array('', '', '', 'right', 'left', 'center', 'center');
$sesstable->size = array('1px', '', '1px', '1px', '1px', '*', '1px', '1px');
$i = 0;
foreach ($sessdata->sessions as $key => $sess) {
$i++;
$actions = '';
$desctext = empty($sess->description) ? get_string('nodescription', 'attforblock') : $sess->description;
if($sess->lasttaken > 0) //attendance has taken
{
if ($sessdata->perm->can_change()) {
$url = $sessdata->url_take($sess->id, $sess->groupid);
$title = get_string('changeattendance','attforblock');
$desc = html_writer::link($url, $desctext, array('title' => $title));
} else {
$desc = '' . $desctext . '';
}
} else {
$desc = $desctext;
if ($sessdata->perm->can_take()) {
$url = $sessdata->url_take($sess->id, $sess->groupid);
$title = get_string('takeattendance','attforblock');
$actions = $this->output->action_icon($url, new pix_icon('t/go', $title));
}
}
if($sessdata->perm->can_manage()) {
$url = $sessdata->url_sessions($sess->id, 'update');
$title = get_string('editsession','attforblock');
$actions .= $this->output->action_icon($url, new pix_icon('t/edit', $title));
$url = $sessdata->url_sessions($sess->id, 'delete');
$title = get_string('deletesession','attforblock');
$actions .= $this->output->action_icon($url, new pix_icon('t/delete', $title));
}
$sesstable->data[$sess->id][] = $i;
$sesstable->data[$sess->id][] = $sess->groupid ? $sessdata->groups[$sess->groupid]->name : get_string('commonsession', 'attforblock');
$sesstable->data[$sess->id][] = userdate($sess->sessdate, get_string('strftimedmyw', 'attforblock'));
$sesstable->data[$sess->id][] = userdate($sess->sessdate, get_string('strftimehm', 'attforblock'));
$hours = floor($sess->duration / HOURSECS);
$mins = floor(($sess->duration - $hours * HOURSECS) / MINSECS);
$mins = $mins < 10 ? "0$mins" : "$mins";
$duration = "{$mins} " . get_string('min');
if ($hours)
$duration = "{$hours} " . get_string('hours') . " " . $duration;
$endtime = userdate($sess->sessdate+$sess->duration, get_string('strftimehm', 'attforblock'));
$sesstable->data[$sess->id][] = ($sessdata->showendtime == 0) ? $duration : $endtime;
$sesstable->data[$sess->id][] = $desc;
$sesstable->data[$sess->id][] = $actions;
$sesstable->data[$sess->id][] = html_writer::checkbox('sessid', $sess->id, false);
}
return html_writer::table($sesstable);
}
private function render_sess_control_table(attforblock_sessions_manage_data $sessdata) {
$controltable = new html_table();
$controltable->attributes['class'] = ' ';
$controltable->width = '100%';
$controltable->align = array('left', 'right');
$controltable->data[0][] = $this->output->help_icon('hiddensessions', 'attforblock',
get_string('hiddensessions', 'attforblock').': '.$sessdata->hiddensessionscount);
$controls = html_writer::link('javascript:checkall();', get_string('selectall')).' / '.
html_writer::link('javascript:checknone();', get_string('deselectall')).
html_writer::empty_tag('br');
if ($sessdata->perm->can_manage()) {
$options = array('deleteselected' => get_string('delete'),
'changeduration' => get_string('changeduration', 'attforblock'));
$controls .= html_writer::select($options, 'action');
$attributes = array(
'type' => 'submit',
'name' => 'ok',
'value' => get_string('ok'));
$controls .= html_writer::empty_tag('input', $attributes);
} else {
$controls .= get_string('youcantdo', 'attforblock'); //You can't do anything
}
$controltable->data[0][] = $controls;
return html_writer::table($controltable);
}
}
?>