From 3c5459f8ace4ff8de2a7c9e35fd19c238843bae4 Mon Sep 17 00:00:00 2001 From: Artem Andreev Date: Fri, 6 May 2011 17:11:51 +0400 Subject: [PATCH] On manage.php implemented session types selector. Code of renderable components moved from locallib.php into renderables.php --- locallib.php | 328 ++++++++++++++++-------------------------------- manage.php | 7 +- renderables.php | 266 +++++++++++++++++++++++++++++++++++++++ renderer.php | 106 +++++++++++++++- 4 files changed, 479 insertions(+), 228 deletions(-) create mode 100644 renderables.php diff --git a/locallib.php b/locallib.php index fbc6847..76d4e5e 100644 --- a/locallib.php +++ b/locallib.php @@ -4,14 +4,15 @@ global $CFG; require_once($CFG->libdir . '/gradelib.php'); class attforblock_permissions { - private $canview = null; - private $canviewreports = null; - private $cantake = null; - private $canchange = null; - private $canmanage = null; - private $canchangepreferences = null; - private $canexport = null; - private $canbelisted = null; + private $canview; + private $canviewreports; + private $cantake; + private $canchange; + private $canmanage; + private $canchangepreferences; + private $canexport; + private $canbelisted; + private $canaccessallgroups; private $context; @@ -74,6 +75,13 @@ class attforblock_permissions { return $this->canbelisted; } + + public function can_access_all_groups() { + if (is_null($this->canaccessallgroups)) + $this->canaccessallgroups = has_capability('moodle/site:accessallgroups', $this->context); + + return $this->canaccessallgroups; + } } class attforblock_view_params { @@ -224,8 +232,12 @@ class attforblock_view_params { } class attforblock { - const SESSION_COMMON = 1; - const SESSION_GROUP = 2; + const SESSION_COMMON = 0; + const SESSION_GROUP = 1; + + const SELECTOR_COMMON = 0; + const SELECTOR_ALL = -1; + const SELECTOR_NOT_EXISTS = -2; /** @var stdclass course module record */ public $cm; @@ -250,6 +262,13 @@ class attforblock { /** @var attforblock_permissions permission of current user for attendance instance*/ public $perm; + + private $groupmode; + + private $sessgroupslist; + + private $currentgroup; + /** * Initializes the attendance API instance using the data from DB * @@ -374,242 +393,107 @@ class attforblock { $params = array('id' => $this->cm->id); return new moodle_url('/mod/attforblock/attendances.php', $params); } -} + private function calc_groupmode_sessgroupslist_currentgroup(){ + global $USER, $SESSION; -/** - * Represents info about attendance tabs. - * - * Proxy class for security reasons (renderers must not have access to all attforblock methods) - * - */ -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'; + $cm = $this->cm; + $this->groupmode = groups_get_activity_groupmode($cm); - public $currenttab; + if ($this->groupmode == NOGROUPS) + return; - /** @var attforblock */ - private $att; - - /** - * Prepare info about sessions for attendance taking into account view parameters. - * - * @param attforblock $att instance - * @param $currenttab - one of attforblock_tabs constants - */ - public function __construct(attforblock $att, $currenttab=self::TAB_SESSIONS) { - $this->att = $att; - $this->currenttab = $currenttab; - } + if ($this->groupmode == VISIBLEGROUPS or $this->perm->can_access_all_groups()) { + $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]); + } + } - /** - * Return array of rows where each row is an array of tab objects - * taking into account permissions of current user - */ - public function get_tabs() { - $toprow = array(); - 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(), - get_string('sessions','attforblock')); + } 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]); + } + } + } } - if ($this->att->perm->can_manage()) { - $toprow[] = new tabobject(self::TAB_ADD, $this->att->url_sessions()->out(true, array('action' => 'add')), - get_string('add','attforblock')); + $group = optional_param('group', self::SELECTOR_NOT_EXISTS, PARAM_INT); + if (!array_key_exists('attsessiontype', $SESSION)) { + $SESSION->attsessiontype = array(); } - - if ($this->att->perm->can_viewreports()) { - $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), - get_string('report','attforblock')); + if ($group > self::SELECTOR_NOT_EXISTS) { + $SESSION->attsessiontype[$cm->course] = $group; + } elseif (!array_key_exists($cm->course, $SESSION->attsessiontype)) { + $SESSION->attsessiontype[$cm->course] = self::SELECTOR_ALL; } - if ($this->att->perm->can_export()) { - $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), - get_string('export','quiz')); + if ($group == self::SELECTOR_ALL) { + $this->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 { + $this->currentgroup = groups_get_activity_group($cm, true); + if ($this->currentgroup == 0 and $SESSION->attsessiontype[$cm->course] == self::SELECTOR_ALL) { + $this->currentgroup = self::SELECTOR_ALL; + } } - if ($this->att->perm->can_change_preferences()) { - $toprow[] = new tabobject(self::TAB_SETTINGS, $this->att->url_settings()->out(), - get_string('settings','attforblock')); + $this->sessgroupslist = array(); + if ($allowedgroups or $this->groupmode == VISIBLEGROUPS or $this->perm->can_access_all_groups()) { + $this->sessgroupslist[self::SELECTOR_ALL] = get_string('all', 'attforblock'); } - - return array($toprow); - } -} - - -class attforblock_filter_controls implements renderable { - /** @var int current view mode */ - public $view; - - public $curdate; - - public $prevcur; - public $nextcur; - public $curdatetxt; - - private $url_path; - private $url_params; - - private $att; - - public function __construct(attforblock $att) { - global $PAGE; - - $this->view = $att->view_params->view; - - $this->curdate = $att->view_params->curdate; - - $date = usergetdate($att->view_params->curdate); - $mday = $date['mday']; - $wday = $date['wday']; - $mon = $date['mon']; - $year = $date['year']; - - switch ($this->view) { - case attforblock_view_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); - break; - case attforblock_view_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); - break; - case attforblock_view_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); - break; + if ($this->groupmode == VISIBLEGROUPS) { + $this->sessgroupslist[self::SELECTOR_COMMON] = get_string('commonsessions', 'attforblock'); + } + if ($allowedgroups) { + foreach ($allowedgroups as $group) { + $this->sessgroupslist[$group->id] = format_string($group->name); + } } - - $this->url_path = $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; - - $this->att = $att; - } - - public function url($params=array()) { - $params = array_merge($this->url_params, $params); - - return new moodle_url($this->url_path, $params); - } - - public function url_path() { - return $this->url_path; - } - - public function url_params($params=array()) { - $params = array_merge($this->url_params, $params); - - return $params; } -} - -/** - * Represents info about attendance sessions taking into account view parameters. - * - */ -class attforblock_sessions_manage_data implements renderable { - /** @var int start date of displayed date range */ - public $startdate; - - /** @var int end date of displayed date range */ - public $enddate; - - /** @var array of sessions*/ - public $sessions; - - /** @var int number of hidden sessions (sessions before $course->startdate)*/ - public $hiddensessionscount; - - /** @var attforblock_permissions permission of current user for attendance instance*/ - public $perm; - - /** @var int whether sessions end time will be displayed */ - public $showendtime; - - public $groups; - - public $hiddensesscount; - - /** @var attforblock */ - private $att; - /** - * Prepare info about attendance sessions taking into account view parameters. - * - * @param attforblock $att instance - */ - public function __construct(attforblock $att) { - global $DB; - $this->perm = $att->perm; + public function get_group_mode() { + if (is_null($this->groupmode)) + $this->calc_groupmode_sessgroupslist_currentgroup(); - $this->showendtime = $att->view_params->show_endtime; - - $this->startdate = $att->view_params->startdate; - $this->enddate = $att->view_params->enddate; - - if ($this->startdate && $this->enddate) { - $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate AND sessdate >= :sdate AND sessdate < :edate"; - } else { - $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate"; - } - $params = array( - 'cid' => $att->course->id, - 'aid' => $att->id, - 'csdate' => $att->course->startdate, - 'sdate' => $this->startdate, - 'edate' => $this->enddate/*, - 'cgroup' => $currentgroup*/); - $this->sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc'); - - $where = "courseid = :cid AND attendanceid = :aid AND sessdate < :csdate"; - $params = array( - 'cid' => $att->course->id, - 'aid' => $att->id, - 'csdate' => $att->course->startdate); - $this->hiddensessionscount = $DB->count_records_select('attendance_sessions', $where, $params); - - $this->groups = groups_get_all_groups($att->course->id); - - $this->hiddensessionscount = $att->get_hidden_sessions_count(); - - $this->att = $att; + return $this->groupmode; } - public function url_take($sessionid, $grouptype=NULL) { - $params = array('sessionid' => $sessionid); - $url = new moodle_url($this->att->url_take(), $params); - if (isset($grouptype)) - $url->param('grouptype', $grouptype); + public function get_sess_groups_list() { + if (is_null($this->sessgroupslist)) + $this->calc_groupmode_sessgroupslist_currentgroup(); - return $url; + return $this->sessgroupslist; } - /** - * Must be called without or with both parameters - */ - public function url_sessions($sessionid=NULL, $action=NULL) { - $url = new moodle_url($this->att->url_sessions()); - if (isset($sessionid) && isset($action)) - $url->params(array('sessionid' => $sessionid, 'action' => $action)); + public function get_current_group() { + if (is_null($this->currentgroup)) + $this->calc_groupmode_sessgroupslist_currentgroup(); - return $url; + return $this->currentgroup; } } + ?> diff --git a/manage.php b/manage.php index c68b70f..c055585 100644 --- a/manage.php +++ b/manage.php @@ -26,13 +26,10 @@ $att = $DB->get_record('attforblock', array('id' => $cm->instance), ' require_login($course, true, $cm); -$canmanage = !has_capability('mod/attforblock:manageattendances', $PAGE->context); -$cantake = !has_capability('mod/attforblock:takeattendances', $PAGE->context); -$canchange = !has_capability('mod/attforblock:changeattendances', $PAGE->context); -if ($canmanage && $cantake && $canchange) +$att = new attforblock($att, $cm, $course, $PAGE->context); +if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change()) redirect("view.php?id=$cm->id"); -$att = new attforblock($att, $cm, $course, $PAGE->context); $att->view_params->init($view_params); // if teacher is coming from block, then check for a session exists for today diff --git a/renderables.php b/renderables.php new file mode 100644 index 0000000..09c03a4 --- /dev/null +++ b/renderables.php @@ -0,0 +1,266 @@ +att = $att; + $this->currenttab = $currenttab; + } + + /** + * Return array of rows where each row is an array of tab objects + * taking into account permissions of current user + */ + public function get_tabs() { + $toprow = array(); + 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(), + 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')), + get_string('add','attforblock')); + } + + if ($this->att->perm->can_viewreports()) { + $toprow[] = new tabobject(self::TAB_REPORT, $this->att->url_report()->out(), + get_string('report','attforblock')); + } + + if ($this->att->perm->can_export()) { + $toprow[] = new tabobject(self::TAB_EXPORT, $this->att->url_export()->out(), + get_string('export','quiz')); + } + + if ($this->att->perm->can_change_preferences()) { + $toprow[] = new tabobject(self::TAB_SETTINGS, $this->att->url_settings()->out(), + get_string('settings','attforblock')); + } + + return array($toprow); + } +} + + +class attforblock_filter_controls implements renderable { + /** @var int current view mode */ + public $view; + + public $curdate; + + public $prevcur; + public $nextcur; + public $curdatetxt; + + private $url_path; + private $url_params; + + private $att; + + public function __construct(attforblock $att) { + global $PAGE; + + $this->view = $att->view_params->view; + + $this->curdate = $att->view_params->curdate; + + $date = usergetdate($att->view_params->curdate); + $mday = $date['mday']; + $wday = $date['wday']; + $mon = $date['mon']; + $year = $date['year']; + + switch ($this->view) { + case attforblock_view_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); + break; + case attforblock_view_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); + break; + case attforblock_view_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); + break; + } + + $this->url_path = $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; + + $this->att = $att; + } + + public function url($params=array()) { + $params = array_merge($this->url_params, $params); + + return new moodle_url($this->url_path, $params); + } + + public function url_path() { + return $this->url_path; + } + + public function url_params($params=array()) { + $params = array_merge($this->url_params, $params); + + return $params; + } + + public function get_group_mode() { + return $this->att->get_group_mode(); + } + + public function get_sess_groups_list() { + return $this->att->get_sess_groups_list(); + } + + public function get_current_group() { + return $this->att->get_current_group(); + } +} + +/** + * Represents info about attendance sessions taking into account view parameters. + * + */ +class attforblock_sessions_manage_data implements renderable { + /** @var int start date of displayed date range */ + public $startdate; + + /** @var int end date of displayed date range */ + public $enddate; + + /** @var array of sessions*/ + public $sessions; + + /** @var int number of hidden sessions (sessions before $course->startdate)*/ + public $hiddensessionscount; + + /** @var attforblock_permissions permission of current user for attendance instance*/ + public $perm; + + /** @var int whether sessions end time will be displayed */ + public $showendtime; + + public $groups; + + public $hiddensesscount; + + /** @var attforblock */ + private $att; + /** + * Prepare info about attendance sessions taking into account view parameters. + * + * @param attforblock $att instance + */ + public function __construct(attforblock $att) { + global $DB; + + $this->perm = $att->perm; + + $this->showendtime = $att->view_params->show_endtime; + + $this->startdate = $att->view_params->startdate; + $this->enddate = $att->view_params->enddate; + + if ($this->startdate && $this->enddate) { + $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate AND sessdate >= :sdate AND sessdate < :edate"; + } else { + $where = "courseid=:cid AND attendanceid = :aid AND sessdate >= :csdate"; + } + if ($att->get_current_group() > attforblock::SELECTOR_ALL) { + $where .= " AND groupid=:cgroup"; + } + $params = array( + 'cid' => $att->course->id, + 'aid' => $att->id, + 'csdate' => $att->course->startdate, + 'sdate' => $this->startdate, + 'edate' => $this->enddate, + 'cgroup' => $att->get_current_group()); + $this->sessions = $DB->get_records_select('attendance_sessions', $where, $params, 'sessdate asc'); + + $where = "courseid = :cid AND attendanceid = :aid AND sessdate < :csdate"; + $params = array( + 'cid' => $att->course->id, + 'aid' => $att->id, + 'csdate' => $att->course->startdate); + $this->hiddensessionscount = $DB->count_records_select('attendance_sessions', $where, $params); + + $this->groups = groups_get_all_groups($att->course->id); + + $this->hiddensessionscount = $att->get_hidden_sessions_count(); + + $this->att = $att; + } + + public function url_take($sessionid, $grouptype=NULL) { + $params = array('sessionid' => $sessionid); + $url = new moodle_url($this->att->url_take(), $params); + if (isset($grouptype)) + $url->param('grouptype', $grouptype); + + return $url; + } + + /** + * Must be called without or with both parameters + */ + public function url_sessions($sessionid=NULL, $action=NULL) { + $url = new moodle_url($this->att->url_sessions()); + if (isset($sessionid) && isset($action)) + $url->params(array('sessionid' => $sessionid, 'action' => $action)); + + return $url; + } +} + +?> \ No newline at end of file diff --git a/renderer.php b/renderer.php index 6061a5f..22288f6 100644 --- a/renderer.php +++ b/renderer.php @@ -11,6 +11,7 @@ defined('MOODLE_INTERNAL') || die(); require_once(dirname(__FILE__).'/locallib.php'); +require_once(dirname(__FILE__).'/renderables.php'); /** * Attendance module renderer class @@ -45,7 +46,7 @@ class mod_attforblock_renderer extends plugin_renderer_base { $filtertable->width = '100%'; $filtertable->align = array('left', 'center', 'right'); - $filtertable->data[0][] = ''; + $filtertable->data[0][] = $this->render_sess_group_selector($fcontrols); $filtertable->data[0][] = $this->render_curdate_controls($fcontrols); @@ -57,6 +58,109 @@ class mod_attforblock_renderer extends plugin_renderer_base { 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;