Skip to content

Commit

Permalink
1.fix the bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
powermail committed Oct 21, 2021
1 parent e1dea4c commit 4b86923
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 38 deletions.
8 changes: 4 additions & 4 deletions ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
global $DB;
$PAGE->set_context(context_system::instance());
$lookahead = 1;
$courseid = optional_param('courseid',1, PARAM_INT);
$limitnum = optional_param('limitnum',5,PARAM_INT);
$page= optional_param('block_timetable_page',1, PARAM_INT);
$courseid = optional_param('courseid', 1, PARAM_INT);
$limitnum = optional_param('limitnum', 5, PARAM_INT);
$page = optional_param('block_timetable_page', 1, PARAM_INT);
$time = optional_param('time', strtotime('today midnight'), PARAM_INT);
$instance_id=required_param('instance_id', PARAM_INT);
$instanceid = required_param('instanceid', PARAM_INT);
$list = '';
$end = false;
$renderer = $PAGE->get_renderer('block_timetable');
Expand Down
22 changes: 13 additions & 9 deletions block_timetable.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function get_content() {
if (empty($this->config->view)) {
$this->config->view = 'today';
}
$instance_id = optional_param('instance_id', 0, PARAM_INT);
if($instance_id == $this->instance->id) {
$instanceid = optional_param('instanceid', 0, PARAM_INT);
if ($instanceid == $this->instance->id) {
$ulayout = optional_param('ulayout', @$this->config->timetable, PARAM_RAW);
$page = optional_param('block_timetable_page', 1, PARAM_RAW);
$time = optional_param('time', strtotime('today midnight'), PARAM_INT);
Expand All @@ -100,7 +100,6 @@ public function get_content() {
$page = 1;
$time = strtotime('today midnight');
}

if ($ulayout == "nextxday") {
$maxevents = get_user_preferences('calendar_maxevents', 10);
$lookahead = get_user_preferences('calendar_lookahead', 6);
Expand All @@ -110,7 +109,6 @@ public function get_content() {
if ($ulayout == "thisweek") {
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$calendarweek = $calendartype->get_weekdays();
$startwday = get_user_preferences('calendar_startwday', 1);
}
if (empty(@$this->config->limit)) {
$this->config->limit = 5;
Expand All @@ -136,7 +134,8 @@ public function get_content() {
$page,
$blockview,
$time,
$this->instance->id
$this->instance->id,
$ulayout
);
$checkboxtoday = @$this->config->checkboxtoday;
$checkboxthisweek = @$this->config->checkboxthisweek;
Expand Down Expand Up @@ -167,18 +166,21 @@ public function get_content() {
$this->content->text .= '</button><div id="menusortby" role="menu" class="dropdown-menu dropdown-menu-right';
$this->content->text .= 'list-group hidden" data-show-active-item="" data-skip-active-class="true">';
if ( $checkboxtoday ) {
$url = new moodle_url($this->page->url , ['ulayout' => 'today' ,'instance_id'=>$this->context->instanceid]);
$varparams = ['ulayout' => 'today' , 'instanceid' => $this->context->instanceid];
$url = new moodle_url($this->page->url , $varparams);
$this->content->text .= ' <a class="dropdown-item" href="'. $url.'" >';
$this->content->text .= get_string('today', 'block_timetable').'</a>';
}
if ( $checkboxthisweek ) {
$url = new moodle_url($this->page->url, ['ulayout' => 'thisweek','instance_id'=>$this->context->instanceid]);
$varparams = ['ulayout' => 'thisweek' , 'instanceid' => $this->context->instanceid];
$url = new moodle_url($this->page->url, $varparams);
$this->content->text .= ' <a class="dropdown-item" href="'. $url.'" >
'.get_string('thisweek', 'block_timetable').'
</a>';
}
if ( $checkboxnextxday ) {
$url = new moodle_url($this->page->url, ['ulayout' => 'nextxday','instance_id'=>$this->context->instanceid]);
$varparams = ['ulayout' => 'nextxday' , 'instanceid' => $this->context->instanceid];
$url = new moodle_url($this->page->url, $varparams);
$this->content->text .= ' <a class="dropdown-item" href="'. $url.'" >
'.get_string('nextxday', 'block_timetable').'
</a>';
Expand All @@ -188,6 +190,7 @@ public function get_content() {
}
if ($ulayout == "thisweek") {
$this->content->text .= "<div class='timetable_calendar'>";
$startwday = (int)get_user_preferences('calendar_startwday', 1);
$l = $startwday - 1;
$weeknumber = date( 'N' + $startwday - 1);
$todayweek = date( 'N');
Expand All @@ -212,7 +215,8 @@ public function get_content() {
$class = " active";
}
$caltime = strtotime( $cal['fullname'].' '.$midnight.' week midnight');
$url = new moodle_url($this->page->url, ['time' => $caltime , 'instance_id'=>$this->context->instanceid ]);
$varparams = ['time' => $caltime , 'instanceid' => $this->context->instanceid , 'ulayout' => $ulayout ];
$url = new moodle_url($this->page->url, $varparams);
$this->content->text .= "<div class='timetable_day".$class."'><a href='".$url."'>".$cal['shortname'];
$this->content->text .= "</a></div>";
}
Expand Down
32 changes: 19 additions & 13 deletions classes/output/eventlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ class eventlist implements templatable, renderable {
/**
* @var int The instance id page.
*/
public $instance_id;
public $instanceid;
/**
* @var var The ulayout page.
*/
public $ulayout;
/**
* Constructor.
*
Expand All @@ -95,7 +99,8 @@ class eventlist implements templatable, renderable {
* @param int $page
* @param int $blockview
* @param int $time
* @param int $instance_id
* @param int $instanceid
* @param string $ulayout layout of current event
*/
public function __construct(
$lookahead,
Expand All @@ -107,7 +112,8 @@ public function __construct(
$page,
$blockview,
$time,
$instance_id) {
$instanceid,
$ulayout) {
$this->lookahead = $lookahead;
$this->courseid = $courseid;
$this->lastid = $lastid;
Expand All @@ -117,7 +123,8 @@ public function __construct(
$this->page = $page;
$this->blockview = $blockview;
$this->time = $time;
$this->instance_id = $instance_id;
$this->instanceid = $instanceid;
$this->ulayout = $ulayout;
}

/**
Expand All @@ -128,8 +135,9 @@ public function __construct(
*/
public function export_for_template(renderer_base $output) {
$this->output = $output;
$this->output->instance_id = $this->instance_id;
$this->output->instanceid = $this->instanceid;
$this->output->time = $this->time;
$this->output->ulayout = $this->ulayout;
list($more, $events) = $this->get_timetabevents(
$this->lookahead,
$this->courseid,
Expand Down Expand Up @@ -163,7 +171,8 @@ public function export_for_template(renderer_base $output) {
'pagination' => $pagination,
'more' => $more,
'blockview' => $this->blockview,
'instance_id' => $this->instance_id
'instanceid' => $this->instanceid,
'ulayout' => $this->ulayout
];
}

Expand Down Expand Up @@ -224,17 +233,14 @@ public function get_view(\calendar_information $calendar, $lookahead, $lastdate
);
// Remove site events from block if this is course.
if ($calendar->course->id != SITEID) {
$groups = groups_get_user_groups($calendar->course->id, $USER->id);
$groups = groups_get_all_groups($calendar->course->id);
$courseparam = [];
$courseparam[1] = $calendar->course->id;
$userparam = [];
$groupparam = [];
$m = 1;
foreach ($groups as $cgroup) {
foreach ($cgroup as $group) {
$groupparam[$m] = $group;
$m = 0;
foreach ($groups as $group) {
$groupparam[$m] = $group->id;
$m++;
}
}
$categoryparam = array();
}
Expand Down
16 changes: 10 additions & 6 deletions classes/output/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ class main implements templatable, renderable {
* @var int The current page if JS is disabled.
*/
public $time;
/**
/**
* @var int The instance id page.
*/
public $instance_id;
public $instanceid;
/**
* Constructor.
*
Expand All @@ -88,7 +88,8 @@ class main implements templatable, renderable {
* @param int $page
* @param int $blockview
* @param int $time
* @param int $instance_id
* @param int $instanceid
* @param string $ulayout layout of current event
*/
public function __construct(
$lookahead,
Expand All @@ -100,7 +101,8 @@ public function __construct(
$page,
$blockview,
$time,
$instance_id) {
$instanceid,
$ulayout) {
$this->lookahead = $lookahead;
$this->courseid = $courseid;
$this->lastid = $lastid;
Expand All @@ -110,7 +112,8 @@ public function __construct(
$this->page = $page;
$this->blockview = $blockview;
$this->time = $time;
$this->instance_id = $instance_id;
$this->instanceid = $instanceid;
$this->ulayout = $ulayout;
}

/**
Expand All @@ -132,7 +135,8 @@ public function export_for_template(renderer_base $output) {
$this->page,
$this->blockview,
$this->time ,
$this->instance_id
$this->instanceid,
$this->ulayout
);
$templatecontext = $events->export_for_template($output);
return $templatecontext;
Expand Down
13 changes: 9 additions & 4 deletions classes/output/pagination.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct($prev, $next) {
* @return stdClass
*/
public function export_for_template(renderer_base $output) {
$pagination = $this->get_pagination($this->prev, $this->next, $output->instance_id, $output->time);
$pagination = $this->get_pagination($this->prev, $this->next, $output->instanceid, $output->time, $output->ulayout);
return $pagination;
}

Expand All @@ -71,16 +71,20 @@ public function export_for_template(renderer_base $output) {
*
* @param bool $prev whether or not there are previous pages
* @param bool $next whether or not there are following pages
* @param int $instanceid id of current instance
* @param int $time time of current event range start
* @param string $ulayout layout of current event
* @return stdClass
*/
public function get_pagination($prev = false, $next = false, $instance_id, $time) {
public function get_pagination($prev = false, $next = false, $instanceid, $time , $ulayout) {
global $PAGE;

$pagination = new stdClass();

if ($prev) {
$pagination->prev = new stdClass();
$pagination->prev->prevurl = new moodle_url($PAGE->url, ['block_timetable_page' => $prev ,'instance_id' => $instance_id ,'time' => $time]);
$varparams = ['block_timetable_page' => $prev , 'instanceid' => $instanceid , 'time' => $time , 'ulayout' => $ulayout];
$pagination->prev->prevurl = new moodle_url($PAGE->url, $varparams);
$pagination->prev->prevtext = get_string('previous', 'block_timetable');
}
if ($prev && $next) {
Expand All @@ -90,7 +94,8 @@ public function get_pagination($prev = false, $next = false, $instance_id, $time
}
if ($next) {
$pagination->next = new stdClass();
$pagination->next->nexturl = new moodle_url($PAGE->url, ['block_timetable_page' => $next ,'instance_id' => $instance_id ,'time' => $time]);
$varparams = ['block_timetable_page' => $next , 'instanceid' => $instanceid , 'time' => $time , 'ulayout' => $ulayout];
$pagination->next->nexturl = new moodle_url($PAGE->url, $varparams );
$pagination->next->nexttext = get_string('next', 'block_timetable');
}

Expand Down
4 changes: 2 additions & 2 deletions templates/main.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
}
}}

<div id="timetable-events{{instance_id}}" class="timetable {{blockview}}" data-template="block_timetable/event" >
<div id="timetable-events{{instanceid}}" class="timetable {{blockview}}" data-template="block_timetable/event" >
{{> block_timetable/events}}
</div>

{{#js}}
require(['jquery', 'core_calendar/calendar_view'], function($, CalendarView) {
CalendarView.init($("#inst{{instance_id}} .timetable"), 'upcoming');
CalendarView.init($("#inst{{instanceid}} .timetable"), 'upcoming');
});
{{/js}}

0 comments on commit 4b86923

Please sign in to comment.