Browse Source

att_manage_page_params refactoring

MOODLE_23_STABLE
Artem Andreev 14 years ago
parent
commit
511544f320
  1. 61
      locallib.php
  2. 17
      manage.php

61
locallib.php

@ -117,71 +117,50 @@ class att_manage_page_params {
/** @var int whether sessions end time will be displayed on manage.php */ /** @var int whether sessions end time will be displayed on manage.php */
public $showendtime; public $showendtime;
public $studentssort;
public $studentid;
private $courseid; private $courseid;
public static function create_default() { public function init($courseid) {
$instance = new att_manage_page_params();
$instance->view = self::DEFAULT_VIEW;
$instance->curdate = time();
$instance->showendtime = self::DEFAULT_SHOWENDTIME;
return $instance;
}
public function init(att_manage_page_params $view_params, $courseid) {
$this->courseid = $courseid; $this->courseid = $courseid;
$this->init_view();
$this->init_view($view_params->view); $this->init_curdate();
$this->init_show_endtime();
$this->init_curdate($view_params->curdate);
$this->init_show_endtime($view_params->showendtime);
$this->studentssort = $view_params->studentssort;
$this->studentid = $view_params->studentid;
$this->init_start_end_date(); $this->init_start_end_date();
} }
private function init_view($view) { private function init_view() {
global $SESSION; global $SESSION;
if (isset($view)) { if (isset($this->view)) {
$SESSION->attcurrentattview[$this->courseid] = $view; $SESSION->attcurrentattview[$this->courseid] = $this->view;
$this->view = $view;
} }
elseif (isset($SESSION->attcurrentattview[$this->courseid])) { elseif (isset($SESSION->attcurrentattview[$this->courseid])) {
$this->view = $SESSION->attcurrentattview[$this->courseid]; $this->view = $SESSION->attcurrentattview[$this->courseid];
} }
else {
$this->view = self::DEFAULT_VIEW;
}
} }
private function init_curdate($curdate) { private function init_curdate() {
global $SESSION; global $SESSION;
if ($curdate) { if (isset($this->curdate)) {
$SESSION->attcurrentattdate[$this->courseid] = $curdate; $SESSION->attcurrentattdate[$this->courseid] = $this->curdate;
$this->curdate = $curdate;
} }
elseif (isset($SESSION->attcurrentattdate[$this->courseid])) { elseif (isset($SESSION->attcurrentattdate[$this->courseid])) {
$this->curdate = $SESSION->attcurrentattdate[$this->courseid]; $this->curdate = $SESSION->attcurrentattdate[$this->courseid];
} }
else {
$this->curdate = time();
}
} }
private function init_show_endtime($show_endtime) { private function init_show_endtime() {
global $SESSION; if (isset($this->show_endtime)) {
set_user_preference("attforblock_showendtime", $this->show_endtime);
if (isset($show_endtime)) {
set_user_preference("attforblock_showendtime", $show_endtime);
$this->showendtime = $show_endtime;
} }
else { else {
$this->showendtime = get_user_preferences("attforblock_showendtime", $this->showendtime); $this->showendtime = get_user_preferences("attforblock_showendtime", self::DEFAULT_SHOWENDTIME);
} }
} }

17
manage.php

@ -12,13 +12,13 @@
require_once(dirname(__FILE__).'/../../config.php'); require_once(dirname(__FILE__).'/../../config.php');
require_once(dirname(__FILE__).'/locallib.php'); require_once(dirname(__FILE__).'/locallib.php');
$view_params = new att_manage_page_params(); $pageparams = new att_manage_page_params();
$id = required_param('id', PARAM_INT); $id = required_param('id', PARAM_INT);
$from = optional_param('from', NULL, PARAM_ACTION); $from = optional_param('from', NULL, PARAM_ACTION);
$view_params ->view = optional_param('view', NULL, PARAM_INT); // which page to show $pageparams ->view = optional_param('view', NULL, PARAM_INT);
$view_params ->curdate = optional_param('curdate', NULL, PARAM_INT); $pageparams ->curdate = optional_param('curdate', NULL, PARAM_INT);
$view_params ->showendtime = optional_param('showendtime', NULL, PARAM_INT); $pageparams ->showendtime = optional_param('showendtime', NULL, PARAM_INT);
$cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST); $cm = get_coursemodule_from_id('attforblock', $id, 0, false, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
@ -26,12 +26,11 @@ $att = $DB->get_record('attforblock', array('id' => $cm->instance), '
require_login($course, true, $cm); require_login($course, true, $cm);
$att = new attforblock($att, $cm, $course, $PAGE->context, att_manage_page_params::create_default()); $pageparams->init($course->id);
$att = new attforblock($att, $cm, $course, $PAGE->context, $pageparams);
if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change()) if (!$att->perm->can_manage() && !$att->perm->can_take() && !$att->perm->can_change())
redirect("view.php?id=$cm->id"); redirect("view.php?id=$cm->id");
$att->pageparams->init($view_params, $course->id);
// if teacher is coming from block, then check for a session exists for today // if teacher is coming from block, then check for a session exists for today
if ($from === 'block') { if ($from === 'block') {
$atts = $att->get_today_sessions(); $atts = $att->get_today_sessions();

Loading…
Cancel
Save