Skip to content

Commit

Permalink
MDL-52258 calendar: show event duration on block
Browse files Browse the repository at this point in the history
Add class .duration_finish to days when an event with duration
finishes. Removes the .muted class from weekend days. Adds
$daytime for the popup title. Tests duyrationbyday too in order
to report no events for a day. Adds endtime suffix to the finish
date of an event with duration.
  • Loading branch information
juancs committed Jan 4, 2016
1 parent 4f2ff25 commit 6349d1e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 27 deletions.
36 changes: 31 additions & 5 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$eventids = array_unique(array_merge($eventids, $durationbyday[$day]));
}

$finishclass = false;

if (!empty($eventids)) {
// There is at least one event on this day.

Expand All @@ -355,7 +357,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php', $hrefparams), 0, 0, 0, $daytime);

$popupcontent = '';
foreach($eventids as $eventid) {
foreach ($eventids as $eventid) {
if (!isset($events[$eventid])) {
continue;
}
Expand All @@ -376,26 +378,47 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$popupicon = 'i/userevent';
}

if ($event->timeduration) {
$startdate = $calendartype->timestamp_to_date_array($event->timestart);
$enddate = $calendartype->timestamp_to_date_array($event->timestart + $event->timeduration - 1);
if ($enddate['mon'] == $m && $enddate['year'] == $y && $enddate['mday'] == $day) {
$finishclass = true;
}
}

$dayhref->set_anchor('event_'.$event->id);

$popupcontent .= html_writer::start_tag('div');
$popupcontent .= $OUTPUT->pix_icon($popupicon, $popupalt, $component);
$name = format_string($event->name, true);
// Show ical source if needed.
if (!empty($event->subscription) && $CFG->calendar_showicalsource) {
$a = new stdClass();
$a->name = $name;
$a->source = $event->subscription->name;
$name = get_string('namewithsource', 'calendar', $a);
} else {
if ($finishclass) {
$samedate = $startdate['mon'] == $enddate['mon'] &&
$startdate['year'] == $enddate['year'] &&
$startdate['mday'] == $enddate['mday'];

if ($samedate) {
$name = format_string($event->name, true);
} else {
$name = format_string($event->name, true) . ' (' . get_string('eventendtime', 'calendar') . ')';
}
} else {
$name = format_string($event->name, true);
}
}
$popupcontent .= html_writer::link($dayhref, $name);
$popupcontent .= html_writer::end_tag('div');
}

if ($display->thismonth && $day == $d) {
$popupdata = calendar_get_popup(true, $events[$eventid]->timestart, $popupcontent);
$popupdata = calendar_get_popup(true, $daytime, $popupcontent);
} else {
$popupdata = calendar_get_popup(false, $events[$eventid]->timestart, $popupcontent);
$popupdata = calendar_get_popup(false, $daytime, $popupcontent);
}
$cellattributes = array_merge($cellattributes, $popupdata);

Expand All @@ -409,6 +432,9 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
} else if(isset($typesbyday[$day]['startuser'])) {
$class .= ' calendar_event_user';
}
if ($finishclass) {
$class .= ' duration_finish';
}
$cell = html_writer::link($dayhref, $day);
} else {
$cell = $day;
Expand Down Expand Up @@ -448,7 +474,7 @@ function calendar_get_mini($courses, $groups, $users, $calmonth = false, $calyea
$class .= ' today';
$today = get_string('today', 'calendar').' '.userdate(time(), get_string('strftimedayshort'));

if (!isset($eventsbyday[$day])) {
if (!isset($eventsbyday[$day]) && !isset($durationbyday[$day])) {
$class .= ' eventnone';
$popupdata = calendar_get_popup(true, false);
$cellattributes = array_merge($cellattributes, $popupdata);
Expand Down
48 changes: 28 additions & 20 deletions theme/bootstrapbase/less/moodle/calendar.less
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@
background-color: @calendarEventUserColor;
}

.duration_global {
background-color: @calendarEventGlobalColor;
}

.duration_course {
background-color: @calendarEventCourseColor;
}

.duration_group {
background-color: @calendarEventGroupColor;
}

.duration_user {
background-color: @calendarEventUserColor;
}

// Calendar restyling.
.path-calendar {
.calendartable {
Expand Down Expand Up @@ -330,16 +314,40 @@
td {
&.weekend {
.muted;

a {
.muted;
}
}
a {
width: 100%;
height: 100%;
display: block;
}
&.duration_global {
border-top: 1px solid @calendarEventGlobalColor;
border-bottom: 1px solid @calendarEventGlobalColor;
&.duration_finish {
background-color: @calendarEventGlobalColor;
}
}
&.duration_course {
border-top: 1px solid @calendarEventCourseColor;
border-bottom: 1px solid @calendarEventCourseColor;
&.duration_finish {
background-color: @calendarEventCourseColor;
}
}
&.duration_group {
border-top: 1px solid @calendarEventGroupColor;
border-bottom: 1px solid @calendarEventGroupColor;
&.duration_finish {
background-color: @calendarEventGroupColor;
}
}
&.duration_user {
border-top: 1px solid @calendarEventUserColor;
border-bottom: 1px solid @calendarEventUserColor;
&.duration_finish {
background-color: @calendarEventUserColor;
}
}
}
caption {
font-size: inherit;
Expand Down
4 changes: 2 additions & 2 deletions theme/bootstrapbase/style/moodle.css

Large diffs are not rendered by default.

0 comments on commit 6349d1e

Please sign in to comment.